Add `git cl format --mojom` for .mojom file formatting

This is not enabled by default because it is new and should be
considered beta.

Bug: 780263
Change-Id: I7a4813c7ac4cef7441c5373dff4bb1289e7b99b6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5259981
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Robert Sesek <rsesek@chromium.org>
changes/81/5259981/4
Robert Sesek 1 year ago committed by LUCI CQ
parent 7142bf166c
commit 911e2a0893

@ -6338,6 +6338,29 @@ def _RunGnFormat(opts, paths, top_dir, upstream_commit):
return return_value
def _RunMojomFormat(opts, paths, top_dir, upstream_commit):
primary_solution_path = gclient_paths.GetPrimarySolutionPath()
if not primary_solution_path:
DieWithError('Could not find the primary solution path (e.g. '
'the chromium checkout)')
mojom_format_path = os.path.join(primary_solution_path, 'mojo', 'public',
'tools', 'mojom', 'mojom_format.py')
if not os.path.exists(mojom_format_path):
DieWithError('Could not find mojom formater at '
f'"{mojom_format_path}"')
cmd = [mojom_format_path]
if opts.dry_run:
cmd.append('--dry-run')
cmd.extend(paths)
ret = subprocess2.call(cmd)
if opts.dry_run and ret != 0:
return 2
return ret
def _FormatXml(opts, paths, top_dir, upstream_commit):
# Skip the metrics formatting from the global presubmit hook. These files
# have a separate presubmit hook that issues an error if the files need
@ -6454,6 +6477,10 @@ def CMDformat(parser, args):
action='store_false',
help='Disables formatting of Swift file types using swift-format.')
parser.add_option('--mojom',
action='store_true',
help='Enables formatting of .mojom files.')
parser.add_option('--no-java',
action='store_true',
help='Disable auto-formatting of .java')
@ -6510,6 +6537,8 @@ def CMDformat(parser, args):
formatters += [(['.swift'], _RunSwiftFormat)]
if opts.python is not False:
formatters += [(['.py'], _RunYapf)]
if opts.mojom:
formatters += [(['.mojom'], _RunMojomFormat)]
top_dir = settings.GetRoot()
return_value = 0

Loading…
Cancel
Save