feat(rustup): install packages

Rustup is now able to install toolchains and
components and works with multiple toolchains and
components for each toolchain.

Signed-off-by: innocentzero <isfarulhaque@proton.me>
This commit is contained in:
innocentzero
2024-04-02 04:51:15 +05:30
parent ea2c51620a
commit fbedd6da49
@@ -4,6 +4,7 @@ use crate::{Group, Package};
use anyhow::Context; use anyhow::Context;
use core::panic; use core::panic;
use std::collections::HashSet; use std::collections::HashSet;
use std::os::unix::process::ExitStatusExt;
use std::process::Command; use std::process::Command;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@@ -57,6 +58,49 @@ impl Backend for Rustup {
panic!("Not supported by {}", BINARY) panic!("Not supported by {}", BINARY)
} }
fn install_packages(
&self,
packages: &[Package],
_noconfirm: bool,
) -> anyhow::Result<std::process::ExitStatus> {
let mut result: anyhow::Result<std::process::ExitStatus> =
Ok(std::process::ExitStatus::from_raw(0));
for p in packages {
let repo = p
.repo
.as_ref()
.expect("Not specified whether it is a toolchain or a component!");
if repo == "toolchain" {
let mut cmd = Command::new(self.get_binary());
cmd.args(&[&"toolchain", &"install"]);
cmd.arg(format!("{}", p.name));
result = cmd.status().context("Installing toolchain {p}");
if !result.as_ref().is_ok_and(|exit| exit.success()) {
return result;
}
};
}
for p in packages {
let repo = p
.repo
.as_ref()
.expect("Not specified wether it is a component or a toolchain!");
if repo == "component" {
let mut iter = p.name.split('/');
let toolchain = iter.next().expect("Toolchain not specified!");
let component = iter.next().expect("Component not specified!");
let mut cmd = Command::new(self.get_binary());
cmd.args(&[&"component", &"add"]);
cmd.args([&"--toolchain", format!("{toolchain}").as_str()]);
cmd.arg(format!("{component}"));
result = cmd.status().context("Installing component {p}");
if !result.as_ref().is_ok_and(|exit| exit.success()) {
return result;
}
}
}
result
}
} }
impl Rustup { impl Rustup {