absl::make_unique presubmit check.
Starting from [1], WebRTC has been migrated to std::make_unique, in order to keep the codebase consistent, absl::make_unique is now banned. Output example: ** Presubmit ERRORS ** Please use std::make_unique instead of absl::make_unique. Affected files: call/rtp_demuxer.cc [1] - https://webrtc-review.googlesource.com/c/src/+/153221 Bug: webrtc:10945 Change-Id: I5b727ecc5ea8ac2ecd89cbd5fba866baf6de9012 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/153355 Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29210}
This commit is contained in:

committed by
Commit Bot

parent
317a1f09ed
commit
9fa8ef1f4f
30
PRESUBMIT.py
30
PRESUBMIT.py
@ -891,6 +891,8 @@ def CommonChecks(input_api, output_api):
|
||||
results.extend(CheckApiDepsFileIsUpToDate(input_api, output_api))
|
||||
results.extend(CheckAbslMemoryInclude(
|
||||
input_api, output_api, non_third_party_sources))
|
||||
results.extend(CheckBannedAbslMakeUnique(
|
||||
input_api, output_api, non_third_party_sources))
|
||||
return results
|
||||
|
||||
|
||||
@ -948,6 +950,25 @@ def CheckApiDepsFileIsUpToDate(input_api, output_api):
|
||||
|
||||
return results
|
||||
|
||||
def CheckBannedAbslMakeUnique(input_api, output_api, source_file_filter):
|
||||
file_filter = lambda f: (f.LocalPath().endswith(('.cc', '.h'))
|
||||
and source_file_filter(f))
|
||||
|
||||
files = []
|
||||
for f in input_api.AffectedFiles(
|
||||
include_deletes=False, file_filter=file_filter):
|
||||
for _, line in f.ChangedContents():
|
||||
if 'absl::make_unique' in line:
|
||||
files.append(f)
|
||||
break
|
||||
|
||||
if len(files):
|
||||
return [output_api.PresubmitError(
|
||||
'Please use std::make_unique instead of absl::make_unique.\n'
|
||||
'Affected files:',
|
||||
files)]
|
||||
return []
|
||||
|
||||
def CheckAbslMemoryInclude(input_api, output_api, source_file_filter):
|
||||
pattern = input_api.re.compile(
|
||||
r'^#include\s*"absl/memory/memory.h"', input_api.re.MULTILINE)
|
||||
@ -961,16 +982,15 @@ def CheckAbslMemoryInclude(input_api, output_api, source_file_filter):
|
||||
if pattern.search(contents):
|
||||
continue
|
||||
for _, line in f.ChangedContents():
|
||||
if 'absl::make_unique' in line or 'absl::WrapUnique' in line:
|
||||
if 'absl::WrapUnique' in line:
|
||||
files.append(f)
|
||||
break
|
||||
|
||||
if len(files):
|
||||
return [output_api.PresubmitError(
|
||||
'Please include "absl/memory/memory.h" header for'
|
||||
' absl::make_unique or absl::WrapUnique.\nThis header may or'
|
||||
' may not be included transitively depending on the C++ standard'
|
||||
' version.',
|
||||
'Please include "absl/memory/memory.h" header for absl::WrapUnique.\n'
|
||||
'This header may or may not be included transitively depending on the '
|
||||
'C++ standard version.',
|
||||
files)]
|
||||
return []
|
||||
|
||||
|
Reference in New Issue
Block a user