|
@@ -495,21 +495,28 @@ fn override_toolchain(cfg_override: &ConfigOverride) -> Result<RestoreToolchainC
|
|
|
|
|
|
let cfg = Config::discover(cfg_override)?;
|
|
|
if let Some(cfg) = cfg {
|
|
|
- fn get_current_version(cmd_name: &str) -> Result<String> {
|
|
|
- let output = std::process::Command::new(cmd_name)
|
|
|
- .arg("--version")
|
|
|
- .output()?;
|
|
|
- let output_version = std::str::from_utf8(&output.stdout)?;
|
|
|
- let version = Regex::new(r"(\d+\.\d+\.\S+)")
|
|
|
+ fn parse_version(text: &str) -> String {
|
|
|
+ Regex::new(r"(\d+\.\d+\.\S+)")
|
|
|
.unwrap()
|
|
|
- .captures_iter(output_version)
|
|
|
+ .captures_iter(text)
|
|
|
.next()
|
|
|
.unwrap()
|
|
|
.get(0)
|
|
|
.unwrap()
|
|
|
.as_str()
|
|
|
- .to_string();
|
|
|
+ .to_string()
|
|
|
+ }
|
|
|
|
|
|
+ fn get_current_version(cmd_name: &str) -> Result<String> {
|
|
|
+ let output = std::process::Command::new(cmd_name)
|
|
|
+ .arg("--version")
|
|
|
+ .output()?;
|
|
|
+ if !output.status.success() {
|
|
|
+ return Err(anyhow!("Failed to run `{cmd_name} --version`"));
|
|
|
+ }
|
|
|
+
|
|
|
+ let output_version = std::str::from_utf8(&output.stdout)?;
|
|
|
+ let version = parse_version(output_version);
|
|
|
Ok(version)
|
|
|
}
|
|
|
|
|
@@ -519,15 +526,33 @@ fn override_toolchain(cfg_override: &ConfigOverride) -> Result<RestoreToolchainC
|
|
|
// We are overriding with `solana-install` command instead of using the binaries
|
|
|
// from `~/.local/share/solana/install/releases` because we use multiple Solana
|
|
|
// binaries in various commands.
|
|
|
- fn override_solana_version(version: String) -> std::io::Result<bool> {
|
|
|
+ fn override_solana_version(version: String) -> Result<bool> {
|
|
|
+ let output = std::process::Command::new("solana-install")
|
|
|
+ .arg("list")
|
|
|
+ .output()?;
|
|
|
+ if !output.status.success() {
|
|
|
+ return Err(anyhow!("Failed to list installed `solana` versions"));
|
|
|
+ }
|
|
|
+
|
|
|
+ // Hide the installation progress if the version is already installed
|
|
|
+ let is_installed = std::str::from_utf8(&output.stdout)?
|
|
|
+ .lines()
|
|
|
+ .any(|line| parse_version(line) == version);
|
|
|
+ let (stderr, stdout) = if is_installed {
|
|
|
+ (Stdio::null(), Stdio::null())
|
|
|
+ } else {
|
|
|
+ (Stdio::inherit(), Stdio::inherit())
|
|
|
+ };
|
|
|
+
|
|
|
std::process::Command::new("solana-install")
|
|
|
.arg("init")
|
|
|
.arg(&version)
|
|
|
- .stderr(Stdio::null())
|
|
|
- .stdout(Stdio::null())
|
|
|
+ .stderr(stderr)
|
|
|
+ .stdout(stdout)
|
|
|
.spawn()?
|
|
|
.wait()
|
|
|
.map(|status| status.success())
|
|
|
+ .map_err(|err| anyhow!("Failed to run `solana-install` command: {err}"))
|
|
|
}
|
|
|
|
|
|
match override_solana_version(solana_version.to_owned())? {
|
|
@@ -537,12 +562,10 @@ fn override_toolchain(cfg_override: &ConfigOverride) -> Result<RestoreToolchainC
|
|
|
false => Err(anyhow!("Failed to restore `solana` version")),
|
|
|
}
|
|
|
})),
|
|
|
- false => {
|
|
|
- eprintln!(
|
|
|
- "Failed to override `solana` version to {solana_version}, \
|
|
|
+ false => eprintln!(
|
|
|
+ "Failed to override `solana` version to {solana_version}, \
|
|
|
using {current_version} instead"
|
|
|
- );
|
|
|
- }
|
|
|
+ ),
|
|
|
}
|
|
|
}
|
|
|
}
|