Skip to content
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

Do not install toolchain on rustup show * and rustup --version #2658

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
10 changes: 6 additions & 4 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ pub fn main() -> Result<utils::ExitCode> {
cfg.set_toolchain_override(&t[1..]);
}

let toolchain = cfg.find_or_install_override_toolchain_or_default(&cwd)?.0;
let toolchain = cfg
.find_or_install_override_toolchain_or_default(&cwd, false)?
.0;

Ok(toolchain.rustc_version())
}
Expand Down Expand Up @@ -1051,7 +1053,7 @@ fn show(cfg: &Cfg) -> 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);
let active_toolchain = cfg.find_or_install_override_toolchain_or_default(&cwd, false);

// 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 Expand Up @@ -1176,7 +1178,7 @@ fn show(cfg: &Cfg) -> Result<utils::ExitCode> {

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

let cwd = utils::current_dir()?;
let (toolchain, _) = cfg.toolchain_for_dir(&cwd)?;
let (toolchain, _) = cfg.find_or_install_override_toolchain_or_default(&cwd, true)?;

Ok(toolchain)
}
Expand Down
16 changes: 6 additions & 10 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ impl Cfg {
}

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

Expand Down Expand Up @@ -620,6 +620,7 @@ impl Cfg {
pub fn find_or_install_override_toolchain_or_default(
&self,
path: &Path,
install: bool,
) -> Result<(Toolchain<'_>, Option<OverrideReason>)> {
fn components_exist(
distributable: &DistributableToolchain<'_>,
Expand Down Expand Up @@ -699,7 +700,9 @@ impl Cfg {
let targets: Vec<_> = targets.iter().map(AsRef::as_ref).collect();

let distributable = DistributableToolchain::new(&toolchain)?;
if !toolchain.exists() || !components_exist(&distributable, &components, &targets)?
if install
&& (!toolchain.exists()
|| !components_exist(&distributable, &components, &targets)?)
{
distributable.install_from_dist(true, false, &components, &targets, profile)?;
}
Expand Down Expand Up @@ -789,15 +792,8 @@ impl Cfg {
})
}

pub fn toolchain_for_dir(
&self,
path: &Path,
) -> Result<(Toolchain<'_>, Option<OverrideReason>)> {
self.find_or_install_override_toolchain_or_default(path)
}

pub fn create_command_for_dir(&self, path: &Path, binary: &str) -> Result<Command> {
let (ref toolchain, _) = self.toolchain_for_dir(path)?;
let (ref toolchain, _) = self.find_or_install_override_toolchain_or_default(path, true)?;

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