Commit 4b8ed59b authored by brettw's avatar brettw Committed by Commit bot

Update "git cl format" for GN changes.

"gn format" changed to remove the --in-place argument. This updates the
instructions for formatting and fixes existing usage.

git cl format --diff never worked, it just printed the full formatted output
unconditionally. This change improves things slightly by indicating there's a
diff for a file. A proper diff can be hooked up in a later stage if somebody
so desires.

Review-Url: https://codereview.chromium.org/2220123002
parent d7553298
......@@ -4983,15 +4983,24 @@ def CMDformat(parser, args):
# Format GN build files. Always run on full build files for canonical form.
if gn_diff_files:
cmd = ['gn', 'format']
if not opts.dry_run and not opts.diff:
cmd.append('--in-place')
cmd = ['gn', 'format' ]
if opts.dry_run or opts.diff:
cmd.append('--dry-run')
for gn_diff_file in gn_diff_files:
stdout = RunCommand(cmd + [gn_diff_file],
shell=sys.platform == 'win32',
cwd=top_dir)
if opts.diff:
sys.stdout.write(stdout)
gn_ret = subprocess2.call(cmd + [gn_diff_file],
shell=sys.platform == 'win32',
cwd=top_dir)
if opts.dry_run and gn_ret == 2:
return_value = 2 # Not formatted.
elif opts.diff and gn_ret == 2:
# TODO this should compute and print the actual diff.
print("This change has GN build file diff for " + gn_diff_file)
elif gn_ret != 0:
# For non-dry run cases (and non-2 return values for dry-run), a
# nonzero error code indicates a failure, probably because the file
# doesn't parse.
DieWithError("gn format failed on " + gn_diff_file +
"\nTry running 'gn format' on this file manually.")
return return_value
......
......@@ -1178,7 +1178,7 @@ def CheckGNFormatted(input_api, output_api):
rc = gn.main(cmd)
if rc == 2:
warnings.append(output_api.PresubmitPromptWarning(
'%s requires formatting. Please run `gn format --in-place %s`.' % (
'%s requires formatting. Please run:\n gn format %s' % (
f.AbsoluteLocalPath(), f.LocalPath())))
# It's just a warning, so ignore other types of failures assuming they'll be
# caught elsewhere.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment