From f9bff6734a09b664311f6843da29f09d8c6928d1 Mon Sep 17 00:00:00 2001 From: rami3l Date: Tue, 6 Aug 2024 19:30:41 +0800 Subject: [PATCH] feat(rustup-mode): install the active toolchain by default on `rustup toolchain install` --- src/cli/rustup_mode.rs | 9 +++-- ...rustup_toolchain_cmd_help_flag_stdout.toml | 2 +- ...hain_cmd_install_cmd_help_flag_stdout.toml | 7 ++-- tests/suite/cli_rustup.rs | 34 +++++++++++++++++++ 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index c7d0f0c376..03a6470805 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -100,7 +100,7 @@ fn plus_toolchain_value_parser(s: &str) -> clap::error::Result Result common::dump_testament(process), - RustupSubcmd::Install { opts } => update(cfg, opts, false).await, + RustupSubcmd::Install { opts } => update(cfg, opts, true).await, RustupSubcmd::Uninstall { opts } => toolchain_remove(cfg, opts), RustupSubcmd::Show { verbose, subcmd } => handle_epipe(match subcmd { None => show(cfg, verbose), @@ -615,7 +614,7 @@ pub async fn main(current_dir: PathBuf, process: &Process) -> Result match subcmd { - ToolchainSubcmd::Install { opts } => update(cfg, opts, false).await, + ToolchainSubcmd::Install { opts } => update(cfg, opts, true).await, ToolchainSubcmd::List { verbose, quiet } => { handle_epipe(common::list_toolchains(cfg, verbose, quiet)) } diff --git a/tests/suite/cli-ui/rustup/rustup_toolchain_cmd_help_flag_stdout.toml b/tests/suite/cli-ui/rustup/rustup_toolchain_cmd_help_flag_stdout.toml index fdec438e70..841e8232ea 100644 --- a/tests/suite/cli-ui/rustup/rustup_toolchain_cmd_help_flag_stdout.toml +++ b/tests/suite/cli-ui/rustup/rustup_toolchain_cmd_help_flag_stdout.toml @@ -8,7 +8,7 @@ Usage: rustup[EXE] toolchain Commands: list List installed toolchains - install Install or update a given toolchain + install Install or update the given toolchains, or by default the active toolchain uninstall Uninstall the given toolchains link Create a custom toolchain by symlinking to a directory help Print this message or the help of the given subcommand(s) diff --git a/tests/suite/cli-ui/rustup/rustup_toolchain_cmd_install_cmd_help_flag_stdout.toml b/tests/suite/cli-ui/rustup/rustup_toolchain_cmd_install_cmd_help_flag_stdout.toml index e986981ed9..6c56df7f7e 100644 --- a/tests/suite/cli-ui/rustup/rustup_toolchain_cmd_install_cmd_help_flag_stdout.toml +++ b/tests/suite/cli-ui/rustup/rustup_toolchain_cmd_install_cmd_help_flag_stdout.toml @@ -1,13 +1,12 @@ bin.name = "rustup" args = ["toolchain", "install", "--help"] stdout = """ -... -Install or update a given toolchain +Install or update the given toolchains, or by default the active toolchain -Usage: rustup[EXE] toolchain install [OPTIONS] ... +Usage: rustup[EXE] toolchain install [OPTIONS] [TOOLCHAIN]... Arguments: - ... Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see + [TOOLCHAIN]... Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see `rustup help toolchain` Options: diff --git a/tests/suite/cli_rustup.rs b/tests/suite/cli_rustup.rs index 5ae0e97385..c61832aca4 100644 --- a/tests/suite/cli_rustup.rs +++ b/tests/suite/cli_rustup.rs @@ -1460,6 +1460,40 @@ async fn toolchain_install_is_like_update_except_that_bare_install_is_an_error() .await; } +#[tokio::test] +async fn toolchain_install_without_args_installs_active() { + let cx = CliTestContext::new(Scenario::SimpleV2).await; + + let cwd = cx.config.current_dir(); + let toolchain_file = cwd.join("rust-toolchain.toml"); + raw::write_file( + &toolchain_file, + r#" +[toolchain] +profile = "minimal" +channel = "nightly" +"#, + ) + .unwrap(); + + cx.config + .expect_stderr_ok( + &["rustup", "toolchain", "install"], + &format!( + "\ +info: syncing channel updates for 'nightly-{0}' +info: latest update on 2015-01-02, rust version 1.3.0 (hash-nightly-2) +info: downloading component 'rustc' +info: installing component 'rustc' +info: the active toolchain `nightly-{0}` has been installed +info: it's active because: overridden by '{1}'", + this_host_triple(), + toolchain_file.display(), + ), + ) + .await; +} + #[tokio::test] async fn toolchain_update_is_like_update() { let mut cx = CliTestContext::new(Scenario::SimpleV2).await;