Index: PRESUBMIT.py |
diff --git a/PRESUBMIT.py b/PRESUBMIT.py |
index 900e7c9ba418374119751ad8996bd01bcc15d673..4b26a4315f0df12cb252b54e68fdc6c7586d7a14 100644 |
--- a/PRESUBMIT.py |
+++ b/PRESUBMIT.py |
@@ -1517,6 +1517,29 @@ def _CheckSingletonInHeaders(input_api, output_api): |
return [] |
+def _CheckBaseMacrosInHeaders(input_api, output_api): |
+ """Check for base/macros.h if DISALLOW_* macro is used.""" |
+ |
+ disallows = ['DISALLOW_%s' % s for s in ('ASSIGN', 'COPY', 'EVIL')] |
M-A Ruel
2015/10/16 21:09:25
I'd call this an early generalisation;
disallows
Dan Beam
2015/10/16 21:24:15
Done. (those 2 characters thank you!)
|
+ macros = '#include "base/macros.h"' |
+ basictypes = '#include "base/basictypes.h"' |
+ |
+ files = [] |
+ for f in input_api.AffectedSourceFiles(None): |
+ if not f.LocalPath().endswith('.h'): |
+ continue |
+ for line_num, line in f.ChangedContents(): |
+ if any(d in line for d in disallows): |
+ contents = input_api.ReadFile(f) |
+ if not (macros in contents or basictypes in contents): |
+ files.append(f) |
+ break |
+ |
+ msg = ('The following files appear to be using DISALLOW_* macros.\n' |
+ 'Please #include "base/macros.h" in them.') |
+ return [output_api.PresubmitError(msg, files)] if files else [] |
+ |
+ |
_DEPRECATED_CSS = [ |
# Values |
( "-webkit-box", "flex" ), |
@@ -1646,6 +1669,7 @@ def _CommonChecks(input_api, output_api): |
results.extend(_CheckForCopyrightedCode(input_api, output_api)) |
results.extend(_CheckForWindowsLineEndings(input_api, output_api)) |
results.extend(_CheckSingletonInHeaders(input_api, output_api)) |
+ results.extend(_CheckBaseMacrosInHeaders(input_api, output_api)) |
if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): |
results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |