Skip to content

Commit 6d6e137

Browse files
authored
Merge pull request #2339 from kinnison/update-or-check-on-install
Update on install
2 parents 771725d + b02bc1a commit 6d6e137

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

src/cli/self_update.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub struct InstallOpts<'a> {
7171
pub default_toolchain: Option<String>,
7272
pub profile: String,
7373
pub no_modify_path: bool,
74+
pub no_update_toolchain: bool,
7475
pub components: &'a [&'a str],
7576
pub targets: &'a [&'a str],
7677
}
@@ -328,6 +329,7 @@ pub fn install(
328329
opts.default_toolchain.as_deref(),
329330
&opts.profile,
330331
opts.default_host_triple.as_deref(),
332+
!opts.no_update_toolchain,
331333
opts.components,
332334
opts.targets,
333335
verbose,
@@ -712,6 +714,7 @@ fn maybe_install_rust(
712714
toolchain: Option<&str>,
713715
profile_str: &str,
714716
default_host_triple: Option<&str>,
717+
update_existing_toolchain: bool,
715718
components: &[&str],
716719
targets: &[&str],
717720
verbose: bool,
@@ -728,8 +731,10 @@ fn maybe_install_rust(
728731
info!("default host triple is {}", cfg.get_default_host_triple()?);
729732
}
730733

731-
let user_specified_something =
732-
toolchain.is_some() || !targets.is_empty() || !components.is_empty();
734+
let user_specified_something = toolchain.is_some()
735+
|| !targets.is_empty()
736+
|| !components.is_empty()
737+
|| update_existing_toolchain;
733738

734739
// If the user specified they want no toolchain, we skip this, otherwise
735740
// if they specify something directly, or we have no default, then we install
@@ -754,16 +759,21 @@ fn maybe_install_rust(
754759
}
755760
writeln!(process().stdout())?;
756761
} else if user_specified_something || cfg.find_default()?.is_none() {
757-
let toolchain_str = toolchain.unwrap_or("stable");
758-
let toolchain = cfg.get_toolchain(toolchain_str, false)?;
762+
let (toolchain_str, toolchain) = match toolchain {
763+
Some(s) => (s.to_owned(), cfg.get_toolchain(s, false)?),
764+
None => match cfg.find_default()? {
765+
Some(t) => (t.name().to_owned(), t),
766+
None => ("stable".to_owned(), cfg.get_toolchain("stable", false)?),
767+
},
768+
};
759769
if toolchain.exists() {
760770
warn!("Updating existing toolchain, profile choice will be ignored");
761771
}
762772
let distributable = DistributableToolchain::new(&toolchain)?;
763773
let status = distributable.install_from_dist(true, false, components, targets)?;
764-
cfg.set_default(toolchain_str)?;
774+
cfg.set_default(&toolchain_str)?;
765775
writeln!(process().stdout())?;
766-
common::show_channel_update(&cfg, toolchain_str, Ok(status))?;
776+
common::show_channel_update(&cfg, &toolchain_str, Ok(status))?;
767777
} else {
768778
info!("updating existing rustup installation - leaving toolchains alone");
769779
writeln!(process().stdout())?;

src/cli/setup_mode.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ pub fn main() -> Result<utils::ExitCode> {
8181
.multiple(true)
8282
.use_delimiter(true),
8383
)
84+
.arg(
85+
Arg::with_name("no-update-default-toolchain")
86+
.long("no-update-default-toolchain")
87+
.help("Don't update any existing default toolchain after install"),
88+
)
8489
.arg(
8590
Arg::with_name("no-modify-path")
8691
.long("no-modify-path")
@@ -106,6 +111,7 @@ pub fn main() -> Result<utils::ExitCode> {
106111
.value_of("profile")
107112
.expect("Unreachable: Clap should supply a default");
108113
let no_modify_path = matches.is_present("no-modify-path");
114+
let no_update_toolchain = matches.is_present("no-update-default-toolchain");
109115

110116
let components: Vec<_> = matches
111117
.values_of("components")
@@ -122,6 +128,7 @@ pub fn main() -> Result<utils::ExitCode> {
122128
default_toolchain,
123129
profile: profile.to_owned(),
124130
no_modify_path,
131+
no_update_toolchain,
125132
components: &components,
126133
targets: &targets,
127134
};

tests/cli-inst-interactive.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ use std::io::Write;
1414
use std::process::Stdio;
1515
use std::sync::Mutex;
1616

17+
macro_rules! for_host {
18+
($s: expr) => {
19+
&format!($s, this_host_triple())
20+
};
21+
}
22+
1723
pub fn setup_(complex: bool, f: &dyn Fn(&Config)) {
1824
let scenario = if complex {
1925
Scenario::UnavailableRls
@@ -124,7 +130,11 @@ Rust is installed now. Great!
124130
fn blank_lines_around_stderr_log_output_update() {
125131
setup(&|config| {
126132
run_input(config, &["rustup-init"], "\n\n");
127-
let out = run_input(config, &["rustup-init"], "\n\n");
133+
let out = run_input(
134+
config,
135+
&["rustup-init", "--no-update-default-toolchain"],
136+
"\n\n",
137+
);
128138
println!("-- stdout --\n {}", out.stdout);
129139
println!("-- stderr --\n {}", out.stderr);
130140

@@ -407,3 +417,15 @@ fn test_succeed_if_rustup_sh_already_installed_env_var_set() {
407417
assert!(!out.stdout.contains("Continue? (y/N)"));
408418
})
409419
}
420+
421+
#[test]
422+
fn installing_when_already_installed_updates_toolchain() {
423+
setup(&|config| {
424+
run_input(config, &["rustup-init"], "\n\n");
425+
let out = run_input(config, &["rustup-init"], "\n\n");
426+
println!("stdout:\n{}\n...\n", out.stdout);
427+
assert!(out
428+
.stdout
429+
.contains(for_host!("stable-{} unchanged - 1.1.0 (hash-stable-1.1.0)")));
430+
})
431+
}

tests/cli-self-upd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ fn reinstall_exact() {
904904
expect_ok(config, &["rustup-init", "-y"]);
905905
expect_stderr_ok(
906906
config,
907-
&["rustup-init", "-y"],
907+
&["rustup-init", "-y", "--no-update-default-toolchain"],
908908
r"info: updating existing rustup installation - leaving toolchains alone",
909909
);
910910
});

0 commit comments

Comments
 (0)