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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « gn.py ('k') | tests/presubmit_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Generic presubmit checks that can be reused by other presubmit checks.""" 5 """Generic presubmit checks that can be reused by other presubmit checks."""
6 6
7 import os as _os 7 import os as _os
8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) 8 _HERE = _os.path.dirname(_os.path.abspath(__file__))
9 9
10 10
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 code, _ = git_cl.RunGitWithCode(cmd, suppress_stderr=True) 1106 code, _ = git_cl.RunGitWithCode(cmd, suppress_stderr=True)
1107 if code == 2: 1107 if code == 2:
1108 return [output_api.PresubmitPromptWarning( 1108 return [output_api.PresubmitPromptWarning(
1109 'The %s directory requires clang-formatting. ' 1109 'The %s directory requires clang-formatting. '
1110 'Please run git cl format %s' % 1110 'Please run git cl format %s' %
1111 (input_api.basename(input_api.PresubmitLocalPath()), 1111 (input_api.basename(input_api.PresubmitLocalPath()),
1112 input_api.basename(input_api.PresubmitLocalPath())))] 1112 input_api.basename(input_api.PresubmitLocalPath())))]
1113 # As this is just a warning, ignore all other errors if the user 1113 # As this is just a warning, ignore all other errors if the user
1114 # happens to have a broken clang-format, doesn't use git, etc etc. 1114 # happens to have a broken clang-format, doesn't use git, etc etc.
1115 return [] 1115 return []
1116
1117
1118 def CheckGNFormatted(input_api, output_api):
1119 import gn
1120 affected_files = input_api.AffectedFiles(
1121 include_deletes=False,
1122 file_filter=lambda x: x.LocalPath().endswith('.gn') or
1123 x.LocalPath().endswith('.gni'))
1124 warnings = []
1125 for f in affected_files:
1126 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()]
1127 rc = gn.main(cmd)
1128 if rc == 2:
1129 warnings.append(output_api.PresubmitPromptWarning(
1130 '%s requires formatting. Please run `gn format --in-place %s`.' % (
1131 f.AbsoluteLocalPath(), f.LocalPath())))
1132 # It's just a warning, so ignore other types of failures assuming they'll be
1133 # caught elsewhere.
1134 return warnings
OLDNEW
« 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