Skip to content
Draft
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
60 changes: 33 additions & 27 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,34 +689,40 @@ pub async fn main(
toolchain,
force_non_host,
} => default_(cfg, toolchain, force_non_host).await,
RustupSubcmd::Target { subcmd } => match subcmd {
TargetSubcmd::List {
toolchain,
installed,
quiet,
} => handle_epipe(target_list(cfg, toolchain, installed, quiet).await),
TargetSubcmd::Add { target, toolchain } => target_add(cfg, target, toolchain).await,
TargetSubcmd::Remove { target, toolchain } => {
target_remove(cfg, target, toolchain).await
RustupSubcmd::Target { subcmd } => {
cfg.skip_auto_install = true;
match subcmd {
TargetSubcmd::List {
toolchain,
installed,
quiet,
} => handle_epipe(target_list(cfg, toolchain, installed, quiet).await),
TargetSubcmd::Add { target, toolchain } => target_add(cfg, target, toolchain).await,
TargetSubcmd::Remove { target, toolchain } => {
target_remove(cfg, target, toolchain).await
}
}
},
RustupSubcmd::Component { subcmd } => match subcmd {
ComponentSubcmd::List {
toolchain,
installed,
quiet,
} => handle_epipe(component_list(cfg, toolchain, installed, quiet).await),
ComponentSubcmd::Add {
component,
toolchain,
target,
} => component_add(cfg, component, toolchain, target).await,
ComponentSubcmd::Remove {
component,
toolchain,
target,
} => component_remove(cfg, component, toolchain, target).await,
},
}
RustupSubcmd::Component { subcmd } => {
cfg.skip_auto_install = true;
match subcmd {
ComponentSubcmd::List {
toolchain,
installed,
quiet,
} => handle_epipe(component_list(cfg, toolchain, installed, quiet).await),
ComponentSubcmd::Add {
component,
toolchain,
target,
} => component_add(cfg, component, toolchain, target).await,
ComponentSubcmd::Remove {
component,
toolchain,
target,
} => component_remove(cfg, component, toolchain, target).await,
}
}
RustupSubcmd::Override { subcmd } => match subcmd {
OverrideSubcmd::List => handle_epipe(common::list_overrides(cfg)),
OverrideSubcmd::Set { toolchain, path } => {
Expand Down
13 changes: 13 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ pub(crate) struct Cfg<'a> {
pub quiet: bool,
pub current_dir: PathBuf,
pub process: &'a Process,

/// If this flag is set to `true`, it can stop `rustup` from automatically installing the active
/// toolchain in certain undesired cases, such as under `rustup component` and `rustup target`
/// subcommands. This effect has higher precedence than the `RUSTUP_AUTO_INSTALL` environment
/// variable and the `rustup set auto-install` setting.
pub skip_auto_install: bool,
}

impl<'a> Cfg<'a> {
Expand Down Expand Up @@ -317,6 +323,7 @@ impl<'a> Cfg<'a> {
quiet,
current_dir,
process,
skip_auto_install: false,
};

// Run some basic checks against the constructed configuration
Expand Down Expand Up @@ -373,6 +380,10 @@ impl<'a> Cfg<'a> {
}

pub(crate) fn should_auto_install(&self) -> Result<bool> {
if self.skip_auto_install {
return Ok(false);
}

if let Ok(mode) = self.process.var("RUSTUP_AUTO_INSTALL") {
Ok(mode != "0")
} else {
Expand Down Expand Up @@ -959,6 +970,7 @@ impl Debug for Cfg<'_> {
dist_root_url,
quiet,
current_dir,
skip_auto_install,
process: _,
} = self;

Expand All @@ -976,6 +988,7 @@ impl Debug for Cfg<'_> {
.field("dist_root_url", dist_root_url)
.field("quiet", quiet)
.field("current_dir", current_dir)
.field("skip_auto_install", skip_auto_install)
.finish()
}
}
Expand Down
Loading