diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 47a03962d4..629bddda4f 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -43,6 +43,7 @@ pub fn main() -> Result<()> { ("dump-testament", _) => common::dump_testament(), ("show", Some(c)) => match c.subcommand() { ("active-toolchain", Some(_)) => handle_epipe(show_active_toolchain(cfg))?, + ("home", Some(_)) => handle_epipe(show_rustup_home(cfg))?, (_, _) => handle_epipe(show(cfg))?, }, ("install", Some(m)) => update(cfg, m)?, @@ -132,7 +133,11 @@ pub fn cli() -> App<'static, 'static> { SubCommand::with_name("active-toolchain") .about("Show the active toolchain") .after_help(SHOW_ACTIVE_TOOLCHAIN_HELP), - ), + ) + .subcommand( + SubCommand::with_name("home") + .about("Display the computed value of RUSTUP_HOME"), + ) ) .subcommand( SubCommand::with_name("install") @@ -720,6 +725,15 @@ fn show(cfg: &Cfg) -> Result<()> { write!(t, "Default host: ")?; t.reset()?; writeln!(t, "{}", cfg.get_default_host_triple()?)?; + } + + // Print rustup home directory + { + let mut t = term2::stdout(); + t.attr(term2::Attr::Bold)?; + write!(t, "rustup home: ")?; + t.reset()?; + writeln!(t, "{}", cfg.rustup_dir.display())?; writeln!(t)?; } @@ -859,6 +873,11 @@ fn show_active_toolchain(cfg: &Cfg) -> Result<()> { Ok(()) } +fn show_rustup_home(cfg: &Cfg) -> Result<()> { + println!("{}", cfg.rustup_dir.display()); + Ok(()) +} + fn target_list(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let toolchain = explicit_or_dir_toolchain(cfg, m)?; diff --git a/tests/cli-rustup.rs b/tests/cli-rustup.rs index 52a3a9e403..674b4ea096 100644 --- a/tests/cli-rustup.rs +++ b/tests/cli-rustup.rs @@ -17,6 +17,12 @@ macro_rules! for_host { }; } +macro_rules! for_host_and_home { + ($config:ident, $s: expr) => { + &format!($s, this_host_triple(), $config.rustupdir.display()) + }; +} + pub fn setup(f: &dyn Fn(&Config)) { clitools::setup(Scenario::ArchivesV2, &|config| { f(config); @@ -509,14 +515,32 @@ fn fallback_cargo_calls_correct_rustc() { }); } +#[test] +fn show_home() { + setup(&|config| { + expect_ok_ex( + config, + &["rustup", "show", "home"], + &format!( + r"{} +", + config.rustupdir.display() + ), + r"", + ); + }); +} + #[test] fn show_toolchain_none() { setup(&|config| { expect_ok_ex( config, &["rustup", "show"], - for_host!( + &for_host_and_home!( + config, r"Default host: {0} +rustup home: {1} no active toolchain " @@ -533,8 +557,10 @@ fn show_toolchain_default() { expect_ok_ex( config, &["rustup", "show"], - for_host!( + for_host_and_home!( + config, r"Default host: {0} +rustup home: {1} nightly-{0} (default) 1.3.0 (hash-n-2) @@ -553,8 +579,10 @@ fn show_multiple_toolchains() { expect_ok_ex( config, &["rustup", "show"], - for_host!( + for_host_and_home!( + config, r"Default host: {0} +rustup home: {1} installed toolchains -------------------- @@ -597,6 +625,7 @@ fn show_multiple_targets() { &["rustup", "show"], &format!( r"Default host: {2} +rustup home: {3} installed targets for active toolchain -------------------------------------- @@ -613,7 +642,8 @@ nightly-{0} (default) ", clitools::MULTI_ARCH1, clitools::CROSS_ARCH2, - this_host_triple() + this_host_triple(), + config.rustupdir.display() ), r"", ); @@ -650,6 +680,7 @@ fn show_multiple_toolchains_and_targets() { &["rustup", "show"], &format!( r"Default host: {2} +rustup home: {3} installed toolchains -------------------- @@ -672,7 +703,8 @@ nightly-{0} (default) ", clitools::MULTI_ARCH1, clitools::CROSS_ARCH2, - this_host_triple() + this_host_triple(), + config.rustupdir.display() ), r"", ); @@ -706,12 +738,14 @@ fn show_toolchain_override() { &["rustup", "show"], &format!( r"Default host: {0} +rustup home: {1} -nightly-{0} (directory override for '{1}') +nightly-{0} (directory override for '{2}') 1.3.0 (hash-n-2) ", this_host_triple(), - cwd.display() + config.rustupdir.display(), + cwd.display(), ), r"", ); @@ -735,6 +769,7 @@ fn show_toolchain_toolchain_file_override() { &["rustup", "show"], &format!( r"Default host: {0} +rustup home: {1} installed toolchains -------------------- @@ -745,11 +780,12 @@ nightly-{0} active toolchain ---------------- -nightly-{0} (overridden by '{1}') +nightly-{0} (overridden by '{2}') 1.3.0 (hash-n-2) ", this_host_triple(), + config.rustupdir.display(), toolchain_file.display() ), r"", @@ -890,8 +926,10 @@ fn show_toolchain_env() { let stdout = String::from_utf8(out.stdout).unwrap(); assert_eq!( &stdout, - for_host!( + for_host_and_home!( + config, r"Default host: {0} +rustup home: {1} nightly-{0} (environment override by RUSTUP_TOOLCHAIN) 1.3.0 (hash-n-2)