Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: PRESUBMIT.py

Issue 10806049: Add checkdeps presubmit check. Warns on new #includes of dependencies (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to review comments. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/checkdeps/checkdeps.py » ('j') | tools/checkdeps/checkdeps.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12 import re
13 import sys
13 14
14 15
15 _EXCLUDED_PATHS = ( 16 _EXCLUDED_PATHS = (
16 r"^breakpad[\\\/].*", 17 r"^breakpad[\\\/].*",
17 r"^native_client_sdk[\\\/].*", 18 r"^native_client_sdk[\\\/].*",
18 r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*", 19 r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*",
19 r"^skia[\\\/].*", 20 r"^skia[\\\/].*",
20 r"^v8[\\\/].*", 21 r"^v8[\\\/].*",
21 r".*MakeFile$", 22 r".*MakeFile$",
22 r".+_autogen\.h$", 23 r".+_autogen\.h$",
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 files.append(f) 368 files.append(f)
368 369
369 if files: 370 if files:
370 return [output_api.PresubmitError( 371 return [output_api.PresubmitError(
371 'Do not use #pragma once in header files.\n' 372 'Do not use #pragma once in header files.\n'
372 'See http://www.chromium.org/developers/coding-style#TOC-File-headers', 373 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
373 files)] 374 files)]
374 return [] 375 return []
375 376
376 377
378 def _CheckUnwantedDependencies(input_api, output_api):
379 """Runs checkdeps on #include statements added in this
380 change. Breaking - rules is an error, breaking ! rules is a
381 warning.
382 """
383 # We need to wait until we have an input_api object and use this
384 # roundabout construct to import checkdeps because this file is
385 # eval-ed and thus doesn't have __file__.
386 original_sys_path = sys.path
387 try:
388 sys.path = sys.path + [input_api.os_path.join(
389 input_api.PresubmitLocalPath(), 'tools', 'checkdeps')]
390 import checkdeps
391 finally:
392 # Restore sys.path to what it was before.
393 sys.path = original_sys_path
394
395 added_includes = []
396 for f in input_api.AffectedFiles():
397 if not checkdeps.ShouldCheckAddedIncludesInFile(f.LocalPath()):
398 continue
399
400 changed_lines = [line for line_num, line in f.ChangedContents()]
401 added_includes.append([f.LocalPath(), changed_lines])
402
403 error_descriptions = []
404 warning_descriptions = []
405 for path, rule_type, rule_description in checkdeps.CheckAddedIncludes(
406 added_includes):
407 description_with_path = '%s\n %s' % (path, rule_description)
408 if rule_type == checkdeps.Rule.DISALLOW:
409 error_descriptions.append(description_with_path)
410 else:
411 warning_descriptions.append(description_with_path)
412
413 results = []
414 if error_descriptions:
415 results.append(output_api.PresubmitError(
416 'You added one or more #includes that violate checkdeps rules.',
417 error_descriptions))
418 if warning_descriptions:
419 results.append(output_api.PresubmitPromptWarning(
420 'You added one or more #includes of files that are temporarily\n'
421 'allowed but being removed. Can you avoid introducing the\n'
422 '#include? See relevant DEPS file(s) for details and contacts.',
423 warning_descriptions))
424 return results
425
426
377 def _CommonChecks(input_api, output_api): 427 def _CommonChecks(input_api, output_api):
378 """Checks common to both upload and commit.""" 428 """Checks common to both upload and commit."""
379 results = [] 429 results = []
380 results.extend(input_api.canned_checks.PanProjectChecks( 430 results.extend(input_api.canned_checks.PanProjectChecks(
381 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)) 431 input_api, output_api, excluded_paths=_EXCLUDED_PATHS))
382 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) 432 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
383 results.extend( 433 results.extend(
384 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) 434 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
385 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) 435 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
386 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api)) 436 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
387 results.extend(_CheckNoNewWStrings(input_api, output_api)) 437 results.extend(_CheckNoNewWStrings(input_api, output_api))
388 results.extend(_CheckNoDEPSGIT(input_api, output_api)) 438 results.extend(_CheckNoDEPSGIT(input_api, output_api))
389 results.extend(_CheckNoBannedFunctions(input_api, output_api)) 439 results.extend(_CheckNoBannedFunctions(input_api, output_api))
390 results.extend(_CheckNoPragmaOnce(input_api, output_api)) 440 results.extend(_CheckNoPragmaOnce(input_api, output_api))
441 results.extend(_CheckUnwantedDependencies(input_api, output_api))
391 return results 442 return results
392 443
393 444
394 def _CheckSubversionConfig(input_api, output_api): 445 def _CheckSubversionConfig(input_api, output_api):
395 """Verifies the subversion config file is correctly setup. 446 """Verifies the subversion config file is correctly setup.
396 447
397 Checks that autoprops are enabled, returns an error otherwise. 448 Checks that autoprops are enabled, returns an error otherwise.
398 """ 449 """
399 join = input_api.os_path.join 450 join = input_api.os_path.join
400 if input_api.platform == 'win32': 451 if input_api.platform == 'win32':
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 if all(re.search('[/_]android[/_.]', f) for f in files): 561 if all(re.search('[/_]android[/_.]', f) for f in files):
511 return ['android'] 562 return ['android']
512 563
513 trybots = ['win_rel', 'linux_rel', 'mac_rel', 'linux_clang:compile', 564 trybots = ['win_rel', 'linux_rel', 'mac_rel', 'linux_clang:compile',
514 'android'] 565 'android']
515 # match things like aurax11.cc or aura_oak.cc 566 # match things like aurax11.cc or aura_oak.cc
516 if any(re.search('[/_]aura', f) for f in files): 567 if any(re.search('[/_]aura', f) for f in files):
517 trybots.append('linux_chromeos') 568 trybots.append('linux_chromeos')
518 569
519 return trybots 570 return trybots
OLDNEW
« no previous file with comments | « no previous file | tools/checkdeps/checkdeps.py » ('j') | tools/checkdeps/checkdeps.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698