Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}