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

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: Merge to parent. Created 8 years, 4 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') | no next file with comments »
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 from cpp_checker import CppChecker
392 from rules import Rule
393 finally:
394 # Restore sys.path to what it was before.
395 sys.path = original_sys_path
396
397 added_includes = []
398 for f in input_api.AffectedFiles():
399 if not CppChecker.IsCppFile(f.LocalPath()):
400 continue
401
402 changed_lines = [line for line_num, line in f.ChangedContents()]
403 added_includes.append([f.LocalPath(), changed_lines])
404
405 deps_checker = checkdeps.DepsChecker()
406
407 error_descriptions = []
408 warning_descriptions = []
409 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
410 added_includes):
411 description_with_path = '%s\n %s' % (path, rule_description)
412 if rule_type == Rule.DISALLOW:
413 error_descriptions.append(description_with_path)
414 else:
415 warning_descriptions.append(description_with_path)
416
417 results = []
418 if error_descriptions:
419 results.append(output_api.PresubmitError(
420 'You added one or more #includes that violate checkdeps rules.',
421 error_descriptions))
422 if warning_descriptions:
423 results.append(output_api.PresubmitPromptWarning(
424 'You added one or more #includes of files that are temporarily\n'
425 'allowed but being removed. Can you avoid introducing the\n'
426 '#include? See relevant DEPS file(s) for details and contacts.',
427 warning_descriptions))
428 return results
429
430
377 def _CommonChecks(input_api, output_api): 431 def _CommonChecks(input_api, output_api):
378 """Checks common to both upload and commit.""" 432 """Checks common to both upload and commit."""
379 results = [] 433 results = []
380 results.extend(input_api.canned_checks.PanProjectChecks( 434 results.extend(input_api.canned_checks.PanProjectChecks(
381 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)) 435 input_api, output_api, excluded_paths=_EXCLUDED_PATHS))
382 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) 436 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
383 results.extend( 437 results.extend(
384 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) 438 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
385 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) 439 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
386 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api)) 440 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
387 results.extend(_CheckNoNewWStrings(input_api, output_api)) 441 results.extend(_CheckNoNewWStrings(input_api, output_api))
388 results.extend(_CheckNoDEPSGIT(input_api, output_api)) 442 results.extend(_CheckNoDEPSGIT(input_api, output_api))
389 results.extend(_CheckNoBannedFunctions(input_api, output_api)) 443 results.extend(_CheckNoBannedFunctions(input_api, output_api))
390 results.extend(_CheckNoPragmaOnce(input_api, output_api)) 444 results.extend(_CheckNoPragmaOnce(input_api, output_api))
445 results.extend(_CheckUnwantedDependencies(input_api, output_api))
391 return results 446 return results
392 447
393 448
394 def _CheckSubversionConfig(input_api, output_api): 449 def _CheckSubversionConfig(input_api, output_api):
395 """Verifies the subversion config file is correctly setup. 450 """Verifies the subversion config file is correctly setup.
396 451
397 Checks that autoprops are enabled, returns an error otherwise. 452 Checks that autoprops are enabled, returns an error otherwise.
398 """ 453 """
399 join = input_api.os_path.join 454 join = input_api.os_path.join
400 if input_api.platform == 'win32': 455 if input_api.platform == 'win32':
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 if all(re.search('[/_]android[/_.]', f) for f in files): 563 if all(re.search('[/_]android[/_.]', f) for f in files):
509 return ['android'] 564 return ['android']
510 565
511 trybots = ['win_rel', 'linux_rel', 'mac_rel', 'linux_clang:compile', 566 trybots = ['win_rel', 'linux_rel', 'mac_rel', 'linux_clang:compile',
512 'android'] 567 'android']
513 # match things like aurax11.cc or aura_oak.cc 568 # match things like aurax11.cc or aura_oak.cc
514 if any(re.search('[/_]aura', f) for f in files): 569 if any(re.search('[/_]aura', f) for f in files):
515 trybots.append('linux_chromeos') 570 trybots.append('linux_chromeos')
516 571
517 return trybots 572 return trybots
OLDNEW
« no previous file with comments | « no previous file | tools/checkdeps/checkdeps.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698