Chromium Code Reviews| Index: PRESUBMIT.py |
| diff --git a/PRESUBMIT.py b/PRESUBMIT.py |
| index 6751f06d18b4676e92e14bba1c44d6b3379c4ed3..6c4d8d16f6c163ca3a1bfc4efbffe3c24b843c8a 100644 |
| --- a/PRESUBMIT.py |
| +++ b/PRESUBMIT.py |
| @@ -9,10 +9,6 @@ for more details about the presubmit API built into gcl. |
| """ |
| -import re |
| -import sys |
| - |
| - |
| _EXCLUDED_PATHS = ( |
| r"^breakpad[\\\/].*", |
| r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_rules.py", |
| @@ -517,6 +513,7 @@ def _CheckUnwantedDependencies(input_api, output_api): |
| change. Breaking - rules is an error, breaking ! rules is a |
| warning. |
| """ |
| + import sys |
| # We need to wait until we have an input_api object and use this |
| # roundabout construct to import checkdeps because this file is |
| # eval-ed and thus doesn't have __file__. |
| @@ -567,6 +564,7 @@ def _CheckUnwantedDependencies(input_api, output_api): |
| def _CheckFilePermissions(input_api, output_api): |
| """Check that all files have their permissions properly set.""" |
| + import sys |
| if input_api.platform == 'win32': |
| return [] |
| args = [sys.executable, 'tools/checkperms/checkperms.py', '--root', |
| @@ -969,14 +967,14 @@ def _CheckSpamLogging(input_api, output_api): |
| for f in input_api.AffectedSourceFiles(source_file_filter): |
| contents = input_api.ReadFile(f, 'rb') |
| - if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents): |
| + if input_api.re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents): |
| log_info.append(f.LocalPath()) |
| - elif re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents): |
| + elif input_api.re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents): |
| log_info.append(f.LocalPath()) |
| - if re.search(r"\bprintf\(", contents): |
| + if input_api.re.search(r"\bprintf\(", contents): |
| printf.append(f.LocalPath()) |
| - elif re.search(r"\bfprintf\((stdout|stderr)", contents): |
| + elif input_api.re.search(r"\bfprintf\((stdout|stderr)", contents): |
| printf.append(f.LocalPath()) |
| if log_info: |
| @@ -1198,6 +1196,7 @@ def _CheckParseErrors(input_api, output_api): |
| def _CheckJavaStyle(input_api, output_api): |
| """Runs checkstyle on changed java files and returns errors if any exist.""" |
| + import sys |
| original_sys_path = sys.path |
| try: |
| sys.path = sys.path + [input_api.os_path.join( |
| @@ -1259,6 +1258,23 @@ def _CheckNoDeprecatedCSS(input_api, output_api): |
| (fpath.LocalPath(), line_num, deprecated_value, value))) |
| return results |
| + |
| +def _CheckForOverrideAndFinalRules(input_api, output_api): |
| + """Checks for override and final used as per C++11""" |
| + problems = [] |
| + for f in input_api.AffectedFiles(): |
| + if (f.LocalPath().endswith(('.cc', '.mm', '.cpp', '.h'))): |
|
M-A Ruel
2014/10/15 12:57:03
sort the items in the tuple
MRV
2014/10/15 13:34:46
Done.
|
| + for line_num, line in f.ChangedContents(): |
| + if (input_api.re.search(r"\b(OVERRIDE|FINAL)\b", line)): |
|
M-A Ruel
2014/10/15 12:57:03
FINAL|OVERRIDE
And use single quotes consistently
MRV
2014/10/15 13:34:46
Done.
M-A Ruel
2014/10/15 13:59:22
I meant r'\b(FINAL|OVERRIDE)\b' in the same order
|
| + problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
| + |
| + if not problems: |
| + return [] |
| + return [output_api.PresubmitError('Use C++11\'s |override| and |final| ' |
| + 'rather than OVERRIDE and FINAL.' |
|
M-A Ruel
2014/10/15 12:57:03
comma always at the end of the string, never at th
MRV
2014/10/15 13:34:46
Done.
|
| + , problems)] |
| + |
| + |
| def _CommonChecks(input_api, output_api): |
| """Checks common to both upload and commit.""" |
| results = [] |
| @@ -1300,6 +1316,7 @@ def _CommonChecks(input_api, output_api): |
| results.extend(_CheckNoDeprecatedCSS(input_api, output_api)) |
| results.extend(_CheckParseErrors(input_api, output_api)) |
| results.extend(_CheckForIPCRules(input_api, output_api)) |
| + results.extend(_CheckForOverrideAndFinalRules(input_api, output_api)) |
| if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): |
| results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |
| @@ -1453,7 +1470,7 @@ def _CheckForUsingSideEffectsOfPass(input_api, output_api): |
| if f.LocalPath().endswith(('.h', '.c', '.cc', '.m', '.mm')): |
| for lnum, line in f.ChangedContents(): |
| # Disallow Foo(*my_scoped_thing.Pass()); See crbug.com/418297. |
| - if re.search(r'\*[a-zA-Z0-9_]+\.Pass\(\)', line): |
| + if input_api.re.search(r'\*[a-zA-Z0-9_]+\.Pass\(\)', line): |
| errors.append(output_api.PresubmitError( |
| ('%s:%d uses *foo.Pass() to delete the contents of scoped_ptr. ' + |
| 'See crbug.com/418297.') % (f.LocalPath(), lnum))) |
| @@ -1647,6 +1664,7 @@ def CheckChangeOnCommit(input_api, output_api): |
| def GetPreferredTryMasters(project, change): |
| + import re |
| files = change.LocalPaths() |
| if not files or all(re.search(r'[\\\/]OWNERS$', f) for f in files): |