From 8b61f11e220a7865f3728254e2eae395473f779e Mon Sep 17 00:00:00 2001 From: "kylechar@chromium.org" Date: Fri, 5 Feb 2016 13:28:58 +0000 Subject: [PATCH] Make "git cl format" format GN files. Always formats full GN files that are modified since the format should be canonical. I tried to make it consistent in style with the existing formatters. I've tested running it locally. For "git cl format" it formats GN files. For "git cl format --diff" it outputs the full formatted files like clang but doesn't modify. For "git cl format --dry-run" it doesn't modify or output. TEST=Works running locally. BUG= Review URL: https://codereview.chromium.org/1666403002 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@298617 0039d316-1c4b-4281-b951-d872f2087c98 --- git_cl.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/git_cl.py b/git_cl.py index 8eda0dc62..5b5872bbd 100755 --- a/git_cl.py +++ b/git_cl.py @@ -3534,6 +3534,7 @@ def MatchingFileType(file_name, extensions): def CMDformat(parser, args): """Runs auto-formatting tools (clang-format etc.) on the diff.""" CLANG_EXTS = ['.cc', '.cpp', '.h', '.mm', '.proto', '.java'] + GN_EXTS = ['.gn', '.gni'] parser.add_option('--full', action='store_true', help='Reformat the full content of all touched files') parser.add_option('--dry-run', action='store_true', @@ -3574,6 +3575,7 @@ def CMDformat(parser, args): clang_diff_files = [x for x in diff_files if MatchingFileType(x, CLANG_EXTS)] python_diff_files = [x for x in diff_files if MatchingFileType(x, ['.py'])] dart_diff_files = [x for x in diff_files if MatchingFileType(x, ['.dart'])] + gn_diff_files = [x for x in diff_files if MatchingFileType(x, GN_EXTS)] top_dir = os.path.normpath( RunGit(["rev-parse", "--show-toplevel"]).rstrip('\n')) @@ -3655,6 +3657,16 @@ def CMDformat(parser, args): 'found in this checkout. Files in other languages are still ' + 'formatted.') + # 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') + for gn_diff_file in gn_diff_files: + stdout = RunCommand(cmd + [gn_diff_file], cwd=top_dir) + if opts.diff: + sys.stdout.write(stdout) + return return_value