Commit Graph

2506 Commits

Author SHA1 Message Date
Alex Ovsienko
4d6030e6b1 siso: create function to kill potentially running collector.
It checks running processed for what ports they occupy and kills the first process that occupies otlp_health_port that is known from config and quits.

Bug: b/455433899

Change-Id: Ib588be4c44021e55c67f1601040ac72a6a6a6964
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7183397
Reviewed-by: Junji Watanabe <jwata@google.com>
Commit-Queue: Alex Ovsienko <ovsienko@google.com>
2025-12-01 16:53:57 -08:00
Adam Norberg
3d401c263f Caffeinate fetches on Mac.
Since fetches involve multiple subprocess calls, any of which can be
slow, the per-subprocess caffeination strategy does not seem suitable --
the Mac might sleep as soon as the wake lock is dropped, before it
starts a new one. This instead implements a context manager to allow
caffeinating a scope.

To allow flag control, caffeinate.scope takes an argument that decides
whether or not it should actually do anything useful; it looks silly,
but the alternative is to interfere with flag parsing more or to require
users to write separate codepaths to decide whether to enter the context
manager scope or not; the "use the context manager in a mode where it
does not do anything" prevents this.

Bug: 462507017
Change-Id: Icc5bb9cadda30b5a120f112b10bf96ffd3b6550f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7183647
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Adam Norberg <norberg@google.com>
2025-11-21 14:01:25 -08:00
Fumitoshi Ukai
a40c63a40b siso: fix GOOGLE_API_USE_CLIENT_CERTIFICATE
GOOGLE_API_USE_CLIENT_CERTIFICATE=false was not passed
to siso process.

Change-Id: I44e1d63c7fbf8184822d9d888495b4818b511eac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7171141
Auto-Submit: Fumitoshi Ukai <ukai@google.com>
Commit-Queue: Alex Ovsienko <ovsienko@google.com>
Reviewed-by: Alex Ovsienko <ovsienko@google.com>
2025-11-18 23:49:18 -08:00
Allen Li
02f950a7cd git_auth: Add test for url rewrite override case
To prevent possible future regressios

Change-Id: I873be512b621f57f1dd9f54a68d093cd65228bf0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7164718
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
2025-11-18 15:43:06 -08:00
Scott Lee
039035332b bug fix for diff hunk parsing
The diff hunk can omit the number of lines after the line position.
For example, the following hunks are all valid
- @@ -1,2 +1,3 @@
- @@ -1 +1,3 @@
- @@ -1,2 +1 @@
- @@ -1 +1 @@

However, the existing regex assumes that the number of lines is always
given. It wasn't a problem before crrev.com/c/6952890, because -U3 was
applied always. However, since it changed the context lines to -U0,
git diff started generating hunks without the number of lines, if
a given changed section contains only a single line.

This CL fixes the regex.

Bug: 453641840
Change-Id: I67f680bc1d8fa046e373b065e8ccbb6ce652eb3f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7158599
Auto-Submit: Scott Lee <ddoman@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Scott Lee <ddoman@chromium.org>
2025-11-17 09:06:06 -08:00
Alex Ovsienko
926832f6db siso: extract command line args handling into _process_args.
Add tests for _process_args to make sure all flags operate as expected.

Bug: b/459690822
Change-Id: I98086cb0a274420f440b2ac3490473566a6a6964
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7161336
Commit-Queue: Alex Ovsienko <ovsienko@google.com>
Reviewed-by: Takuto Ikuta <tikuta@chromium.org>
2025-11-16 23:38:15 -08:00
Alex Ovsienko
ca5576a48f siso: cover apply_metrics_labels and apply_telemetry_flags functions with tests.
Bug: b/459690822

Change-Id: Iccb5b83e8572afa8d6a66252fc69cf766a6a6964
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7141140
Commit-Queue: Alex Ovsienko <ovsienko@google.com>
Reviewed-by: Takuto Ikuta <tikuta@chromium.org>
2025-11-16 21:57:17 -08:00
Alex Ovsienko
c527a62fe0 siso: create simple function to check if subcommand is present is siso using help.
That will help with starting collector from subcommand when clients may have older siso versions installed.

Bug: b/455433899

Change-Id: I5949b46017619a1717ef87781d8430b56a6a6964
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7155815
Commit-Queue: Alex Ovsienko <ovsienko@google.com>
Reviewed-by: Fumitoshi Ukai <ukai@google.com>
2025-11-16 19:03:44 -08:00
Jiewei Qian
240cd02c29 reauth: implement GitCreds credential pre-flight checks
This CL implements ensure_authenticated() for GitCredsAuthenticator, and
adds ReAuth support.

This check performs best-effort credential checks before performing
expensive operations such as presubmit hooks. This allows us to fail fast when an ReAuth token is missing for a contributor subject to
ReAuth requirements.

If you suspect this CL has caused a breakage on CL upload, please
revert.

Bug: 451651615
Change-Id: I42f3ffe3c830ed7bd2322f6cf2ad8adbba7e7251
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7036772
Reviewed-by: Allen Li <ayatane@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Jiewei Qian <qjw@chromium.org>
2025-11-04 11:38:19 -08:00
Jiewei Qian
5567ad1ea0 gerrit_util: add ReAuth support to ensure_authenticated
This CL makes it possible for ensure_authenticated to check whether
the current credential would satisfy ReAuth requirement.

Right now, only GitCredsAuthenticator performs additional ReAuth
check. For other Authenticator, either ReAuth is not relevant
(e.g. SSO), or not supported or implied (e.g. .gitcookies).

This CL does nothing on its own, because ensure_autheticated with
ReAuth is opt-in. Subsequent CL will update callsites to pass in
ReAuthContext to make the check effective.

Bug: 451651615
Change-Id: Idb1e70c52aaa844e672331fad8d462a2a7577d45
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7104363
Commit-Queue: Jiewei Qian <qjw@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
Reviewed-by: Allen Li <ayatane@chromium.org>
2025-11-04 11:21:10 -08:00
Jiewei Qian
1faea18c64 git-cl-test: rename auth parameter to creds
This avoids a import name clash in future CLs.

Bug: 451651615
Change-Id: Ie35cbe58f36ec98b33c48a70e61a2678a9ce52db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7104382
Auto-Submit: Jiewei Qian <qjw@chromium.org>
Reviewed-by: Allen Li <ayatane@chromium.org>
Commit-Queue: Scott Lee <ddoman@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
2025-11-04 11:05:03 -08:00
Milad Fa
a4fa14bf0d remove ppc and s390 from the host_arch list
We only support ppc64 and s390x.

Change-Id: I1ec46bbfc0bdd266b84336e5af46b0503efd4751
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7100932
Auto-Submit: Milad Farazmand <mfarazma@ibm.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Reviewed-by: Brian Ryner <bryner@google.com>
2025-11-03 09:28:07 -08:00
Jiewei Qian
52dbf26660 git_common: bump minimum git version
For ReAuth to work, git must be >=2.46.0. Updating depot_tools check according to:

https://chromium.googlesource.com/chromium/src/+/main/docs/gerrit_reauth.md#latest-git

Change-Id: I95a5bcc336e287d150140d35878ae8521e8817a2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7094398
Auto-Submit: Jiewei Qian <qjw@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Scott Lee <ddoman@chromium.org>
2025-10-29 11:17:20 -07:00
Gavin Mak
f5117c0007 Make CheckLicense warn locally
Only emit errors on standard CQ runs. Keep as warning for local runs to
reduce friction, and for full-tree CI checks to avoid breakage from
legacy files.

Bug: 454681814
Change-Id: I621ecc75cf5df40e4fd33ff439bfdc4f4c62e4fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7092462
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Gavin Mak <gavinmak@google.com>
2025-10-29 09:58:56 -07:00
Allen Li
da1bb1b99d git_auth: Delete unused ConfigChanger
All usages have been removed a while ago.

Bug: 446999231
Change-Id: I40de9de7dc027c22652dd45ad75bbba3377bd923
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7082062
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
2025-10-28 14:00:42 -07:00
Jiewei Qian
e2bb3cd558 tests: refactor CookiesAuthenticator mock
This CL refactors _test_gerrit_ensure_authenticated_common by splitting
it into:

- The actual mock and common code path
- Test case specific setup (e.g. scm.GIT.SetConfig)

In addition, fixes a few issues with the existing code:

- _Authenticator.get() is now mocked correctly, so a CookiesAuthenticator
  is returned in relevant tests. Previously it returned the "production"
  ChainedAuthenticator, which could call other authenticators (such as
  GitCredsAuthenticator based on the runtime environment)
- Adds mock patch cleanup functions. Previously, cleanup functions
  aren't registered, so the mock leaks and got overwritten by other test
  cases.
- Rewrite 'Bearer' in Authorization header check to be more robust.
  Previously, the test case raise a KeyError exception when the
  Authorization header isn't set at all in request headers.

This is a preparation CL for implementing ensure_authenticated() method
in ChainedAuthenticator and GitCredsAuthenticator in future CLs.

Bug: 348024314
Change-Id: I28a7fabbc6cf2dc33dccc1339b89d20a22dc12ea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7082265
Commit-Queue: Jiewei Qian <qjw@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
2025-10-27 15:45:01 -07:00
Jiewei Qian
32bbdf42e7 gerrit_util: only require ReAuth for Code-Review label
Only Code-Review label is subject to review enforcement. Setting other
labels don't need to ReAuth.

Bug: 450326417
Change-Id: I0d46ecc64dec847d82219fb069d8172ffc43d736
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7033952
Commit-Queue: Jiewei Qian <qjw@chromium.org>
Reviewed-by: Joey Scarr <jsca@google.com>
Reviewed-by: Scott Lee <ddoman@chromium.org>
Reviewed-by: Allen Li <ayatane@chromium.org>
2025-10-14 19:05:51 -07:00
Gavin Mak
8d28f8ce96 Fix git cl patch for sso:// URLs
URL normalization logic incorrectly compares sso:// and https:// URLs.
Unify the logic to treat both schemes identically.

Bug: 450461206, 429002243
Change-Id: I912b286d787a43b34304ed3be521d9d6927ba414
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7031038
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: Scott Lee <ddoman@chromium.org>
2025-10-13 13:29:42 -07:00
Jiewei Qian
73e46667ed Reland "git-cl: make SetReview ReAuth capable"
This is a reland of commit 6da6aecbb4

There's no change from the original CL and this reland. The revert was
addressed by adding ReAuth support to machine / bot authenticators,
namely GceAuthenticator (https://crrev.com/c/6965527) and
LuciContextAuthenticator (https://crrev.com/c/6967915).

The above changes should stop gerrit_util.SetReview from raising ReAuthRequired errors.

Bug: 442666611

Original change's description:
> git-cl: make SetReview ReAuth capable
>
> This CL changes SetReview to be ReAuth capable.
>
> This is a potential breaking change if an downstream script relies on
> gerrit_util.SetReview but hasn't implemented ReAuth.
>
> If this caused breakage, please refer to https://chromium.googlesource.com/chromium/src.git/+/HEAD/docs/gerrit_reauth.md#Troubleshooting for troubleshooting instructions.
>
> If the above doesn't work, please report a bug, then add `LUCI_BYPASS_REAUTH=1` to the environment to disable ReAuth for now.
>
> Bug: 442666611
> Change-Id: I7724f15f166f9975fc88be5d8e1c93be4e1ec302
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6939308
> Reviewed-by: Allen Li <ayatane@chromium.org>
> Reviewed-by: Scott Lee <ddoman@chromium.org>
> Commit-Queue: Jiewei Qian <qjw@chromium.org>

Bug: 442666611
Change-Id: I53636e54c732ec399b053500d664097ebacca05e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6967916
Commit-Queue: Jiewei Qian <qjw@chromium.org>
Reviewed-by: Allen Li <ayatane@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
2025-09-24 20:59:02 -07:00
Jiewei Qian
e028bec84c reauth: add LuciContextAuthenticator support
This CL implements attempt_authenticate_with_reauth in LuciContextAuthenticator according to the base _Authenticator's
interface definition.

This allows LuciContextAuthenticator to be used where an action that needs to meet ReAuth requirement (instead of raising an exception
saying "ReAuth
is required").

Luci context access tokens should already satisfy ReAuth requirement.

Bug: 442666611
Change-Id: I2e4d43a75b230932fc779c805f75b5828c9d0980
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6967915
Reviewed-by: Allen Li <ayatane@chromium.org>
Commit-Queue: Jiewei Qian <qjw@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
2025-09-24 16:45:20 -07:00
Jiewei Qian
dfd4523a42 reauth: add GceAuthenticator support
This CL implements attempt_authenticate_with_reauth in GceAuthenticator
according to the base _Authenticator's interface definition.

This allows GceAuthenticator to be used where an action that needs to
meet ReAuth requirement (instead of raising an exception saying "ReAuth
is required").

GceAuthenticator's credential already satisfies ReAuth requirement.
ReAuth is satisfied if the GCE bot is trusted (controlled by Gerrit
server side config).

Bug:442666611
Change-Id: I9a801e3fd6ab9fb446e7842a93bcd9ee1ff953c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6965527
Reviewed-by: Allen Li <ayatane@chromium.org>
Commit-Queue: Jiewei Qian <qjw@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
2025-09-24 16:31:36 -07:00
Allen Li
06da8b2a8f git_cl: Delete usages of AutoConfigure
Has been no-op for a while, remove it now

Bug: 446999231
Change-Id: I9f4e5b9cbd6a5cb8e84fba2f0ebb949b2a88d9ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6981220
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
2025-09-24 16:06:55 -07:00
Andrew Grieve
9d57bd01e8 git cl comments: Add --unresolved & improve --json-file
* Don't output to non-json format when --json-file is passed
* Format individual comments as JSON when --json-file is used
* Add "unresolved" field to comments
* --unresolved flag will show only unresolved comments
* Better error message when no issue is associated with the branch

I intend to use this to have gemini-cli fix comments:
https://chromium-review.googlesource.com/c/chromium/src/+/6944524

Change-Id: I3b4d594b065751a600661a89925c69ffbf22aed5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6944465
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
2025-09-17 11:28:23 -07:00
Jacek Dobrowolski
c932af8f97 Revert "git-cl: make SetReview ReAuth capable"
This reverts commit 6da6aecbb4.

Reason for revert: Breaks official chrome release.

Original change's description:
> git-cl: make SetReview ReAuth capable
>
> This CL changes SetReview to be ReAuth capable.
>
> This is a potential breaking change if an downstream script relies on
> gerrit_util.SetReview but hasn't implemented ReAuth.
>
> If this caused breakage, please refer to https://chromium.googlesource.com/chromium/src.git/+/HEAD/docs/gerrit_reauth.md#Troubleshooting for troubleshooting instructions.
>
> If the above doesn't work, please report a bug, then add `LUCI_BYPASS_REAUTH=1` to the environment to disable ReAuth for now.
>
> Bug: 442666611
> Change-Id: I7724f15f166f9975fc88be5d8e1c93be4e1ec302
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6939308
> Reviewed-by: Allen Li <ayatane@chromium.org>
> Reviewed-by: Scott Lee <ddoman@chromium.org>
> Commit-Queue: Jiewei Qian <qjw@chromium.org>

Bug: 442666611
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: I7b7e769b5a8011d45e976e471d0f2e43f186e0c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6955930
Commit-Queue: Alex Kravchuk <alexanderkr@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Owners-Override: Ben Mason <benmason@chromium.org>
2025-09-17 03:52:50 -07:00
Jiewei Qian
6da6aecbb4 git-cl: make SetReview ReAuth capable
This CL changes SetReview to be ReAuth capable.

This is a potential breaking change if an downstream script relies on
gerrit_util.SetReview but hasn't implemented ReAuth.

If this caused breakage, please refer to https://chromium.googlesource.com/chromium/src.git/+/HEAD/docs/gerrit_reauth.md#Troubleshooting for troubleshooting instructions.

If the above doesn't work, please report a bug, then add `LUCI_BYPASS_REAUTH=1` to the environment to disable ReAuth for now.

Bug: 442666611
Change-Id: I7724f15f166f9975fc88be5d8e1c93be4e1ec302
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6939308
Reviewed-by: Allen Li <ayatane@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Jiewei Qian <qjw@chromium.org>
2025-09-16 17:00:01 -07:00
Scott Lee
927f7dad38 presubmit: use git diff -U0 for CheckPatchFormatted()
git cl format uses `git diff -U0` when it has to find the files
and ranges to format. Similarly, CiderG generates diffs with
-U0 and run presubmits for the checks.

However, the scm.py:GenerateDiff(), which CheckPatchFormatted() uses,
doesn't specify -U and it defaults to -U3.

This CL updates CheckPatchFormatted() to pass -U0 to
scm.py:GenerateDiff() so that Presubmit and git cl format are
always given diffs generated with -U0.

Bug: 386840832
Change-Id: I19479ab139b7dba8ba4e5e5fed89eca4d2e66412
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6952890
Auto-Submit: Scott Lee <ddoman@chromium.org>
Commit-Queue: Brian Ryner <bryner@google.com>
Commit-Queue: Scott Lee <ddoman@chromium.org>
Reviewed-by: Brian Ryner <bryner@google.com>
2025-09-16 09:50:19 -07:00
Jiewei Qian
9d7425377e reauth: add reauth capabilities to HttpConn
This CL makes it possible to create HttpConn RPC calls with ReAuth
credential.

Callers can specify whether they want to fail when ReAuth token isn't
available, or fallback to access token.

Bug: 442666611
Change-Id: I748a01634eea8ebe321779c8ae4f52d7beed3407
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6938952
Commit-Queue: Jiewei Qian <qjw@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
Reviewed-by: Allen Li <ayatane@chromium.org>
2025-09-16 00:32:10 -07:00
Jiewei Qian
024aacb38b auth.py: add ReAuth support
This CL adds ReAuth support to GerritAuthenticator. ReAuth token can be
obtained with a new get_authorization_header() call.

The task of obtaining such a token is delegated to different
authenticators to check if ReAuth is necessary, and if the existing
authentication token already satisfies ReAuth requirements.

Bug: 442666611
Change-Id: Ic661b868f1c61c653de0da43eb784ad5938342f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6914237
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Jiewei Qian <qjw@chromium.org>
Reviewed-by: Allen Li <ayatane@chromium.org>
2025-09-16 00:15:47 -07:00
Scott Lee
077e02a769 presubmit: generate a diff with prefix a/ and b/
Historically, git_cl.py and presubmit_support.py generated diffs
inconsistently.

==== git_cl.py ====
1) git_cl.py:_RunClangFormatDiff() assumed the input diff was
generated with --no-prefix. Therefore, it hard-coded -p0 as a param
for clang_format_diff.py. If the diff was generated without --no-prefix,
it would have to pass -p1 instead.

2) git_cl.py _RunYapf() and _RunGoogleJavaFormat assumed that
the input diff was generated with prefixes. Therefore,
it parsed the diffs, assuming that the diff was generated with
a/ and b/ prefixes.

This discrepancy wasn't an issue because each of the Run functions
generated and consumed the diffs within themselves. It became an issue
when https://crrev.com/c/6931775 was developed. The CL consolidated
the diff generation into a common function, so that all _Run functions
need to agree with the presence of the prefixes.

The CL changed _RunClangFormatDiff() to use -p1 instead of -p0,
mainly because
- it's the p level for the default git-diff option
- it's the p level for the unix diff util
- CiderG Chromium also generates the diff with the prefixes to
emulate the default diff output.
- I highly believe that --no-prefix was chosen for no reasons.
It seems to be a random choice to work with -p0.
- Either Java/Python or Clang wrapper should be changed.

==== presubmit_support.py ====

presubmit_support.py can be given a diff_file via --diff_file.
Otherwise, it generates the diff based on --upstream_commit.

a) it doesn't enforce the presence of the prefixes in the input
diff_file. As stated above, the Chromium extension generates
a diff with prefixes.

b) in contrast, when it is not given --diff_file, it generates
the diff with --no-prefix, and I don't find any reasons for it.
I believe that it's from a copy-pasted random choice.

==== the problem ====

This discarepancy became a problem, when crrev.com/c/6937365
was landed. It enforces git_cl.py and presubmit_support.py to agree
for the format of the input diff. That is, the presence of
the prefixes must be agreed by all the following.
- presubmit_support.py with --diff_file /tmp/abc
- presubmit_suppory.py without --diff_file /tmp/abc
- git cl format
- git cl format --input_diff_file /tmp/abc

==== possible solutions ====
Obviously, there are 3 choices.

1) update the regex and parsers of git_cl.py to auto detect the best
-p{num}.
This was the least preferred option, as it can be fragile.

2) update Chromium extension and git_cl.py to use --no-prefix.
i.e.,
- update the Chromium CiderG to generate diffs without the prefix.
- update the regex used in _ComputeFormatDiffLineRanges() to assume
that the input is generated with --no-prefix.
- change _RunClangFormatDiff() to pass -p0 instead of -p1.

3) update presubmit_support.py to generate diff without --no-prefix.

==== What this CL does ====
It implements (3).
- That is the default option for git-diff.
- I don't find obvious reasons to use --no-prefix.
- CiderG has been generating diffs with prefixes for weeks.
- It implies that presubmit_support.py works fine with a prefixed diff.

Bug: 386840832
Change-Id: Iac8a4fc30f101e70e3ccc56f9f8ee48198dfa833
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6939737
Commit-Queue: Scott Lee <ddoman@chromium.org>
Reviewed-by: Gavin Mak <gavinmak@google.com>
2025-09-12 10:34:21 -07:00
Scott Lee
363e910475 git_cl: update the clang, java, and yapf formatters to be git-free
This makes the formatter runners to be git-free if --input_diff_file
is given. They still run `git diff`, if --diff is given. However,
for the purpose of making the presubmit check for format verification
git-free, it's ok as --diff is not used by the presubmit check.


Bug: 386840832
Change-Id: If5ab68fa4e2fec1aafa22e15ddeabb744993342b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6931775
Commit-Queue: Scott Lee <ddoman@chromium.org>
Reviewed-by: Gavin Mak <gavinmak@google.com>
2025-09-11 10:28:39 -07:00
Scott Lee
5ed7fd0ea5 git_cl: add --input_diff_file for git cl format
If the option is given, git cl format uses the input diff file to
determine the files and sections to format instead of git-diff.

The intended use case is to remove git dependencies in case
presubmit_support.py is executed with a diff file and it calls
presubmit_canned_checks.CheckPatchFormatted().

Bug: 386840832
Change-Id: Ia1eacd1bdb81731e07753df19ebf1d2470c9f1aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6912693
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Scott Lee <ddoman@chromium.org>
2025-09-10 14:38:11 -07:00
Allen Li
e46459f0d3 git cl: Handle URL variations more robustly
Bug: 429002243
Change-Id: I0638da9f7ddf8f82078b13331d5890ad8b2421ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6917276
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
2025-09-04 15:41:18 -07:00
Fumitoshi Ukai
0f565fa858 siso: add .sisorc support
if build/config/siso/.sisorc exists, it will add global flags
or subcmd flags.

global flags is line starting with "-"
e.g.
--credential_helper=gcloud

subcmd flags are line starting with subcmd name.
e.g.
ninja --verbose_failures=false -k=0

Bug: b/269554009
Change-Id: I4691b9e17571721dd5b70f6ffb063e2d2f0ac4e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6910278
Reviewed-by: Scott Lee <ddoman@chromium.org>
Reviewed-by: Philipp Wollermann <philwo@google.com>
Commit-Queue: Fumitoshi Ukai <ukai@google.com>
Reviewed-by: Takuto Ikuta <tikuta@chromium.org>
2025-09-03 19:03:18 -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
Scott Lee
f88b25b610 Reland "presubmit: emit errors instead of warnings for bad copyright headers"
This reverts commit eb60ab38de.

Reason for revert: re-landing with an additional patch

-------------
* Problem
Browser infra runs ci.*-presubmit builders, such as linux-presubmit,
with --all to ensure that the entire chromium/src passes
presubmit checks.

crrev.com/c/6842238 changed the finding type for License Check
from warning to error, but the CI presubmit builders failed because
there are many files without valid CopyRight.

