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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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.""" |
570 if input_api.platform == 'win32': | 567 if input_api.platform == 'win32': |
571 return [] | 568 return [] |
572 args = [sys.executable, 'tools/checkperms/checkperms.py', '--root', | 569 args = [input_api.python_executable, 'tools/checkperms/checkperms.py', |
573 input_api.change.RepositoryRoot()] | 570 '--root', input_api.change.RepositoryRoot()] |
574 for f in input_api.AffectedFiles(): | 571 for f in input_api.AffectedFiles(): |
575 args += ['--file', f.LocalPath()] | 572 args += ['--file', f.LocalPath()] |
576 checkperms = input_api.subprocess.Popen(args, | 573 checkperms = input_api.subprocess.Popen(args, |
577 stdout=input_api.subprocess.PIPE) | 574 stdout=input_api.subprocess.PIPE) |
578 errors = checkperms.communicate()[0].strip() | 575 errors = checkperms.communicate()[0].strip() |
579 if errors: | 576 if errors: |
580 return [output_api.PresubmitError('checkperms.py failed.', | 577 return [output_api.PresubmitError('checkperms.py failed.', |
581 errors.splitlines())] | 578 errors.splitlines())] |
582 return [] | 579 return [] |
583 | 580 |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 r"^webkit[\\\/]browser[\\\/]fileapi[\\\/]" + | 959 r"^webkit[\\\/]browser[\\\/]fileapi[\\\/]" + |
963 r"dump_file_system.cc$",)) | 960 r"dump_file_system.cc$",)) |
964 source_file_filter = lambda x: input_api.FilterSourceFile( | 961 source_file_filter = lambda x: input_api.FilterSourceFile( |
965 x, white_list=(file_inclusion_pattern,), black_list=black_list) | 962 x, white_list=(file_inclusion_pattern,), black_list=black_list) |
966 | 963 |
967 log_info = [] | 964 log_info = [] |
968 printf = [] | 965 printf = [] |
969 | 966 |
970 for f in input_api.AffectedSourceFiles(source_file_filter): | 967 for f in input_api.AffectedSourceFiles(source_file_filter): |
971 contents = input_api.ReadFile(f, 'rb') | 968 contents = input_api.ReadFile(f, 'rb') |
972 if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents): | 969 if input_api.re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents): |
973 log_info.append(f.LocalPath()) | 970 log_info.append(f.LocalPath()) |
974 elif re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents): | 971 elif input_api.re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents): |
975 log_info.append(f.LocalPath()) | 972 log_info.append(f.LocalPath()) |
976 | 973 |
977 if re.search(r"\bprintf\(", contents): | 974 if input_api.re.search(r"\bprintf\(", contents): |
978 printf.append(f.LocalPath()) | 975 printf.append(f.LocalPath()) |
979 elif re.search(r"\bfprintf\((stdout|stderr)", contents): | 976 elif input_api.re.search(r"\bfprintf\((stdout|stderr)", contents): |
980 printf.append(f.LocalPath()) | 977 printf.append(f.LocalPath()) |
981 | 978 |
982 if log_info: | 979 if log_info: |
983 return [output_api.PresubmitError( | 980 return [output_api.PresubmitError( |
984 'These files spam the console log with LOG(INFO):', | 981 'These files spam the console log with LOG(INFO):', |
985 items=log_info)] | 982 items=log_info)] |
986 if printf: | 983 if printf: |
987 return [output_api.PresubmitError( | 984 return [output_api.PresubmitError( |
988 'These files spam the console log with printf/fprintf:', | 985 'These files spam the console log with printf/fprintf:', |
989 items=printf)] | 986 items=printf)] |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 affected_file.AbsoluteLocalPath(), | 1188 affected_file.AbsoluteLocalPath(), |
1192 **kwargs) | 1189 **kwargs) |
1193 if parse_error: | 1190 if parse_error: |
1194 results.append(output_api.PresubmitError('%s could not be parsed: %s' % | 1191 results.append(output_api.PresubmitError('%s could not be parsed: %s' % |
1195 (affected_file.LocalPath(), parse_error))) | 1192 (affected_file.LocalPath(), parse_error))) |
1196 return results | 1193 return results |
1197 | 1194 |
1198 | 1195 |
1199 def _CheckJavaStyle(input_api, output_api): | 1196 def _CheckJavaStyle(input_api, output_api): |
1200 """Runs checkstyle on changed java files and returns errors if any exist.""" | 1197 """Runs checkstyle on changed java files and returns errors if any exist.""" |
| 1198 import sys |
1201 original_sys_path = sys.path | 1199 original_sys_path = sys.path |
1202 try: | 1200 try: |
1203 sys.path = sys.path + [input_api.os_path.join( | 1201 sys.path = sys.path + [input_api.os_path.join( |
1204 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')] | 1202 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')] |
1205 import checkstyle | 1203 import checkstyle |
1206 finally: | 1204 finally: |
1207 # Restore sys.path to what it was before. | 1205 # Restore sys.path to what it was before. |
1208 sys.path = original_sys_path | 1206 sys.path = original_sys_path |
1209 | 1207 |
1210 return checkstyle.RunCheckstyle( | 1208 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) | 1250 f, white_list=file_inclusion_pattern, black_list=black_list) |
1253 for fpath in input_api.AffectedFiles(file_filter=file_filter): | 1251 for fpath in input_api.AffectedFiles(file_filter=file_filter): |
1254 for line_num, line in fpath.ChangedContents(): | 1252 for line_num, line in fpath.ChangedContents(): |
1255 for (deprecated_value, value) in _DEPRECATED_CSS: | 1253 for (deprecated_value, value) in _DEPRECATED_CSS: |
1256 if input_api.re.search(deprecated_value, line): | 1254 if input_api.re.search(deprecated_value, line): |
1257 results.append(output_api.PresubmitError( | 1255 results.append(output_api.PresubmitError( |
1258 "%s:%d: Use of deprecated CSS %s, use %s instead" % | 1256 "%s:%d: Use of deprecated CSS %s, use %s instead" % |
1259 (fpath.LocalPath(), line_num, deprecated_value, value))) | 1257 (fpath.LocalPath(), line_num, deprecated_value, value))) |
1260 return results | 1258 return results |
1261 | 1259 |
| 1260 |
| 1261 def _CheckForOverrideAndFinalRules(input_api, output_api): |
| 1262 """Checks for final and override used as per C++11""" |
| 1263 problems = [] |
| 1264 for f in input_api.AffectedFiles(): |
| 1265 if (f.LocalPath().endswith(('.cc', '.cpp', '.h', '.mm'))): |
| 1266 for line_num, line in f.ChangedContents(): |
| 1267 if (input_api.re.search(r'\b(FINAL|OVERRIDE)\b', line)): |
| 1268 problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
| 1269 |
| 1270 if not problems: |
| 1271 return [] |
| 1272 return [output_api.PresubmitError('Use C++11\'s |final| and |override| ' |
| 1273 'rather than FINAL and OVERRIDE.', |
| 1274 problems)] |
| 1275 |
| 1276 |
1262 def _CommonChecks(input_api, output_api): | 1277 def _CommonChecks(input_api, output_api): |
1263 """Checks common to both upload and commit.""" | 1278 """Checks common to both upload and commit.""" |
1264 results = [] | 1279 results = [] |
1265 results.extend(input_api.canned_checks.PanProjectChecks( | 1280 results.extend(input_api.canned_checks.PanProjectChecks( |
1266 input_api, output_api, | 1281 input_api, output_api, |
1267 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS)) | 1282 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS)) |
1268 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) | 1283 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) |
1269 results.extend( | 1284 results.extend( |
1270 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) | 1285 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) |
1271 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) | 1286 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) |
(...skipping 21 matching lines...) Expand all Loading... |
1293 input_api, | 1308 input_api, |
1294 output_api, | 1309 output_api, |
1295 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) | 1310 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) |
1296 results.extend(_CheckSpamLogging(input_api, output_api)) | 1311 results.extend(_CheckSpamLogging(input_api, output_api)) |
1297 results.extend(_CheckForAnonymousVariables(input_api, output_api)) | 1312 results.extend(_CheckForAnonymousVariables(input_api, output_api)) |
1298 results.extend(_CheckCygwinShell(input_api, output_api)) | 1313 results.extend(_CheckCygwinShell(input_api, output_api)) |
1299 results.extend(_CheckUserActionUpdate(input_api, output_api)) | 1314 results.extend(_CheckUserActionUpdate(input_api, output_api)) |
1300 results.extend(_CheckNoDeprecatedCSS(input_api, output_api)) | 1315 results.extend(_CheckNoDeprecatedCSS(input_api, output_api)) |
1301 results.extend(_CheckParseErrors(input_api, output_api)) | 1316 results.extend(_CheckParseErrors(input_api, output_api)) |
1302 results.extend(_CheckForIPCRules(input_api, output_api)) | 1317 results.extend(_CheckForIPCRules(input_api, output_api)) |
| 1318 results.extend(_CheckForOverrideAndFinalRules(input_api, output_api)) |
1303 | 1319 |
1304 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): | 1320 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): |
1305 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( | 1321 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |
1306 input_api, output_api, | 1322 input_api, output_api, |
1307 input_api.PresubmitLocalPath(), | 1323 input_api.PresubmitLocalPath(), |
1308 whitelist=[r'^PRESUBMIT_test\.py$'])) | 1324 whitelist=[r'^PRESUBMIT_test\.py$'])) |
1309 return results | 1325 return results |
1310 | 1326 |
1311 | 1327 |
1312 def _CheckAuthorizedAuthor(input_api, output_api): | 1328 def _CheckAuthorizedAuthor(input_api, output_api): |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1446 bad_macros)] | 1462 bad_macros)] |
1447 | 1463 |
1448 | 1464 |
1449 def _CheckForUsingSideEffectsOfPass(input_api, output_api): | 1465 def _CheckForUsingSideEffectsOfPass(input_api, output_api): |
1450 """Check all affected files for using side effects of Pass.""" | 1466 """Check all affected files for using side effects of Pass.""" |
1451 errors = [] | 1467 errors = [] |
1452 for f in input_api.AffectedFiles(): | 1468 for f in input_api.AffectedFiles(): |
1453 if f.LocalPath().endswith(('.h', '.c', '.cc', '.m', '.mm')): | 1469 if f.LocalPath().endswith(('.h', '.c', '.cc', '.m', '.mm')): |
1454 for lnum, line in f.ChangedContents(): | 1470 for lnum, line in f.ChangedContents(): |
1455 # Disallow Foo(*my_scoped_thing.Pass()); See crbug.com/418297. | 1471 # Disallow Foo(*my_scoped_thing.Pass()); See crbug.com/418297. |
1456 if re.search(r'\*[a-zA-Z0-9_]+\.Pass\(\)', line): | 1472 if input_api.re.search(r'\*[a-zA-Z0-9_]+\.Pass\(\)', line): |
1457 errors.append(output_api.PresubmitError( | 1473 errors.append(output_api.PresubmitError( |
1458 ('%s:%d uses *foo.Pass() to delete the contents of scoped_ptr. ' + | 1474 ('%s:%d uses *foo.Pass() to delete the contents of scoped_ptr. ' + |
1459 'See crbug.com/418297.') % (f.LocalPath(), lnum))) | 1475 'See crbug.com/418297.') % (f.LocalPath(), lnum))) |
1460 return errors | 1476 return errors |
1461 | 1477 |
1462 | 1478 |
1463 def _CheckForIPCRules(input_api, output_api): | 1479 def _CheckForIPCRules(input_api, output_api): |
1464 """Check for same IPC rules described in | 1480 """Check for same IPC rules described in |
1465 http://www.chromium.org/Home/chromium-security/education/security-tips-for-ipc | 1481 http://www.chromium.org/Home/chromium-security/education/security-tips-for-ipc |
1466 """ | 1482 """ |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1640 json_url='http://chromium-status.appspot.com/current?format=json')) | 1656 json_url='http://chromium-status.appspot.com/current?format=json')) |
1641 | 1657 |
1642 results.extend(input_api.canned_checks.CheckChangeHasBugField( | 1658 results.extend(input_api.canned_checks.CheckChangeHasBugField( |
1643 input_api, output_api)) | 1659 input_api, output_api)) |
1644 results.extend(input_api.canned_checks.CheckChangeHasDescription( | 1660 results.extend(input_api.canned_checks.CheckChangeHasDescription( |
1645 input_api, output_api)) | 1661 input_api, output_api)) |
1646 return results | 1662 return results |
1647 | 1663 |
1648 | 1664 |
1649 def GetPreferredTryMasters(project, change): | 1665 def GetPreferredTryMasters(project, change): |
| 1666 import re |
1650 files = change.LocalPaths() | 1667 files = change.LocalPaths() |
1651 | 1668 |
1652 if not files or all(re.search(r'[\\\/]OWNERS$', f) for f in files): | 1669 if not files or all(re.search(r'[\\\/]OWNERS$', f) for f in files): |
1653 return {} | 1670 return {} |
1654 | 1671 |
1655 if all(re.search(r'\.(m|mm)$|(^|[\\\/_])mac[\\\/_.]', f) for f in files): | 1672 if all(re.search(r'\.(m|mm)$|(^|[\\\/_])mac[\\\/_.]', f) for f in files): |
1656 return GetDefaultTryConfigs([ | 1673 return GetDefaultTryConfigs([ |
1657 'mac_chromium_compile_dbg', | 1674 'mac_chromium_compile_dbg', |
1658 'mac_chromium_rel_swarming', | 1675 'mac_chromium_rel_swarming', |
1659 ]) | 1676 ]) |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1715 builders.extend(['cros_x86']) | 1732 builders.extend(['cros_x86']) |
1716 | 1733 |
1717 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it | 1734 # 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 | 1735 # unless they're .gyp(i) files as changes to those files can break the gyp |
1719 # step on that bot. | 1736 # step on that bot. |
1720 if (not all(re.search('^chrome', f) for f in files) or | 1737 if (not all(re.search('^chrome', f) for f in files) or |
1721 any(re.search('\.gypi?$', f) for f in files)): | 1738 any(re.search('\.gypi?$', f) for f in files)): |
1722 builders.extend(['android_aosp']) | 1739 builders.extend(['android_aosp']) |
1723 | 1740 |
1724 return GetDefaultTryConfigs(builders) | 1741 return GetDefaultTryConfigs(builders) |
OLD | NEW |