Make google-java-format easier to use for non-chromium checkouts like R8

1. Use "codereview.settings" in addition to "buildtools" as the marker
   that identifies a project root.
2. Allow the presence of any .jar file to indicate the availability of
   google-java-format.
3. Do not pass --aosp when running google-java-format

Bug: 456461246
Change-Id: Id27b3c03f592a0ed73fb7a6b4dd662707a649166
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7102758
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
changes/58/7102758/4
Andrew Grieve 2 weeks ago committed by LUCI CQ
parent 251779412a
commit 33744dc6bc

@ -80,7 +80,8 @@ def _GetPrimarySolutionPathInternal(cwd):
return os.path.join(gclient_root, source_dir_name)
# Some projects might not use .gclient. Try to see whether we're in a git
# checkout that contains a 'buildtools' subdir.
# checkout that contains a "buildtools" directory or "codereview.settings"
# file.
top_dir = cwd
try:
top_dir = subprocess2.check_output(
@ -90,7 +91,8 @@ def _GetPrimarySolutionPathInternal(cwd):
except subprocess2.CalledProcessError:
pass
if os.path.exists(os.path.join(top_dir, 'buildtools')):
if (os.path.exists(os.path.join(top_dir, 'codereview.settings'))
or os.path.exists(os.path.join(top_dir, 'buildtools'))):
return top_dir
return None

@ -6839,7 +6839,14 @@ def _RunGoogleJavaFormat(opts, paths, top_dir, diffs):
print('google-java-format not found, skipping java formatting.')
return 0
base_cmd = [tool, '--aosp']
base_cmd = [tool]
# The script now adds --aosp, but this shim is needed for the window where
# devs are using depot_tools that is newer than their chromium checkout.
# This can be remove after Dec 2025.
if os.path.exists(
os.path.join(os.path.dirname(tool), 'chromium-overrides.jar')):
base_cmd += ['--aosp']
if not opts.diff:
if opts.dry_run:
base_cmd += ['--dry-run']

@ -9,6 +9,7 @@ you sync Chrome. This script finds and runs the executable.
"""
import gclient_paths
import glob
import os
import subprocess
import sys
@ -24,19 +25,16 @@ def FindGoogleJavaFormat():
# Make relative to solution root if not an absolute path.
return os.path.join(primary_solution_path, override)
bin_path = os.path.join(primary_solution_path, 'third_party',
'google-java-format', 'google-java-format')
cipd_path = os.path.join(primary_solution_path, 'third_party',
'google-java-format', 'cipd',
'google-java-format.jar')
bin_dir = os.path.join(primary_solution_path, 'third_party',
'google-java-format')
bin_path = os.path.join(bin_dir, 'google-java-format')
# Check that the .jar exists, since it is conditionally downloaded via
# DEPS conditions.
# TODO(b/345761161): Remove old os.path.exists(path + '.jar') check,
# when third_party/google-java-format
# -> third_party/google-java-format/cipd is fully rolled out.
if os.path.exists(bin_path) and (os.path.exists(bin_path + '.jar')
or os.path.exists(cipd_path)):
return bin_path
if os.path.exists(bin_path):
if glob.glob(os.path.join(bin_dir, '*.jar')) or glob.glob(
os.path.join(bin_dir, 'cipd', '*.jar')):
return bin_path
return None

Loading…
Cancel
Save