Chromium Code Reviews| Index: base/PRESUBMIT.py |
| diff --git a/base/PRESUBMIT.py b/base/PRESUBMIT.py |
| index 732ac27e2a2ad81242510881a0978782f71229be..31d083b316805f9503af2b59120a603eb436bb4c 100644 |
| --- a/base/PRESUBMIT.py |
| +++ b/base/PRESUBMIT.py |
| @@ -8,6 +8,10 @@ See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| for more details on the presubmit API built into gcl. |
| """ |
| +import re |
| + |
| +CC_SOURCE_FILES=(r'^base/.*\.(cc|h|mm)$',) |
|
danakj
2014/10/07 14:33:23
BASE_?
Mostyn Bramley-Moore
2014/10/07 14:42:18
Done.
|
| + |
| def _CheckNoInterfacesInBase(input_api, output_api): |
| """Checks to make sure no files in libbase.a have |@interface|.""" |
| pattern = input_api.re.compile(r'^\s*@interface', input_api.re.MULTILINE) |
| @@ -36,8 +40,45 @@ def _CommonChecks(input_api, output_api): |
| results.extend(_CheckNoInterfacesInBase(input_api, output_api)) |
| return results |
| +def _CheckOverrideFinal(input_api, output_api, |
| + whitelist=CC_SOURCE_FILES, blacklist=None): |
| + """Make sure new lines of code don't use the OVERRIDE or FINAL macros.""" |
| + |
| + # TODO(mostynb): remove this check once the macros are removed |
| + # from base/compiler_specific.h. |
| + |
| + errors = [] |
| + |
| + source_file_filter = lambda x: input_api.FilterSourceFile( |
| + x, white_list=CC_SOURCE_FILES, black_list=None) |
| + |
| + override_files = [] |
| + final_files = [] |
| + |
| + for f in input_api.AffectedSourceFiles(source_file_filter): |
| + contents = input_api.ReadFile(f, 'rb') |
| + |
| + # "override" and "final" should be used instead of OVERRIDE/FINAL now. |
| + if re.search(r"\bOVERRIDE\b", contents): |
| + override_files.append(f.LocalPath()) |
| + |
| + if re.search(r"\bFINAL\b", contents): |
| + final_files.append(f.LocalPath()) |
| + |
| + if override_files: |
| + return [output_api.PresubmitError( |
| + 'These files use OVERRIDE instead of using override:', |
| + items=override_files)] |
| + if final_files: |
| + return [output_api.PresubmitError( |
| + 'These files use FINAL instead of using final:', |
| + items=final_files)] |
| + |
| + return [] |
| + |
| def CheckChangeOnUpload(input_api, output_api): |
| results = [] |
| + results.extend(_CheckOverrideFinal(input_api, output_api)) |
| results.extend(_CommonChecks(input_api, output_api)) |
| return results |