 Chromium Code Reviews
 Chromium Code Reviews Issue 6713101:
  Moving several chromium presubmit checks into the common pool for use in other  (Closed) 
  Base URL: svn://chrome-svn/chrome/trunk/tools/depot_tools/
    
  
    Issue 6713101:
  Moving several chromium presubmit checks into the common pool for use in other  (Closed) 
  Base URL: svn://chrome-svn/chrome/trunk/tools/depot_tools/| OLD | NEW | 
|---|---|
| 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 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 """Generic presubmit checks that can be reused by other presubmit checks.""" | 5 """Generic presubmit checks that can be reused by other presubmit checks.""" | 
| 6 | 6 | 
| 7 import time | |
| 8 | |
| 9 | |
| 7 ### Description checks | 10 ### Description checks | 
| 8 | 11 | 
| 9 def CheckChangeHasTestField(input_api, output_api): | 12 def CheckChangeHasTestField(input_api, output_api): | 
| 10 """Requires that the changelist have a TEST= field.""" | 13 """Requires that the changelist have a TEST= field.""" | 
| 11 if input_api.change.TEST: | 14 if input_api.change.TEST: | 
| 12 return [] | 15 return [] | 
| 13 else: | 16 else: | 
| 14 return [output_api.PresubmitNotifyResult( | 17 return [output_api.PresubmitNotifyResult( | 
| 15 'If this change requires manual test instructions to QA team, add ' | 18 'If this change requires manual test instructions to QA team, add ' | 
| 16 'TEST=[instructions].')] | 19 'TEST=[instructions].')] | 
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 672 # redundant (since the commit queue also enforces the presubmit checks). | 675 # redundant (since the commit queue also enforces the presubmit checks). | 
| 673 def match_reviewer(r): | 676 def match_reviewer(r): | 
| 674 return email_regexp.match(r) and not input_api.re.match(owner, r) | 677 return email_regexp.match(r) and not input_api.re.match(owner, r) | 
| 675 | 678 | 
| 676 approvers = [] | 679 approvers = [] | 
| 677 for m in issue_props.get('messages', []): | 680 for m in issue_props.get('messages', []): | 
| 678 if 'lgtm' in m['text'].lower() and match_reviewer(m['sender']): | 681 if 'lgtm' in m['text'].lower() and match_reviewer(m['sender']): | 
| 679 approvers.append(m['sender']) | 682 approvers.append(m['sender']) | 
| 680 return set(approvers) | 683 return set(approvers) | 
| 681 | 684 | 
| 685 | |
| 686 _TEXT_FILES = ( | |
| 
M-A Ruel
2011/03/24 17:08:04
Maybe better to be local variables?
 
bradn
2011/03/24 17:29:03
Done.
 | |
| 687 r".*\.txt", | |
| 688 r".*\.json", | |
| 689 ) | |
| 690 | |
| 691 _LICENSE_HEADER = ( | |
| 692 r".*? Copyright \(c\) %(year)s The %(project)s Authors\. " | |
| 
M-A Ruel
2011/03/24 17:08:04
I prefer ' but I'm silly.
 
bradn
2011/03/24 17:29:03
Done.
 | |
| 693 r"All rights reserved\.\n" | |
| 694 r".*? Use of this source code is governed by a BSD-style license that can " | |
| 695 "be\n" | |
| 696 r".*? found in the LICENSE file\." | |
| 697 "\n" | |
| 698 ) | |
| 699 | |
| 700 | |
| 701 def _CheckConstNSObject(input_api, output_api, source_file_filter): | |
| 702 """Checks to make sure no objective-c files have |const NSSomeClass*|.""" | |
| 703 pattern = input_api.re.compile(r'const\s+NS\w*\s*\*') | |
| 704 files = [] | |
| 705 for f in input_api.AffectedSourceFiles(source_file_filter): | |
| 706 if f.LocalPath().endswith('.h') or f.LocalPath().endswith('.mm'): | |
| 
M-A Ruel
2011/03/24 17:08:04
source_file_filter should be doing the filtering a
 
bradn
2011/03/24 17:29:03
Done.
 | |
| 707 contents = input_api.ReadFile(f) | |
| 708 if pattern.search(contents): | |
| 709 files.append(f) | |
| 710 | |
| 711 if len(files): | |
| 
M-A Ruel
2011/03/24 17:08:04
if files:
 
bradn
2011/03/24 17:29:03
Done.
 | |
