Skip to content

Commit 0acc67c

Browse files
committed
Fix wrong profile selection for cargo build and cargo rustc.
1 parent 390e957 commit 0acc67c

File tree

4 files changed

+74
-8
lines changed

4 files changed

+74
-8
lines changed

src/cargo/ops/cargo_compile.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,16 @@ fn generate_targets<'a>(pkg: &'a Package,
611611

612612
let test_profile = if profile.check {
613613
&profiles.check_test
614+
} else if mode == CompileMode::Build {
615+
test
616+
} else {
617+
profile
618+
};
619+
620+
let bench_profile = if profile.check {
621+
&profiles.check_test
622+
} else if mode == CompileMode::Build {
623+
&profiles.bench
614624
} else {
615625
profile
616626
};
@@ -645,7 +655,7 @@ fn generate_targets<'a>(pkg: &'a Package,
645655
targets.append(&mut propose_indicated_targets(
646656
pkg, tests, "test", Target::is_test, test_profile)?);
647657
targets.append(&mut propose_indicated_targets(
648-
pkg, benches, "bench", Target::is_bench, test_profile)?);
658+
pkg, benches, "bench", Target::is_bench, bench_profile)?);
649659
targets
650660
}
651661
};

tests/build.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3902,3 +3902,59 @@ fn uplift_dsym_of_bin_on_mac() {
39023902
assert_that(&p.bin("c.dSYM"), is_not(existing_dir()));
39033903
assert_that(&p.bin("d.dSYM"), is_not(existing_dir()));
39043904
}
3905+
3906+
// Make sure that `cargo build` chooses the correct profile for building
3907+
// targets based on filters (assuming --profile is not specified).
3908+
#[test]
3909+
fn build_filter_infer_profile() {
3910+
let p = project("foo")
3911+
.file("Cargo.toml", r#"
3912+
[package]
3913+
name = "foo"
3914+
version = "0.1.0"
3915+
authors = []
3916+
"#)
3917+
.file("src/lib.rs", "")
3918+
.file("src/main.rs", "fn main() {}")
3919+
.file("tests/t1.rs", "")
3920+
.file("benches/b1.rs", "")
3921+
.file("examples/ex1.rs", "fn main() {}")
3922+
.build();
3923+
3924+
assert_that(p.cargo("build").arg("-v"),
3925+
execs().with_status(0)
3926+
.with_stderr_contains("\
3927+
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
3928+
--emit=dep-info,link[..]")
3929+
.with_stderr_contains("\
3930+
[RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
3931+
--emit=dep-info,link[..]")
3932+
);
3933+
3934+
p.root().join("target").rm_rf();
3935+
assert_that(p.cargo("build").arg("-v").arg("--test=t1"),
3936+
execs().with_status(0)
3937+
.with_stderr_contains("\
3938+
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
3939+
--emit=dep-info,link[..]")
3940+
.with_stderr_contains("\
3941+
[RUNNING] `rustc --crate-name t1 tests[/]t1.rs --emit=dep-info,link[..]")
3942+
.with_stderr_contains("\
3943+
[RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
3944+
--emit=dep-info,link[..]")
3945+
);
3946+
3947+
p.root().join("target").rm_rf();
3948+
assert_that(p.cargo("build").arg("-v").arg("--bench=b1"),
3949+
execs().with_status(0)
3950+
.with_stderr_contains("\
3951+
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
3952+
--emit=dep-info,link[..]")
3953+
.with_stderr_contains("\
3954+
[RUNNING] `rustc --crate-name b1 benches[/]b1.rs --emit=dep-info,link \
3955+
-C opt-level=3[..]")
3956+
.with_stderr_contains("\
3957+
[RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
3958+
--emit=dep-info,link[..]")
3959+
);
3960+
}

tests/check.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,9 @@ fn check_unit_test_profile() {
478478
badtext
479479
}
480480
}
481-
"#);
481+
"#)
482+
.build();
482483

483-
foo.build();
484484
assert_that(foo.cargo("check"),
485485
execs().with_status(0));
486486
assert_that(foo.cargo("check").arg("--profile").arg("test"),
@@ -529,9 +529,9 @@ fn check_unit_test_all_tests() {
529529
mod tests {
530530
fn unused_unit_b1() {}
531531
}
532-
"#);
532+
"#)
533+
.build();
533534

534-
p.build();
535535
assert_that(p.cargo("check"),
536536
execs().with_status(0)
537537
.with_stderr_contains("[..]unused_normal_lib[..]")
@@ -575,8 +575,8 @@ fn check_artifacts()
575575
.file("src/main.rs", "fn main() {}")
576576
.file("tests/t1.rs", "")
577577
.file("examples/ex1.rs", "fn main() {}")
578-
.file("benches/b1.rs", "");
579-
p.build();
578+
.file("benches/b1.rs", "")
579+
.build();
580580
assert_that(p.cargo("check"), execs().with_status(0));
581581
assert_that(&p.root().join("target/debug/libfoo.rmeta"),
582582
existing_file());

tests/rustc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ fn build_with_args_to_one_of_multiple_tests() {
217217
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib --emit=dep-info,link \
218218
-C debuginfo=2 -C metadata=[..] \
219219
--out-dir [..]`
220-
[RUNNING] `rustc --crate-name bar tests[/]bar.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 \
220+
[RUNNING] `rustc --crate-name bar tests[/]bar.rs --emit=dep-info,link -C debuginfo=2 \
221221
-C debug-assertions [..]--test[..]`
222222
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
223223
", url = p.url())));

0 commit comments

Comments
 (0)