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 <hi@alecbcs.com>

* rust: pick first rustc found

Co-authored-by: Alec Scott <hi@alecbcs.com>

* rust: list comprehensions

Co-authored-by: Alec Scott <hi@alecbcs.com>

---------

Co-authored-by: wdconinc <wdconinc@users.noreply.github.com>
Co-authored-by: Alec Scott <hi@alecbcs.com>
This commit is contained in:
Wouter Deconinck 2024-07-18 15:19:50 -05:00 committed by GitHub
parent ab723b25d0
commit ad1fc34199
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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"))