Chromium Code Reviews| Index: PRESUBMIT.py |
| diff --git a/PRESUBMIT.py b/PRESUBMIT.py |
| index de0e49d65750255fb06707223f5908944d124136..b5a3ba8cc0ac8228681a84980b37aa00872213d0 100644 |
| --- a/PRESUBMIT.py |
| +++ b/PRESUBMIT.py |
| @@ -2158,6 +2158,45 @@ https://chromium.googlesource.com/chromium/src/+/master/docs/es6_chromium.md#Arr |
| """ % "\n".join(" %s:%d\n" % line for line in arrow_lines))] |
| +def _CheckForRelativeIncludes(input_api, output_api): |
| + from cpp_checker import CppChecker |
| + |
| + bad_files = {} |
| + for f in input_api.AffectedFiles(include_deletes=False): |
| + if (f.LocalPath().startswith('third_party') and |
| + not f.LocalPath().startswith('third_party/WebKit') and |
| + not f.LocalPath().startswith('third_party\\WebKit')): |
| + continue |
| + |
| + if not CppChecker.IsCppFile(f.LocalPath()): |
| + continue |
| + |
| + relative_includes = [line for line_num, line in f.ChangedContents() |
| + if "#include" in line and "../" in line] |
| + if not relative_includes: |
|
rlanday
2017/05/24 21:10:37
This is the fix here: skip files without relative_
|
| + continue |
| + bad_files[f.LocalPath()] = relative_includes |
| + |
| + if not bad_files: |
| + return [] |
| + |
| + error_descriptions = [] |
| + for file_path, bad_lines in bad_files.iteritems(): |
| + error_description = file_path |
| + for line in bad_lines: |
| + error_description += '\n ' + line |
| + error_descriptions.append(error_description) |
| + |
| + results = [] |
| + results.append(output_api.PresubmitError( |
| + 'You added one or more relative #include paths (including "../").\n' |
| + 'These shouldn\'t be used because they can be used to include headers\n' |
| + 'from code that\'s not correctly specified as a dependency in the\n' |
| + 'relevant BUILD.gn file(s).', |
| + error_descriptions)) |
| + |
| + return results |
| + |
| def _AndroidSpecificOnUploadChecks(input_api, output_api): |
| """Groups checks that target android code.""" |
| results = [] |
| @@ -2219,6 +2258,7 @@ def _CommonChecks(input_api, output_api): |
| results.extend(_CheckIpcOwners(input_api, output_api)) |
| results.extend(_CheckUselessForwardDeclarations(input_api, output_api)) |
| results.extend(_CheckForRiskyJsFeatures(input_api, output_api)) |
| + results.extend(_CheckForRelativeIncludes(input_api, output_api)) |
| if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): |
| results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |