Skip to content

Commit

Permalink
Merge pull request #1808 from onatm/list-installed-targets
Browse files Browse the repository at this point in the history
Add listing of installed targets
  • Loading branch information
kinnison authored Apr 27, 2019
2 parents b149243 + 584c672 commit 701c6f4
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,23 @@ pub fn list_targets(toolchain: &Toolchain<'_>) -> Result<()> {
Ok(())
}

pub fn list_installed_targets(toolchain: &Toolchain<'_>) -> Result<()> {
let mut t = term2::stdout();
for component in toolchain.list_components()? {
if component.component.short_name_in_manifest() == "rust-std" {
let target = component
.component
.target
.as_ref()
.expect("rust-std should have a target");
if component.installed {
writeln!(t, "{}", target)?;
}
}
}
Ok(())
}

pub fn list_components(toolchain: &Toolchain<'_>) -> Result<()> {
let mut t = term2::stdout();
for component in toolchain.list_components()? {
Expand Down
11 changes: 10 additions & 1 deletion src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ pub fn cli() -> App<'static, 'static> {
.subcommand(
SubCommand::with_name("list")
.about("List installed and available targets")
.arg(
Arg::with_name("installed")
.long("--installed")
.help("List only installed targets"),
)
.arg(
Arg::with_name("toolchain")
.help(TOOLCHAIN_ARG_HELP)
Expand Down Expand Up @@ -829,7 +834,11 @@ fn show_active_toolchain(cfg: &Cfg) -> Result<()> {
fn target_list(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
let toolchain = explicit_or_dir_toolchain(cfg, m)?;

common::list_targets(&toolchain)
if m.is_present("installed") {
common::list_installed_targets(&toolchain)
} else {
common::list_targets(&toolchain)
}
}

fn target_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
Expand Down
25 changes: 25 additions & 0 deletions tests/cli-exact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,31 @@ fn list_targets() {
});
}

#[test]
fn list_installed_targets() {
setup(&|config| {
let trip = this_host_triple();
let mut sorted = vec![
trip,
clitools::CROSS_ARCH1.to_string(),
clitools::CROSS_ARCH2.to_string(),
];
sorted.sort();

let expected = format!("{}\n{}\n{}\n", sorted[0], sorted[1], sorted[2]);

expect_ok(config, &["rustup", "default", "nightly"]);
expect_ok(config, &["rustup", "target", "add", clitools::CROSS_ARCH1]);
expect_ok(config, &["rustup", "target", "add", clitools::CROSS_ARCH2]);
expect_ok_ex(
config,
&["rustup", "target", "list", "--installed"],
&expected,
r"",
);
});
}

#[test]
fn cross_install_indicates_target() {
setup(&|config| {
Expand Down
10 changes: 10 additions & 0 deletions tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,16 @@ fn list_targets() {
});
}

#[test]
fn list_installed_targets() {
setup(&|config| {
let trip = this_host_triple();

expect_ok(config, &["rustup", "default", "nightly"]);
expect_stdout_ok(config, &["rustup", "target", "list", "--installed"], &trip);
});
}

#[test]
fn add_target_explicit() {
setup(&|config| {
Expand Down
10 changes: 10 additions & 0 deletions tests/cli-v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,16 @@ fn list_targets() {
});
}

#[test]
fn list_installed_targets() {
setup(&|config| {
let trip = this_host_triple();

expect_ok(config, &["rustup", "default", "nightly"]);
expect_stdout_ok(config, &["rustup", "target", "list", "--installed"], &trip);
});
}

#[test]
fn add_target() {
setup(&|config| {
Expand Down

0 comments on commit 701c6f4

Please sign in to comment.