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

Add listing of installed targets #1808

Merged
merged 2 commits into from
Apr 27, 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
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