mirror of
https://github.com/rust-lang/cargo
synced 2024-10-01 21:43:45 +00:00
Fix required-features using renamed dependencies.
The dep_name/feat_name syntax in required-features should use the "name in toml" for dep_name, not the actual package name.
This commit is contained in:
parent
972b9f55a7
commit
cafec11467
|
@ -903,9 +903,11 @@ fn resolve_all_features(
|
|||
|
||||
// Include features enabled for use by dependencies so targets can also use them with the
|
||||
// required-features field when deciding whether to be built or skipped.
|
||||
for (dep, _) in resolve_with_overrides.deps(package_id) {
|
||||
for feature in resolve_with_overrides.features(dep) {
|
||||
features.insert(dep.name().to_string() + "/" + feature);
|
||||
for (dep_id, deps) in resolve_with_overrides.deps(package_id) {
|
||||
for feature in resolve_with_overrides.features(dep_id) {
|
||||
for dep in deps {
|
||||
features.insert(dep.name_in_toml().to_string() + "/" + feature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1163,3 +1163,96 @@ available binaries: foo1, foo2",
|
|||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn renamed_required_features() {
|
||||
// Test that required-features uses renamed package feature names.
|
||||
let p = project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[[bin]]
|
||||
name = "x"
|
||||
required-features = ["a1/f1"]
|
||||
|
||||
[dependencies]
|
||||
a1 = {path="a1", package="a"}
|
||||
a2 = {path="a2", package="a"}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"src/bin/x.rs",
|
||||
r#"
|
||||
fn main() {
|
||||
a1::f();
|
||||
a2::f();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"a1/Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "a"
|
||||
version = "0.1.0"
|
||||
|
||||
[features]
|
||||
f1 = []
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"a1/src/lib.rs",
|
||||
r#"
|
||||
pub fn f() {
|
||||
if cfg!(feature="f1") {
|
||||
println!("a1 f1");
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"a2/Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "a"
|
||||
version = "0.2.0"
|
||||
|
||||
[features]
|
||||
f2 = []
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"a2/src/lib.rs",
|
||||
r#"
|
||||
pub fn f() {
|
||||
if cfg!(feature="f2") {
|
||||
println!("a2 f2");
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.build();
|
||||
|
||||
p.cargo("run")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
[ERROR] target `x` in package `foo` requires the features: `a1/f1`
|
||||
Consider enabling them by passing, e.g., `--features=\"a1/f1\"`
|
||||
",
|
||||
)
|
||||
.run();
|
||||
|
||||
p.cargo("build --features a1/f1").run();
|
||||
p.rename_run("x", "x_with_f1").with_stdout("a1 f1").run();
|
||||
|
||||
p.cargo("build --features a1/f1,a2/f2").run();
|
||||
p.rename_run("x", "x_with_f1_f2")
|
||||
.with_stdout("a1 f1\na2 f2")
|
||||
.run();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue