Skip to content

Commit

Permalink
Merge pull request #1933 from fisherdarling/query_rustup_home
Browse files Browse the repository at this point in the history
Display RUSTUP_HOME in `rustup show` and `rustup show home`
  • Loading branch information
kinnison authored Jul 28, 2019
2 parents bc42691 + eef4211 commit 7f3ce52
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 10 deletions.
21 changes: 20 additions & 1 deletion src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)?;
}

Expand Down Expand Up @@ -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)?;

Expand Down
56 changes: 47 additions & 9 deletions tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
"
Expand All @@ -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)
Expand All @@ -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
--------------------
Expand Down Expand Up @@ -597,6 +625,7 @@ fn show_multiple_targets() {
&["rustup", "show"],
&format!(
r"Default host: {2}
rustup home: {3}
installed targets for active toolchain
--------------------------------------
Expand All @@ -613,7 +642,8 @@ nightly-{0} (default)
",
clitools::MULTI_ARCH1,
clitools::CROSS_ARCH2,
this_host_triple()
this_host_triple(),
config.rustupdir.display()
),
r"",
);
Expand Down Expand Up @@ -650,6 +680,7 @@ fn show_multiple_toolchains_and_targets() {
&["rustup", "show"],
&format!(
r"Default host: {2}
rustup home: {3}
installed toolchains
--------------------
Expand All @@ -672,7 +703,8 @@ nightly-{0} (default)
",
clitools::MULTI_ARCH1,
clitools::CROSS_ARCH2,
this_host_triple()
this_host_triple(),
config.rustupdir.display()
),
r"",
);
Expand Down Expand Up @@ -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"",
);
Expand All @@ -735,6 +769,7 @@ fn show_toolchain_toolchain_file_override() {
&["rustup", "show"],
&format!(
r"Default host: {0}
rustup home: {1}
installed toolchains
--------------------
Expand All @@ -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"",
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7f3ce52

Please sign in to comment.