OLD | NEW |
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 2132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2143 return [] | 2143 return [] |
2144 | 2144 |
2145 return [output_api.PresubmitPromptWarning(""" | 2145 return [output_api.PresubmitPromptWarning(""" |
2146 Use of => operator detected in: | 2146 Use of => operator detected in: |
2147 %s | 2147 %s |
2148 Please ensure your code does not run on iOS9 (=> (arrow) does not work there). | 2148 Please ensure your code does not run on iOS9 (=> (arrow) does not work there). |
2149 https://chromium.googlesource.com/chromium/src/+/master/docs/es6_chromium.md#Arr
ow-Functions | 2149 https://chromium.googlesource.com/chromium/src/+/master/docs/es6_chromium.md#Arr
ow-Functions |
2150 """ % "\n".join(" %s:%d\n" % line for line in arrow_lines))] | 2150 """ % "\n".join(" %s:%d\n" % line for line in arrow_lines))] |
2151 | 2151 |
2152 | 2152 |
| 2153 def _CheckForRelativeIncludes(input_api, output_api): |
| 2154 # Need to set the sys.path so PRESUBMIT_test.py runs properly |
| 2155 import sys |
| 2156 original_sys_path = sys.path |
| 2157 try: |
| 2158 sys.path = sys.path + [input_api.os_path.join( |
| 2159 input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')] |
| 2160 from cpp_checker import CppChecker |
| 2161 finally: |
| 2162 # Restore sys.path to what it was before. |
| 2163 sys.path = original_sys_path |
| 2164 |
| 2165 bad_files = {} |
| 2166 for f in input_api.AffectedFiles(include_deletes=False): |
| 2167 if (f.LocalPath().startswith('third_party') and |
| 2168 not f.LocalPath().startswith('third_party/WebKit') and |
| 2169 not f.LocalPath().startswith('third_party\\WebKit')): |
| 2170 continue |
| 2171 |
| 2172 if not CppChecker.IsCppFile(f.LocalPath()): |
| 2173 continue |
| 2174 |
| 2175 relative_includes = [line for line_num, line in f.ChangedContents() |
| 2176 if "#include" in line and "../" in line] |
| 2177 if not relative_includes: |
| 2178 continue |
| 2179 bad_files[f.LocalPath()] = relative_includes |
| 2180 |
| 2181 if not bad_files: |
| 2182 return [] |
| 2183 |
| 2184 error_descriptions = [] |
| 2185 for file_path, bad_lines in bad_files.iteritems(): |
| 2186 error_description = file_path |
| 2187 for line in bad_lines: |
| 2188 error_description += '\n ' + line |
| 2189 error_descriptions.append(error_description) |
| 2190 |
| 2191 results = [] |
| 2192 results.append(output_api.PresubmitError( |
| 2193 'You added one or more relative #include paths (including "../").\n' |
| 2194 'These shouldn\'t be used because they can be used to include headers\n' |
| 2195 'from code that\'s not correctly specified as a dependency in the\n' |
| 2196 'relevant BUILD.gn file(s).', |
| 2197 error_descriptions)) |
| 2198 |
| 2199 return results |
| 2200 |
2153 def _AndroidSpecificOnUploadChecks(input_api, output_api): | 2201 def _AndroidSpecificOnUploadChecks(input_api, output_api): |
2154 """Groups checks that target android code.""" | 2202 """Groups checks that target android code.""" |
2155 results = [] | 2203 results = [] |
2156 results.extend(_CheckAndroidCrLogUsage(input_api, output_api)) | 2204 results.extend(_CheckAndroidCrLogUsage(input_api, output_api)) |
2157 results.extend(_CheckAndroidNewMdpiAssetLocation(input_api, output_api)) | 2205 results.extend(_CheckAndroidNewMdpiAssetLocation(input_api, output_api)) |
2158 results.extend(_CheckAndroidToastUsage(input_api, output_api)) | 2206 results.extend(_CheckAndroidToastUsage(input_api, output_api)) |
2159 results.extend(_CheckAndroidTestAnnotationUsage(input_api, output_api)) | 2207 results.extend(_CheckAndroidTestAnnotationUsage(input_api, output_api)) |
2160 return results | 2208 return results |
2161 | 2209 |
2162 | 2210 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2204 results.extend(_CheckNoDeprecatedJs(input_api, output_api)) | 2252 results.extend(_CheckNoDeprecatedJs(input_api, output_api)) |
2205 results.extend(_CheckParseErrors(input_api, output_api)) | 2253 results.extend(_CheckParseErrors(input_api, output_api)) |
2206 results.extend(_CheckForIPCRules(input_api, output_api)) | 2254 results.extend(_CheckForIPCRules(input_api, output_api)) |
2207 results.extend(_CheckForWindowsLineEndings(input_api, output_api)) | 2255 results.extend(_CheckForWindowsLineEndings(input_api, output_api)) |
2208 results.extend(_CheckSingletonInHeaders(input_api, output_api)) | 2256 results.extend(_CheckSingletonInHeaders(input_api, output_api)) |
2209 results.extend(_CheckPydepsNeedsUpdating(input_api, output_api)) | 2257 results.extend(_CheckPydepsNeedsUpdating(input_api, output_api)) |
2210 results.extend(_CheckJavaStyle(input_api, output_api)) | 2258 results.extend(_CheckJavaStyle(input_api, output_api)) |
2211 results.extend(_CheckIpcOwners(input_api, output_api)) | 2259 results.extend(_CheckIpcOwners(input_api, output_api)) |
2212 results.extend(_CheckUselessForwardDeclarations(input_api, output_api)) | 2260 results.extend(_CheckUselessForwardDeclarations(input_api, output_api)) |
2213 results.extend(_CheckForRiskyJsFeatures(input_api, output_api)) | 2261 results.extend(_CheckForRiskyJsFeatures(input_api, output_api)) |
| 2262 results.extend(_CheckForRelativeIncludes(input_api, output_api)) |
2214 | 2263 |
2215 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): | 2264 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): |
2216 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( | 2265 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |
2217 input_api, output_api, | 2266 input_api, output_api, |
2218 input_api.PresubmitLocalPath(), | 2267 input_api.PresubmitLocalPath(), |
2219 whitelist=[r'^PRESUBMIT_test\.py$'])) | 2268 whitelist=[r'^PRESUBMIT_test\.py$'])) |
2220 return results | 2269 return results |
2221 | 2270 |
2222 | 2271 |
2223 def _CheckPatchFiles(input_api, output_api): | 2272 def _CheckPatchFiles(input_api, output_api): |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2464 output_api, | 2513 output_api, |
2465 json_url='http://chromium-status.appspot.com/current?format=json')) | 2514 json_url='http://chromium-status.appspot.com/current?format=json')) |
2466 | 2515 |
2467 results.extend( | 2516 results.extend( |
2468 input_api.canned_checks.CheckPatchFormatted(input_api, output_api)) | 2517 input_api.canned_checks.CheckPatchFormatted(input_api, output_api)) |
2469 results.extend(input_api.canned_checks.CheckChangeHasBugField( | 2518 results.extend(input_api.canned_checks.CheckChangeHasBugField( |
2470 input_api, output_api)) | 2519 input_api, output_api)) |
2471 results.extend(input_api.canned_checks.CheckChangeHasDescription( | 2520 results.extend(input_api.canned_checks.CheckChangeHasDescription( |
2472 input_api, output_api)) | 2521 input_api, output_api)) |
2473 return results | 2522 return results |
OLD | NEW |