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 | |
| 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 | |
|
M-A Ruel
2012/07/26 12:37:42
old_sys = sys.path
try:
sys.path = sys.path + [o
Jói
2012/07/26 13:00:34
Done.
| |
| 385 # roundabout construct to import checkdeps because this file is | |
| 386 # eval-ed and thus doesn't have __file__. | |
| 387 sys.path.append(os.path.join(input_api.change.RepositoryRoot(), | |
| 388 'tools/checkdeps')) | |
| 389 import checkdeps | |
| 390 | |
| 391 added_includes = [] | |
| 392 for f in input_api.AffectedFiles(): | |
| 393 if not checkdeps.ShouldCheckAddedIncludesInFile(f.LocalPath()): | |
| 394 continue | |
| 395 | |
| 396 include_lines = [] | |
|
M-A Ruel
2012/07/26 12:37:42
include_lines = [line for line_num, line in f.Chan
Jói
2012/07/26 13:00:34
It should be named changed_lines rather than inclu
| |
| 397 for line_num, line in f.ChangedContents(): | |
| 398 include_lines.append(line) | |
| 399 added_includes.append([f.LocalPath(), include_lines]) | |
| 400 | |
| 401 error_descriptions = [] | |
| 402 warning_descriptions = [] | |
| 403 for path, rule_type, rule_description in checkdeps.CheckAddedIncludes( | |
| 404 added_includes): | |
| 405 description_with_path = '%s\n %s' % (path, rule_description) | |
| 406 if rule_type == checkdeps.Rule.DISALLOW: | |
| 407 error_descriptions.append(description_with_path) | |
| 408 else: | |
| 409 warning_descriptions.append(description_with_path) | |
| 410 | |
| 411 results = [] | |
| 412 if error_descriptions: | |
| 413 results.append(output_api.PresubmitError( | |
| 414 'You added one or more #includes that violate checkdeps rules.', | |
| 415 error_descriptions)) | |
| 416 if warning_descriptions: | |
| 417 results.append(output_api.PresubmitPromptWarning( | |
| 418 'You added one or more #includes of files that are temporarily\n' | |
| 419 'allowed but being removed. Can you avoid introducing the\n' | |
| 420 '#include? See relevant DEPS file(s) for details and contacts.', | |
| 421 warning_descriptions)) | |
| 422 return results | |
|
M-A Ruel
2012/07/26 12:37:42
Personally, I would probably have just input_api.s
Jói
2012/07/26 13:00:34
It's more efficient to check only the changed line
| |
| 423 | |
| 424 | |
| 377 def _CommonChecks(input_api, output_api): | 425 def _CommonChecks(input_api, output_api): |
| 378 """Checks common to both upload and commit.""" | 426 """Checks common to both upload and commit.""" |
| 379 results = [] | 427 results = [] |
| 380 results.extend(input_api.canned_checks.PanProjectChecks( | 428 results.extend(input_api.canned_checks.PanProjectChecks( |
| 381 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)) | 429 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)) |
| 382 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) | 430 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) |
| 383 results.extend( | 431 results.extend( |
| 384 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) | 432 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) |
| 385 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) | 433 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) |
| 386 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api)) | 434 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api)) |
| 387 results.extend(_CheckNoNewWStrings(input_api, output_api)) | 435 results.extend(_CheckNoNewWStrings(input_api, output_api)) |
| 388 results.extend(_CheckNoDEPSGIT(input_api, output_api)) | 436 results.extend(_CheckNoDEPSGIT(input_api, output_api)) |
| 389 results.extend(_CheckNoBannedFunctions(input_api, output_api)) | 437 results.extend(_CheckNoBannedFunctions(input_api, output_api)) |
| 390 results.extend(_CheckNoPragmaOnce(input_api, output_api)) | 438 results.extend(_CheckNoPragmaOnce(input_api, output_api)) |
| 439 results.extend(_CheckUnwantedDependencies(input_api, output_api)) | |
| 391 return results | 440 return results |
| 392 | 441 |
| 393 | 442 |
| 394 def _CheckSubversionConfig(input_api, output_api): | 443 def _CheckSubversionConfig(input_api, output_api): |
| 395 """Verifies the subversion config file is correctly setup. | 444 """Verifies the subversion config file is correctly setup. |
| 396 | 445 |
| 397 Checks that autoprops are enabled, returns an error otherwise. | 446 Checks that autoprops are enabled, returns an error otherwise. |
| 398 """ | 447 """ |
| 399 join = input_api.os_path.join | 448 join = input_api.os_path.join |
| 400 if input_api.platform == 'win32': | 449 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): | 559 if all(re.search('[/_]android[/_.]', f) for f in files): |
| 511 return ['android'] | 560 return ['android'] |
| 512 | 561 |
| 513 trybots = ['win_rel', 'linux_rel', 'mac_rel', 'linux_clang:compile', | 562 trybots = ['win_rel', 'linux_rel', 'mac_rel', 'linux_clang:compile', |
| 514 'android'] | 563 'android'] |
| 515 # match things like aurax11.cc or aura_oak.cc | 564 # match things like aurax11.cc or aura_oak.cc |
| 516 if any(re.search('[/_]aura', f) for f in files): | 565 if any(re.search('[/_]aura', f) for f in files): |
| 517 trybots.append('linux_chromeos') | 566 trybots.append('linux_chromeos') |
| 518 | 567 |
| 519 return trybots | 568 return trybots |
| OLD | NEW |