16 Commits

Author SHA1 Message Date
Scott Lee
67741248cf skip printing a warning message for missing .gclient_entries on cog
The function prints a warning message when it finds that
a given directory contains .gclient only without .gclient_entries.

It can possibly happen if gclient sync execution is halted
in the middle, and it causes format function commands to mess up
the format output with the warning message.

This CL is to bypass the warning in Cog env. Find more context
visit the linked bug.

Bug: 450901048
Change-Id: I87e376e9a64c8e2ce2231dc9549e0683a9f393ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7133882
Commit-Queue: Scott Lee <ddoman@chromium.org>
Auto-Submit: Scott Lee <ddoman@chromium.org>
Reviewed-by: Terrence Reilly <treilly@google.com>
2025-11-10 13:01:27 -08:00
Andrew Grieve
33744dc6bc 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>
2025-10-30 12:05:33 -07:00
Fumitoshi Ukai
f80f5bc99e autoninja: support running from outside of workspace
gclient_paths.GetPrimarySolutionPath() finds primary
solution path from current directory, so it would fail
if it is invoked from outside of workspace.

Pass directory to gclient_paths.GetPrimarySolutionPath
so it could find workspace correctly if it is invoked
ninja outside of workspace.

Bug: 441240584
Change-Id: I873f7883873e143ec8a64ee0e636042ac2336a2a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6898614
Auto-Submit: Fumitoshi Ukai <ukai@google.com>
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Scott Lee <ddoman@chromium.org>
Reviewed-by: Takuto Ikuta <tikuta@chromium.org>
2025-09-02 13:08:00 -07:00
Gavin Mak
4edb194e91 Set rootRepo custom-keyed-value push option on upload
This associates a CL with its superproject.

Bug: 401148931
Change-Id: I7fe7bd91485e6e1066963b25f1b95980db6d3381
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6476918
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Gavin Mak <gavinmak@google.com>
2025-04-29 09:30:41 -07:00
Yiwei Zhang
e6f497f72b gclient: resolve symlink in gclient_entries before checking with current path
This allows repo to be symlinked in the workspace and gclient config is
pointing to the symlink. For example, if repo is checked out at
`${WS}/chromium`, a symlink is created from `${WS}/src` and ${WS}/.gclient 
is pointing to `${WS}/src`, when the code is trying to determine the
gclient root with cwd=`${WS}/chromium/XXX/XXX`, the code won't treat ${WS}
as the workspace root. Because .gclient_entries all started with `src/`
and `${WS}/chromium/XXX/XXX` won't match anything in .gclient_entries.

The fix here is to calculate the realpath (i.e. resolving the symlink)
for all paths in .gclient_entries and path_to_check before comparison.

Change-Id: I914ba5a7131588fa99d6900ada954f3694dda197
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5656593
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
2024-06-26 16:15:53 +00:00
Andrew Grieve
6e8c18239d Cache values in gclient_paths.py
Several clients of this module call its methods repeatedly. Cache them
to speed them up.

E.g. "autosiso" calls FindGclientRoot() 5 times before building
E.g. "git cl format" calls it 5 times in one of my CLs.

Bug: None
Change-Id: I70995c2def9689d46a89896640cc748d9629df3b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4904697
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
2023-10-03 20:36:59 +00:00
Mike Frysinger
124bb8e53c switch to 4 space indent
Leave the recipes/ code at 2 space to match the rest of the recipes
project in other repos.

Reformatted using:
files=( $(
	git ls-tree -r --name-only HEAD | \
		grep -Ev -e '^(third_party|recipes)/' | \
		grep '\.py$';
	git grep -l '#!/usr/bin/env.*python' | grep -v '\.py$'
) )
parallel ./yapf -i -- "${files[@]}"
~/chromiumos/chromite/contrib/reflow_overlong_comments "${files[@]}"

The files that still had strings that were too long were manually
reformatted because they were easy and only a few issues.
autoninja.py
clang_format.py
download_from_google_storage.py
fix_encoding.py
gclient_utils.py
git_cache.py
git_common.py
git_map_branches.py
git_reparent_branch.py
gn.py
my_activity.py
owners_finder.py
presubmit_canned_checks.py
reclient_helper.py
reclientreport.py
roll_dep.py
rustfmt.py
siso.py
split_cl.py
subcommand.py
subprocess2.py
swift_format.py
upload_to_google_storage.py

These files still had lines (strings) that were too long, so the pylint
warnings were suppressed with a TODO.
auth.py
gclient.py
gclient_eval.py
gclient_paths.py
gclient_scm.py
gerrit_util.py
git_cl.py
presubmit_canned_checks.py
presubmit_support.py
scm.py

