Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: PRESUBMIT.py

Issue 2900253003: [Reland] Add presubmit rule banning relative header includes (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Top-level presubmit script for Chromium. 5 """Top-level presubmit script for Chromium.
6 6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into depot_tools. 8 for more details about the presubmit API built into depot_tools.
9 """ 9 """
10 10
(...skipping 2140 matching lines...) Expand 10 before | Expand all | Expand 10 after
2151 return [] 2151 return []
2152 2152
2153 return [output_api.PresubmitPromptWarning(""" 2153 return [output_api.PresubmitPromptWarning("""
2154 Use of => operator detected in: 2154 Use of => operator detected in:
2155 %s 2155 %s
2156 Please ensure your code does not run on iOS9 (=> (arrow) does not work there). 2156 Please ensure your code does not run on iOS9 (=> (arrow) does not work there).
2157 https://chromium.googlesource.com/chromium/src/+/master/docs/es6_chromium.md#Arr ow-Functions 2157 https://chromium.googlesource.com/chromium/src/+/master/docs/es6_chromium.md#Arr ow-Functions
2158 """ % "\n".join(" %s:%d\n" % line for line in arrow_lines))] 2158 """ % "\n".join(" %s:%d\n" % line for line in arrow_lines))]
2159 2159
2160 2160
2161 def _CheckForRelativeIncludes(input_api, output_api):
2162 from cpp_checker import CppChecker
2163
2164 bad_files = {}
2165 for f in input_api.AffectedFiles(include_deletes=False):
2166 if (f.LocalPath().startswith('third_party') and
2167 not f.LocalPath().startswith('third_party/WebKit') and
2168 not f.LocalPath().startswith('third_party\\WebKit')):
2169 continue
2170
2171 if not CppChecker.IsCppFile(f.LocalPath()):
2172 continue
2173
2174 relative_includes = [line for line_num, line in f.ChangedContents()
2175 if "#include" in line and "../" in line]
2176 if not relative_includes:
rlanday 2017/05/24 21:10:37 This is the fix here: skip files without relative_
2177 continue
2178 bad_files[f.LocalPath()] = relative_includes
2179
2180 if not bad_files:
2181 return []
2182
2183 error_descriptions = []
2184 for file_path, bad_lines in bad_files.iteritems():
2185 error_description = file_path
2186 for line in bad_lines:
2187 error_description += '\n ' + line
2188 error_descriptions.append(error_description)
2189
2190 results = []
2191 results.append(output_api.PresubmitError(
2192 'You added one or more relative #include paths (including "../").\n'
2193 'These shouldn\'t be used because they can be used to include headers\n'
2194 'from code that\'s not correctly specified as a dependency in the\n'
2195 'relevant BUILD.gn file(s).',
2196 error_descriptions))
2197
2198 return results
2199
2161 def _AndroidSpecificOnUploadChecks(input_api, output_api): 2200 def _AndroidSpecificOnUploadChecks(input_api, output_api):
2162 """Groups checks that target android code.""" 2201 """Groups checks that target android code."""
2163 results = [] 2202 results = []
2164 results.extend(_CheckAndroidCrLogUsage(input_api, output_api)) 2203 results.extend(_CheckAndroidCrLogUsage(input_api, output_api))
2165 results.extend(_CheckAndroidNewMdpiAssetLocation(input_api, output_api)) 2204 results.extend(_CheckAndroidNewMdpiAssetLocation(input_api, output_api))
2166 results.extend(_CheckAndroidToastUsage(input_api, output_api)) 2205 results.extend(_CheckAndroidToastUsage(input_api, output_api))
2167 results.extend(_CheckAndroidTestAnnotationUsage(input_api, output_api)) 2206 results.extend(_CheckAndroidTestAnnotationUsage(input_api, output_api))
2168 return results 2207 return results
2169 2208
2170 2209
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2212 results.extend(_CheckNoDeprecatedJs(input_api, output_api)) 2251 results.extend(_CheckNoDeprecatedJs(input_api, output_api))
2213 results.extend(_CheckParseErrors(input_api, output_api)) 2252 results.extend(_CheckParseErrors(input_api, output_api))
2214 results.extend(_CheckForIPCRules(input_api, output_api)) 2253 results.extend(_CheckForIPCRules(input_api, output_api))
2215 results.extend(_CheckForWindowsLineEndings(input_api, output_api)) 2254 results.extend(_CheckForWindowsLineEndings(input_api, output_api))
2216 results.extend(_CheckSingletonInHeaders(input_api, output_api)) 2255 results.extend(_CheckSingletonInHeaders(input_api, output_api))
2217 results.extend(_CheckPydepsNeedsUpdating(input_api, output_api)) 2256 results.extend(_CheckPydepsNeedsUpdating(input_api, output_api))
2218 results.extend(_CheckJavaStyle(input_api, output_api)) 2257 results.extend(_CheckJavaStyle(input_api, output_api))
2219 results.extend(_CheckIpcOwners(input_api, output_api)) 2258 results.extend(_CheckIpcOwners(input_api, output_api))
2220 results.extend(_CheckUselessForwardDeclarations(input_api, output_api)) 2259 results.extend(_CheckUselessForwardDeclarations(input_api, output_api))
2221 results.extend(_CheckForRiskyJsFeatures(input_api, output_api)) 2260 results.extend(_CheckForRiskyJsFeatures(input_api, output_api))
2261 results.extend(_CheckForRelativeIncludes(input_api, output_api))
2222 2262
2223 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): 2263 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
2224 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( 2264 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
2225 input_api, output_api, 2265 input_api, output_api,
2226 input_api.PresubmitLocalPath(), 2266 input_api.PresubmitLocalPath(),
2227 whitelist=[r'^PRESUBMIT_test\.py$'])) 2267 whitelist=[r'^PRESUBMIT_test\.py$']))
2228 return results 2268 return results
2229 2269
2230 2270
2231 def _CheckPatchFiles(input_api, output_api): 2271 def _CheckPatchFiles(input_api, output_api):
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
2472 output_api, 2512 output_api,
2473 json_url='http://chromium-status.appspot.com/current?format=json')) 2513 json_url='http://chromium-status.appspot.com/current?format=json'))
2474 2514
2475 results.extend( 2515 results.extend(
2476 input_api.canned_checks.CheckPatchFormatted(input_api, output_api)) 2516 input_api.canned_checks.CheckPatchFormatted(input_api, output_api))
2477 results.extend(input_api.canned_checks.CheckChangeHasBugField( 2517 results.extend(input_api.canned_checks.CheckChangeHasBugField(
2478 input_api, output_api)) 2518 input_api, output_api))
2479 results.extend(input_api.canned_checks.CheckChangeHasDescription( 2519 results.extend(input_api.canned_checks.CheckChangeHasDescription(
2480 input_api, output_api)) 2520 input_api, output_api))
2481 return results 2521 return results
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698