OLD | NEW |
1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 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 | 7 |
8 ### Description checks | 8 ### Description checks |
9 | 9 |
10 def CheckChangeHasTestField(input_api, output_api): | 10 def CheckChangeHasTestField(input_api, output_api): |
11 """Requires that the changelist have a TEST= field.""" | 11 """Requires that the changelist have a TEST= field.""" |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 else: | 821 else: |
822 res_type = output_api.PresubmitNotifyResult | 822 res_type = output_api.PresubmitNotifyResult |
823 return [ res_type('|const NSClass*| is wrong, see ' + | 823 return [ res_type('|const NSClass*| is wrong, see ' + |
824 'http://dev.chromium.org/developers/clang-mac', | 824 'http://dev.chromium.org/developers/clang-mac', |
825 files) ] | 825 files) ] |
826 return [] | 826 return [] |
827 | 827 |
828 | 828 |
829 def _CheckSingletonInHeaders(input_api, output_api, source_file_filter): | 829 def _CheckSingletonInHeaders(input_api, output_api, source_file_filter): |
830 """Checks to make sure no header files have |Singleton<|.""" | 830 """Checks to make sure no header files have |Singleton<|.""" |
831 pattern = input_api.re.compile(r'Singleton<') | 831 pattern = input_api.re.compile(r'Singleton\s*<') |
832 files = [] | 832 files = [] |
833 for f in input_api.AffectedSourceFiles(source_file_filter): | 833 for f in input_api.AffectedSourceFiles(source_file_filter): |
834 if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or | 834 if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or |
835 f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')): | 835 f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')): |
836 contents = input_api.ReadFile(f) | 836 contents = input_api.ReadFile(f) |
837 if pattern.search(contents): | 837 for line in contents.splitlines(False): |
838 files.append(f) | 838 line = input_api.re.sub(r'//.*$', '', line) # Strip C++ comment. |
| 839 if pattern.search(line): |
| 840 files.append(f) |
| 841 break |
839 | 842 |
840 if files: | 843 if files: |
841 return [ output_api.PresubmitError( | 844 return [ output_api.PresubmitError( |
842 'Found Singleton<T> in the following header files.\n' + | 845 'Found Singleton<T> in the following header files.\n' + |
843 'Please move them to an appropriate source file so that the ' + | 846 'Please move them to an appropriate source file so that the ' + |
844 'template gets instantiated in a single compilation unit.', | 847 'template gets instantiated in a single compilation unit.', |
845 files) ] | 848 files) ] |
846 return [] | 849 return [] |
847 | 850 |
848 | 851 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( | 939 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( |
937 input_api, output_api)) | 940 input_api, output_api)) |
938 snapshot("checking license") | 941 snapshot("checking license") |
939 results.extend(input_api.canned_checks.CheckLicense( | 942 results.extend(input_api.canned_checks.CheckLicense( |
940 input_api, output_api, license_header, source_file_filter=sources)) | 943 input_api, output_api, license_header, source_file_filter=sources)) |
941 snapshot("checking was uploaded") | 944 snapshot("checking was uploaded") |
942 results.extend(input_api.canned_checks.CheckChangeWasUploaded( | 945 results.extend(input_api.canned_checks.CheckChangeWasUploaded( |
943 input_api, output_api)) | 946 input_api, output_api)) |
944 snapshot("done") | 947 snapshot("done") |
945 return results | 948 return results |
OLD | NEW |