Change-Id: Ia6535c4f2c48d46b589ec1e791dde6c6b2ea858f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4836379
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
Auto-Submit: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
2023-09-06 05:48:55 +00:00
Gavin Mak
65c49b18b9 Drop py2 support in gclient and related files
python3 is the only supported version of python in depot_tools.

Bug: 1475402
Change-Id: I17174d7252b5cbf698700333d3cd561c6591d0a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4809190
Reviewed-by: Aravind Vasudevan <aravindvasudev@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
2023-08-24 18:06:42 +00:00
Wan-Teh Chang
bc5906f6ff Suppress stderr of the git rev-parse command
In GetPrimarySolutionPath(), redirect the stderr of the
git rev-parse --show-toplevel command to /dev/null. This avoids the
following error message when running depot_tools' ninja command outside
the Chrome source tree:
fatal: not a git repository (or any of the parent directories): .git

I believe this error message was an unintended side effect of the work
on bug 1340825.

Bug: 1340825
Change-Id: I5679a854d1ff23f581564c54c765e13f8ba8b534
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4392154
Commit-Queue: Wan-Teh Chang <wtc@google.com>
Reviewed-by: Junji Watanabe <jwata@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
2023-04-03 19:50:41 +00:00
Robert Liao
b888780d17 Change FindGclientRoot to Use os.path.abspath instead of os.path.realpath
os.path.realpath will resolve back to the subst paths, leading to
inappropriate current working directories for all downstream hooks.

BUG=1208688

Change-Id: Idfcb0fe4d25ab1317db5aae34663b1017d4c4937
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2893669
Commit-Queue: Dirk Pranke <dpranke@google.com>
Auto-Submit: Robert Liao <robliao@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@google.com>
2021-05-13 23:20:50 +00:00
Edward Lemur
84b5f9a215 depot_tools: Add tests for gclient_paths
Change-Id: I544aa85b040544508df8ed16310def982356fbcc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1949417
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: Anthony Polito <apolito@google.com>
2020-01-08 20:06:51 +00:00
Robert Liao
7211cf6444 Import gclient_utils for gclient_paths CheckCallAndFilter
CheckCallAndFilter isn't part of the global namespace, and as a result,
this call was silently failing.

BUG=1007553

Change-Id: Ie2f3135fc3d56be189d8be0fe996a068e0645705
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1823664
Auto-Submit: Robert Liao <robliao@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Commit-Queue: Robert Liao <robliao@chromium.org>
2019-09-25 00:53:44 +00:00
Raul Tambre
b946b2389c Improve gclient Python 3 compatibility
This enables gclient sync and gclient runhooks to run, barring hook script failures.
git cl upload also now works.

The scripts still work with Python 2.
There are no intended behaviour changes.

Bug: 942522
Change-Id: I2ac587b5f803ba7f5bb5e412337ce049f4b1a741
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1524583
Commit-Queue: Raul Tambre <raul@tambre.ee>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
2019-03-26 14:48:46 +00:00
Dirk Pranke
112a77f4bf Make sys a top-level import in gclient_paths.
sys takes essentially no time to import (I think possibly because
it's a built-in?), and importing it as-needed is fragile. Make
it a top-level import to gclient_paths to prevent future breakages.

BUG=939959

Change-Id: I1ebe1260afd927355d668acf3cab5067ff0a2e03
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1515669
Reviewed-by: Nico Weber <thakis@chromium.org>
Commit-Queue: Dirk Pranke <dpranke@chromium.org>
2019-03-12 01:50:42 +00:00
Nico Weber
ad116ba9f6 Unbreak clang-format / GetBuildtoolsPlatformBinaryPath() after depot_tools/+/1512058
TBR=tandrii
Bug: 939959
Change-Id: Ia200eb38fda3d2572c4f1c3dc0d9f8f8fbd34362
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1515874
Auto-Submit: Nico Weber <thakis@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
2019-03-11 17:26:39 +00:00
Nico Weber
09e0b38f0f Move gclient path access to separate module.
gclient_utils.py is a kitchen sink and is for that reason expensive
to import. Move the comparatively cheap and simple path routines
to a new gclient_paths module and use that in gn.py, clang_format.py,
dart_format.py.

(To be able to move FindGclientRoot() to gclient_paths.py,
make it use io.open() instead of FileRead(). FileRead() tries
to paper over invalid utf-8, but that was added for presubmits,
not for .gclient files, so this is hopefully fine.)

Cuts gn.py overhead in half (on my Windows laptop from 0.6s to 0.25s,
still high; on my Mac laptop from 0.1s to 0.05s), and probably helps
the other two too.

Completely remove PathDifference() since it's unused.

Bug: 939959
Change-Id: I6a70f6e4c16062b622fb2df8778e8a598d4cc956
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1512058
Commit-Queue: Nico Weber <thakis@chromium.org>
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
2019-03-11 16:54:07 +00:00