Not only the existing files, all the new files that are added with
`Bypass-Check-License: <reason> footer could also cause the presubmit
builder to fail.

* This CL

In addition to the original patch from crrev.com/c/6842238,
this CL makes additional patches to turn the CopyRight errors into
warnings, if --file or --all is given.

The same approach is used in
https://source.chromium.org/chromium/chromium/tools/depot_tools/+/main:presubmit_canned_checks.py;l=982-987;drc=eb60ab38deeda6975c9b0fef883978f2a9f69120


Bug: 435696543,40237859
Original change's description:
> Revert "presubmit: emit errors instead of warnings for bad copyright headers"
>
> This reverts commit fa62515ecb.
>
> Reason for revert: it seems that the existing files without valid copyright headers are causing linux-presubmit builds to fail. b/438791294
>
> Bug: 435696543,40237859
> Original change's description:
> > presubmit: emit errors instead of warnings for bad copyright headers
> >
> > This is an effective revert of https://crrev.com/c/4895337 with
> > additional patches to support a footer.
> >
> > https://crrev.com/c/3887721 updated CheckLicense() to emit errors
> > for bad copyright headers. However, https://crrev.com/c/4895337
> > was changed the finding type from error to warning, claiming that
> > the check is N/A for moved third files, but it's not so easy
> > to programatiically distinguish moved third-party files.
> >
> > After discussions, it was decided to change the finding type back
> > to error to prevent accidental submissions for new files without
> > correct CopyRight headers.
> >
> > To mitigate moved, third-party files, this CL adds support for
> > "Bypass-Check-License: <reason>" footer.
> >
> > If the check should be ignored in a given CL, CL authors should
> > use the footer instead.
> >
> > Bug: 435696543,40237859
> > Change-Id: I177915c65932a3d76ea60ee6a0e396f726bc400d
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6842238
> > Reviewed-by: Gavin Mak <gavinmak@google.com>
> > Commit-Queue: Scott Lee <ddoman@chromium.org>
>
> Bug: 435696543,40237859
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Change-Id: Ibedf8d13e3742249947e29e625a14cceaf89879c
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6852377
> Commit-Queue: Scott Lee <ddoman@chromium.org>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Reviewed-by: Gavin Mak <gavinmak@google.com>

Bug: 435696543,40237859
Change-Id: Iafdb29b928c016eb3949e29fd43a2ba5f53e0ba0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6852108
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Scott Lee <ddoman@chromium.org>
2025-08-15 10:47:31 -07:00
Scott Lee
eb60ab38de Revert "presubmit: emit errors instead of warnings for bad copyright headers"
This reverts commit fa62515ecb.

Reason for revert: it seems that the existing files without valid copyright headers are causing linux-presubmit builds to fail. b/438791294 

Bug: 435696543,40237859
Original change's description:
> presubmit: emit errors instead of warnings for bad copyright headers
>
> This is an effective revert of https://crrev.com/c/4895337 with
> additional patches to support a footer.
>
> https://crrev.com/c/3887721 updated CheckLicense() to emit errors
> for bad copyright headers. However, https://crrev.com/c/4895337
> was changed the finding type from error to warning, claiming that
> the check is N/A for moved third files, but it's not so easy
> to programatiically distinguish moved third-party files.
>
> After discussions, it was decided to change the finding type back
> to error to prevent accidental submissions for new files without
> correct CopyRight headers.
>
> To mitigate moved, third-party files, this CL adds support for
> "Bypass-Check-License: <reason>" footer.
>
> If the check should be ignored in a given CL, CL authors should
> use the footer instead.
>
> Bug: 435696543,40237859
> Change-Id: I177915c65932a3d76ea60ee6a0e396f726bc400d
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6842238
> Reviewed-by: Gavin Mak <gavinmak@google.com>
> Commit-Queue: Scott Lee <ddoman@chromium.org>

Bug: 435696543,40237859
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: Ibedf8d13e3742249947e29e625a14cceaf89879c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6852377
Commit-Queue: Scott Lee <ddoman@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
2025-08-14 14:18:36 -07:00
Scott Lee
fa62515ecb presubmit: emit errors instead of warnings for bad copyright headers
This is an effective revert of https://crrev.com/c/4895337 with
additional patches to support a footer.

https://crrev.com/c/3887721 updated CheckLicense() to emit errors
for bad copyright headers. However, https://crrev.com/c/4895337
was changed the finding type from error to warning, claiming that
the check is N/A for moved third files, but it's not so easy
to programatiically distinguish moved third-party files.

After discussions, it was decided to change the finding type back
to error to prevent accidental submissions for new files without
correct CopyRight headers.

To mitigate moved, third-party files, this CL adds support for
"Bypass-Check-License: <reason>" footer.

If the check should be ignored in a given CL, CL authors should
use the footer instead.

Bug: 435696543,40237859
Change-Id: I177915c65932a3d76ea60ee6a0e396f726bc400d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6842238
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Scott Lee <ddoman@chromium.org>
2025-08-14 09:55:48 -07:00
Scott Lee
7ada09631a presubmit_support: allows description only run
This CL allows presubmit_support to run without any files in diff mode
if it's given --description "..."


Bug: 436813955
Change-Id: I43252c0fdbd1a87b6099d2c9cd19e4b0f9b7f64f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6838150
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Scott Lee <ddoman@chromium.org>
2025-08-12 12:21:17 -07:00
Jiewei Qian
59e46a5d18 Add luci-auth-fido2-plugin
This plugin handles FIDO2 security keys for doing auth and integrates
with luci-auth (specifically git-credential-luci).

(It's in Python because tl;dr the Python library is much better.)

Bug: 433851494
Change-Id: Ib956b614588aad8ad4fda7619bfbae17a670438f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6804585
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Allen Li <ayatane@chromium.org>
2025-08-11 14:54:09 -07:00
Allen Li
342cd35666 [git_auth] Add useHttpPath config for Gerrit auth
This is needed to pass the repo path to the credential helper, so we
can distinguish repos that need ReAuth.

Change-Id: I5aa72d6ec0421dcbff610f48f34129b8962050f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6822598
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
2025-08-07 14:07:49 -07:00
Scott Lee
4fd484473c depot_tools: add create_temp_file.py
It takes text from stdin and dump the read text to a temp file.

Bug: 428193406
Change-Id: I268dc4905e157d619d1af7d0b96f711f224f39db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6789063
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Scott Lee <ddoman@chromium.org>
2025-07-28 11:27:45 -07:00
Andy Perelson
615f4a2f03 Remove support for RobotComments, which have been removed from Gerrit.
Bug: 428171766
Change-Id: I38ddbf4a934f80897301d2fd04d8b83a799b1bd7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6690195
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Andy Perelson <ajp@google.com>
2025-07-01 14:23:35 -07:00
Ben Pastene
52de072b5f Add *.star files as source file from presubmit's PoV
By not considering *.star files as source files, various pan-project
checks (like the copyright header check) weren't running on them.

But *.star files are pretty much python files, so should be treated the
same.

Bug: 428926694
Change-Id: If3f7ff45d9fa825008e6a86b13d60d44ad8387c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6697693
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Ben Pastene <bpastene@chromium.org>
2025-07-01 13:52:53 -07:00
Fumitoshi Ukai
6a1451c0c0 autoninja: disable siso native by --reapi_address=
siso v1.3.1 changed the way to enable reapi.
It allows empty project and empty reapi_instance.

Under reclient mode to disable siso native,
set reapi_address empty.

Bug: 427569563
Change-Id: Ib653186c5200605032de5c0fddab0b64412db85c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6668613
Reviewed-by: Junji Watanabe <jwata@google.com>
Commit-Queue: Fumitoshi Ukai <ukai@google.com>
Auto-Submit: Fumitoshi Ukai <ukai@google.com>
Commit-Queue: Junji Watanabe <jwata@google.com>
2025-06-24 17:43:48 -07:00
Gavin Mak
21c86aad65 Specify full dirmd path in CheckDirMetadataFormat
If dirmd_bin` is not provided, default to an absolute path to dirmd.
Otherwise, some builders can fail with a `No such file or directory:
'dirmd'.` like:
https://ci.chromium.org/ui/p/chromium/builders/ci/linux-presubmit/27711/infra

