diff options
author | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-31 11:02:18 +0000 |
---|---|---|
committer | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-31 11:02:18 +0000 |
commit | 55f9f381b265246b184bf4f8b063edd23fe0ce01 (patch) | |
tree | e43cac3a5d455a590949db786ce21d5eba2df631 /PRESUBMIT.py | |
parent | e68504dac33c871b985769ba0ce2feb5d12eaa43 (diff) | |
download | chromium_src-55f9f381b265246b184bf4f8b063edd23fe0ce01.zip chromium_src-55f9f381b265246b184bf4f8b063edd23fe0ce01.tar.gz chromium_src-55f9f381b265246b184bf4f8b063edd23fe0ce01.tar.bz2 |
Add checkdeps presubmit check. Warns on new #includes of dependencies
we are working to eliminate, and errors on new #includes of disallowed
dependencies.
BUG=138280
Review URL: https://chromiumcodereview.appspot.com/10806049
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149167 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'PRESUBMIT.py')
-rw-r--r-- | PRESUBMIT.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 8954fae..05fd28b 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -10,6 +10,7 @@ for more details about the presubmit API built into gcl. import re +import sys _EXCLUDED_PATHS = ( @@ -374,6 +375,59 @@ 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 + [input_api.os_path.join( + input_api.PresubmitLocalPath(), 'tools', 'checkdeps')] + import checkdeps + from cpp_checker import CppChecker + from rules import Rule + finally: + # Restore sys.path to what it was before. + sys.path = original_sys_path + + added_includes = [] + for f in input_api.AffectedFiles(): + if not CppChecker.IsCppFile(f.LocalPath()): + continue + + changed_lines = [line for line_num, line in f.ChangedContents()] + added_includes.append([f.LocalPath(), changed_lines]) + + deps_checker = checkdeps.DepsChecker() + + error_descriptions = [] + warning_descriptions = [] + for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes( + added_includes): + description_with_path = '%s\n %s' % (path, rule_description) + if rule_type == 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( + '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 +442,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 |