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 gcl. | 8 for more details about the presubmit API built into gcl. |
9 """ | 9 """ |
10 | 10 |
11 | 11 |
12 import re | |
13 import sys | |
14 | |
15 | |
16 _EXCLUDED_PATHS = ( | 12 _EXCLUDED_PATHS = ( |
17 r"^breakpad[\\\/].*", | 13 r"^breakpad[\\\/].*", |
18 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_rules.py", | 14 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_rules.py", |
19 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_simple.py", | 15 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_simple.py", |
20 r"^native_client_sdk[\\\/]src[\\\/]tools[\\\/].*.mk", | 16 r"^native_client_sdk[\\\/]src[\\\/]tools[\\\/].*.mk", |
21 r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*", | 17 r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*", |
22 r"^skia[\\\/].*", | 18 r"^skia[\\\/].*", |
23 r"^v8[\\\/].*", | 19 r"^v8[\\\/].*", |
24 r".*MakeFile$", | 20 r".*MakeFile$", |
25 r".+_autogen\.h$", | 21 r".+_autogen\.h$", |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
510 return [output_api.PresubmitPromptWarning( | 506 return [output_api.PresubmitPromptWarning( |
511 'Please consider avoiding the "? true : false" pattern if possible.\n' + | 507 'Please consider avoiding the "? true : false" pattern if possible.\n' + |
512 '\n'.join(problems))] | 508 '\n'.join(problems))] |
513 | 509 |
514 | 510 |
515 def _CheckUnwantedDependencies(input_api, output_api): | 511 def _CheckUnwantedDependencies(input_api, output_api): |
516 """Runs checkdeps on #include statements added in this | 512 """Runs checkdeps on #include statements added in this |
517 change. Breaking - rules is an error, breaking ! rules is a | 513 change. Breaking - rules is an error, breaking ! rules is a |
518 warning. | 514 warning. |
519 """ | 515 """ |
516 import sys | |
520 # We need to wait until we have an input_api object and use this | 517 # We need to wait until we have an input_api object and use this |
521 # roundabout construct to import checkdeps because this file is | 518 # roundabout construct to import checkdeps because this file is |
522 # eval-ed and thus doesn't have __file__. | 519 # eval-ed and thus doesn't have __file__. |
523 original_sys_path = sys.path | 520 original_sys_path = sys.path |
524 try: | 521 try: |
525 sys.path = sys.path + [input_api.os_path.join( | 522 sys.path = sys.path + [input_api.os_path.join( |
526 input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')] | 523 input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')] |
527 import checkdeps | 524 import checkdeps |
528 from cpp_checker import CppChecker | 525 from cpp_checker import CppChecker |
529 from rules import Rule | 526 from rules import Rule |
(...skipping 30 matching lines...) Expand all Loading... | |
560 results.append(output_api.PresubmitPromptOrNotify( | 557 results.append(output_api.PresubmitPromptOrNotify( |
561 'You added one or more #includes of files that are temporarily\n' | 558 'You added one or more #includes of files that are temporarily\n' |
562 'allowed but being removed. Can you avoid introducing the\n' | 559 'allowed but being removed. Can you avoid introducing the\n' |
563 '#include? See relevant DEPS file(s) for details and contacts.', | 560 '#include? See relevant DEPS file(s) for details and contacts.', |
564 warning_descriptions)) | 561 warning_descriptions)) |
565 return results | 562 return results |
566 | 563 |
567 | 564 |
568 def _CheckFilePermissions(input_api, output_api): | 565 def _CheckFilePermissions(input_api, output_api): |
569 """Check that all files have their permissions properly set.""" | 566 """Check that all files have their permissions properly set.""" |
567 import sys | |
570 if input_api.platform == 'win32': | 568 if input_api.platform == 'win32': |
571 return [] | 569 return [] |
572 args = [sys.executable, 'tools/checkperms/checkperms.py', '--root', | 570 args = [sys.executable, 'tools/checkperms/checkperms.py', '--root', |
M-A Ruel
2014/10/15 13:59:22
Use input_api.python_executable, remove import sys
MRV
2014/10/15 14:14:29
Done.
| |
573 input_api.change.RepositoryRoot()] | 571 input_api.change.RepositoryRoot()] |
574 for f in input_api.AffectedFiles(): | 572 for f in input_api.AffectedFiles(): |
575 args += ['--file', f.LocalPath()] | 573 args += ['--file', f.LocalPath()] |
576 checkperms = input_api.subprocess.Popen(args, | 574 checkperms = input_api.subprocess.Popen(args, |
577 stdout=input_api.subprocess.PIPE) | 575 stdout=input_api.subprocess.PIPE) |
578 errors = checkperms.communicate()[0].strip() | 576 errors = checkperms.communicate()[0].strip() |
579 if errors: | 577 if errors: |
580 return [output_api.PresubmitError('checkperms.py failed.', | 578 return [output_api.PresubmitError('checkperms.py failed.', |
581 errors.splitlines())] | 579 errors.splitlines())] |
582 return [] | 580 return [] |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
962 r"^webkit[\\\/]browser[\\\/]fileapi[\\\/]" + | 960 r"^webkit[\\\/]browser[\\\/]fileapi[\\\/]" + |
963 r"dump_file_system.cc$",)) | 961 r"dump_file_system.cc$",)) |
964 source_file_filter = lambda x: input_api.FilterSourceFile( | 962 source_file_filter = lambda x: input_api.FilterSourceFile( |
965 x, white_list=(file_inclusion_pattern,), black_list=black_list) | 963 x, white_list=(file_inclusion_pattern,), black_list=black_list) |
966 | 964 |
967 log_info = [] | 965 log_info = [] |
968 printf = [] | 966 printf = [] |
969 | 967 |
970 for f in input_api.AffectedSourceFiles(source_file_filter): | 968 for f in input_api.AffectedSourceFiles(source_file_filter): |
971 contents = input_api.ReadFile(f, 'rb') | 969 contents = input_api.ReadFile(f, 'rb') |
972 if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents): | 970 if input_api.re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents): |
973 log_info.append(f.LocalPath()) | 971 log_info.append(f.LocalPath()) |
974 elif re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents): | 972 elif input_api.re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents): |
975 log_info.append(f.LocalPath()) | 973 log_info.append(f.LocalPath()) |
976 | 974 |
977 if re.search(r"\bprintf\(", contents): | 975 if input_api.re.search(r"\bprintf\(", contents): |
978 printf.append(f.LocalPath()) | 976 printf.append(f.LocalPath()) |
979 elif re.search(r"\bfprintf\((stdout|stderr)", contents): | 977 elif input_api.re.search(r"\bfprintf\((stdout|stderr)", contents): |
980 printf.append(f.LocalPath()) | 978 printf.append(f.LocalPath()) |
981 | 979 |
982 if log_info: | 980 if log_info: |
983 return [output_api.PresubmitError( | 981 return [output_api.PresubmitError( |
984 'These files spam the console log with LOG(INFO):', | 982 'These files spam the console log with LOG(INFO):', |
985 items=log_info)] | 983 items=log_info)] |
986 if printf: | 984 if printf: |
987 return [output_api.PresubmitError( | 985 return [output_api.PresubmitError( |
988 'These files spam the console log with printf/fprintf:', | 986 'These files spam the console log with printf/fprintf:', |
989 items=printf)] | 987 items=printf)] |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1191 affected_file.AbsoluteLocalPath(), | 1189 affected_file.AbsoluteLocalPath(), |
1192 **kwargs) | 1190 **kwargs) |
1193 if parse_error: | 1191 if parse_error: |
1194 results.append(output_api.PresubmitError('%s could not be parsed: %s' % | 1192 results.append(output_api.PresubmitError('%s could not be parsed: %s' % |
1195 (affected_file.LocalPath(), parse_error))) | 1193 (affected_file.LocalPath(), parse_error))) |
1196 return results | 1194 return results |
1197 | 1195 |
1198 | 1196 |
1199 def _CheckJavaStyle(input_api, output_api): | 1197 def _CheckJavaStyle(input_api, output_api): |
1200 """Runs checkstyle on changed java files and returns errors if any exist.""" | 1198 """Runs checkstyle on changed java files and returns errors if any exist.""" |
1199 import sys | |
1201 original_sys_path = sys.path | 1200 original_sys_path = sys.path |
1202 try: | 1201 try: |
1203 sys.path = sys.path + [input_api.os_path.join( | 1202 sys.path = sys.path + [input_api.os_path.join( |
1204 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')] | 1203 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')] |
1205 import checkstyle | 1204 import checkstyle |
1206 finally: | 1205 finally: |
1207 # Restore sys.path to what it was before. | 1206 # Restore sys.path to what it was before. |
1208 sys.path = original_sys_path | 1207 sys.path = original_sys_path |
1209 | 1208 |
1210 return checkstyle.RunCheckstyle( | 1209 return checkstyle.RunCheckstyle( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1252 f, white_list=file_inclusion_pattern, black_list=black_list) | 1251 f, white_list=file_inclusion_pattern, black_list=black_list) |
1253 for fpath in input_api.AffectedFiles(file_filter=file_filter): | 1252 for fpath in input_api.AffectedFiles(file_filter=file_filter): |
1254 for line_num, line in fpath.ChangedContents(): | 1253 for line_num, line in fpath.ChangedContents(): |
1255 for (deprecated_value, value) in _DEPRECATED_CSS: | 1254 for (deprecated_value, value) in _DEPRECATED_CSS: |
1256 if input_api.re.search(deprecated_value, line): | 1255 if input_api.re.search(deprecated_value, line): |
1257 results.append(output_api.PresubmitError( | 1256 results.append(output_api.PresubmitError( |
1258 "%s:%d: Use of deprecated CSS %s, use %s instead" % | 1257 "%s:%d: Use of deprecated CSS %s, use %s instead" % |
1259 (fpath.LocalPath(), line_num, deprecated_value, value))) | 1258 (fpath.LocalPath(), line_num, deprecated_value, value))) |
1260 return results | 1259 return results |
1261 | 1260 |
1261 | |
1262 def _CheckForOverrideAndFinalRules(input_api, output_api): | |
1263 """Checks for override and final used as per C++11""" | |
1264 problems = [] | |
1265 for f in input_api.AffectedFiles(): | |
1266 if (f.LocalPath().endswith(('.cc', '.cpp', '.h', '.mm'))): | |
1267 for line_num, line in f.ChangedContents(): | |
1268 if (input_api.re.search(r'\b(OVERRIDE|FINAL)\b', line)): | |
1269 problems.append(' %s:%d' % (f.LocalPath(), line_num)) | |
1270 | |
1271 if not problems: | |
1272 return [] | |
1273 return [output_api.PresubmitError('Use C++11\'s |override| and |final| ' | |
1274 'rather than OVERRIDE and FINAL.', | |
1275 problems)] | |
1276 | |
1277 | |
1262 def _CommonChecks(input_api, output_api): | 1278 def _CommonChecks(input_api, output_api): |
1263 """Checks common to both upload and commit.""" | 1279 """Checks common to both upload and commit.""" |
1264 results = [] | 1280 results = [] |
1265 results.extend(input_api.canned_checks.PanProjectChecks( | 1281 results.extend(input_api.canned_checks.PanProjectChecks( |
1266 input_api, output_api, | 1282 input_api, output_api, |
1267 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS)) | 1283 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS)) |
1268 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) | 1284 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) |
1269 results.extend( | 1285 results.extend( |
1270 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) | 1286 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) |
1271 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) | 1287 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) |
(...skipping 21 matching lines...) Expand all Loading... | |
1293 input_api, | 1309 input_api, |
1294 output_api, | 1310 output_api, |
1295 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) | 1311 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) |
1296 results.extend(_CheckSpamLogging(input_api, output_api)) | 1312 results.extend(_CheckSpamLogging(input_api, output_api)) |
1297 results.extend(_CheckForAnonymousVariables(input_api, output_api)) | 1313 results.extend(_CheckForAnonymousVariables(input_api, output_api)) |
1298 results.extend(_CheckCygwinShell(input_api, output_api)) | 1314 results.extend(_CheckCygwinShell(input_api, output_api)) |
1299 results.extend(_CheckUserActionUpdate(input_api, output_api)) | 1315 results.extend(_CheckUserActionUpdate(input_api, output_api)) |
1300 results.extend(_CheckNoDeprecatedCSS(input_api, output_api)) | 1316 results.extend(_CheckNoDeprecatedCSS(input_api, output_api)) |
1301 results.extend(_CheckParseErrors(input_api, output_api)) | 1317 results.extend(_CheckParseErrors(input_api, output_api)) |
1302 results.extend(_CheckForIPCRules(input_api, output_api)) | 1318 results.extend(_CheckForIPCRules(input_api, output_api)) |
1319 results.extend(_CheckForOverrideAndFinalRules(input_api, output_api)) | |
1303 | 1320 |
1304 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): | 1321 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): |
1305 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( | 1322 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |
1306 input_api, output_api, | 1323 input_api, output_api, |
1307 input_api.PresubmitLocalPath(), | 1324 input_api.PresubmitLocalPath(), |
1308 whitelist=[r'^PRESUBMIT_test\.py$'])) | 1325 whitelist=[r'^PRESUBMIT_test\.py$'])) |
1309 return results | 1326 return results |
1310 | 1327 |
1311 | 1328 |
1312 def _CheckAuthorizedAuthor(input_api, output_api): | 1329 def _CheckAuthorizedAuthor(input_api, output_api): |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1446 bad_macros)] | 1463 bad_macros)] |
1447 | 1464 |
1448 | 1465 |
1449 def _CheckForUsingSideEffectsOfPass(input_api, output_api): | 1466 def _CheckForUsingSideEffectsOfPass(input_api, output_api): |
1450 """Check all affected files for using side effects of Pass.""" | 1467 """Check all affected files for using side effects of Pass.""" |
1451 errors = [] | 1468 errors = [] |
1452 for f in input_api.AffectedFiles(): | 1469 for f in input_api.AffectedFiles(): |
1453 if f.LocalPath().endswith(('.h', '.c', '.cc', '.m', '.mm')): | 1470 if f.LocalPath().endswith(('.h', '.c', '.cc', '.m', '.mm')): |
1454 for lnum, line in f.ChangedContents(): | 1471 for lnum, line in f.ChangedContents(): |
1455 # Disallow Foo(*my_scoped_thing.Pass()); See crbug.com/418297. | 1472 # Disallow Foo(*my_scoped_thing.Pass()); See crbug.com/418297. |
1456 if re.search(r'\*[a-zA-Z0-9_]+\.Pass\(\)', line): | 1473 if input_api.re.search(r'\*[a-zA-Z0-9_]+\.Pass\(\)', line): |
1457 errors.append(output_api.PresubmitError( | 1474 errors.append(output_api.PresubmitError( |
1458 ('%s:%d uses *foo.Pass() to delete the contents of scoped_ptr. ' + | 1475 ('%s:%d uses *foo.Pass() to delete the contents of scoped_ptr. ' + |
1459 'See crbug.com/418297.') % (f.LocalPath(), lnum))) | 1476 'See crbug.com/418297.') % (f.LocalPath(), lnum))) |
1460 return errors | 1477 return errors |
1461 | 1478 |
1462 | 1479 |
1463 def _CheckForIPCRules(input_api, output_api): | 1480 def _CheckForIPCRules(input_api, output_api): |
1464 """Check for same IPC rules described in | 1481 """Check for same IPC rules described in |
1465 http://www.chromium.org/Home/chromium-security/education/security-tips-for-ipc | 1482 http://www.chromium.org/Home/chromium-security/education/security-tips-for-ipc |
1466 """ | 1483 """ |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1640 json_url='http://chromium-status.appspot.com/current?format=json')) | 1657 json_url='http://chromium-status.appspot.com/current?format=json')) |
1641 | 1658 |
1642 results.extend(input_api.canned_checks.CheckChangeHasBugField( | 1659 results.extend(input_api.canned_checks.CheckChangeHasBugField( |
1643 input_api, output_api)) | 1660 input_api, output_api)) |
1644 results.extend(input_api.canned_checks.CheckChangeHasDescription( | 1661 results.extend(input_api.canned_checks.CheckChangeHasDescription( |
1645 input_api, output_api)) | 1662 input_api, output_api)) |
1646 return results | 1663 return results |
1647 | 1664 |
1648 | 1665 |
1649 def GetPreferredTryMasters(project, change): | 1666 def GetPreferredTryMasters(project, change): |
1667 import re | |
1650 files = change.LocalPaths() | 1668 files = change.LocalPaths() |
1651 | 1669 |
1652 if not files or all(re.search(r'[\\\/]OWNERS$', f) for f in files): | 1670 if not files or all(re.search(r'[\\\/]OWNERS$', f) for f in files): |
1653 return {} | 1671 return {} |
1654 | 1672 |
1655 if all(re.search(r'\.(m|mm)$|(^|[\\\/_])mac[\\\/_.]', f) for f in files): | 1673 if all(re.search(r'\.(m|mm)$|(^|[\\\/_])mac[\\\/_.]', f) for f in files): |
1656 return GetDefaultTryConfigs([ | 1674 return GetDefaultTryConfigs([ |
1657 'mac_chromium_compile_dbg', | 1675 'mac_chromium_compile_dbg', |
1658 'mac_chromium_rel_swarming', | 1676 'mac_chromium_rel_swarming', |
1659 ]) | 1677 ]) |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1715 builders.extend(['cros_x86']) | 1733 builders.extend(['cros_x86']) |
1716 | 1734 |
1717 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it | 1735 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it |
1718 # unless they're .gyp(i) files as changes to those files can break the gyp | 1736 # unless they're .gyp(i) files as changes to those files can break the gyp |
1719 # step on that bot. | 1737 # step on that bot. |
1720 if (not all(re.search('^chrome', f) for f in files) or | 1738 if (not all(re.search('^chrome', f) for f in files) or |
1721 any(re.search('\.gypi?$', f) for f in files)): | 1739 any(re.search('\.gypi?$', f) for f in files)): |
1722 builders.extend(['android_aosp']) | 1740 builders.extend(['android_aosp']) |
1723 | 1741 |
1724 return GetDefaultTryConfigs(builders) | 1742 return GetDefaultTryConfigs(builders) |
OLD | NEW |