Commit bb909b5a authored by Tamer Tas's avatar Tamer Tas Committed by Commit Bot

[tools] auto-format unformatted Torque source files

Presubmit script complains when an unformatted Torque file is submitted.

This CL automates the formatting process of the Torque files.

Presubmit script is run before every 'git cl upload', the workflow will make
sure that the upload is canceled, but the files are formatted.

Bug: chromium:898436, v8:8805
Change-Id: I821ce36907c62e222451e883c5e3e18a9359f20e
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/1458222Reviewed-by: 's avatarDaniel Clifford <danno@chromium.org>
Reviewed-by: 's avatarSergiy Belozorov <sergiyb@chromium.org>
Commit-Queue: Tamer Tas <tmrts@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59453}
parent c6d21691
......@@ -86,7 +86,7 @@ def postprocess(output):
return output
def process(filename, only_lint, use_stdout):
def process(filename, lint, should_format):
with open(filename, 'r') as content_file:
content = content_file.read()
......@@ -100,12 +100,11 @@ def process(filename, only_lint, use_stdout):
print "error code " + str(rc) + " running clang-format. Exiting..."
sys.exit(rc);
if only_lint:
if lint:
if (output != original_input):
print >>sys.stderr, filename + ' requires formatting'
elif use_stdout:
print output
else:
if should_format:
output_file = open(filename, 'w')
output_file.write(output);
output_file.close()
......@@ -122,20 +121,28 @@ def Main():
print_usage();
sys.exit(-1)
def is_option(arg):
return arg in ['-i', '-l', '-il']
should_format = lint = False
use_stdout = True
lint = False
if sys.argv[1] == '-i':
use_stdout = False
elif sys.argv[1] == '-l':
lint = True
flag, files = sys.argv[1], sys.argv[2:]
if is_option(flag):
if '-i' == flag:
should_format = True
elif '-l' == flag:
lint = True
else:
lint = True
should_format = True
else:
print "error: -i or -l must be specified as the first argument"
print "error: -i and/or -l flags must be specified"
print_usage();
sys.exit(-1);
for filename in sys.argv[2:]:
process(filename, lint, use_stdout)
for filename in files:
process(filename, lint, should_format)
return 0
......
......@@ -114,7 +114,8 @@ def TorqueLintWorker(command):
error_count += 1
sys.stdout.write(out_lines)
if error_count != 0:
sys.stdout.write("tip: use 'tools/torque/format-torque.py -i <filename>'\n");
sys.stdout.write(
"warning: formatting and overwriting unformatted Torque files\n")
return error_count
except KeyboardInterrupt:
process.kill()
......@@ -371,7 +372,7 @@ class TorqueLintProcessor(CacheableSourceFileProcessor):
def GetProcessorScript(self):
torque_tools = os.path.join(TOOLS_PATH, "torque")
torque_path = os.path.join(torque_tools, "format-torque.py")
arguments = ['-l']
arguments = ["-il"]
if os.path.isfile(torque_path):
return torque_path, arguments
......
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