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 support for rustup target add all to install all available targets #1868

Merged
merged 2 commits into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
36 changes: 33 additions & 3 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,15 @@ pub fn cli() -> App<'static, 'static> {
SubCommand::with_name("add")
.about("Add a target to a Rust toolchain")
.alias("install")
.arg(Arg::with_name("target").required(true).multiple(true))
.arg(
Arg::with_name("target")
.required(true)
.multiple(true)
.help(
"List of targets to install; \
\"all\" installs all available targets"
)
)
.arg(
Arg::with_name("toolchain")
.help(TOOLCHAIN_ARG_HELP)
Expand Down Expand Up @@ -851,9 +859,31 @@ fn target_list(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
fn target_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
let toolchain = explicit_or_dir_toolchain(cfg, m)?;

for target in m.values_of("target").expect("") {
let new_component = Component::new("rust-std".to_string(), Some(TargetTriple::new(target)));
let mut targets: Vec<String> = m
.values_of("target")
.expect("")
.map(ToString::to_string)
.collect();

if targets.contains(&"all".to_string()) {
targets.clear();
gnzlbg marked this conversation as resolved.
Show resolved Hide resolved
for component in toolchain.list_components()? {
if component.component.short_name_in_manifest() == "rust-std"
&& component.available
&& !component.installed
{
let target = component
.component
.target
.as_ref()
.expect("rust-std should have a target");
targets.push(target.to_string());
}
}
}

for target in &targets {
let new_component = Component::new("rust-std".to_string(), Some(TargetTriple::new(target)));
toolchain.add_component(new_component)?;
}

Expand Down
36 changes: 35 additions & 1 deletion tests/cli-v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ fn list_installed_targets() {
}

#[test]
fn add_target() {
fn add_target1() {
setup(&|config| {
expect_ok(config, &["rustup", "default", "nightly"]);
expect_ok(config, &["rustup", "target", "add", clitools::CROSS_ARCH1]);
Expand All @@ -568,6 +568,40 @@ fn add_target() {
});
}

#[test]
fn add_target2() {
setup(&|config| {
expect_ok(config, &["rustup", "default", "nightly"]);
expect_ok(config, &["rustup", "target", "add", clitools::CROSS_ARCH2]);
let path = format!(
"toolchains/nightly-{}/lib/rustlib/{}/lib/libstd.rlib",
this_host_triple(),
clitools::CROSS_ARCH2
);
assert!(config.rustupdir.join(path).exists());
});
}

#[test]
fn add_all_targets() {
setup(&|config| {
expect_ok(config, &["rustup", "default", "nightly"]);
expect_ok(config, &["rustup", "target", "add", "all"]);
let path = format!(
"toolchains/nightly-{}/lib/rustlib/{}/lib/libstd.rlib",
this_host_triple(),
clitools::CROSS_ARCH1
);
assert!(config.rustupdir.join(path).exists());
let path = format!(
"toolchains/nightly-{}/lib/rustlib/{}/lib/libstd.rlib",
this_host_triple(),
clitools::CROSS_ARCH2
);
assert!(config.rustupdir.join(path).exists());
});
}

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