aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Burgess IV <gbiv@google.com>2024-05-06 17:50:37 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2024-05-08 21:31:18 +0000
commit2356b694e062b6c13e9fb8728527718aca3af76b (patch)
tree12226bccdd000b37c115a0a806ce0949bd33085d
parente7959711a881a7beac5462e899a09e3566b61c6e (diff)
downloadtoolchain-utils-2356b694e062b6c13e9fb8728527718aca3af76b.tar.gz
rust_tools: use git_utils
Now that we can import from anywhere, this duplicated code can be removed :party: BUG=b:334932020 TEST=repo upload Change-Id: Idd4ff87d4c456e7b6abb0232f2c93cdc8238c00c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/5519701 Commit-Queue: George Burgess <gbiv@chromium.org> Reviewed-by: Jordan Abrahams-Whitehead <ajordanr@google.com> Tested-by: George Burgess <gbiv@chromium.org>
-rw-r--r--rust_tools/auto_update_rust_bootstrap.py85
-rw-r--r--rust_tools/auto_update_rust_bootstrap_test.py56
2 files changed, 16 insertions, 125 deletions
diff --git a/rust_tools/auto_update_rust_bootstrap.py b/rust_tools/auto_update_rust_bootstrap.py
index d74ad638..f3bbb4da 100644
--- a/rust_tools/auto_update_rust_bootstrap.py
+++ b/rust_tools/auto_update_rust_bootstrap.py
@@ -28,6 +28,7 @@ import sys
import textwrap
from typing import Dict, Iterable, List, Optional, Tuple, Union
+from cros_utils import git_utils
from rust_tools import copy_rust_bootstrap
@@ -359,70 +360,19 @@ def update_ebuild_manifest(rust_bootstrap_ebuild: Path):
)
-def commit_all_changes(
- git_dir: Path, rust_bootstrap_dir: Path, commit_message: str
-):
- subprocess.run(
- ["git", "add", rust_bootstrap_dir.relative_to(git_dir)],
- cwd=git_dir,
- check=True,
- stdin=subprocess.DEVNULL,
- )
- subprocess.run(
- ["git", "commit", "-m", commit_message],
- cwd=git_dir,
- check=True,
- stdin=subprocess.DEVNULL,
- )
-
-
-def scrape_git_push_cl_id_strs(git_push_output: str) -> List[str]:
- id_regex = re.compile(
- r"^remote:\s+https://chromium-review\S+/\+/(\d+)\s", re.MULTILINE
- )
- results = id_regex.findall(git_push_output)
- if not results:
- raise ValueError(
- f"Found 0 matches of {id_regex} in {git_push_output!r}; expected "
- "at least 1."
- )
- return results
-
-
def upload_changes(git_dir: Path):
- logging.info("Uploading changes")
- result = subprocess.run(
- ["git", "push", "cros", "HEAD:refs/for/main"],
- check=True,
- cwd=git_dir,
- encoding="utf-8",
- stdin=subprocess.DEVNULL,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
- )
- # Print this in case anyone's looking at the output.
- print(result.stdout, end=None)
- result.check_returncode()
-
- cl_ids = scrape_git_push_cl_id_strs(result.stdout)
- logging.info(
- "Uploaded %s successfully!", [f"crrev.com/c/{x}" for x in cl_ids]
+ logging.info("Uploading changes...")
+ cl_ids = git_utils.upload_to_gerrit(
+ git_repo=git_dir,
+ remote=git_utils.CROS_EXTERNAL_REMOTE,
+ branch=git_utils.CROS_MAIN_BRANCH,
+ reviewers=DEFAULT_CL_REVIEWERS,
)
for cl_id in cl_ids:
- gerrit_commands = (
- ["gerrit", "label-v", cl_id, "1"],
- ["gerrit", "label-cq", cl_id, "1"],
- ["gerrit", "label-as", cl_id, "1"],
- ["gerrit", "reviewers", cl_id] + list(DEFAULT_CL_REVIEWERS),
- ["gerrit", "ready", cl_id],
+ git_utils.try_set_autosubmit_labels(
+ cwd=git_dir,
+ cl_id=cl_id,
)
- for command in gerrit_commands:
- logging.info("Running gerrit command: %s", command)
- subprocess.run(
- command,
- check=True,
- stdin=subprocess.DEVNULL,
- )
def maybe_add_newest_prebuilts(
@@ -489,10 +439,9 @@ def maybe_add_newest_prebuilts(
pretty_artifacts = "\n".join(pretty_artifact_lines)
logging.info("Committing changes.")
- commit_all_changes(
+ git_utils.commit_all_changes(
chromiumos_overlay,
- rust_bootstrap_dir,
- commit_message=textwrap.dedent(
+ message=textwrap.dedent(
f"""\
rust-bootstrap: use prebuilts
@@ -601,10 +550,9 @@ def maybe_add_new_rust_bootstrap_version(
update_ebuild_manifest(new_ebuild)
if commit:
newest_no_rev = newest_rust_version.without_rev()
- commit_all_changes(
+ git_utils.commit_all_changes(
chromiumos_overlay,
- rust_bootstrap_dir,
- commit_message=textwrap.dedent(
+ message=textwrap.dedent(
f"""\
rust-bootstrap: add version {newest_no_rev}
@@ -754,10 +702,9 @@ def maybe_delete_old_rust_bootstrap_ebuilds(
"no longer needed.",
]
message = textwrap.fill("\n".join(message_lines))
- commit_all_changes(
+ git_utils.commit_all_changes(
chromiumos_overlay,
- rust_bootstrap_dir,
- commit_message=textwrap.dedent(
+ message=textwrap.dedent(
f"""\
rust-bootstrap: remove unused ebuild{"s" if many else ""}
diff --git a/rust_tools/auto_update_rust_bootstrap_test.py b/rust_tools/auto_update_rust_bootstrap_test.py
index 2af5bd83..e838d9c6 100644
--- a/rust_tools/auto_update_rust_bootstrap_test.py
+++ b/rust_tools/auto_update_rust_bootstrap_test.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python3
# Copyright 2023 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -16,46 +15,6 @@ from unittest import mock
from rust_tools import auto_update_rust_bootstrap
-_GIT_PUSH_OUTPUT = r"""
-remote: Waiting for private key checker: 2/2 objects left
-remote:
-remote: Processing changes: new: 1 (\)
-remote: Processing changes: new: 1 (|)
-remote: Processing changes: new: 1 (/)
-remote: Processing changes: refs: 1, new: 1 (/)
-remote: Processing changes: refs: 1, new: 1 (/)
-remote: Processing changes: refs: 1, new: 1 (/)
-remote: Processing changes: refs: 1, new: 1, done
-remote:
-remote: SUCCESS
-remote:
-remote: https://chromium-review.googlesource.com/c/chromiumos/overlays/chromiumos-overlay/+/5018826 rust-bootstrap: use prebuilts [WIP] [NEW]
-remote:
-To https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay
- * [new reference] HEAD -> refs/for/main
-"""
-
-_GIT_PUSH_MULTI_CL_OUTPUT = r"""
-remote: Waiting for private key checker: 2/2 objects left
-remote:
-remote: Processing changes: new: 1 (\)
-remote: Processing changes: new: 1 (|)
-remote: Processing changes: new: 1 (/)
-remote: Processing changes: refs: 1, new: 1 (/)
-remote: Processing changes: refs: 1, new: 1 (/)
-remote: Processing changes: refs: 1, new: 1 (/)
-remote: Processing changes: refs: 1, new: 1, done
-remote:
-remote: SUCCESS
-remote:
-remote: https://chromium-review.googlesource.com/c/chromiumos/overlays/chromiumos-overlay/+/5339923 rust-bootstrap: add version 1.75.0 [NEW]
-remote: https://chromium-review.googlesource.com/c/chromiumos/overlays/chromiumos-overlay/+/5339924 rust-bootstrap: remove unused ebuilds [NEW]
-remote:
-To https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay
- * [new reference] HEAD -> refs/for/main
-"""
-
-
class Test(unittest.TestCase):
"""Tests for auto_update_rust_bootstrap."""
@@ -66,21 +25,6 @@ class Test(unittest.TestCase):
self.addCleanup(shutil.rmtree, tempdir)
return tempdir
- def test_git_cl_id_scraping(self):
- self.assertEqual(
- auto_update_rust_bootstrap.scrape_git_push_cl_id_strs(
- _GIT_PUSH_OUTPUT
- ),
- ["5018826"],
- )
-
- self.assertEqual(
- auto_update_rust_bootstrap.scrape_git_push_cl_id_strs(
- _GIT_PUSH_MULTI_CL_OUTPUT
- ),
- ["5339923", "5339924"],
- )
-
def test_ebuild_linking_logic_handles_direct_relative_symlinks(self):
tempdir = self.make_tempdir()
target = tempdir / "target.ebuild"