Chromium Code Reviews| Index: PRESUBMIT.py |
| diff --git a/PRESUBMIT.py b/PRESUBMIT.py |
| index ba38fedca0196e563c275661bb01302b3ff8329a..cf2608a5a9bb0389558ec218e8136a628bf5c480 100644 |
| --- a/PRESUBMIT.py |
| +++ b/PRESUBMIT.py |
| @@ -9,7 +9,9 @@ for more details about the presubmit API built into gcl. |
| """ |
| +import os |
|
M-A Ruel
2012/07/26 13:09:38
Remove
Jói
2012/07/26 13:37:21
Done.
|
| import re |
| +import sys |
| _EXCLUDED_PATHS = ( |
| @@ -374,6 +376,55 @@ def _CheckNoPragmaOnce(input_api, output_api): |
| return [] |
| +def _CheckUnwantedDependencies(input_api, output_api): |
| + """Runs checkdeps on #include statements added in this |
| + change. Breaking - rules is an error, breaking ! rules is a |
| + warning. |
| + """ |
| + # 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__. |
| + original_sys_path = sys.path |
| + try: |
| + sys.path = sys.path + [os.path.join( |
|
M-A Ruel
2012/07/26 13:09:38
input_api.os_path.join(
Jói
2012/07/26 13:37:21
Done.
|
| + input_api.change.RepositoryRoot(), 'tools', 'checkdeps')] |
|
M-A Ruel
2012/07/26 13:09:38
It is relatively unsafe to use RepositoryRoot(). W
Jói
2012/07/26 13:37:21
Ah, sorry I missed that. Thanks for catching.
|
| + import checkdeps |
| + finally: |
| + # Restore sys.path to what it was before. |
| + sys.path = original_sys_path |
| + |
| + added_includes = [] |
| + for f in input_api.AffectedFiles(): |
| + if not checkdeps.ShouldCheckAddedIncludesInFile(f.LocalPath()): |
| + continue |
| + |
| + changed_lines = [line for line_num, line in f.ChangedContents()] |
| + added_includes.append([f.LocalPath(), changed_lines]) |
| + |
| + error_descriptions = [] |
| + warning_descriptions = [] |
| + for path, rule_type, rule_description in checkdeps.CheckAddedIncludes( |
| + added_includes): |
| + description_with_path = '%s\n %s' % (path, rule_description) |
| + if rule_type == checkdeps.Rule.DISALLOW: |
| + error_descriptions.append(description_with_path) |
| + else: |
| + warning_descriptions.append(description_with_path) |
| + |
| + results = [] |
| + if error_descriptions: |
| + results.append(output_api.PresubmitError( |
| + 'You added one or more #includes that violate checkdeps rules.', |
| + error_descriptions)) |
| + if warning_descriptions: |
| + results.append(output_api.PresubmitPromptWarning( |
|
M-A Ruel
2012/07/26 13:09:38
On commit, it would need to be a notification othe
Jói
2012/07/26 13:37:21
I would prefer if people need to jump through hoop
|
| + 'You added one or more #includes of files that are temporarily\n' |
| + 'allowed but being removed. Can you avoid introducing the\n' |
| + '#include? See relevant DEPS file(s) for details and contacts.', |
| + warning_descriptions)) |
| + return results |
| + |
| + |
| def _CommonChecks(input_api, output_api): |
| """Checks common to both upload and commit.""" |
| results = [] |
| @@ -388,6 +439,7 @@ def _CommonChecks(input_api, output_api): |
| results.extend(_CheckNoDEPSGIT(input_api, output_api)) |
| results.extend(_CheckNoBannedFunctions(input_api, output_api)) |
| results.extend(_CheckNoPragmaOnce(input_api, output_api)) |
| + results.extend(_CheckUnwantedDependencies(input_api, output_api)) |
| return results |