| 712 if input_api.is_committing: | |
| 713 res_type = output_api.PresubmitPromptWarning | |
| 714 else: | |
| 715 res_type = output_api.PresubmitNotifyResult | |
| 716 return [ res_type('|const NSClass*| is wrong, see ' + | |
| 717 'http://dev.chromium.org/developers/clang-mac', | |
| 718 files) ] | |
| 719 return [] | |
| 720 | |
| 721 | |
| 722 def _CheckSingletonInHeaders(input_api, output_api, source_file_filter): | |
| 723 """Checks to make sure no header files have |Singleton<|.""" | |
| 724 pattern = input_api.re.compile(r'Singleton<') | |
| 725 files = [] | |
| 726 for f in input_api.AffectedSourceFiles(source_file_filter): | |
| 727 if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or | |
| 728 f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')): | |
| 729 contents = input_api.ReadFile(f) | |
| 730 if pattern.search(contents): | |
| 731 files.append(f) | |
| 732 | |
| 733 if len(files): | |
| 
M-A Ruel
2011/03/24 17:08:04
if files:
 
bradn
2011/03/24 17:29:03
Done.
 | |
| 734 return [ output_api.PresubmitError( | |
| 735 'Found Singleton<T> in the following header files.\n' + | |
| 736 'Please move them to an appropriate source file so that the ' + | |
| 737 'template gets instantiated in a single compilation unit.', | |
| 738 files) ] | |
| 739 return [] | |
| 740 | |
| 741 | |
| 742 def PanProjectChecks(input_api, output_api, | |
| 743 excluded_paths=None, text_files=None, | |
| 744 license_header=None, project_name=None): | |
| 745 """Checks that ALL chromium orbit projects should use. | |
| 746 | |
| 747 These are checks to be run on all Chromium orbit project, including: | |
| 748 Chromium | |
| 749 Native Client | |
| 750 V8 | |
| 751 When you update this function, please take this broad scope into account. | |
| 752 Args: | |
| 753 input_api: Bag of input related interfaces. | |
| 754 output_api: Bag of output related interfaces. | |
| 755 excluded_paths: Don't include these paths in common checks. | |
| 756 text_files: Which file are to be treated as documentation text files. | |
| 757 license_header: What license header should be on files. | |
| 758 project_name: What is the name of the project as it appears in the license. | |
| 759 Returns: | |
| 760 A list of warning or error objects. | |
| 761 """ | |
| 762 if excluded_paths is None: | |
| 763 excluded_paths = tuple() | |
| 764 if text_files is None: | |
| 765 text_files = _TEXT_FILES | |
| 766 if project_name is None: | |
| 
M-A Ruel
2011/03/24 17:08:04
project_name = project_name or 'Chromium'
same fo
 
bradn
2011/03/24 17:29:03
Done.
 | |
| 767 project_name = 'Chromium' | |
| 768 if license_header is None: | |
| 769 license_header = _LICENSE_HEADER % { | |
| 770 'year': time.strftime("%Y"), | |
| 771 'project': project_name, | |
| 772 } | |
| 773 | |
| 774 results = [] | |
| 775 # What does this code do? | |
| 
M-A Ruel
2011/03/24 17:08:04
funny but unnecessary.
 
bradn
2011/03/24 17:29:03
Done.
 | |
| 776 # It loads the default black list (e.g. third_party, experimental, etc) and | |
| 777 # add our black list (breakpad, skia and v8 are still not following | |
| 778 # google style and are not really living this repository). | |
| 779 # See presubmit_support.py InputApi.FilterSourceFile for the (simple) usage. | |
| 780 black_list = input_api.DEFAULT_BLACK_LIST + excluded_paths | |
| 781 white_list = input_api.DEFAULT_WHITE_LIST + text_files | |
| 782 sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list) | |
| 783 text_files = lambda x: input_api.FilterSourceFile(x, black_list=black_list, | |
| 784 white_list=white_list) | |
| 785 | |
| 786 # TODO(dpranke): enable upload as well | |
| 
M-A Ruel
2011/03/24 17:08:04
I'm not sure Dirk is ready to enable it for NaCl a
 
bradn
2011/03/24 17:29:03
Uh, NaCl's trying it out, that's what's prompted t
 | |
| 787 if input_api.is_committing: | |
| 788 results.extend(input_api.canned_checks.CheckOwners( | |
| 789 input_api, output_api, source_file_filter=sources)) | |
| 790 | |
| 791 results.extend(input_api.canned_checks.CheckLongLines( | |
| 792 input_api, output_api, source_file_filter=sources)) | |
| 793 results.extend(input_api.canned_checks.CheckChangeHasNoTabs( | |
| 794 input_api, output_api, source_file_filter=sources)) | |
| 795 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace( | |
| 796 input_api, output_api, source_file_filter=sources)) | |
| 797 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle( | |
| 798 input_api, output_api, source_file_filter=text_files)) | |
| 799 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( | |
| 800 input_api, output_api)) | |
| 801 results.extend(input_api.canned_checks.CheckLicense( | |
| 802 input_api, output_api, license_header, source_file_filter=sources)) | |
| 803 results.extend(_CheckConstNSObject( | |
| 804 input_api, output_api, source_file_filter=sources)) | |
| 805 results.extend(_CheckSingletonInHeaders( | |
| 806 input_api, output_api, source_file_filter=sources)) | |
| 807 return results | |
| OLD | NEW |