| 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 1282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1293 import checkstyle | 1293 import checkstyle |
| 1294 finally: | 1294 finally: |
| 1295 # Restore sys.path to what it was before. | 1295 # Restore sys.path to what it was before. |
| 1296 sys.path = original_sys_path | 1296 sys.path = original_sys_path |
| 1297 | 1297 |
| 1298 return checkstyle.RunCheckstyle( | 1298 return checkstyle.RunCheckstyle( |
| 1299 input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml', | 1299 input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml', |
| 1300 black_list=_EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST) | 1300 black_list=_EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST) |
| 1301 | 1301 |
| 1302 | 1302 |
| 1303 def _CheckNoNewUtilLogUsage(input_api, output_api): |
| 1304 """Checks that new logs are using org.chromium.base.Log.""" |
| 1305 |
| 1306 chromium_log_import_pattern = input_api.re.compile( |
| 1307 r'^import org\.chromium\.base\.Log;$', input_api.re.MULTILINE); |
| 1308 log_pattern = input_api.re.compile(r'^\s*(android\.util\.)?Log\.\w') |
| 1309 sources = lambda x: input_api.FilterSourceFile(x, white_list=(r'.*\.java$',)) |
| 1310 |
| 1311 errors = [] |
| 1312 |
| 1313 for f in input_api.AffectedSourceFiles(sources): |
| 1314 if chromium_log_import_pattern.search(input_api.ReadFile(f)) is not None: |
| 1315 # Uses org.chromium.base.Log already |
| 1316 continue |
| 1317 |
| 1318 for line_num, line in f.ChangedContents(): |
| 1319 if log_pattern.search(line): |
| 1320 errors.append("%s:%d" % (f.LocalPath(), line_num)) |
| 1321 |
| 1322 results = [] |
| 1323 if len(errors): |
| 1324 results.append(output_api.PresubmitPromptWarning( |
| 1325 'Please use org.chromium.base.Log for new logs.\n' + |
| 1326 'See base/android/java/src/org/chromium/base/README_logging.md ' + |
| 1327 'or contact dgn@chromium.org for more info.', |
| 1328 errors)) |
| 1329 return results |
| 1330 |
| 1331 |
| 1303 def _CheckForCopyrightedCode(input_api, output_api): | 1332 def _CheckForCopyrightedCode(input_api, output_api): |
| 1304 """Verifies that newly added code doesn't contain copyrighted material | 1333 """Verifies that newly added code doesn't contain copyrighted material |
| 1305 and is properly licensed under the standard Chromium license. | 1334 and is properly licensed under the standard Chromium license. |
| 1306 | 1335 |
| 1307 As there can be false positives, we maintain a whitelist file. This check | 1336 As there can be false positives, we maintain a whitelist file. This check |
| 1308 also verifies that the whitelist file is up to date. | 1337 also verifies that the whitelist file is up to date. |
| 1309 """ | 1338 """ |
| 1310 import sys | 1339 import sys |
| 1311 original_sys_path = sys.path | 1340 original_sys_path = sys.path |
| 1312 try: | 1341 try: |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1461 results.extend(_CheckForAnonymousVariables(input_api, output_api)) | 1490 results.extend(_CheckForAnonymousVariables(input_api, output_api)) |
| 1462 results.extend(_CheckCygwinShell(input_api, output_api)) | 1491 results.extend(_CheckCygwinShell(input_api, output_api)) |
| 1463 results.extend(_CheckUserActionUpdate(input_api, output_api)) | 1492 results.extend(_CheckUserActionUpdate(input_api, output_api)) |
| 1464 results.extend(_CheckNoDeprecatedCSS(input_api, output_api)) | 1493 results.extend(_CheckNoDeprecatedCSS(input_api, output_api)) |
| 1465 results.extend(_CheckNoDeprecatedJS(input_api, output_api)) | 1494 results.extend(_CheckNoDeprecatedJS(input_api, output_api)) |
| 1466 results.extend(_CheckParseErrors(input_api, output_api)) | 1495 results.extend(_CheckParseErrors(input_api, output_api)) |
| 1467 results.extend(_CheckForIPCRules(input_api, output_api)) | 1496 results.extend(_CheckForIPCRules(input_api, output_api)) |
| 1468 results.extend(_CheckForCopyrightedCode(input_api, output_api)) | 1497 results.extend(_CheckForCopyrightedCode(input_api, output_api)) |
| 1469 results.extend(_CheckForWindowsLineEndings(input_api, output_api)) | 1498 results.extend(_CheckForWindowsLineEndings(input_api, output_api)) |
| 1470 results.extend(_CheckSingletonInHeaders(input_api, output_api)) | 1499 results.extend(_CheckSingletonInHeaders(input_api, output_api)) |
| 1500 results.extend(_CheckNoNewUtilLogUsage(input_api, output_api)) |
| 1471 | 1501 |
| 1472 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): | 1502 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): |
| 1473 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( | 1503 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |
| 1474 input_api, output_api, | 1504 input_api, output_api, |
| 1475 input_api.PresubmitLocalPath(), | 1505 input_api.PresubmitLocalPath(), |
| 1476 whitelist=[r'^PRESUBMIT_test\.py$'])) | 1506 whitelist=[r'^PRESUBMIT_test\.py$'])) |
| 1477 return results | 1507 return results |
| 1478 | 1508 |
| 1479 | 1509 |
| 1480 def _CheckAuthorizedAuthor(input_api, output_api): | 1510 def _CheckAuthorizedAuthor(input_api, output_api): |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1773 # Explicitly iterate over copies of dicts since we mutate them. | 1803 # Explicitly iterate over copies of dicts since we mutate them. |
| 1774 for master in builders.keys(): | 1804 for master in builders.keys(): |
| 1775 for builder in builders[master].keys(): | 1805 for builder in builders[master].keys(): |
| 1776 # Do not trigger presubmit builders, since they're likely to fail | 1806 # Do not trigger presubmit builders, since they're likely to fail |
| 1777 # (e.g. OWNERS checks before finished code review), and we're | 1807 # (e.g. OWNERS checks before finished code review), and we're |
| 1778 # running local presubmit anyway. | 1808 # running local presubmit anyway. |
| 1779 if 'presubmit' in builder: | 1809 if 'presubmit' in builder: |
| 1780 builders[master].pop(builder) | 1810 builders[master].pop(builder) |
| 1781 | 1811 |
| 1782 return builders | 1812 return builders |
| OLD | NEW |