Add a presubmit check to catch usage of Singleton<T> in header files.
BUG=65298
TEST=none
Review URL: http://codereview.chromium.org/5753006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69129 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 4a4f8579..311cb20 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -29,6 +29,24 @@
"\n"
)
+def _CheckSingletonInHeaders(input_api, output_api, source_file_filter):
+ """Checks to make sure no header files have |Singleton<|."""
+ pattern = input_api.re.compile(r'Singleton<')
+ files = []
+ for f in input_api.AffectedSourceFiles(source_file_filter):
+ if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or
+ f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')):
+ contents = input_api.ReadFile(f)
+ if pattern.search(contents):
+ files.append(f)
+
+ if len(files):
+ return [ output_api.PresubmitError(
+ 'Found Singleton<T> in the following header files.\n' +
+ 'Please move them to an appropriate source file so that the ' +
+ 'template gets instantiated in a single compilation unit.',
+ files) ]
+ return []
def _CheckConstNSObject(input_api, output_api, source_file_filter):
"""Checks to make sure no objective-c files have |const NSSomeClass*|."""
@@ -81,6 +99,8 @@
input_api, output_api, _LICENSE_HEADER, source_file_filter=sources))
results.extend(_CheckConstNSObject(
input_api, output_api, source_file_filter=sources))
+ results.extend(_CheckSingletonInHeaders(
+ input_api, output_api, source_file_filter=sources))
return results