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

Side by Side Diff: tools/checkdeps/checkdeps.py

Issue 8678023: Fix python scripts in src/tools/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes Created 9 years 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 | « tools/bisect-builds.py ('k') | tools/checklicenses/checklicenses.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 #!/usr/bin/python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Makes sure that files include headers from allowed directories. 6 """Makes sure that files include headers from allowed directories.
7 7
8 Checks DEPS files in the source tree for rules, and applies those rules to 8 Checks DEPS files in the source tree for rules, and applies those rules to
9 "#include" commands in source files. Any source file including something not 9 "#include" commands in source files. Any source file including something not
10 permitted by the DEPS files will fail. 10 permitted by the DEPS files will fail.
11 11
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 # statements. 84 # statements.
85 EXTRACT_INCLUDE_PATH = re.compile('[ \t]*#[ \t]*(?:include|import)[ \t]+"(.*)"') 85 EXTRACT_INCLUDE_PATH = re.compile('[ \t]*#[ \t]*(?:include|import)[ \t]+"(.*)"')
86 86
87 # In lowercase, using forward slashes as directory separators, ending in a 87 # In lowercase, using forward slashes as directory separators, ending in a
88 # forward slash. Set by the command line options. 88 # forward slash. Set by the command line options.
89 BASE_DIRECTORY = "" 89 BASE_DIRECTORY = ""
90 90
91 # The directories which contain the sources managed by git. 91 # The directories which contain the sources managed by git.
92 GIT_SOURCE_DIRECTORY = set() 92 GIT_SOURCE_DIRECTORY = set()
93 93
94
94 # Specifies a single rule for an include, which can be either allow or disallow. 95 # Specifies a single rule for an include, which can be either allow or disallow.
95 class Rule(object): 96 class Rule(object):
96 def __init__(self, allow, dir, source): 97 def __init__(self, allow, dir, source):
97 self._allow = allow 98 self._allow = allow
98 self._dir = dir 99 self._dir = dir
99 self._source = source 100 self._source = source
100 101
101 def __str__(self): 102 def __str__(self):
102 if (self._allow): 103 if (self._allow):
103 return '"+%s" from %s.' % (self._dir, self._source) 104 return '"+%s" from %s.' % (self._dir, self._source)
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 of the script in "<root>/tools/checkdeps". 439 of the script in "<root>/tools/checkdeps".
439 440
440 tocheck Specifies the directory, relative to root, to check. This defaults 441 tocheck Specifies the directory, relative to root, to check. This defaults
441 to "." so it checks everything. Only one level deep is currently 442 to "." so it checks everything. Only one level deep is currently
442 supported, so you can say "chrome" but not "chrome/browser". 443 supported, so you can say "chrome" but not "chrome/browser".
443 444
444 Examples: 445 Examples:
445 python checkdeps.py 446 python checkdeps.py
446 python checkdeps.py --root c:\\source chrome""" 447 python checkdeps.py --root c:\\source chrome"""
447 448
448 def main(options, args): 449
450 def checkdeps(options, args):
449 global VERBOSE 451 global VERBOSE
450 if options.verbose: 452 if options.verbose:
451 VERBOSE = True 453 VERBOSE = True
452 454
453 # Optional base directory of the repository. 455 # Optional base directory of the repository.
454 global BASE_DIRECTORY 456 global BASE_DIRECTORY
455 if not options.base_directory: 457 if not options.base_directory:
456 BASE_DIRECTORY = os.path.abspath( 458 BASE_DIRECTORY = os.path.abspath(
457 os.path.join(os.path.abspath(os.path.dirname(__file__)), "../..")) 459 os.path.join(os.path.abspath(os.path.dirname(__file__)), "../.."))
458 else: 460 else:
459 BASE_DIRECTORY = os.path.abspath(options.base_directory) 461 BASE_DIRECTORY = os.path.abspath(options.base_directory)
460 462
461 # Figure out which directory we have to check. 463 # Figure out which directory we have to check.
462 if len(args) == 0: 464 if len(args) == 0:
463 # No directory to check specified, use the repository root. 465 # No directory to check specified, use the repository root.
464 start_dir = BASE_DIRECTORY 466 start_dir = BASE_DIRECTORY
465 elif len(args) == 1: 467 elif len(args) == 1:
466 # Directory specified. Start here. It's supposed to be relative to the 468 # Directory specified. Start here. It's supposed to be relative to the
467 # base directory. 469 # base directory.
468 start_dir = os.path.abspath(os.path.join(BASE_DIRECTORY, args[0])) 470 start_dir = os.path.abspath(os.path.join(BASE_DIRECTORY, args[0]))
469 else: 471 else:
470 # More than one argument, we don't handle this. 472 # More than one argument, we don't handle this.
471 PrintUsage() 473 PrintUsage()
472 sys.exit(1) 474 return 1
473 475
474 print "Using base directory:", BASE_DIRECTORY 476 print "Using base directory:", BASE_DIRECTORY
475 print "Checking:", start_dir 477 print "Checking:", start_dir
476 478
477 base_rules = Rules() 479 base_rules = Rules()
478 480
479 # The base directory should be lower case from here on since it will be used 481 # The base directory should be lower case from here on since it will be used
480 # for substring matching on the includes, and we compile on case-insensitive 482 # for substring matching on the includes, and we compile on case-insensitive
481 # systems. Plus, we always use slashes here since the include parsing code 483 # systems. Plus, we always use slashes here since the include parsing code
482 # will also normalize to slashes. 484 # will also normalize to slashes.
483 BASE_DIRECTORY = BASE_DIRECTORY.lower() 485 BASE_DIRECTORY = BASE_DIRECTORY.lower()
484 BASE_DIRECTORY = BASE_DIRECTORY.replace("\\", "/") 486 BASE_DIRECTORY = BASE_DIRECTORY.replace("\\", "/")
485 start_dir = start_dir.replace("\\", "/") 487 start_dir = start_dir.replace("\\", "/")
486 488
487 if os.path.exists(os.path.join(BASE_DIRECTORY, ".git")): 489 if os.path.exists(os.path.join(BASE_DIRECTORY, ".git")):
488 global GIT_SOURCE_DIRECTORY 490 global GIT_SOURCE_DIRECTORY
489 GIT_SOURCE_DIRECTORY = GetGitSourceDirectory(BASE_DIRECTORY) 491 GIT_SOURCE_DIRECTORY = GetGitSourceDirectory(BASE_DIRECTORY)
490 492
491 success = CheckDirectory(base_rules, start_dir) 493 success = CheckDirectory(base_rules, start_dir)
492 if not success: 494 if not success:
493 print "\nFAILED\n" 495 print "\nFAILED\n"
494 sys.exit(1) 496 return 1
495 print "\nSUCCESS\n" 497 print "\nSUCCESS\n"
496 sys.exit(0) 498 return 0
497 499
498 if '__main__' == __name__: 500
501 def main():
499 option_parser = optparse.OptionParser() 502 option_parser = optparse.OptionParser()
500 option_parser.add_option("", "--root", default="", dest="base_directory", 503 option_parser.add_option("", "--root", default="", dest="base_directory",
501 help='Specifies the repository root. This defaults ' 504 help='Specifies the repository root. This defaults '
502 'to "../../.." relative to the script file, which ' 505 'to "../../.." relative to the script file, which '
503 'will normally be the repository root.') 506 'will normally be the repository root.')
504 option_parser.add_option("-v", "--verbose", action="store_true", 507 option_parser.add_option("-v", "--verbose", action="store_true",
505 default=False, help="Print debug logging") 508 default=False, help="Print debug logging")
506 options, args = option_parser.parse_args() 509 options, args = option_parser.parse_args()
507 main(options, args) 510 return checkdeps(options, args)
511
512
513 if '__main__' == __name__:
514 sys.exit(main())
OLDNEW
« no previous file with comments | « tools/bisect-builds.py ('k') | tools/checklicenses/checklicenses.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698