From 39e8e91235769e9ba7a979a3f9c5dc36e82fab0c Mon Sep 17 00:00:00 2001 From: John Kelly Date: Sun, 21 May 2023 16:42:47 +0100 Subject: [PATCH] Default host: aarch64-apple-darwin rustup home: /Users/johnk/.rustup installed toolchains -------------------- stable-aarch64-apple-darwin (default) nightly-2023-04-23-aarch64-apple-darwin nightly-aarch64-apple-darwin 1.60-aarch64-apple-darwin 1.69-aarch64-apple-darwin dev stage1 stage2 1.65.0-aarch64-apple-darwin 1.69.0-aarch64-apple-darwin installed targets for active toolchain -------------------------------------- aarch64-apple-darwin aarch64-pc-windows-msvc wasm32-unknown-unknown active toolchain ---------------- stable-aarch64-apple-darwin (default) rustc 1.69.0 (84c898d65 2023-04-16) shouldn't install things --- src/cli/rustup_mode.rs | 4 ++-- src/config.rs | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 56d3c5c0cd..8097179584 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -1069,8 +1069,8 @@ fn show(cfg: &Cfg, m: &ArgMatches) -> Result { let cwd = utils::current_dir()?; let installed_toolchains = cfg.list_toolchains()?; - // XXX: we may want a find_without_install capability for show. - let active_toolchain = cfg.find_or_install_override_toolchain_or_default(&cwd); + // Retrieve the active toolchain but do not install it + let active_toolchain = cfg.find_override_toolchain_or_default(&cwd); // active_toolchain will carry the reason we don't have one in its detail. let active_targets = if let Ok(ref at) = active_toolchain { diff --git a/src/config.rs b/src/config.rs index 3e1fbcd8a1..b0d9e7016d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -659,6 +659,22 @@ impl Cfg { pub(crate) fn find_or_install_override_toolchain_or_default( &self, path: &Path, + ) -> Result<(Toolchain<'_>, Option)> { + self.find_toolchain(path, true) + } + + #[cfg_attr(feature = "otel", tracing::instrument(skip_all))] + pub(crate) fn find_override_toolchain_or_default( + &self, + path: &Path, + ) -> Result<(Toolchain<'_>, Option)> { + self.find_toolchain(path, false) + } + + fn find_toolchain( + &self, + path: &Path, + install_if_missing: bool, ) -> Result<(Toolchain<'_>, Option)> { let (toolchain, components, targets, reason, profile) = match self.find_override_config(path)? { @@ -688,7 +704,7 @@ impl Cfg { let components: Vec<_> = components.iter().map(AsRef::as_ref).collect(); let targets: Vec<_> = targets.iter().map(AsRef::as_ref).collect(); let toolchain = match DistributableToolchain::new(self, desc.clone()) { - Err(RustupError::ToolchainNotInstalled(_)) => { + Err(RustupError::ToolchainNotInstalled(_)) if install_if_missing => { DistributableToolchain::install( self, &desc, @@ -700,7 +716,9 @@ impl Cfg { .1 } Ok(mut distributable) => { - if !distributable.components_exist(&components, &targets)? { + if install_if_missing + && !distributable.components_exist(&components, &targets)? + { distributable.update( &components, &targets,