OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Top-level presubmit script for Chromium. | 5 """Top-level presubmit script for Chromium. |
6 | 6 |
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
8 for more details about the presubmit API built into depot_tools. | 8 for more details about the presubmit API built into depot_tools. |
9 """ | 9 """ |
10 | 10 |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 problems.append(' %s:%d' % (f.LocalPath(), line_num)) | 670 problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
671 | 671 |
672 if not problems: | 672 if not problems: |
673 return [] | 673 return [] |
674 return [output_api.PresubmitPromptWarning( | 674 return [output_api.PresubmitPromptWarning( |
675 'Please consider avoiding the "? true : false" pattern if possible.\n' + | 675 'Please consider avoiding the "? true : false" pattern if possible.\n' + |
676 '\n'.join(problems))] | 676 '\n'.join(problems))] |
677 | 677 |
678 | 678 |
679 def _CheckUnwantedDependencies(input_api, output_api): | 679 def _CheckUnwantedDependencies(input_api, output_api): |
680 """Runs checkdeps on #include statements added in this | 680 """Runs checkdeps on #include and import statements added in this |
681 change. Breaking - rules is an error, breaking ! rules is a | 681 change. Breaking - rules is an error, breaking ! rules is a |
682 warning. | 682 warning. |
683 """ | 683 """ |
684 import sys | 684 import sys |
685 # We need to wait until we have an input_api object and use this | 685 # We need to wait until we have an input_api object and use this |
686 # roundabout construct to import checkdeps because this file is | 686 # roundabout construct to import checkdeps because this file is |
687 # eval-ed and thus doesn't have __file__. | 687 # eval-ed and thus doesn't have __file__. |
688 original_sys_path = sys.path | 688 original_sys_path = sys.path |
689 try: | 689 try: |
690 sys.path = sys.path + [input_api.os_path.join( | 690 sys.path = sys.path + [input_api.os_path.join( |
691 input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')] | 691 input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')] |
692 import checkdeps | 692 import checkdeps |
693 from cpp_checker import CppChecker | 693 from cpp_checker import CppChecker |
| 694 from proto_checker import ProtoChecker |
694 from rules import Rule | 695 from rules import Rule |
695 finally: | 696 finally: |
696 # Restore sys.path to what it was before. | 697 # Restore sys.path to what it was before. |
697 sys.path = original_sys_path | 698 sys.path = original_sys_path |
698 | 699 |
699 added_includes = [] | 700 added_includes = [] |
| 701 added_imports = [] |
700 for f in input_api.AffectedFiles(): | 702 for f in input_api.AffectedFiles(): |
701 if not CppChecker.IsCppFile(f.LocalPath()): | 703 if CppChecker.IsCppFile(f.LocalPath()): |
702 continue | 704 changed_lines = [line for line_num, line in f.ChangedContents()] |
703 | 705 added_includes.append([f.LocalPath(), changed_lines]) |
704 changed_lines = [line for line_num, line in f.ChangedContents()] | 706 elif ProtoChecker.IsProtoFile(f.LocalPath()): |
705 added_includes.append([f.LocalPath(), changed_lines]) | 707 changed_lines = [line for line_num, line in f.ChangedContents()] |
| 708 added_imports.append([f.LocalPath(), changed_lines]) |
706 | 709 |
707 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath()) | 710 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath()) |
708 | 711 |
709 error_descriptions = [] | 712 error_descriptions = [] |
710 warning_descriptions = [] | 713 warning_descriptions = [] |
| 714 error_subjects = set() |
| 715 warning_subjects = set() |
711 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes( | 716 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes( |
712 added_includes): | 717 added_includes): |
713 description_with_path = '%s\n %s' % (path, rule_description) | 718 description_with_path = '%s\n %s' % (path, rule_description) |
714 if rule_type == Rule.DISALLOW: | 719 if rule_type == Rule.DISALLOW: |
715 error_descriptions.append(description_with_path) | 720 error_descriptions.append(description_with_path) |
| 721 error_subjects.add("#includes") |
716 else: | 722 else: |
717 warning_descriptions.append(description_with_path) | 723 warning_descriptions.append(description_with_path) |
| 724 warning_subjects.add("#includes") |
| 725 |
| 726 for path, rule_type, rule_description in deps_checker.CheckAddedProtoImports( |
| 727 added_imports): |
| 728 description_with_path = '%s\n %s' % (path, rule_description) |
| 729 if rule_type == Rule.DISALLOW: |
| 730 error_descriptions.append(description_with_path) |
| 731 error_subjects.add("imports") |
| 732 else: |
| 733 warning_descriptions.append(description_with_path) |
| 734 warning_subjects.add("imports") |
718 | 735 |
719 results = [] | 736 results = [] |
720 if error_descriptions: | 737 if error_descriptions: |
721 results.append(output_api.PresubmitError( | 738 results.append(output_api.PresubmitError( |
722 'You added one or more #includes that violate checkdeps rules.', | 739 'You added one or more %s that violate checkdeps rules.' |
| 740 % " and ".join(error_subjects), |
723 error_descriptions)) | 741 error_descriptions)) |
724 if warning_descriptions: | 742 if warning_descriptions: |
725 results.append(output_api.PresubmitPromptOrNotify( | 743 results.append(output_api.PresubmitPromptOrNotify( |
726 'You added one or more #includes of files that are temporarily\n' | 744 'You added one or more %s of files that are temporarily\n' |
727 'allowed but being removed. Can you avoid introducing the\n' | 745 'allowed but being removed. Can you avoid introducing the\n' |
728 '#include? See relevant DEPS file(s) for details and contacts.', | 746 '%s? See relevant DEPS file(s) for details and contacts.' % |
| 747 (" and ".join(warning_subjects), "/".join(warning_subjects)), |
729 warning_descriptions)) | 748 warning_descriptions)) |
730 return results | 749 return results |
731 | 750 |
732 | 751 |
733 def _CheckFilePermissions(input_api, output_api): | 752 def _CheckFilePermissions(input_api, output_api): |
734 """Check that all files have their permissions properly set.""" | 753 """Check that all files have their permissions properly set.""" |
735 if input_api.platform == 'win32': | 754 if input_api.platform == 'win32': |
736 return [] | 755 return [] |
737 checkperms_tool = input_api.os_path.join( | 756 checkperms_tool = input_api.os_path.join( |
738 input_api.PresubmitLocalPath(), | 757 input_api.PresubmitLocalPath(), |
(...skipping 1628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2367 results.extend(input_api.canned_checks.CheckTreeIsOpen( | 2386 results.extend(input_api.canned_checks.CheckTreeIsOpen( |
2368 input_api, | 2387 input_api, |
2369 output_api, | 2388 output_api, |
2370 json_url='http://chromium-status.appspot.com/current?format=json')) | 2389 json_url='http://chromium-status.appspot.com/current?format=json')) |
2371 | 2390 |
2372 results.extend(input_api.canned_checks.CheckChangeHasBugField( | 2391 results.extend(input_api.canned_checks.CheckChangeHasBugField( |
2373 input_api, output_api)) | 2392 input_api, output_api)) |
2374 results.extend(input_api.canned_checks.CheckChangeHasDescription( | 2393 results.extend(input_api.canned_checks.CheckChangeHasDescription( |
2375 input_api, output_api)) | 2394 input_api, output_api)) |
2376 return results | 2395 return results |
OLD | NEW |