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 """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 os as _os | 7 import os as _os |
8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) | 8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) |
9 | 9 |
10 # Justifications for each filter: | 10 # Justifications for each filter: |
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
963 if input_api.is_committing: | 963 if input_api.is_committing: |
964 res_type = output_api.PresubmitPromptWarning | 964 res_type = output_api.PresubmitPromptWarning |
965 else: | 965 else: |
966 res_type = output_api.PresubmitNotifyResult | 966 res_type = output_api.PresubmitNotifyResult |
967 return [ res_type('|const NSClass*| is wrong, see ' + | 967 return [ res_type('|const NSClass*| is wrong, see ' + |
968 'http://dev.chromium.org/developers/clang-mac', | 968 'http://dev.chromium.org/developers/clang-mac', |
969 files) ] | 969 files) ] |
970 return [] | 970 return [] |
971 | 971 |
972 | 972 |
973 def CheckSingletonInHeaders(input_api, output_api, source_file_filter=None): | 973 def CheckSingletonInHeaders(input_api, output_api, source_file_filter=None): |
M-A Ruel
2015/02/13 17:04:18
I wonder why this check is in presubmit_canned_che
| |
974 """Checks to make sure no header files have |Singleton<|.""" | 974 """Checks to make sure no header files have |Singleton<|.""" |
975 pattern = input_api.re.compile(r'(?<!class\s)Singleton\s*<') | 975 pattern = input_api.re.compile(r'(?<!class\s)Singleton\s*<') |
976 files = [] | 976 files = [] |
977 for f in input_api.AffectedSourceFiles(source_file_filter): | 977 for f in input_api.AffectedSourceFiles(source_file_filter): |
978 if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or | 978 if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or |
979 f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')): | 979 f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')): |
980 # It's ok for base/memory/singleton.h to have |Singleton<|. | |
981 singleton_h_path = input_api.os_path.join( | |
982 'base', 'memory', 'singleton.h') | |
M-A Ruel
2015/02/13 17:04:17
You can't hardcode src.git paths here.
| |
983 if f.LocalPath().endswith(singleton_h_path): | |
984 break | |
980 contents = input_api.ReadFile(f) | 985 contents = input_api.ReadFile(f) |
981 for line in contents.splitlines(False): | 986 for line in contents.splitlines(False): |
982 if (not input_api.re.match(r'//', line) and # Strip C++ comment. | 987 if (not input_api.re.match(r'//', line) and # Strip C++ comment. |
983 pattern.search(line)): | 988 pattern.search(line)): |
984 files.append(f) | 989 files.append(f) |
985 break | 990 break |
986 | 991 |
987 if files: | 992 if files: |
988 return [ output_api.PresubmitError( | 993 return [ output_api.PresubmitError( |
989 'Found Singleton<T> in the following header files.\n' + | 994 'Found Singleton<T> in the following header files.\n' + |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1134 for f in affected_files: | 1139 for f in affected_files: |
1135 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] | 1140 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] |
1136 rc = gn.main(cmd) | 1141 rc = gn.main(cmd) |
1137 if rc == 2: | 1142 if rc == 2: |
1138 warnings.append(output_api.PresubmitPromptWarning( | 1143 warnings.append(output_api.PresubmitPromptWarning( |
1139 '%s requires formatting. Please run `gn format --in-place %s`.' % ( | 1144 '%s requires formatting. Please run `gn format --in-place %s`.' % ( |
1140 f.AbsoluteLocalPath(), f.LocalPath()))) | 1145 f.AbsoluteLocalPath(), f.LocalPath()))) |
1141 # It's just a warning, so ignore other types of failures assuming they'll be | 1146 # It's just a warning, so ignore other types of failures assuming they'll be |
1142 # caught elsewhere. | 1147 # caught elsewhere. |
1143 return warnings | 1148 return warnings |
OLD | NEW |