mirror of
https://github.com/rust-lang/cargo
synced 2024-08-27 19:29:21 +00:00
Auto merge of #12817 - alexcrichton:workspace-public-dep, r=epage
Support `public` dependency configuration with workspace deps
This commit updates the processing of `workspace = true` dependencies in the `[dependencies]` section to process the `public` field. Previously this field was ignored and didn't get plumbed through as configured.
Also 👋 it's been awhile!
This commit is contained in:
commit
a9d71d291f
|
@ -2080,6 +2080,7 @@ pub struct TomlWorkspaceDependency {
|
|||
#[serde(rename = "default_features")]
|
||||
default_features2: Option<bool>,
|
||||
optional: Option<bool>,
|
||||
public: Option<bool>,
|
||||
/// This is here to provide a way to see the "unused manifest keys" when deserializing
|
||||
#[serde(skip_serializing)]
|
||||
#[serde(flatten)]
|
||||
|
@ -2114,11 +2115,12 @@ impl TomlWorkspaceDependency {
|
|||
if let Some(false) = self.default_features.or(self.default_features2) {
|
||||
default_features_msg(name, None, cx);
|
||||
}
|
||||
if self.optional.is_some() || self.features.is_some() {
|
||||
if self.optional.is_some() || self.features.is_some() || self.public.is_some() {
|
||||
TomlDependency::Detailed(DetailedTomlDependency {
|
||||
version: Some(s),
|
||||
optional: self.optional,
|
||||
features: self.features.clone(),
|
||||
public: self.public,
|
||||
..Default::default()
|
||||
})
|
||||
} else {
|
||||
|
@ -2150,6 +2152,11 @@ impl TomlWorkspaceDependency {
|
|||
}
|
||||
_ => {}
|
||||
}
|
||||
// Inherit the workspace configuration for `public` unless
|
||||
// it's explicitly specified for this dependency.
|
||||
if let Some(public) = self.public {
|
||||
d.public = Some(public);
|
||||
}
|
||||
d.add_features(self.features.clone());
|
||||
d.update_optional(self.optional);
|
||||
TomlDependency::Detailed(d)
|
||||
|
|
|
@ -197,3 +197,52 @@ Caused by:
|
|||
)
|
||||
.run()
|
||||
}
|
||||
|
||||
#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
|
||||
fn workspace_dep_made_public() {
|
||||
Package::new("foo1", "0.1.0")
|
||||
.file("src/lib.rs", "pub struct FromFoo;")
|
||||
.publish();
|
||||
Package::new("foo2", "0.1.0")
|
||||
.file("src/lib.rs", "pub struct FromFoo;")
|
||||
.publish();
|
||||
Package::new("foo3", "0.1.0")
|
||||
.file("src/lib.rs", "pub struct FromFoo;")
|
||||
.publish();
|
||||
|
||||
let p = project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
cargo-features = ["public-dependency"]
|
||||
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
|
||||
[workspace.dependencies]
|
||||
foo1 = "0.1.0"
|
||||
foo2 = { version = "0.1.0", public = true }
|
||||
foo3 = { version = "0.1.0", public = false }
|
||||
|
||||
[dependencies]
|
||||
foo1 = { workspace = true, public = true }
|
||||
foo2 = { workspace = true }
|
||||
foo3 = { workspace = true, public = true }
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
"
|
||||
#![deny(exported_private_dependencies)]
|
||||
pub fn use_priv1(_: foo1::FromFoo) {}
|
||||
pub fn use_priv2(_: foo2::FromFoo) {}
|
||||
pub fn use_priv3(_: foo3::FromFoo) {}
|
||||
",
|
||||
)
|
||||
.build();
|
||||
|
||||
p.cargo("check")
|
||||
.masquerade_as_nightly_cargo(&["public-dependency"])
|
||||
.run()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue