diff options
author | Bob Haarman <inglorion@chromium.org> | 2022-05-16 14:37:41 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-09-27 10:03:12 +0000 |
commit | 17d9a5c3229a2033a834eaf6284694683bb400a0 (patch) | |
tree | 7b30bf4b29f2e47acca1538f55d1345b3a41abd6 | |
parent | a92f49cb65b31da40958279c80f49a7a46e89fe2 (diff) | |
download | toolchain-utils-17d9a5c3229a2033a834eaf6284694683bb400a0.tar.gz |
rust_uprev: Ensure that packages can be built
Although rust_uprev emerges rust, this does not ensure that
all affected packages (rust, rust-bootstrap, rust-host) can be built
from the new sources. For example, it is possible to build and install
rust-host, then make changes to it, and re-running rust_uprev will then
not rebuild it, because it is already installed at the requested version.
This CL changes rust_uprev so that it first removes rust, rust-host, and
rust-bootstrap if they are installed, so that unbuildable packages will
be detected by rust_uprev.
BUG=b:232833366
TEST=Run with installed rust-host package that is unbuildable, see error
Change-Id: I7aeb7d1ac01e737e322bf005a31f1d678e52e042
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/3653197
Tested-by: Bob Haarman <inglorion@chromium.org>
Reviewed-by: George Burgess <gbiv@chromium.org>
Commit-Queue: Bob Haarman <inglorion@chromium.org>
-rwxr-xr-x | rust_tools/rust_uprev.py | 55 |
1 files changed, 51 insertions, 4 deletions
diff --git a/rust_tools/rust_uprev.py b/rust_tools/rust_uprev.py index 3c87a134..382d991a 100755 --- a/rust_tools/rust_uprev.py +++ b/rust_tools/rust_uprev.py @@ -33,6 +33,7 @@ import os import pathlib from pathlib import Path import re +import shlex import shutil import subprocess import sys @@ -552,6 +553,20 @@ def update_virtual_rust( subprocess.check_call(["git", "add", new_name], cwd=virtual_rust_dir) +def unmerge_package_if_installed(pkgatom: str) -> None: + """Unmerges a package if it is installed.""" + shpkg = shlex.quote(pkgatom) + subprocess.check_call( + [ + "sudo", + "bash", + "-c", + f"! emerge --pretend --quiet --unmerge {shpkg}" + f" || emerge --rage-clean {shpkg}", + ] + ) + + def perform_step( state_file: pathlib.Path, tmp_state_file: pathlib.Path, @@ -659,10 +674,7 @@ def create_rust_uprev( lambda: update_manifest(Path(target_file)), ) if not skip_compile: - run_step( - "emerge rust", - lambda: subprocess.check_call(["sudo", "emerge", "dev-lang/rust"]), - ) + run_step("build packages", lambda: rebuild_packages(rust_version)) run_step( "insert host version into rust packages", lambda: update_rust_packages( @@ -708,6 +720,41 @@ def find_ebuild_for_rust_version(version: RustVersion) -> str: return rust_ebuilds[0] +def rebuild_packages(version: RustVersion): + """Rebuild packages modified by this script.""" + # Remove all packages we modify to avoid depending on preinstalled + # versions. This ensures that the packages can really be built. + packages = [ + "dev-lang/rust", + "dev-lang/rust-host", + "dev-lang/rust-bootstrap", + ] + for pkg in packages: + unmerge_package_if_installed(pkg) + # Mention only dev-lang/rust explicitly, so that others are pulled + # in as dependencies (letting us detect dependency errors). + # Packages we modify are listed in --usepkg-exclude to ensure they + # are built from source. + try: + subprocess.check_call( + [ + "sudo", + "emerge", + "--quiet-build", + "--usepkg-exclude", + " ".join(packages), + f"=dev-lang/rust-{version}", + ] + ) + except: + logging.warning( + "Failed to build dev-lang/rust or one of its dependencies." + " If necessary, you can restore rust and rust-host from" + " binary packages:\n sudo emerge --getbinpkgonly dev-lang/rust" + ) + raise + + def remove_ebuild_version(path: os.PathLike, name: str, version: RustVersion): """Remove the specified version of an ebuild. |