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

self update after updating a specific toolchain #1605

Merged
merged 4 commits into from
Jan 11, 2019
Merged
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
32 changes: 22 additions & 10 deletions src/rustup-cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,30 +200,42 @@ fn show_channel_updates(
Ok(())
}

pub fn update_all_channels(cfg: &Cfg, self_update: bool, force_update: bool) -> Result<()> {
pub fn update_all_channels(cfg: &Cfg, do_self_update: bool, force_update: bool) -> Result<()> {
let toolchains = cfg.update_all_channels(force_update)?;

if toolchains.is_empty() {
info!("no updatable toolchains installed");
}

let setup_path = if self_update {
self_update::prepare_update()?
} else {
None
};
let show_channel_updates = || {
if !toolchains.is_empty() {
println!("");

if !toolchains.is_empty() {
println!("");
show_channel_updates(cfg, toolchains)?;
}
Ok(())
};

show_channel_updates(cfg, toolchains)?;
if do_self_update {
self_update(show_channel_updates)
} else {
show_channel_updates()
}
}

pub fn self_update<F>(before_restart: F) -> Result<()>
where
F: FnOnce() -> Result<()>,
{
let setup_path = self_update::prepare_update()?;

before_restart()?;

if let Some(ref setup_path) = setup_path {
self_update::run_update(setup_path)?;

unreachable!(); // update exits on success
} else if self_update {
} else {
// Try again in case we emitted "tool `{}` is already installed" last time.
self_update::install_proxies()?;
}
Expand Down
30 changes: 25 additions & 5 deletions src/rustup-cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ pub fn cli() -> App<'static, 'static> {
.help(TOOLCHAIN_ARG_HELP)
.required(true)
.multiple(true),
)
.arg(
Arg::with_name("no-self-update")
.help("Don't perform self update when running the `rustup` command")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be:

.help("Don't perform self update when running the `rustup install` command")

perhaps?

.long("no-self-update")
.takes_value(false)
.hidden(true),
)
.arg(
Arg::with_name("force")
.help("Force an update, even if some components are missing")
.long("force")
.takes_value(false),
),
)
.subcommand(
Expand Down Expand Up @@ -196,6 +209,13 @@ pub fn cli() -> App<'static, 'static> {
.help(TOOLCHAIN_ARG_HELP)
.required(true)
.multiple(true),
)
.arg(
Arg::with_name("no-self-update")
.help("Don't perform self update when running the `rustup` command")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here but with

.help("Don't perform self update when running the `rustup toolchain install` command")

perhaps?

.long("no-self-update")
.takes_value(false)
.hidden(true),
),
)
.subcommand(
Expand Down Expand Up @@ -577,6 +597,7 @@ fn default_(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
}

fn update(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
let self_update = !m.is_present("no-self-update") && !self_update::NEVER_SELF_UPDATE;
if let Some(names) = m.values_of("toolchain") {
for name in names {
update_bare_triple_check(cfg, name)?;
Expand All @@ -595,12 +616,11 @@ fn update(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
common::show_channel_update(cfg, toolchain.name(), Ok(status))?;
}
}
if self_update {
common::self_update(|| Ok(()))?;
}
} else {
common::update_all_channels(
cfg,
!m.is_present("no-self-update") && !self_update::NEVER_SELF_UPDATE,
m.is_present("force"),
)?;
common::update_all_channels(cfg, self_update, m.is_present("force"))?;
}

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions tests/cli-exact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn update() {
setup(&|config| {
expect_ok_ex(
config,
&["rustup", "update", "nightly"],
&["rustup", "update", "nightly", "--no-self-update"],
for_host!(
r"
nightly-{0} installed - 1.3.0 (hash-n-2)
Expand All @@ -52,10 +52,10 @@ info: installing component 'rust-docs'
#[test]
fn update_again() {
setup(&|config| {
expect_ok(config, &["rustup", "update", "nightly"]);
expect_ok(config, &["rustup", "update", "nightly", "--no-self-update"]);
expect_ok_ex(
config,
&["rustup", "update", "nightly"],
&["rustup", "update", "nightly", "--no-self-update"],
for_host!(
r"
nightly-{0} unchanged - 1.3.0 (hash-n-2)
Expand Down
24 changes: 12 additions & 12 deletions tests/cli-misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fn upgrade_v2_metadata_to_v12() {
&["rustc", "--version"],
for_host!("toolchain 'nightly-{0}' is not installed"),
);
expect_ok(config, &["rustup", "update", "nightly"]);
expect_ok(config, &["rustup", "update", "nightly", "--no-self-update"]);
expect_stdout_ok(config, &["rustc", "--version"], "hash-n-2");
});
}
Expand Down Expand Up @@ -185,7 +185,7 @@ fn update_all_no_update_whitespace() {
setup(&|config| {
expect_stdout_ok(
config,
&["rustup", "update", "nightly"],
&["rustup", "update", "nightly", "--no-self-update"],
for_host!(
r"
nightly-{} installed - 1.3.0 (hash-n-2)
Expand All @@ -200,7 +200,7 @@ fn update_all_no_update_whitespace() {
#[test]
fn update_works_without_term() {
setup(&|config| {
let mut cmd = clitools::cmd(config, "rustup", &["update", "nightly"]);
let mut cmd = clitools::cmd(config, "rustup", &["update", "nightly", "--no-self-update"]);
clitools::env(config, &mut cmd);
cmd.env_remove("TERM");

Expand Down Expand Up @@ -295,13 +295,13 @@ fn custom_toolchain_cargo_fallback_proxy() {
);
expect_ok(config, &["rustup", "default", "mytoolchain"]);

expect_ok(config, &["rustup", "update", "stable"]);
expect_ok(config, &["rustup", "update", "stable", "--no-self-update"]);
expect_stdout_ok(config, &["cargo", "--version"], "hash-s-2");

expect_ok(config, &["rustup", "update", "beta"]);
expect_ok(config, &["rustup", "update", "beta", "--no-self-update"]);
expect_stdout_ok(config, &["cargo", "--version"], "hash-b-2");

expect_ok(config, &["rustup", "update", "nightly"]);
expect_ok(config, &["rustup", "update", "nightly", "--no-self-update"]);
expect_stdout_ok(config, &["cargo", "--version"], "hash-n-2");
});
}
Expand All @@ -323,21 +323,21 @@ fn custom_toolchain_cargo_fallback_run() {
);
expect_ok(config, &["rustup", "default", "mytoolchain"]);

expect_ok(config, &["rustup", "update", "stable"]);
expect_ok(config, &["rustup", "update", "stable", "--no-self-update"]);
expect_stdout_ok(
config,
&["rustup", "run", "mytoolchain", "cargo", "--version"],
"hash-s-2",
);

expect_ok(config, &["rustup", "update", "beta"]);
expect_ok(config, &["rustup", "update", "beta", "--no-self-update"]);
expect_stdout_ok(
config,
&["rustup", "run", "mytoolchain", "cargo", "--version"],
"hash-b-2",
);

expect_ok(config, &["rustup", "update", "nightly"]);
expect_ok(config, &["rustup", "update", "nightly", "--no-self-update"]);
expect_stdout_ok(
config,
&["rustup", "run", "mytoolchain", "cargo", "--version"],
Expand Down Expand Up @@ -395,7 +395,7 @@ fn rustup_failed_path_search() {
#[test]
fn rustup_run_not_installed() {
setup(&|config| {
expect_ok(config, &["rustup", "install", "stable"]);
expect_ok(config, &["rustup", "install", "stable", "--no-self-update"]);
expect_err(
config,
&["rustup", "run", "nightly", "rustc", "--version"],
Expand All @@ -407,7 +407,7 @@ fn rustup_run_not_installed() {
#[test]
fn rustup_run_install() {
setup(&|config| {
expect_ok(config, &["rustup", "install", "stable"]);
expect_ok(config, &["rustup", "install", "stable", "--no-self-update"]);
expect_stderr_ok(
config,
&[
Expand All @@ -426,7 +426,7 @@ fn rustup_run_install() {
#[test]
fn multirust_env_compat() {
setup(&|config| {
let mut cmd = clitools::cmd(config, "rustup", &["update", "nightly"]);
let mut cmd = clitools::cmd(config, "rustup", &["update", "nightly", "--no-self-update"]);
clitools::env(config, &mut cmd);
cmd.env_remove("RUSTUP_HOME");
cmd.env("MULTIRUST_HOME", &config.rustupdir);
Expand Down
Loading