Skip to content

Commit a9d0c67

Browse files
committed
Do not install toolchain on rustup show * and rustup --version
1 parent 3ac5076 commit a9d0c67

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/cli/rustup_mode.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ pub fn main() -> Result<utils::ExitCode> {
8585
cfg.set_toolchain_override(&t[1..]);
8686
}
8787

88-
let toolchain = cfg.find_or_install_override_toolchain_or_default(&cwd)?.0;
88+
let toolchain = cfg
89+
.find_or_install_override_toolchain_or_default(&cwd, false)?
90+
.0;
8991

9092
Ok(toolchain.rustc_version())
9193
}
@@ -1051,7 +1053,7 @@ fn show(cfg: &Cfg) -> Result<utils::ExitCode> {
10511053
let cwd = utils::current_dir()?;
10521054
let installed_toolchains = cfg.list_toolchains()?;
10531055
// XXX: we may want a find_without_install capability for show.
1054-
let active_toolchain = cfg.find_or_install_override_toolchain_or_default(&cwd);
1056+
let active_toolchain = cfg.find_or_install_override_toolchain_or_default(&cwd, false);
10551057

10561058
// active_toolchain will carry the reason we don't have one in its detail.
10571059
let active_targets = if let Ok(ref at) = active_toolchain {
@@ -1176,7 +1178,7 @@ fn show(cfg: &Cfg) -> Result<utils::ExitCode> {
11761178

11771179
fn show_active_toolchain(cfg: &Cfg) -> Result<utils::ExitCode> {
11781180
let cwd = utils::current_dir()?;
1179-
match cfg.find_or_install_override_toolchain_or_default(&cwd) {
1181+
match cfg.find_or_install_override_toolchain_or_default(&cwd, false) {
11801182
Err(crate::Error(crate::ErrorKind::ToolchainNotSelected, _)) => {}
11811183
Err(e) => return Err(e.into()),
11821184
Ok((toolchain, reason)) => {
@@ -1337,7 +1339,7 @@ fn explicit_or_dir_toolchain<'a>(cfg: &'a Cfg, m: &ArgMatches<'_>) -> Result<Too
13371339
}
13381340

13391341
let cwd = utils::current_dir()?;
1340-
let (toolchain, _) = cfg.toolchain_for_dir(&cwd)?;
1342+
let (toolchain, _) = cfg.find_or_install_override_toolchain_or_default(&cwd, true)?;
13411343

13421344
Ok(toolchain)
13431345
}

src/config.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ impl Cfg {
409409
}
410410

411411
pub fn which_binary(&self, path: &Path, binary: &str) -> Result<Option<PathBuf>> {
412-
let (toolchain, _) = self.find_or_install_override_toolchain_or_default(path)?;
412+
let (toolchain, _) = self.find_or_install_override_toolchain_or_default(path, true)?;
413413
Ok(Some(toolchain.binary_file(binary)))
414414
}
415415

@@ -620,6 +620,7 @@ impl Cfg {
620620
pub fn find_or_install_override_toolchain_or_default(
621621
&self,
622622
path: &Path,
623+
install: bool,
623624
) -> Result<(Toolchain<'_>, Option<OverrideReason>)> {
624625
fn components_exist(
625626
distributable: &DistributableToolchain<'_>,
@@ -699,7 +700,9 @@ impl Cfg {
699700
let targets: Vec<_> = targets.iter().map(AsRef::as_ref).collect();
700701

701702
let distributable = DistributableToolchain::new(&toolchain)?;
702-
if !toolchain.exists() || !components_exist(&distributable, &components, &targets)?
703+
if install
704+
&& (!toolchain.exists()
705+
|| !components_exist(&distributable, &components, &targets)?)
703706
{
704707
distributable.install_from_dist(true, false, &components, &targets, profile)?;
705708
}
@@ -789,15 +792,8 @@ impl Cfg {
789792
})
790793
}
791794

792-
pub fn toolchain_for_dir(
793-
&self,
794-
path: &Path,
795-
) -> Result<(Toolchain<'_>, Option<OverrideReason>)> {
796-
self.find_or_install_override_toolchain_or_default(path)
797-
}
798-
799795
pub fn create_command_for_dir(&self, path: &Path, binary: &str) -> Result<Command> {
800-
let (ref toolchain, _) = self.toolchain_for_dir(path)?;
796+
let (ref toolchain, _) = self.find_or_install_override_toolchain_or_default(path, true)?;
801797

802798
if let Some(cmd) = self.maybe_do_cargo_fallback(toolchain, binary)? {
803799
Ok(cmd)

0 commit comments

Comments
 (0)