diff options
author | George Burgess IV <gbiv@google.com> | 2024-04-08 15:36:08 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2024-04-10 23:00:06 +0000 |
commit | 9418ce841b65c955a4b836f271feabc0f5092c4e (patch) | |
tree | 254e8e83be0ce04553011c8f0a710097b4aafbc9 | |
parent | 91004c1369b35a2d7127bb5b6c1ae33e582fe993 (diff) | |
download | toolchain-utils-9418ce841b65c955a4b836f271feabc0f5092c4e.tar.gz |
llvm_tools: add gerrit cwd
This has to be run in a worktree on Chrotomation, which might not be in
a `repo` checkout.
BUG=b:332601837
TEST=None :)
Change-Id: Ia9a9888db302ca28ce76b3bb7802003dab140755
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/5436084
Reviewed-by: Jordan Abrahams-Whitehead <ajordanr@google.com>
Commit-Queue: George Burgess <gbiv@chromium.org>
Tested-by: George Burgess <gbiv@chromium.org>
-rw-r--r-- | cros_utils/git_utils.py | 10 | ||||
-rwxr-xr-x | llvm_tools/clean_up_old_llvm_patches.py | 19 |
2 files changed, 24 insertions, 5 deletions
diff --git a/cros_utils/git_utils.py b/cros_utils/git_utils.py index 6910a0ca..c4245280 100644 --- a/cros_utils/git_utils.py +++ b/cros_utils/git_utils.py @@ -79,11 +79,17 @@ def upload_to_gerrit( return _parse_cls_from_upload_output(run_result.stdout) -def try_set_autosubmit_labels(chromeos_tree: Path, cl_id: int) -> None: +def try_set_autosubmit_labels(cwd: Path, cl_id: int) -> None: """Sets autosubmit on a CL. Logs - not raises - on failure. This sets a series of convenience labels on the given cl_number, so landing it (e.g., for the detective) is as easy as possible. + + Args: + cwd: the directory that the `gerrit` tool should be run in. Anywhere in + a ChromeOS tree will do. The `gerrit` command fails if it isn't run + from within a ChromeOS tree. + cl_id: The CL number to apply labels to. """ gerrit_cl_id = str(cl_id) gerrit_commands = ( @@ -98,7 +104,7 @@ def try_set_autosubmit_labels(chromeos_tree: Path, cl_id: int) -> None: # script is expeted to be used. return_code = subprocess.run( cmd, - cwd=chromeos_tree, + cwd=cwd, check=False, stdin=subprocess.DEVNULL, ).returncode diff --git a/llvm_tools/clean_up_old_llvm_patches.py b/llvm_tools/clean_up_old_llvm_patches.py index 5418c707..d1ae54b2 100755 --- a/llvm_tools/clean_up_old_llvm_patches.py +++ b/llvm_tools/clean_up_old_llvm_patches.py @@ -79,7 +79,7 @@ def commit_changes(cros_overlay: Path, min_rev: int): ) -def upload_changes(cros_overlay: Path) -> None: +def upload_changes(cros_overlay: Path, autosubmit_cwd: Path) -> None: cl_ids = git_utils.upload_to_gerrit( cros_overlay, remote="cros", @@ -93,7 +93,7 @@ def upload_changes(cros_overlay: Path) -> None: cl_id = cl_ids[0] logging.info("Uploaded CL http://crrev.com/c/%s successfully.", cl_id) - git_utils.try_set_autosubmit_labels(cros_overlay, cl_id) + git_utils.try_set_autosubmit_labels(autosubmit_cwd, cl_id) def find_chromeos_llvm_version(chromiumos_overlay: Path) -> int: @@ -169,6 +169,15 @@ def get_opts(my_dir: Path, argv: List[str]) -> argparse.Namespace: """, ) parser.add_argument( + "--gerrit-tool-cwd", + type=Path, + help=""" + Working directory for `gerrit` tool invocations. This should point to + somewhere within a ChromeOS source tree. If none is passed, this will + try running them in the path specified by `--chromiumos-overlay`. + """, + ) + parser.add_argument( "--chromiumos-overlay", type=Path, help=""" @@ -219,6 +228,9 @@ def get_opts(my_dir: Path, argv: List[str]) -> argparse.Namespace: ) opts.chromiumos_overlay = maybe_overlay + if not opts.gerrit_tool_cwd: + opts.gerrit_tool_cwd = opts.chromiumos_overlay + if opts.autodetect_revision: if not opts.android_toolchain: parser.error( @@ -249,6 +261,7 @@ def main(argv: List[str]) -> None: opts = get_opts(my_dir, argv) cros_overlay = opts.chromiumos_overlay + gerrit_tool_cwd = opts.gerrit_tool_cwd upload = opts.upload_with_autoreview commit = opts.commit or upload min_revision = opts.revision @@ -271,7 +284,7 @@ def main(argv: List[str]) -> None: return logging.info("Uploading changes...") - upload_changes(cros_overlay) + upload_changes(cros_overlay, gerrit_tool_cwd) logging.info("Change sent for review.") |