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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 directory_rules[norm_dir_path] = None | 333 directory_rules[norm_dir_path] = None |
334 else: | 334 else: |
335 ApplyDirectoryRulesAndSkipSubdirs(parent_rules, dir_path) | 335 ApplyDirectoryRulesAndSkipSubdirs(parent_rules, dir_path) |
336 return directory_rules[norm_dir_path] | 336 return directory_rules[norm_dir_path] |
337 | 337 |
338 cpp = cpp_checker.CppChecker(self.verbose) | 338 cpp = cpp_checker.CppChecker(self.verbose) |
339 | 339 |
340 problems = [] | 340 problems = [] |
341 for file_path, include_lines in added_includes: | 341 for file_path, include_lines in added_includes: |
342 # TODO(joi): Make this cover Java as well. | 342 # TODO(joi): Make this cover Java as well. |
343 if not os.path.splitext(file_path)[1] in cpp.EXTENSIONS: | 343 if not cpp.IsCppFile(file_path): |
344 pass | 344 pass |
345 rules_for_file = GetDirectoryRules(os.path.dirname(file_path)) | 345 rules_for_file = GetDirectoryRules(os.path.dirname(file_path)) |
346 if rules_for_file: | 346 if rules_for_file: |
347 for line in include_lines: | 347 for line in include_lines: |
348 is_include, line_status, rule_type = cpp.CheckLine( | 348 is_include, line_status, rule_type = cpp.CheckLine( |
349 rules_for_file, line, True) | 349 rules_for_file, line, True) |
350 if rule_type != Rule.ALLOW: | 350 if rule_type != Rule.ALLOW: |
351 problems.append((file_path, rule_type, line_status)) | 351 problems.append((file_path, rule_type, line_status)) |
352 return problems | 352 return problems |
353 | 353 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 for result in results: | 418 for result in results: |
419 print result | 419 print result |
420 print "\nFAILED\n" | 420 print "\nFAILED\n" |
421 return 1 | 421 return 1 |
422 print "\nSUCCESS\n" | 422 print "\nSUCCESS\n" |
423 return 0 | 423 return 0 |
424 | 424 |
425 | 425 |
426 if '__main__' == __name__: | 426 if '__main__' == __name__: |
427 sys.exit(main()) | 427 sys.exit(main()) |
OLD | NEW |