Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: Migrate to agave-install when solana_version is >= 1.18.19 #3185

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- idl: Disallow empty discriminators ([#3166](https://github.com/coral-xyz/anchor/pull/3166)).
- cli: Add `--no-idl` option to the `test` command ([#3175](https://github.com/coral-xyz/anchor/pull/3175)).
- spl: Add `burn_checked`, `mint_to_checked` and `approve_checked` instructions ([#3186]([https://github.com/coral-xyz/anchor/pull/3186)).
- cli: Migrate to `agave-install` when `solana_version` is `>= 1.18.19` ([#3185](https://github.com/coral-xyz/anchor/pull/3185)).

### Fixes

Expand Down
47 changes: 42 additions & 5 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,46 @@ fn override_toolchain(cfg_override: &ConfigOverride) -> Result<RestoreToolchainC
// from `~/.local/share/solana/install/releases` because we use multiple Solana
// binaries in various commands.
fn override_solana_version(version: String) -> Result<bool> {
let output = std::process::Command::new("solana-install")
.arg("list")
.output()?;
// There is a deprecation warning message starting with `1.18.19` which causes
// parsing problems https://github.com/coral-xyz/anchor/issues/3147
let (cmd_name, domain) =
if Version::parse(&version)? < Version::parse("1.18.19")? {
("solana-install", "solana.com")
} else {
("agave-install", "anza.xyz")
};

// Install the command if it's not installed
if get_current_version(cmd_name).is_err() {
// `solana-install` and `agave-install` are not usable at the same time i.e.
// using one of them makes the other unusable with the default installation,
// causing the installation process to run each time users switch between
// `agave` supported versions. For example, if the user's active Solana
// version is `1.18.17`, and he specifies `solana_version = "2.0.6"`, this
// code path will run each time an Anchor command gets executed.
eprintln!(
"Command not installed: `{cmd_name}`. \
See https://github.com/anza-xyz/agave/wiki/Agave-Transition, \
installing..."
);
let install_script = std::process::Command::new("curl")
.args([
"-sSfL",
&format!("https://release.{domain}/v{version}/install"),
])
.output()?;
let is_successful = std::process::Command::new("sh")
.args(["-c", std::str::from_utf8(&install_script.stdout)?])
.spawn()?
.wait_with_output()?
.status
.success();
if !is_successful {
return Err(anyhow!("Failed to install `{cmd_name}`"));
}
}

let output = std::process::Command::new(cmd_name).arg("list").output()?;
if !output.status.success() {
return Err(anyhow!("Failed to list installed `solana` versions"));
}
Expand All @@ -590,15 +627,15 @@ fn override_toolchain(cfg_override: &ConfigOverride) -> Result<RestoreToolchainC
(Stdio::inherit(), Stdio::inherit())
};

std::process::Command::new("solana-install")
std::process::Command::new(cmd_name)
.arg("init")
.arg(&version)
.stderr(stderr)
.stdout(stdout)
.spawn()?
.wait()
.map(|status| status.success())
.map_err(|err| anyhow!("Failed to run `solana-install` command: {err}"))
.map_err(|err| anyhow!("Failed to run `{cmd_name}` command: {err}"))
}

match override_solana_version(solana_version.to_owned())? {
Expand Down
Loading