mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
Add a presubmit check for absl/memory/memory.h inclusion
This adds a presubmit check that warns missing memory.h inclusion when a source file use absl::make_unique. That header tends to be included transitively on pre-C++17 mode, but doesn't on C++17 mode. Bug: chromium:752720 Change-Id: I235287f4f7407d48bfad35da86da47bc602f03ce Reviewed-on: https://webrtc-review.googlesource.com/c/111040 Commit-Queue: Taiju Tsuiki <tzik@chromium.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/master@{#25655}
This commit is contained in:
parent
9514071500
commit
a06bf8506f
1 changed files with 26 additions and 0 deletions
26
PRESUBMIT.py
26
PRESUBMIT.py
|
@ -864,6 +864,8 @@ def CommonChecks(input_api, output_api):
|
||||||
input_api, output_api, non_third_party_sources))
|
input_api, output_api, non_third_party_sources))
|
||||||
results.extend(CheckAddedDepsHaveTargetApprovals(input_api, output_api))
|
results.extend(CheckAddedDepsHaveTargetApprovals(input_api, output_api))
|
||||||
results.extend(CheckApiDepsFileIsUpToDate(input_api, output_api))
|
results.extend(CheckApiDepsFileIsUpToDate(input_api, output_api))
|
||||||
|
results.extend(CheckAbslMemoryInclude(
|
||||||
|
input_api, output_api, non_third_party_sources))
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
@ -920,6 +922,30 @@ def CheckApiDepsFileIsUpToDate(input_api, output_api):
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
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)
|
||||||
|
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):
|
||||||
|
contents = input_api.ReadFile(f)
|
||||||
|
if pattern.search(contents):
|
||||||
|
continue
|
||||||
|
for _, line in f.ChangedContents():
|
||||||
|
if 'absl::make_unique' in line:
|
||||||
|
files.append(f)
|
||||||
|
break
|
||||||
|
|
||||||
|
if len(files):
|
||||||
|
return [output_api.PresubmitError(
|
||||||
|
'Please include "absl/memory/memory.h" header for'
|
||||||
|
' absl::make_unique.\nThis header may or may not be included'
|
||||||
|
' transitively depends on the C++ standard version.',
|
||||||
|
files)]
|
||||||
|
return []
|
||||||
|
|
||||||
def CheckChangeOnUpload(input_api, output_api):
|
def CheckChangeOnUpload(input_api, output_api):
|
||||||
results = []
|
results = []
|
||||||
|
|
Loading…
Reference in a new issue