Skip to content

Commit

Permalink
Auto merge of #7525 - ehuss:allow-all-features-virtual-ws, r=alexcric…
Browse files Browse the repository at this point in the history
…hton

Allow --all-features in root of virtual workspace.

Accidentally restricted in #7507, pointed out by @hjmallon, `--all-features` flag is allowed in the root of a virtual workspace.  Added a test to demonstrate its strange behavior.

For anyone that is curious, [this line](https://github.com/rust-lang/cargo/blob/3a9abe3f065554a7fbc59f440df2baba4a6e47ee/src/cargo/ops/resolve.rs#L302) is the code responsible for this behavior.
  • Loading branch information
bors committed Oct 18, 2019
2 parents 3a9abe3 + 4d524ea commit 06ddf35
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,9 @@ pub trait ArgMatchesExt {
ws.set_require_optional_deps(false);
}
if ws.is_virtual() && !config.cli_unstable().package_features {
for flag in &["features", "all-features", "no-default-features"] {
// --all-features is actually honored. In general, workspaces and
// feature flags are a bit of a mess right now.
for flag in &["features", "no-default-features"] {
if self._is_present(flag) {
bail!(
"--{} is not allowed in the root of a virtual workspace",
Expand Down
89 changes: 84 additions & 5 deletions tests/testsuite/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2026,11 +2026,6 @@ fn virtual_ws_flags() {
.with_status(101)
.run();

p.cargo("build --all-features")
.with_stderr("[ERROR] --all-features is not allowed in the root of a virtual workspace")
.with_status(101)
.run();

// It's OK if cwd is in a member.
p.cargo("check --features=f1 -v")
.cwd("a")
Expand All @@ -2057,3 +2052,87 @@ fn virtual_ws_flags() {
)
.run();
}

#[cargo_test]
fn all_features_virtual_ws() {
// What happens with `--all-features` in the root of a virtual workspace.
// Some of this behavior is a little strange (member dependencies also
// have all features enabled, one might expect `f4` to be disabled).
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["a", "b"]
"#,
)
.file(
"a/Cargo.toml",
r#"
[package]
name = "a"
version = "0.1.0"
edition = "2018"
[dependencies]
b = {path="../b", optional=true}
[features]
default = ["f1"]
f1 = []
f2 = []
"#,
)
.file(
"a/src/main.rs",
r#"
fn main() {
if cfg!(feature="f1") {
println!("f1");
}
if cfg!(feature="f2") {
println!("f2");
}
#[cfg(feature="b")]
b::f();
}
"#,
)
.file(
"b/Cargo.toml",
r#"
[package]
name = "b"
version = "0.1.0"
[features]
default = ["f3"]
f3 = []
f4 = []
"#,
)
.file(
"b/src/lib.rs",
r#"
pub fn f() {
if cfg!(feature="f3") {
println!("f3");
}
if cfg!(feature="f4") {
println!("f4");
}
}
"#,
)
.build();

p.cargo("run").with_stdout("f1\n").run();
p.cargo("run --all-features")
.with_stdout("f1\nf2\nf3\nf4\n")
.run();
// In `a`, it behaves differently. :(
p.cargo("run --all-features")
.cwd("a")
.with_stdout("f1\nf2\nf3\n")
.run();
}

0 comments on commit 06ddf35

Please sign in to comment.