Skip to content

Commit

Permalink
fix!(config): re-enable implicit toolchain installation in `Cfg::loca…
Browse files Browse the repository at this point in the history
…l_toolchain()` with optional opt-out
  • Loading branch information
rami3l committed Mar 5, 2025
1 parent 2e8ad9d commit d5deaef
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
19 changes: 13 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,16 +784,23 @@ impl<'a> Cfg<'a> {
}

async fn local_toolchain(&self, name: Option<LocalToolchainName>) -> Result<Toolchain<'_>> {
let toolchain = match name {
Some(tc) => tc,
match name {
Some(tc) => {
let install_if_missing = self
.process
.var("RUSTUP_AUTO_INSTALL")
.map_or(true, |it| it != "0");
Toolchain::from_local(tc, install_if_missing, self).await
}
None => {
self.find_active_toolchain(None)
let tc = self
.find_active_toolchain(None)
.await?
.ok_or_else(|| no_toolchain_error(self.process))?
.0
.0;
Ok(Toolchain::new(self, tc)?)
}
};
Ok(Toolchain::new(self, toolchain)?)
}
}

#[tracing::instrument(level = "trace", skip_all)]
Expand Down
4 changes: 2 additions & 2 deletions tests/suite/cli_exact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,9 @@ info: installing component 'rust-std' for '{0}'
async fn show_suggestion_for_missing_toolchain() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect_err_ex(
.expect_err_env(
&["cargo", "+nightly", "fmt"],
r"",
&[("RUSTUP_AUTO_INSTALL", "0")],
for_host!(
r"error: toolchain 'nightly-{0}' is not installed
help: run `rustup toolchain install nightly-{0}` to install it
Expand Down
4 changes: 2 additions & 2 deletions tests/suite/cli_misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,9 +1088,9 @@ async fn which_asking_uninstalled_toolchain() {
)
.await;
cx.config
.expect_err(
.expect_stdout_ok(
&["rustup", "which", "--toolchain=nightly", "rustc"],
for_host!("toolchain 'nightly-{}' is not installed"),
for_host!("toolchains/nightly-{0}/bin/rustc"),
)
.await;
}
Expand Down
13 changes: 9 additions & 4 deletions tests/suite/cli_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,9 @@ async fn file_override_toolchain_err_handling() {
async fn plus_override_toolchain_err_handling() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect_err(
.expect_err_env(
&["rustc", "+beta"],
&[("RUSTUP_AUTO_INSTALL", "0")],
for_host!("toolchain 'beta-{0}' is not installed"),
)
.await;
Expand Down Expand Up @@ -776,8 +777,9 @@ async fn upgrade_v2_to_v1() {
async fn list_targets_no_toolchain() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect_err(
.expect_err_env(
&["rustup", "target", "list", "--toolchain=nightly"],
&[("RUSTUP_AUTO_INSTALL", "0")],
for_host!("toolchain 'nightly-{0}' is not installed"),
)
.await;
Expand Down Expand Up @@ -962,18 +964,20 @@ async fn remove_target_by_component_remove() {
async fn add_target_no_toolchain() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect_err(
.expect_err_env(
&[
"rustup",
"target",
"add",
CROSS_ARCH1,
"--toolchain=nightly",
],
&[("RUSTUP_AUTO_INSTALL", "0")],
for_host!("toolchain 'nightly-{0}' is not installed"),
)
.await;
}

#[tokio::test]
async fn add_target_bogus() {
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
Expand Down Expand Up @@ -1120,14 +1124,15 @@ async fn remove_target_not_installed() {
async fn remove_target_no_toolchain() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect_err(
.expect_err_env(
&[
"rustup",
"target",
"remove",
CROSS_ARCH1,
"--toolchain=nightly",
],
&[("RUSTUP_AUTO_INSTALL", "0")],
for_host!("toolchain 'nightly-{0}' is not installed"),
)
.await;
Expand Down

0 comments on commit d5deaef

Please sign in to comment.