OLD | NEW |
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 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 of the script in "<root>/tools/checkdeps". | 438 of the script in "<root>/tools/checkdeps". |
439 | 439 |
440 tocheck Specifies the directory, relative to root, to check. This defaults | 440 tocheck Specifies the directory, relative to root, to check. This defaults |
441 to "." so it checks everything. Only one level deep is currently | 441 to "." so it checks everything. Only one level deep is currently |
442 supported, so you can say "chrome" but not "chrome/browser". | 442 supported, so you can say "chrome" but not "chrome/browser". |
443 | 443 |
444 Examples: | 444 Examples: |
445 python checkdeps.py | 445 python checkdeps.py |
446 python checkdeps.py --root c:\\source chrome""" | 446 python checkdeps.py --root c:\\source chrome""" |
447 | 447 |
448 def main(options, args): | 448 |
| 449 def checkdeps(options, args): |
449 global VERBOSE | 450 global VERBOSE |
450 if options.verbose: | 451 if options.verbose: |
451 VERBOSE = True | 452 VERBOSE = True |
452 | 453 |
453 # Optional base directory of the repository. | 454 # Optional base directory of the repository. |
454 global BASE_DIRECTORY | 455 global BASE_DIRECTORY |
455 if not options.base_directory: | 456 if not options.base_directory: |
456 BASE_DIRECTORY = os.path.abspath( | 457 BASE_DIRECTORY = os.path.abspath( |
457 os.path.join(os.path.abspath(os.path.dirname(__file__)), "../..")) | 458 os.path.join(os.path.abspath(os.path.dirname(__file__)), "../..")) |
458 else: | 459 else: |
459 BASE_DIRECTORY = os.path.abspath(options.base_directory) | 460 BASE_DIRECTORY = os.path.abspath(options.base_directory) |
460 | 461 |
461 # Figure out which directory we have to check. | 462 # Figure out which directory we have to check. |
462 if len(args) == 0: | 463 if len(args) == 0: |
463 # No directory to check specified, use the repository root. | 464 # No directory to check specified, use the repository root. |
464 start_dir = BASE_DIRECTORY | 465 start_dir = BASE_DIRECTORY |
465 elif len(args) == 1: | 466 elif len(args) == 1: |
466 # Directory specified. Start here. It's supposed to be relative to the | 467 # Directory specified. Start here. It's supposed to be relative to the |
467 # base directory. | 468 # base directory. |
468 start_dir = os.path.abspath(os.path.join(BASE_DIRECTORY, args[0])) | 469 start_dir = os.path.abspath(os.path.join(BASE_DIRECTORY, args[0])) |
469 else: | 470 else: |
470 # More than one argument, we don't handle this. | 471 # More than one argument, we don't handle this. |
471 PrintUsage() | 472 PrintUsage() |
472 sys.exit(1) | 473 return 1 |
473 | 474 |
474 print "Using base directory:", BASE_DIRECTORY | 475 print "Using base directory:", BASE_DIRECTORY |
475 print "Checking:", start_dir | 476 print "Checking:", start_dir |
476 | 477 |
477 base_rules = Rules() | 478 base_rules = Rules() |
478 | 479 |
479 # The base directory should be lower case from here on since it will be used | 480 # 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 | 481 # 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 | 482 # systems. Plus, we always use slashes here since the include parsing code |
482 # will also normalize to slashes. | 483 # will also normalize to slashes. |
483 BASE_DIRECTORY = BASE_DIRECTORY.lower() | 484 BASE_DIRECTORY = BASE_DIRECTORY.lower() |
484 BASE_DIRECTORY = BASE_DIRECTORY.replace("\\", "/") | 485 BASE_DIRECTORY = BASE_DIRECTORY.replace("\\", "/") |
485 start_dir = start_dir.replace("\\", "/") | 486 start_dir = start_dir.replace("\\", "/") |
486 | 487 |
487 if os.path.exists(os.path.join(BASE_DIRECTORY, ".git")): | 488 if os.path.exists(os.path.join(BASE_DIRECTORY, ".git")): |
488 global GIT_SOURCE_DIRECTORY | 489 global GIT_SOURCE_DIRECTORY |
489 GIT_SOURCE_DIRECTORY = GetGitSourceDirectory(BASE_DIRECTORY) | 490 GIT_SOURCE_DIRECTORY = GetGitSourceDirectory(BASE_DIRECTORY) |
490 | 491 |
491 success = CheckDirectory(base_rules, start_dir) | 492 success = CheckDirectory(base_rules, start_dir) |
492 if not success: | 493 if not success: |
493 print "\nFAILED\n" | 494 print "\nFAILED\n" |
494 sys.exit(1) | 495 return 1 |
495 print "\nSUCCESS\n" | 496 print "\nSUCCESS\n" |
496 sys.exit(0) | 497 return 0 |
497 | 498 |
498 if '__main__' == __name__: | 499 |
| 500 def main(): |
499 option_parser = optparse.OptionParser() | 501 option_parser = optparse.OptionParser() |
500 option_parser.add_option("", "--root", default="", dest="base_directory", | 502 option_parser.add_option("", "--root", default="", dest="base_directory", |
501 help='Specifies the repository root. This defaults ' | 503 help='Specifies the repository root. This defaults ' |
502 'to "../../.." relative to the script file, which ' | 504 'to "../../.." relative to the script file, which ' |
503 'will normally be the repository root.') | 505 'will normally be the repository root.') |
504 option_parser.add_option("-v", "--verbose", action="store_true", | 506 option_parser.add_option("-v", "--verbose", action="store_true", |
505 default=False, help="Print debug logging") | 507 default=False, help="Print debug logging") |
506 options, args = option_parser.parse_args() | 508 options, args = option_parser.parse_args() |
507 main(options, args) | 509 return checkdeps(options, args) |
| 510 |
| 511 |
| 512 if '__main__' == __name__: |
| 513 sys.exit(main()) |
OLD | NEW |