Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 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" 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. |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 success = False | 224 success = False |
| 225 | 225 |
| 226 # Next recurse into the subdirectories. | 226 # Next recurse into the subdirectories. |
| 227 for cur in dirs_to_check: | 227 for cur in dirs_to_check: |
| 228 if not CheckDirectory(rules, checkers, cur): | 228 if not CheckDirectory(rules, checkers, cur): |
| 229 success = False | 229 success = False |
| 230 | 230 |
| 231 return success | 231 return success |
| 232 | 232 |
| 233 | 233 |
| 234 def ShouldCheckAddedIncludesInFile(file_path): | |
|
M-A Ruel
2012/07/26 14:03:28
ShouldcheckIncludesInCppFile ?
Just to be clearer
| |
| 235 """Whether to check added includes in the given file.""" | |
| 236 return os.path.splitext(file_path)[1] in cpp_checker.CppChecker.EXTENSIONS | |
| 237 | |
| 238 | |
| 234 def CheckAddedIncludes(added_includes): | 239 def CheckAddedIncludes(added_includes): |
|
M-A Ruel
2012/07/26 14:03:28
I'd like to have Cpp here too but this is outside
| |
| 235 """This is used from PRESUBMIT.py to check new #include statements added in | 240 """This is used from PRESUBMIT.py to check new #include statements added in |
| 236 the change being presubmit checked. | 241 the change being presubmit checked. |
| 237 | 242 |
| 238 Args: | 243 Args: |
| 239 added_includes: ((file_path, (include_line, include_line, ...), ...) | 244 added_includes: ((file_path, (include_line, include_line, ...), ...) |
| 240 | 245 |
| 241 Return: | 246 Return: |
| 242 A list of tuples, (bad_file_path, rule_type, rule_description) | 247 A list of tuples, (bad_file_path, rule_type, rule_description) |
| 243 where rule_type is one of Rule.DISALLOW or Rule.TEMP_ALLOW and | 248 where rule_type is one of Rule.DISALLOW or Rule.TEMP_ALLOW and |
| 244 rule_description is human-readable. Empty if no problems. | 249 rule_description is human-readable. Empty if no problems. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 directory_rules[dir_path] = None | 286 directory_rules[dir_path] = None |
| 282 else: | 287 else: |
| 283 ApplyDirectoryRulesAndSkipSubdirs(parent_rules, dir_path) | 288 ApplyDirectoryRulesAndSkipSubdirs(parent_rules, dir_path) |
| 284 return directory_rules[dir_path] | 289 return directory_rules[dir_path] |
| 285 | 290 |
| 286 cpp = cpp_checker.CppChecker(VERBOSE) | 291 cpp = cpp_checker.CppChecker(VERBOSE) |
| 287 | 292 |
| 288 problems = [] | 293 problems = [] |
| 289 for file_path, include_lines in added_includes: | 294 for file_path, include_lines in added_includes: |
| 290 # TODO(joi): Make this cover Java as well. | 295 # TODO(joi): Make this cover Java as well. |
| 291 if not os.path.splitext(file_path)[1] in cpp.EXTENSIONS: | 296 if not ShouldCheckAddedIncludesInFile(file_path): |
| 292 pass | 297 pass |
| 293 rules_for_file = GetDirectoryRules(os.path.dirname(file_path)) | 298 rules_for_file = GetDirectoryRules(os.path.dirname(file_path)) |
| 294 if rules_for_file: | 299 if rules_for_file: |
| 295 for line in include_lines: | 300 for line in include_lines: |
| 296 is_include, line_status, rule_type = cpp.CheckLine( | 301 is_include, line_status, rule_type = cpp.CheckLine( |
| 297 rules_for_file, line, True) | 302 rules_for_file, line, True) |
| 298 if rule_type != Rule.ALLOW: | 303 if rule_type != Rule.ALLOW: |
| 299 problems.append((file_path, rule_type, line_status)) | 304 problems.append((file_path, rule_type, line_status)) |
| 300 return problems | 305 return problems |
| 301 | 306 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 'to "../../.." relative to the script file, which ' | 408 'to "../../.." relative to the script file, which ' |
| 404 'will normally be the repository root.') | 409 'will normally be the repository root.') |
| 405 option_parser.add_option("-v", "--verbose", action="store_true", | 410 option_parser.add_option("-v", "--verbose", action="store_true", |
| 406 default=False, help="Print debug logging") | 411 default=False, help="Print debug logging") |
| 407 options, args = option_parser.parse_args() | 412 options, args = option_parser.parse_args() |
| 408 return checkdeps(options, args) | 413 return checkdeps(options, args) |
| 409 | 414 |
| 410 | 415 |
| 411 if '__main__' == __name__: | 416 if '__main__' == __name__: |
| 412 sys.exit(main()) | 417 sys.exit(main()) |
| OLD | NEW |