Skip to content

Commit

Permalink
Suggest adding flags to filter the package in the error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Sondre Lefsaker committed May 6, 2015
1 parent 98c0e2d commit 2cd3c86
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,16 @@ pub fn compile_pkg(package: &Package, options: &CompileOptions)
let targets = try!(generate_targets(to_build, mode, filter, release));

let target_with_args = match *target_rustc_args {
Some(args) => {
if targets.len() > 1 {
return Err(human("extra arguments to `rustc` can only be \
invoked for one target"))
}
Some(args) if targets.len() == 1 => {
let (target, profile) = targets[0];
let mut profile = profile.clone();
profile.rustc_args = Some(args.to_vec());
Some((target, profile))
},
}
Some(_) =>
return Err(human("extra arguments to `rustc` can only be passed to one target, \
consider filtering\nthe package by passing e.g. `--lib` or \
`--bin NAME` to specify a single target")),
None => None,
};

Expand Down
9 changes: 7 additions & 2 deletions tests/test_cargo_rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ use hamcrest::{assert_that};
fn setup() {
}

fn cargo_rustc_error() -> &'static str {
"extra arguments to `rustc` can only be passed to one target, consider filtering\n\
the package by passing e.g. `--lib` or `--bin NAME` to specify a single target"
}

test!(build_lib_for_foo {
let p = project("foo")
.file("Cargo.toml", r#"
Expand Down Expand Up @@ -118,7 +123,7 @@ test!(fails_when_trying_to_build_main_and_lib_with_args {
.arg("--").arg("-Z").arg("unstable-options"),
execs()
.with_status(101)
.with_stderr("extra arguments to `rustc` can only be invoked for one target"));
.with_stderr(cargo_rustc_error()));
});

test!(build_with_args_to_one_of_multiple_binaries {
Expand Down Expand Up @@ -178,7 +183,7 @@ test!(fails_with_args_to_all_binaries {
.arg("--").arg("-Z").arg("unstable-options"),
execs()
.with_status(101)
.with_stderr("extra arguments to `rustc` can only be invoked for one target"));
.with_stderr(cargo_rustc_error()));
});

test!(build_with_args_to_one_of_multiple_tests {
Expand Down

0 comments on commit 2cd3c86

Please sign in to comment.