From ad1fc341993b32357a83e3c13861880187b535e7 Mon Sep 17 00:00:00 2001 From: Wouter Deconinck Date: Thu, 18 Jul 2024 15:19:50 -0500 Subject: rust: rework external find to require both rustc and cargo (#45286) * rust: rework external find to require both rustc and cargo * rust: handle unable to parse version * [@spackbot] updating style on behalf of wdconinc * rust: not x or not y -> not (x and y) Co-authored-by: Alec Scott * rust: pick first rustc found Co-authored-by: Alec Scott * rust: list comprehensions Co-authored-by: Alec Scott --------- Co-authored-by: wdconinc Co-authored-by: Alec Scott --- var/spack/repos/builtin/packages/rust/package.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/var/spack/repos/builtin/packages/rust/package.py b/var/spack/repos/builtin/packages/rust/package.py index 81ab540ade..230d64ca05 100644 --- a/var/spack/repos/builtin/packages/rust/package.py +++ b/var/spack/repos/builtin/packages/rust/package.py @@ -103,10 +103,17 @@ class Rust(Package): phases = ["configure", "build", "install"] @classmethod - def determine_version(csl, exe): - output = Executable(exe)("--version", output=str, error=str) + def determine_spec_details(cls, prefix, exes_in_prefix): + rustc_candidates = [x for x in exes_in_prefix if os.path.basename(x) == "rustc"] + cargo_candidates = [x for x in exes_in_prefix if os.path.basename(x) == "cargo"] + # Both rustc and cargo must be present + if not (rustc_candidates and cargo_candidates): + return + output = Executable(rustc_candidates[0])("--version", output=str, error=str) match = re.match(r"rustc (\S+)", output) - return match.group(1) if match else None + if match: + version_str = match.group(1) + return Spec.from_detection(f"rust@{version_str}") def setup_dependent_package(self, module, dependent_spec): module.cargo = Executable(os.path.join(self.spec.prefix.bin, "cargo")) -- cgit v1.2.3-70-g09d2