Skip to content

Commit

Permalink
Fix wrong profile selection for cargo build and cargo rustc.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Oct 15, 2017
1 parent 390e957 commit 0acc67c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 8 deletions.
12 changes: 11 additions & 1 deletion src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,16 @@ fn generate_targets<'a>(pkg: &'a Package,

let test_profile = if profile.check {
&profiles.check_test
} else if mode == CompileMode::Build {
test
} else {
profile
};

let bench_profile = if profile.check {
&profiles.check_test
} else if mode == CompileMode::Build {
&profiles.bench
} else {
profile
};
Expand Down Expand Up @@ -645,7 +655,7 @@ fn generate_targets<'a>(pkg: &'a Package,
targets.append(&mut propose_indicated_targets(
pkg, tests, "test", Target::is_test, test_profile)?);
targets.append(&mut propose_indicated_targets(
pkg, benches, "bench", Target::is_bench, test_profile)?);
pkg, benches, "bench", Target::is_bench, bench_profile)?);
targets
}
};
Expand Down
56 changes: 56 additions & 0 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3902,3 +3902,59 @@ fn uplift_dsym_of_bin_on_mac() {
assert_that(&p.bin("c.dSYM"), is_not(existing_dir()));
assert_that(&p.bin("d.dSYM"), is_not(existing_dir()));
}

// Make sure that `cargo build` chooses the correct profile for building
// targets based on filters (assuming --profile is not specified).
#[test]
fn build_filter_infer_profile() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.1.0"
authors = []
"#)
.file("src/lib.rs", "")
.file("src/main.rs", "fn main() {}")
.file("tests/t1.rs", "")
.file("benches/b1.rs", "")
.file("examples/ex1.rs", "fn main() {}")
.build();

assert_that(p.cargo("build").arg("-v"),
execs().with_status(0)
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
--emit=dep-info,link[..]")
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
--emit=dep-info,link[..]")
);

p.root().join("target").rm_rf();
assert_that(p.cargo("build").arg("-v").arg("--test=t1"),
execs().with_status(0)
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
--emit=dep-info,link[..]")
.with_stderr_contains("\
[RUNNING] `rustc --crate-name t1 tests[/]t1.rs --emit=dep-info,link[..]")
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
--emit=dep-info,link[..]")
);

p.root().join("target").rm_rf();
assert_that(p.cargo("build").arg("-v").arg("--bench=b1"),
execs().with_status(0)
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
--emit=dep-info,link[..]")
.with_stderr_contains("\
[RUNNING] `rustc --crate-name b1 benches[/]b1.rs --emit=dep-info,link \
-C opt-level=3[..]")
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
--emit=dep-info,link[..]")
);
}
12 changes: 6 additions & 6 deletions tests/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,9 @@ fn check_unit_test_profile() {
badtext
}
}
"#);
"#)
.build();

foo.build();
assert_that(foo.cargo("check"),
execs().with_status(0));
assert_that(foo.cargo("check").arg("--profile").arg("test"),
Expand Down Expand Up @@ -529,9 +529,9 @@ fn check_unit_test_all_tests() {
mod tests {
fn unused_unit_b1() {}
}
"#);
"#)
.build();

p.build();
assert_that(p.cargo("check"),
execs().with_status(0)
.with_stderr_contains("[..]unused_normal_lib[..]")
Expand Down Expand Up @@ -575,8 +575,8 @@ fn check_artifacts()
.file("src/main.rs", "fn main() {}")
.file("tests/t1.rs", "")
.file("examples/ex1.rs", "fn main() {}")
.file("benches/b1.rs", "");
p.build();
.file("benches/b1.rs", "")
.build();
assert_that(p.cargo("check"), execs().with_status(0));
assert_that(&p.root().join("target/debug/libfoo.rmeta"),
existing_file());
Expand Down
2 changes: 1 addition & 1 deletion tests/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ fn build_with_args_to_one_of_multiple_tests() {
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib --emit=dep-info,link \
-C debuginfo=2 -C metadata=[..] \
--out-dir [..]`
[RUNNING] `rustc --crate-name bar tests[/]bar.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 \
[RUNNING] `rustc --crate-name bar tests[/]bar.rs --emit=dep-info,link -C debuginfo=2 \
-C debug-assertions [..]--test[..]`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
", url = p.url())));
Expand Down

0 comments on commit 0acc67c

Please sign in to comment.