Chromium Code Reviews| Index: presubmit_canned_checks.py | 
| =================================================================== | 
| --- presubmit_canned_checks.py (revision 79277) | 
| +++ presubmit_canned_checks.py (working copy) | 
| @@ -4,6 +4,9 @@ | 
| """Generic presubmit checks that can be reused by other presubmit checks.""" | 
| +import time | 
| + | 
| + | 
| ### Description checks | 
| def CheckChangeHasTestField(input_api, output_api): | 
| @@ -679,3 +682,126 @@ | 
| approvers.append(m['sender']) | 
| return set(approvers) | 
| + | 
| +_TEXT_FILES = ( | 
| 
 
M-A Ruel
2011/03/24 17:08:04
Maybe better to be local variables?
 
bradn
2011/03/24 17:29:03
Done.
 
 | 
| + r".*\.txt", | 
| + r".*\.json", | 
| +) | 
| + | 
| +_LICENSE_HEADER = ( | 
| + r".*? Copyright \(c\) %(year)s The %(project)s Authors\. " | 
| 
 
M-A Ruel
2011/03/24 17:08:04
I prefer ' but I'm silly.
 
bradn
2011/03/24 17:29:03
Done.
 
 | 
| + r"All rights reserved\.\n" | 
| + r".*? Use of this source code is governed by a BSD-style license that can " | 
| + "be\n" | 
| + r".*? found in the LICENSE file\." | 
| + "\n" | 
| +) | 
| + | 
| + | 
| +def _CheckConstNSObject(input_api, output_api, source_file_filter): | 
| + """Checks to make sure no objective-c files have |const NSSomeClass*|.""" | 
| + pattern = input_api.re.compile(r'const\s+NS\w*\s*\*') | 
| + files = [] | 
| + for f in input_api.AffectedSourceFiles(source_file_filter): | 
| + if f.LocalPath().endswith('.h') or f.LocalPath().endswith('.mm'): | 
| 
 
M-A Ruel
2011/03/24 17:08:04
source_file_filter should be doing the filtering a
 
bradn
2011/03/24 17:29:03
Done.
 
 | 
| + contents = input_api.ReadFile(f) | 
| + if pattern.search(contents): | 
| + files.append(f) | 
| + | 
| + if len(files): | 
| 
 
M-A Ruel
2011/03/24 17:08:04
if files:
 
bradn
2011/03/24 17:29:03
Done.
 
 | 
| + if input_api.is_committing: | 
| + res_type = output_api.PresubmitPromptWarning | 
| + else: | 
| + res_type = output_api.PresubmitNotifyResult | 
| + return [ res_type('|const NSClass*| is wrong, see ' + | 
| + 'http://dev.chromium.org/developers/clang-mac', | 
| + files) ] | 
| + return [] | 
| + | 
| + | 
| +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): | 
| 
 
M-A Ruel
2011/03/24 17:08:04
if files:
 
bradn
2011/03/24 17:29:03
Done.
 
 | 
| + 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 PanProjectChecks(input_api, output_api, | 
| + excluded_paths=None, text_files=None, | 
| + license_header=None, project_name=None): | 
| + """Checks that ALL chromium orbit projects should use. | 
| + | 
| + These are checks to be run on all Chromium orbit project, including: | 
| + Chromium | 
| + Native Client | 
| + V8 | 
| + When you update this function, please take this broad scope into account. | 
| + Args: | 
| + input_api: Bag of input related interfaces. | 
| + output_api: Bag of output related interfaces. | 
| + excluded_paths: Don't include these paths in common checks. | 
| + text_files: Which file are to be treated as documentation text files. | 
| + license_header: What license header should be on files. | 
| + project_name: What is the name of the project as it appears in the license. | 
| + Returns: | 
| + A list of warning or error objects. | 
| + """ | 
| + if excluded_paths is None: | 
| + excluded_paths = tuple() | 
| + if text_files is None: | 
| + text_files = _TEXT_FILES | 
| + if project_name is None: | 
| 
 
M-A Ruel
2011/03/24 17:08:04
project_name = project_name or 'Chromium'
same fo
 
bradn
2011/03/24 17:29:03
Done.
 
 | 
| + project_name = 'Chromium' | 
| + if license_header is None: | 
| + license_header = _LICENSE_HEADER % { | 
| + 'year': time.strftime("%Y"), | 
| + 'project': project_name, | 
| + } | 
| + | 
| + results = [] | 
| + # What does this code do? | 
| 
 
M-A Ruel
2011/03/24 17:08:04
funny but unnecessary.
 
bradn
2011/03/24 17:29:03
Done.
 
 | 
| + # It loads the default black list (e.g. third_party, experimental, etc) and | 
| + # add our black list (breakpad, skia and v8 are still not following | 
| + # google style and are not really living this repository). | 
| + # See presubmit_support.py InputApi.FilterSourceFile for the (simple) usage. | 
| + black_list = input_api.DEFAULT_BLACK_LIST + excluded_paths | 
| + white_list = input_api.DEFAULT_WHITE_LIST + text_files | 
| + sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list) | 
| + text_files = lambda x: input_api.FilterSourceFile(x, black_list=black_list, | 
| + white_list=white_list) | 
| + | 
| + # TODO(dpranke): enable upload as well | 
| 
 
M-A Ruel
2011/03/24 17:08:04
I'm not sure Dirk is ready to enable it for NaCl a
 
bradn
2011/03/24 17:29:03
Uh, NaCl's trying it out, that's what's prompted t
 
 | 
| + if input_api.is_committing: | 
| + results.extend(input_api.canned_checks.CheckOwners( | 
| + input_api, output_api, source_file_filter=sources)) | 
| + | 
| + results.extend(input_api.canned_checks.CheckLongLines( | 
| + input_api, output_api, source_file_filter=sources)) | 
| + results.extend(input_api.canned_checks.CheckChangeHasNoTabs( | 
| + input_api, output_api, source_file_filter=sources)) | 
| + results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace( | 
| + input_api, output_api, source_file_filter=sources)) | 
| + results.extend(input_api.canned_checks.CheckChangeSvnEolStyle( | 
| + input_api, output_api, source_file_filter=text_files)) | 
| + results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( | 
| + input_api, output_api)) | 
| + results.extend(input_api.canned_checks.CheckLicense( | 
| + 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 |