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

Unified Diff: presubmit_canned_checks.py

Issue 779513005: Add canned presubmit check for GN formatting (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 6 years 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 | « gn.py ('k') | tests/presubmit_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: presubmit_canned_checks.py
diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py
index 05b045de61fc5b22668322d61265db3d0c04020a..a93a4fddd5c6f54dbd66d898009fe5b422ebff22 100644
--- a/presubmit_canned_checks.py
+++ b/presubmit_canned_checks.py
@@ -1113,3 +1113,22 @@ def CheckPatchFormatted(input_api, output_api):
# As this is just a warning, ignore all other errors if the user
# happens to have a broken clang-format, doesn't use git, etc etc.
return []
+
+
+def CheckGNFormatted(input_api, output_api):
+ import gn
+ affected_files = input_api.AffectedFiles(
+ include_deletes=False,
+ file_filter=lambda x: x.LocalPath().endswith('.gn') or
+ x.LocalPath().endswith('.gni'))
+ warnings = []
+ for f in affected_files:
+ cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()]
+ rc = gn.main(cmd)
+ if rc == 2:
+ warnings.append(output_api.PresubmitPromptWarning(
+ '%s requires formatting. Please run `gn format --in-place %s`.' % (
+ f.AbsoluteLocalPath(), f.LocalPath())))
+ # It's just a warning, so ignore other types of failures assuming they'll be
+ # caught elsewhere.
+ return warnings
« no previous file with comments | « gn.py ('k') | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698