From ede341924dc6bc64e89c41da9f3397d0fe2ce91b Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 13 Jun 2020 15:09:55 +0100 Subject: [PATCH 1/3] install: Support --no-update-default-toolchain Signed-off-by: Daniel Silverstone --- src/cli/self_update.rs | 22 ++++++++++++++++------ src/cli/setup_mode.rs | 7 +++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs index 60606f486f..41f93f50c8 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -71,6 +71,7 @@ pub struct InstallOpts<'a> { pub default_toolchain: Option, pub profile: String, pub no_modify_path: bool, + pub no_update_toolchain: bool, pub components: &'a [&'a str], pub targets: &'a [&'a str], } @@ -328,6 +329,7 @@ pub fn install( opts.default_toolchain.as_deref(), &opts.profile, opts.default_host_triple.as_deref(), + !opts.no_update_toolchain, opts.components, opts.targets, verbose, @@ -712,6 +714,7 @@ fn maybe_install_rust( toolchain: Option<&str>, profile_str: &str, default_host_triple: Option<&str>, + update_existing_toolchain: bool, components: &[&str], targets: &[&str], verbose: bool, @@ -728,8 +731,10 @@ fn maybe_install_rust( info!("default host triple is {}", cfg.get_default_host_triple()?); } - let user_specified_something = - toolchain.is_some() || !targets.is_empty() || !components.is_empty(); + let user_specified_something = toolchain.is_some() + || !targets.is_empty() + || !components.is_empty() + || update_existing_toolchain; // If the user specified they want no toolchain, we skip this, otherwise // if they specify something directly, or we have no default, then we install @@ -754,16 +759,21 @@ fn maybe_install_rust( } writeln!(process().stdout())?; } else if user_specified_something || cfg.find_default()?.is_none() { - let toolchain_str = toolchain.unwrap_or("stable"); - let toolchain = cfg.get_toolchain(toolchain_str, false)?; + let (toolchain_str, toolchain) = match toolchain { + Some(s) => (s.to_owned(), cfg.get_toolchain(s, false)?), + None => match cfg.find_default()? { + Some(t) => (t.name().to_owned(), t), + None => ("stable".to_owned(), cfg.get_toolchain("stable", false)?), + }, + }; if toolchain.exists() { warn!("Updating existing toolchain, profile choice will be ignored"); } let distributable = DistributableToolchain::new(&toolchain)?; let status = distributable.install_from_dist(true, false, components, targets)?; - cfg.set_default(toolchain_str)?; + cfg.set_default(&toolchain_str)?; writeln!(process().stdout())?; - common::show_channel_update(&cfg, toolchain_str, Ok(status))?; + common::show_channel_update(&cfg, &toolchain_str, Ok(status))?; } else { info!("updating existing rustup installation - leaving toolchains alone"); writeln!(process().stdout())?; diff --git a/src/cli/setup_mode.rs b/src/cli/setup_mode.rs index 1d115a858d..84ba9e334d 100644 --- a/src/cli/setup_mode.rs +++ b/src/cli/setup_mode.rs @@ -81,6 +81,11 @@ pub fn main() -> Result { .multiple(true) .use_delimiter(true), ) + .arg( + Arg::with_name("no-update-default-toolchain") + .long("no-update-default-toolchain") + .help("Don't update any existing default toolchain after install"), + ) .arg( Arg::with_name("no-modify-path") .long("no-modify-path") @@ -106,6 +111,7 @@ pub fn main() -> Result { .value_of("profile") .expect("Unreachable: Clap should supply a default"); let no_modify_path = matches.is_present("no-modify-path"); + let no_update_toolchain = matches.is_present("no-update-default-toolchain"); let components: Vec<_> = matches .values_of("components") @@ -122,6 +128,7 @@ pub fn main() -> Result { default_toolchain, profile: profile.to_owned(), no_modify_path, + no_update_toolchain, components: &components, targets: &targets, }; From 9bf7f461cdcd902b0dc1fd67bcd195f6d10c131b Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 13 Jun 2020 15:11:08 +0100 Subject: [PATCH 2/3] test: Do not update toolchain in exact output check Signed-off-by: Daniel Silverstone --- tests/cli-inst-interactive.rs | 6 +++++- tests/cli-self-upd.rs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/cli-inst-interactive.rs b/tests/cli-inst-interactive.rs index 0d8dbfcd1c..4ecd5e7f3f 100644 --- a/tests/cli-inst-interactive.rs +++ b/tests/cli-inst-interactive.rs @@ -124,7 +124,11 @@ Rust is installed now. Great! fn blank_lines_around_stderr_log_output_update() { setup(&|config| { run_input(config, &["rustup-init"], "\n\n"); - let out = run_input(config, &["rustup-init"], "\n\n"); + let out = run_input( + config, + &["rustup-init", "--no-update-default-toolchain"], + "\n\n", + ); println!("-- stdout --\n {}", out.stdout); println!("-- stderr --\n {}", out.stderr); diff --git a/tests/cli-self-upd.rs b/tests/cli-self-upd.rs index 78abc60ed3..23437d6c39 100644 --- a/tests/cli-self-upd.rs +++ b/tests/cli-self-upd.rs @@ -901,7 +901,7 @@ fn reinstall_exact() { expect_ok(config, &["rustup-init", "-y"]); expect_stderr_ok( config, - &["rustup-init", "-y"], + &["rustup-init", "-y", "--no-update-default-toolchain"], r"info: updating existing rustup installation - leaving toolchains alone", ); }); From b02bc1a7995f2448e7f4255ee373a227317a3d2b Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 13 Jun 2020 15:24:24 +0100 Subject: [PATCH 3/3] test: Ensure we try and update by default Signed-off-by: Daniel Silverstone --- tests/cli-inst-interactive.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/cli-inst-interactive.rs b/tests/cli-inst-interactive.rs index 4ecd5e7f3f..d135734494 100644 --- a/tests/cli-inst-interactive.rs +++ b/tests/cli-inst-interactive.rs @@ -14,6 +14,12 @@ use std::io::Write; use std::process::Stdio; use std::sync::Mutex; +macro_rules! for_host { + ($s: expr) => { + &format!($s, this_host_triple()) + }; +} + pub fn setup_(complex: bool, f: &dyn Fn(&Config)) { let scenario = if complex { Scenario::UnavailableRls @@ -411,3 +417,15 @@ fn test_succeed_if_rustup_sh_already_installed_env_var_set() { assert!(!out.stdout.contains("Continue? (y/N)")); }) } + +#[test] +fn installing_when_already_installed_updates_toolchain() { + setup(&|config| { + run_input(config, &["rustup-init"], "\n\n"); + let out = run_input(config, &["rustup-init"], "\n\n"); + println!("stdout:\n{}\n...\n", out.stdout); + assert!(out + .stdout + .contains(for_host!("stable-{} unchanged - 1.1.0 (hash-stable-1.1.0)"))); + }) +}