| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2012 The Chromium Authors. All rights reserved. | 2 # Copyright 2012 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" and "import" directives in the .cpp and .java source files. | 9 "#include" and "import" directives in the .cpp and .java source files. |
| 10 Any source file including something not permitted by the DEPS files will fail. | 10 Any source file including something not permitted by the DEPS files will fail. |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 action='store_true', dest='count_violations', default=False, | 179 action='store_true', dest='count_violations', default=False, |
| 180 help='Count #includes in violation of intended rules.') | 180 help='Count #includes in violation of intended rules.') |
| 181 option_parser.add_option( | 181 option_parser.add_option( |
| 182 '', '--skip-tests', | 182 '', '--skip-tests', |
| 183 action='store_true', dest='skip_tests', default=False, | 183 action='store_true', dest='skip_tests', default=False, |
| 184 help='Skip checking test files (best effort).') | 184 help='Skip checking test files (best effort).') |
| 185 option_parser.add_option( | 185 option_parser.add_option( |
| 186 '-v', '--verbose', | 186 '-v', '--verbose', |
| 187 action='store_true', default=False, | 187 action='store_true', default=False, |
| 188 help='Print debug logging') | 188 help='Print debug logging') |
| 189 option_parser.add_option( |
| 190 '', '--json', |
| 191 help='Path to JSON output file') |
| 189 options, args = option_parser.parse_args() | 192 options, args = option_parser.parse_args() |
| 190 | 193 |
| 191 deps_checker = DepsChecker(options.base_directory, | 194 deps_checker = DepsChecker(options.base_directory, |
| 192 verbose=options.verbose, | 195 verbose=options.verbose, |
| 193 ignore_temp_rules=options.ignore_temp_rules, | 196 ignore_temp_rules=options.ignore_temp_rules, |
| 194 skip_tests=options.skip_tests) | 197 skip_tests=options.skip_tests) |
| 195 | 198 |
| 196 # Figure out which directory we have to check. | 199 # Figure out which directory we have to check. |
| 197 start_dir = deps_checker.base_directory | 200 start_dir = deps_checker.base_directory |
| 198 if len(args) == 1: | 201 if len(args) == 1: |
| 199 # Directory specified. Start here. It's supposed to be relative to the | 202 # Directory specified. Start here. It's supposed to be relative to the |
| 200 # base directory. | 203 # base directory. |
| 201 start_dir = os.path.abspath( | 204 start_dir = os.path.abspath( |
| 202 os.path.join(deps_checker.base_directory, args[0])) | 205 os.path.join(deps_checker.base_directory, args[0])) |
| 203 elif len(args) >= 2 or (options.generate_temp_rules and | 206 elif len(args) >= 2 or (options.generate_temp_rules and |
| 204 options.count_violations): | 207 options.count_violations): |
| 205 # More than one argument, or incompatible flags, we don't handle this. | 208 # More than one argument, or incompatible flags, we don't handle this. |
| 206 PrintUsage() | 209 PrintUsage() |
| 207 return 1 | 210 return 1 |
| 208 | 211 |
| 209 print 'Using base directory:', deps_checker.base_directory | 212 print 'Using base directory:', deps_checker.base_directory |
| 210 print 'Checking:', start_dir | 213 print 'Checking:', start_dir |
| 211 | 214 |
| 212 if options.generate_temp_rules: | 215 if options.generate_temp_rules: |
| 213 deps_checker.results_formatter = results.TemporaryRulesFormatter() | 216 deps_checker.results_formatter = results.TemporaryRulesFormatter() |
| 214 elif options.count_violations: | 217 elif options.count_violations: |
| 215 deps_checker.results_formatter = results.CountViolationsFormatter() | 218 deps_checker.results_formatter = results.CountViolationsFormatter() |
| 219 |
| 220 if options.json: |
| 221 deps_checker.results_formatter = results.JSONResultsFormatter( |
| 222 options.json, deps_checker.results_formatter) |
| 223 |
| 216 deps_checker.CheckDirectory(start_dir) | 224 deps_checker.CheckDirectory(start_dir) |
| 217 return deps_checker.Report() | 225 return deps_checker.Report() |
| 218 | 226 |
| 219 | 227 |
| 220 if '__main__' == __name__: | 228 if '__main__' == __name__: |
| 221 sys.exit(main()) | 229 sys.exit(main()) |
| OLD | NEW |