Skip to content

Commit

Permalink
Reject feature flags in a virtual workspace.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Oct 14, 2019
1 parent d5d7557 commit bf474ba
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
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();
}

0 comments on commit bf474ba

Please sign in to comment.