diff --git a/build/commands/lib/util.js b/build/commands/lib/util.js index f3d8777ce0b6..43fea119c053 100755 --- a/build/commands/lib/util.js +++ b/build/commands/lib/util.js @@ -512,7 +512,7 @@ const util = { let cmd_options = config.defaultOptions cmd_options.cwd = config.braveCoreDir cmd_options = mergeWithDefault(cmd_options) - util.run('vpython', [path.join(config.braveCoreDir, 'build', 'commands', 'scripts', 'format.py')], cmd_options) + util.run('vpython', [path.join(config.braveCoreDir, 'build', 'commands', 'scripts', 'format.py'), options.full ? '--full' : ''], cmd_options) }, diff --git a/build/commands/scripts/commands.js b/build/commands/scripts/commands.js index 21493a5ab30b..622a09f84f8c 100755 --- a/build/commands/scripts/commands.js +++ b/build/commands/scripts/commands.js @@ -208,6 +208,7 @@ program program .command('format') + .option('--full', 'format all lines in changed files instead of only the changed lines') .action(util.format) program diff --git a/build/commands/scripts/format.py b/build/commands/scripts/format.py index d9e19866c184..197a3b03b066 100644 --- a/build/commands/scripts/format.py +++ b/build/commands/scripts/format.py @@ -19,7 +19,7 @@ def main(args): """Runs clang-format and gn format on the current changelist.""" parser = git_cl.OptionParser() - options, args = parser.parse_args(args) + parser.parse_args([]) # Change the current working directory before calling so that it # shows the correct base. @@ -27,7 +27,8 @@ def main(args): previous_cwd = os.getcwd() os.chdir(settings.GetRoot()) try: - cmd = ['cl', 'format', '--full'] + args + cmd = ['cl', 'format'] + args + print('git ' + ' '.join(cmd)) git_cl.RunGit(cmd) except: e = sys.exc_info()[1] diff --git a/build/commands/scripts/lint.py b/build/commands/scripts/lint.py index e823c8812db3..cb6fae1a449c 100644 --- a/build/commands/scripts/lint.py +++ b/build/commands/scripts/lint.py @@ -18,8 +18,8 @@ import git_cl import git_common -def HasFormatErrors(): - print('Running git cl format and gn format...') +def HasFormatErrors(base_commit): + print('Running git cl format and gn format on the diff from %s...' % base_commit) # For more options, see vendor/depot_tools/git_cl.py cmd = ['cl', 'format', '--diff'] diff = git_cl.RunGit(cmd) @@ -55,11 +55,11 @@ def main(args): # Check for clang/gn format errors. cl = git_cl.Changelist() + upstream_branch = cl.GetUpstreamBranch() + upstream_commit = git_cl.RunGit(['merge-base', 'HEAD', upstream_branch]) try: - if HasFormatErrors(): - upstream_branch = cl.GetUpstreamBranch() - upstream_commit = git_cl.RunGit(['merge-base', 'HEAD', upstream_branch]) - print('Format check failed against commit %s. Run npm format to fix.' % upstream_commit) + if HasFormatErrors(upstream_commit): + print('Format check failed. Run npm format to fix.') exit_code = 1 except: e = sys.exc_info()[1] @@ -69,7 +69,7 @@ def main(args): if exit_code == 0: print('Format check succeeded.') - print('Running lint...') + print('Running cpplint...') try: files = cl.GetAffectedFiles(git_common.get_or_create_merge_base(cl.GetBranch(), options.base_branch)) if not files: @@ -98,7 +98,7 @@ def main(args): print('Skipping file %s' % filename) finally: os.chdir(previous_cwd) - print('Total errors found: %d\n' % cpplint._cpplint_state.error_count) + print('cpplint errors found: %d\n' % cpplint._cpplint_state.error_count) if cpplint._cpplint_state.error_count != 0: return 1 return exit_code