Skip to content

rustup show shouldn't install things #3360

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

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,8 +1069,8 @@ fn show(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {

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 {
Expand Down
22 changes: 20 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,22 @@ impl Cfg {
pub(crate) fn find_or_install_override_toolchain_or_default(
&self,
path: &Path,
) -> Result<(Toolchain<'_>, Option<OverrideReason>)> {
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<OverrideReason>)> {
self.find_toolchain(path, false)
}

fn find_toolchain(
&self,
path: &Path,
install_if_missing: bool,
) -> Result<(Toolchain<'_>, Option<OverrideReason>)> {
let (toolchain, components, targets, reason, profile) =
match self.find_override_config(path)? {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down