Bug: 416037494
Change-Id: Ibe3c0a80f2b605583321cce95241de62edcaec4b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6533317
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
2025-05-12 09:20:27 -07:00
Jordan Brown
977c37458f Change readme updating to be on by default for roll_dep.py
Change-Id: Id6d5a365e55ad0a79e512af24e72f141f8b9a60a
Bug: b/390067679
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6521682
Reviewed-by: Rachael Newitt <renewitt@google.com>
Reviewed-by: Andy Perelson <ajp@google.com>
Commit-Queue: Jordan Brown <rop@google.com>
2025-05-09 15:35:10 -07:00
Aleksei Khoroshilov
998f7bfaf2 Improve ensure_gsutil reliability
The current gsutil download code silently fails when the connection
drops mid-download, as read() returns an empty buffer instead of raising
an exception. This may lead to errors such as "zipfile.BadZipFile: File
is not a zip file" on Chromium sync with freshly-bootstrapped
depot_tools when downloading gcs deps.

This change solves this by hardening the process:
- Use retry mechanism with exponential backoff for gsutil download
- Switch to urlretrieve, which looks at Content-Length
- Compare MD5 of the downloaded file with the value from API
- Move exponential_backoff_retry from git_cache.py to gclient_utils.py

Change-Id: I25242948399e01373eb2afd9352e5c78a889051d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6485485
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Auto-Submit: Aleksei Khoroshilov <akhoroshilov@brave.com>
Reviewed-by: Scott Lee <ddoman@chromium.org>
2025-04-28 10:31:42 -07:00
Scott Lee
b128c9967e split: update SelectReviewersForFiles to work with repository root
The current implementation relies on the current working directory,
when it traverses the file tree to find the nearest OWNERS. It also
causes an infinite loop when it cannot find any OWNERS.

This CL changes the implementation so that it works
no matter what the cwd is.

Bug: 412904761
Change-Id: Ic4e25217aa64bd2eb6514ccdd486fe3b57a82312
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6484531
Commit-Queue: Scott Lee <ddoman@chromium.org>
Reviewed-by: Gavin Mak <gavinmak@google.com>
2025-04-24 08:36:02 -07:00
Yiwei Zhang
d49e17e19f presubmit: add location data to presubmit result
This will help us to display preusbmit result as findings both in
Gerrit and in Cider workspaces.

Change-Id: I0f5a9c503c1b14dc8dcbf9794cc556ef215a46a2
Bug: 404837554
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6469939
Commit-Queue: Yiwei Zhang <yiwzhang@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
2025-04-22 12:26:12 -07:00
Allen Li
d28539d200 [git_auth] Move gitcookies to free backup name
Bug: 410576093
Change-Id: Ib2d9db97f4e4e1e8cfe1914ba7ffb881f9e16bbf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6453918
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Yiwei Zhang <yiwzhang@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
2025-04-15 14:54:46 -07:00