Skip to content

Commit

Permalink
Auto merge of #8027 - ehuss:fix-features-dev_dep-check-test, r=alexcr…
Browse files Browse the repository at this point in the history
…ichton

Fix bug with -Zfeatures=dev_dep and `check --profile=test`.

`-Zfeatures=dev_dep` with `cargo check --profile=test` would crash because the check of whether or not dev dependencies are needed erroneously ignored the "test" flag of `CompileMode::Check`.  The feature resolver needs to correctly know whether or not dev-dependencies are needed.
  • Loading branch information
bors committed Mar 23, 2020
2 parents 7dec94d + b112255 commit 71fbc99
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,16 +608,18 @@ impl CompileFilter {
pub fn need_dev_deps(&self, mode: CompileMode) -> bool {
match mode {
CompileMode::Test | CompileMode::Doctest | CompileMode::Bench => true,
CompileMode::Build | CompileMode::Doc { .. } | CompileMode::Check { .. } => match *self
{
CompileFilter::Default { .. } => false,
CompileFilter::Only {
ref examples,
ref tests,
ref benches,
..
} => examples.is_specific() || tests.is_specific() || benches.is_specific(),
},
CompileMode::Check { test: true } => true,
CompileMode::Build | CompileMode::Doc { .. } | CompileMode::Check { test: false } => {
match *self {
CompileFilter::Default { .. } => false,
CompileFilter::Only {
ref examples,
ref tests,
ref benches,
..
} => examples.is_specific() || tests.is_specific() || benches.is_specific(),
}
}
CompileMode::RunCustomBuild => panic!("Invalid mode"),
}
}
Expand Down
77 changes: 77 additions & 0 deletions tests/testsuite/features2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,3 +1108,80 @@ fn proc_macro_ws() {
.with_stderr_line_without(&["[RUNNING] `rustc --crate-name foo"], &["--cfg[..]feat1"])
.run();
}

#[cargo_test]
fn has_dev_dep_for_test() {
// Check for a bug where the decision on whether or not "dev dependencies"
// should be used did not consider `check --profile=test`.
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[dev-dependencies]
dep = { path = 'dep', features = ['f1'] }
"#,
)
.file(
"src/lib.rs",
r#"
#[test]
fn t1() {
dep::f();
}
"#,
)
.file(
"dep/Cargo.toml",
r#"
[package]
name = "dep"
version = "0.1.0"
[features]
f1 = []
"#,
)
.file(
"dep/src/lib.rs",
r#"
#[cfg(feature = "f1")]
pub fn f() {}
"#,
)
.build();

p.cargo("check -v")
.with_stderr(
"\
[CHECKING] foo v0.1.0 [..]
[RUNNING] `rustc --crate-name foo [..]
[FINISHED] [..]
",
)
.run();
p.cargo("check -v --profile=test -Zfeatures=dev_dep")
.masquerade_as_nightly_cargo()
.with_stderr(
"\
[CHECKING] dep v0.1.0 [..]
[RUNNING] `rustc --crate-name dep [..]
[CHECKING] foo v0.1.0 [..]
[RUNNING] `rustc --crate-name foo [..]
[FINISHED] [..]
",
)
.run();
p.cargo("check -v --profile=test")
.with_stderr(
"\
[FRESH] dep [..]
[FRESH] foo [..]
[FINISHED] [..]
",
)
.run();
}

0 comments on commit 71fbc99

Please sign in to comment.