Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Unified Diff: PRESUBMIT.py

Issue 1434393003: Check DEPS during presubmit before uploads. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: PRESUBMIT.py
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 1ad3a5ea3e3339ac60f85cb8323c128271c016bd..459d3da755ed1706ab904c4349a2b6f65985759b 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -8,7 +8,66 @@ See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details about the presubmit API built into depot_tools.
"""
+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.
+ """
+ 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__.
+ original_sys_path = sys.path
+ try:
+ sys.path = sys.path + [input_api.os_path.join(
+ input_api.PresubmitLocalPath(), 'buildtools', '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(input_api.PresubmitLocalPath())
+
+ 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.PresubmitPromptOrNotify(
+ '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 CheckChangeOnUpload(input_api, output_api):
results = []
results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api)
+ results += _CheckUnwantedDependencies(input_api, output_api)
return results
+
+
+def CheckChangeOnCommit(input_api, output_api):
Tom Sepez 2015/11/13 17:36:20 Are you sure you want to turn commit time checks o
Lei Zhang 2015/11/13 23:27:27 It succeeds locally. Do you see any reasons why ch
+ return CheckChangeOnUpload(input_api, output_api)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698