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

Reject feature flags in a virtual workspace. #7507

Merged
merged 1 commit into from
Oct 15, 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
10 changes: 10 additions & 0 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ pub trait ArgMatchesExt {
if config.cli_unstable().avoid_dev_deps {
ws.set_require_optional_deps(false);
}
if ws.is_virtual() && !config.cli_unstable().package_features {
for flag in &["features", "all-features", "no-default-features"] {
if self._is_present(flag) {
bail!(
"--{} is not allowed in the root of a virtual workspace",
flag
);
}
}
}
Ok(ws)
}

Expand Down
69 changes: 69 additions & 0 deletions tests/testsuite/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1988,3 +1988,72 @@ fn cli_parse_ok() {

p.cargo("run --features a b").run();
}

#[cargo_test]
fn virtual_ws_flags() {
// Reject features flags in the root of a virtual workspace.
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["a"]
"#,
)
.file(
"a/Cargo.toml",
r#"
[package]
name = "a"
version = "0.1.0"

[features]
f1 = []
"#,
)
.file("a/src/lib.rs", "")
.build();

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

p.cargo("build --no-default-features")
.with_stderr(
"[ERROR] --no-default-features is not allowed in the root of a virtual workspace",
)
.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")
.with_stderr(
"\
[CHECKING] a [..]
[RUNNING] `rustc --crate-name a a/src/lib.rs [..]--cfg [..]feature[..]f1[..]
[FINISHED] dev [..]
",
)
.run();

p.cargo("clean").run();

// And -Zpackage-features is OK because it is designed to support this.
p.cargo("check --features=f1 -p a -Z package-features -v")
.masquerade_as_nightly_cargo()
.with_stderr(
"\
[CHECKING] a [..]
[RUNNING] `rustc --crate-name a a/src/lib.rs [..]--cfg [..]feature[..]f1[..]
[FINISHED] dev [..]
",
)
.run();
}