| Index: PRESUBMIT.py
|
| diff --git a/PRESUBMIT.py b/PRESUBMIT.py
|
| index 4ba36c1e391eb6f7a314e8df636bce7aa1c2cad4..8af2e6749d11732536c0351139fa3a258f7bc1b7 100644
|
| --- a/PRESUBMIT.py
|
| +++ b/PRESUBMIT.py
|
| @@ -2158,6 +2158,43 @@ 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]
|
| + 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 +2256,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(
|
|
|