Chromium Code Reviews| 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 os | |
|
M-A Ruel
2012/07/26 13:09:38
Remove
Jói
2012/07/26 13:37:21
Done.
| |
| 12 import re | 13 import re |
| 14 import sys | |
| 13 | 15 |
| 14 | 16 |
| 15 _EXCLUDED_PATHS = ( | 17 _EXCLUDED_PATHS = ( |
| 16 r"^breakpad[\\\/].*", | 18 r"^breakpad[\\\/].*", |
| 17 r"^native_client_sdk[\\\/].*", | 19 r"^native_client_sdk[\\\/].*", |
| 18 r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*", | 20 r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*", |
| 19 r"^skia[\\\/].*", | 21 r"^skia[\\\/].*", |
| 20 r"^v8[\\\/].*", | 22 r"^v8[\\\/].*", |
| 21 r".*MakeFile$", | 23 r".*MakeFile$", |
| 22 r".+_autogen\.h$", | 24 r".+_autogen\.h$", |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 files.append(f) | 369 files.append(f) |
| 368 | 370 |
| 369 if files: | 371 if files: |
| 370 return [output_api.PresubmitError( | 372 return [output_api.PresubmitError( |
| 371 'Do not use #pragma once in header files.\n' | 373 'Do not use #pragma once in header files.\n' |
| 372 'See http://www.chromium.org/developers/coding-style#TOC-File-headers', | 374 'See http://www.chromium.org/developers/coding-style#TOC-File-headers', |
| 373 files)] | 375 files)] |
| 374 return [] | 376 return [] |
| 375 | 377 |
| 376 | 378 |
| 379 def _CheckUnwantedDependencies(input_api, output_api): | |
| 380 """Runs checkdeps on #include statements added in this | |
| 381 change. Breaking - rules is an error, breaking ! rules is a | |
| 382 warning. | |
| 383 """ | |
| 384 # We need to wait until we have an input_api object and use this | |
| 385 # roundabout construct to import checkdeps because this file is | |
| 386 # eval-ed and thus doesn't have __file__. | |
| 387 original_sys_path = sys.path | |
| 388 try: | |
| 389 sys.path = sys.path + [os.path.join( | |
|
M-A Ruel
2012/07/26 13:09:38
input_api.os_path.join(
Jói
2012/07/26 13:37:21
Done.
| |
| 390 input_api.change.RepositoryRoot(), 'tools', 'checkdeps')] | |
|
M-A Ruel
2012/07/26 13:09:38
It is relatively unsafe to use RepositoryRoot(). W
Jói
2012/07/26 13:37:21
Ah, sorry I missed that. Thanks for catching.
| |
| 391 import checkdeps | |
| 392 finally: | |
| 393 # Restore sys.path to what it was before. | |
| 394 sys.path = original_sys_path | |
| 395 | |
| 396 added_includes = [] | |
| 397 for f in input_api.AffectedFiles(): | |
| 398 if not checkdeps.ShouldCheckAddedIncludesInFile(f.LocalPath()): | |
| 399 continue | |
| 400 | |
| 401 changed_lines = [line for line_num, line in f.ChangedContents()] | |
| 402 added_includes.append([f.LocalPath(), changed_lines]) | |
| 403 | |
| 404 error_descriptions = [] | |
| 405 warning_descriptions = [] | |
| 406 for path, rule_type, rule_description in checkdeps.CheckAddedIncludes( | |
| 407 added_includes): | |
| 408 description_with_path = '%s\n %s' % (path, rule_description) | |
| 409 if rule_type == checkdeps.Rule.DISALLOW: | |
| 410 error_descriptions.append(description_with_path) | |
| 411 else: | |
| 412 warning_descriptions.append(description_with_path) | |
| 413 | |
| 414 results = [] | |
| 415 if error_descriptions: | |
| 416 results.append(output_api.PresubmitError( | |
| 417 'You added one or more #includes that violate checkdeps rules.', | |
| 418 error_descriptions)) | |
| 419 if warning_descriptions: | |
| 420 results.append(output_api.PresubmitPromptWarning( | |
|
M-A Ruel
2012/07/26 13:09:38
On commit, it would need to be a notification othe
Jói
2012/07/26 13:37:21
I would prefer if people need to jump through hoop
| |
| 421 'You added one or more #includes of files that are temporarily\n' | |
| 422 'allowed but being removed. Can you avoid introducing the\n' | |
| 423 '#include? See relevant DEPS file(s) for details and contacts.', | |
| 424 warning_descriptions)) | |
| 425 return results | |
| 426 | |
| 427 | |
| 377 def _CommonChecks(input_api, output_api): | 428 def _CommonChecks(input_api, output_api): |
| 378 """Checks common to both upload and commit.""" | 429 """Checks common to both upload and commit.""" |
| 379 results = [] | 430 results = [] |
| 380 results.extend(input_api.canned_checks.PanProjectChecks( | 431 results.extend(input_api.canned_checks.PanProjectChecks( |
| 381 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)) | 432 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)) |
| 382 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) | 433 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) |
| 383 results.extend( | 434 results.extend( |
| 384 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) | 435 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) |
| 385 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) | 436 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) |
| 386 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api)) | 437 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api)) |
| 387 results.extend(_CheckNoNewWStrings(input_api, output_api)) | 438 results.extend(_CheckNoNewWStrings(input_api, output_api)) |
| 388 results.extend(_CheckNoDEPSGIT(input_api, output_api)) | 439 results.extend(_CheckNoDEPSGIT(input_api, output_api)) |
| 389 results.extend(_CheckNoBannedFunctions(input_api, output_api)) | 440 results.extend(_CheckNoBannedFunctions(input_api, output_api)) |
| 390 results.extend(_CheckNoPragmaOnce(input_api, output_api)) | 441 results.extend(_CheckNoPragmaOnce(input_api, output_api)) |
| 442 results.extend(_CheckUnwantedDependencies(input_api, output_api)) | |
| 391 return results | 443 return results |
| 392 | 444 |
| 393 | 445 |
| 394 def _CheckSubversionConfig(input_api, output_api): | 446 def _CheckSubversionConfig(input_api, output_api): |
| 395 """Verifies the subversion config file is correctly setup. | 447 """Verifies the subversion config file is correctly setup. |
| 396 | 448 |
| 397 Checks that autoprops are enabled, returns an error otherwise. | 449 Checks that autoprops are enabled, returns an error otherwise. |
| 398 """ | 450 """ |
| 399 join = input_api.os_path.join | 451 join = input_api.os_path.join |
| 400 if input_api.platform == 'win32': | 452 if input_api.platform == 'win32': |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 if all(re.search('[/_]android[/_.]', f) for f in files): | 562 if all(re.search('[/_]android[/_.]', f) for f in files): |
| 511 return ['android'] | 563 return ['android'] |
| 512 | 564 |
| 513 trybots = ['win_rel', 'linux_rel', 'mac_rel', 'linux_clang:compile', | 565 trybots = ['win_rel', 'linux_rel', 'mac_rel', 'linux_clang:compile', |
| 514 'android'] | 566 'android'] |
| 515 # match things like aurax11.cc or aura_oak.cc | 567 # match things like aurax11.cc or aura_oak.cc |
| 516 if any(re.search('[/_]aura', f) for f in files): | 568 if any(re.search('[/_]aura', f) for f in files): |
| 517 trybots.append('linux_chromeos') | 569 trybots.append('linux_chromeos') |
| 518 | 570 |
| 519 return trybots | 571 return trybots |
| OLD | NEW |