Skip to content

Commit ffafda8

Browse files
authored
fix(package): Register workspace member renames in overlay (#15228)
### What does this PR try to resolve? This was reported at #10948 (comment) For the exact mapping between the publish payload and the index, see https://doc.rust-lang.org/cargo/reference/registry-index.html#json-schema, particularly the note about differences. ### How should we test and review this PR? ### Additional information I suspect there is a second bug here because my debugging only showed us hitting this scenario for `val-json` and not `concepts` and only when building `utils`. That difference in behavior between a transitive and direct dependency is odd.
2 parents ef12f10 + e1d61b8 commit ffafda8

File tree

2 files changed

+131
-16
lines changed

2 files changed

+131
-16
lines changed

src/cargo/ops/cargo_package/mod.rs

+27-16
Original file line numberDiff line numberDiff line change
@@ -1032,22 +1032,33 @@ impl<'a> TmpRegistry<'a> {
10321032
let deps: Vec<_> = new_crate
10331033
.deps
10341034
.into_iter()
1035-
.map(|dep| RegistryDependency {
1036-
name: dep.name.into(),
1037-
req: dep.version_req.into(),
1038-
features: dep.features.into_iter().map(|x| x.into()).collect(),
1039-
optional: dep.optional,
1040-
default_features: dep.default_features,
1041-
target: dep.target.map(|x| x.into()),
1042-
kind: Some(dep.kind.into()),
1043-
registry: dep.registry.map(|x| x.into()),
1044-
package: None,
1045-
public: None,
1046-
artifact: dep
1047-
.artifact
1048-
.map(|xs| xs.into_iter().map(|x| x.into()).collect()),
1049-
bindep_target: dep.bindep_target.map(|x| x.into()),
1050-
lib: dep.lib,
1035+
.map(|dep| {
1036+
let name = dep
1037+
.explicit_name_in_toml
1038+
.clone()
1039+
.unwrap_or_else(|| dep.name.clone())
1040+
.into();
1041+
let package = dep
1042+
.explicit_name_in_toml
1043+
.as_ref()
1044+
.map(|_| dep.name.clone().into());
1045+
RegistryDependency {
1046+
name: name,
1047+
req: dep.version_req.into(),
1048+
features: dep.features.into_iter().map(|x| x.into()).collect(),
1049+
optional: dep.optional,
1050+
default_features: dep.default_features,
1051+
target: dep.target.map(|x| x.into()),
1052+
kind: Some(dep.kind.into()),
1053+
registry: dep.registry.map(|x| x.into()),
1054+
package: package,
1055+
public: None,
1056+
artifact: dep
1057+
.artifact
1058+
.map(|xs| xs.into_iter().map(|x| x.into()).collect()),
1059+
bindep_target: dep.bindep_target.map(|x| x.into()),
1060+
lib: dep.lib,
1061+
}
10511062
})
10521063
.collect();
10531064

tests/testsuite/package.rs

+104
Original file line numberDiff line numberDiff line change
@@ -6492,6 +6492,110 @@ fn workspace_with_capitalized_member() {
64926492
.run();
64936493
}
64946494

6495+
#[cargo_test]
6496+
fn workspace_with_renamed_member() {
6497+
let reg = registry::init();
6498+
6499+
let p = project()
6500+
.file(
6501+
"Cargo.toml",
6502+
r#"
6503+
[workspace]
6504+
members = ["crates/*"]
6505+
"#,
6506+
)
6507+
.file(
6508+
"crates/val-json/Cargo.toml",
6509+
r#"
6510+
[package]
6511+
name = "obeli-sk-val-json"
6512+
version = "0.16.2"
6513+
edition = "2015"
6514+
authors = []
6515+
license = "MIT"
6516+
description = "main"
6517+
repository = "bar"
6518+
6519+
[dependencies]
6520+
"#,
6521+
)
6522+
.file("crates/val-json/src/lib.rs", "pub fn foo() {}")
6523+
.file(
6524+
"crates/concepts/Cargo.toml",
6525+
r#"
6526+
[package]
6527+
name = "obeli-sk-concepts"
6528+
version = "0.16.2"
6529+
edition = "2015"
6530+
authors = []
6531+
license = "MIT"
6532+
description = "main"
6533+
repository = "bar"
6534+
6535+
[dependencies]
6536+
val-json = { package = "obeli-sk-val-json", path = "../val-json", version = "0.16.2" }
6537+
"#,
6538+
)
6539+
.file(
6540+
"crates/concepts/src/lib.rs",
6541+
"pub fn foo() { val_json::foo() }",
6542+
)
6543+
.file(
6544+
"crates/utils/Cargo.toml",
6545+
r#"
6546+
[package]
6547+
name = "obeli-sk-utils"
6548+
version = "0.16.2"
6549+
edition = "2015"
6550+
authors = []
6551+
license = "MIT"
6552+
description = "main"
6553+
repository = "bar"
6554+
6555+
[dependencies]
6556+
concepts = { package = "obeli-sk-concepts", path = "../concepts", version = "0.16.2" }
6557+
val-json = { package = "obeli-sk-val-json", path = "../val-json", version = "0.16.2" }
6558+
"#,
6559+
)
6560+
.file(
6561+
"crates/utils/src/lib.rs",
6562+
"pub fn foo() { val_json::foo(); concepts::foo(); }",
6563+
)
6564+
.build();
6565+
6566+
p.cargo("package -Zpackage-workspace")
6567+
.masquerade_as_nightly_cargo(&["package-workspace"])
6568+
.replace_crates_io(reg.index_url())
6569+
.with_stderr_data(
6570+
str![[r#"
6571+
[UPDATING] crates.io index
6572+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
6573+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
6574+
[PACKAGING] obeli-sk-val-json v0.16.2 ([ROOT]/foo/crates/val-json)
6575+
[PACKAGING] obeli-sk-concepts v0.16.2 ([ROOT]/foo/crates/concepts)
6576+
[PACKAGING] obeli-sk-utils v0.16.2 ([ROOT]/foo/crates/utils)
6577+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
6578+
[VERIFYING] obeli-sk-val-json v0.16.2 ([ROOT]/foo/crates/val-json)
6579+
[COMPILING] obeli-sk-val-json v0.16.2 ([ROOT]/foo/target/package/obeli-sk-val-json-0.16.2)
6580+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
6581+
[VERIFYING] obeli-sk-concepts v0.16.2 ([ROOT]/foo/crates/concepts)
6582+
[UNPACKING] obeli-sk-val-json v0.16.2 (registry `[ROOT]/foo/target/package/tmp-registry`)
6583+
[COMPILING] obeli-sk-val-json v0.16.2
6584+
[COMPILING] obeli-sk-concepts v0.16.2 ([ROOT]/foo/target/package/obeli-sk-concepts-0.16.2)
6585+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
6586+
[VERIFYING] obeli-sk-utils v0.16.2 ([ROOT]/foo/crates/utils)
6587+
[UNPACKING] obeli-sk-concepts v0.16.2 (registry `[ROOT]/foo/target/package/tmp-registry`)
6588+
[COMPILING] obeli-sk-val-json v0.16.2
6589+
[COMPILING] obeli-sk-concepts v0.16.2
6590+
[COMPILING] obeli-sk-utils v0.16.2 ([ROOT]/foo/target/package/obeli-sk-utils-0.16.2)
6591+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
6592+
6593+
"#]]
6594+
.unordered(),
6595+
)
6596+
.run();
6597+
}
6598+
64956599
#[cargo_test]
64966600
fn registry_not_in_publish_list() {
64976601
let p = project()

0 commit comments

Comments
 (0)