From d05ab352965e0333d751563cd54aa27aeb0b7971 Mon Sep 17 00:00:00 2001 From: "scottmg@chromium.org" Date: Fri, 5 Dec 2014 17:24:26 +0000 Subject: [PATCH] Add canned presubmit check for GN formatting Requires https://codereview.chromium.org/779883002/ to be landed/rolled before it's useful. R=dpranke@chromium.org BUG=348474 Review URL: https://codereview.chromium.org/779513005 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@293269 0039d316-1c4b-4281-b951-d872f2087c98 --- gn.py | 2 +- presubmit_canned_checks.py | 19 +++++++++++++++++++ tests/presubmit_unittest.py | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/gn.py b/gn.py index 325e685d7..7837dbddc 100755 --- a/gn.py +++ b/gn.py @@ -30,7 +30,7 @@ def main(args): print >> sys.stderr, 'gn.py: Could not find gn executable at: %s' % gn_path return 2 else: - return subprocess.call([gn_path] + sys.argv[1:]) + return subprocess.call([gn_path] + args[1:]) if __name__ == '__main__': diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 05b045de6..a93a4fddd 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 diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index 9df0b830e..593708068 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -1878,6 +1878,7 @@ class CannedChecksUnittest(PresubmitTestsBase): 'CheckLicense', 'CheckOwners', 'CheckPatchFormatted', + 'CheckGNFormatted', 'CheckRietveldTryJobExecution', 'CheckSingletonInHeaders', 'CheckSvnModifiedDirectories',