fix(package): Register workspace member renames in overlay (#15228)

### What does this PR try to resolve?

This was reported at
https://github.com/rust-lang/cargo/issues/10948#issuecomment-2674289330

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.
This commit is contained in:
Ed Page 2025-02-25 15:19:55 +00:00 committed by GitHub
commit ffafda8fd4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 131 additions and 16 deletions

View File

@ -1032,22 +1032,33 @@ impl<'a> TmpRegistry<'a> {
let deps: Vec<_> = new_crate
.deps
.into_iter()
.map(|dep| RegistryDependency {
name: dep.name.into(),
req: dep.version_req.into(),
features: dep.features.into_iter().map(|x| x.into()).collect(),
optional: dep.optional,
default_features: dep.default_features,
target: dep.target.map(|x| x.into()),
kind: Some(dep.kind.into()),
registry: dep.registry.map(|x| x.into()),
package: None,
public: None,
artifact: dep
.artifact
.map(|xs| xs.into_iter().map(|x| x.into()).collect()),
bindep_target: dep.bindep_target.map(|x| x.into()),
lib: dep.lib,
.map(|dep| {
let name = dep
.explicit_name_in_toml
.clone()
.unwrap_or_else(|| dep.name.clone())
.into();
let package = dep
.explicit_name_in_toml
.as_ref()
.map(|_| dep.name.clone().into());
RegistryDependency {
name: name,
req: dep.version_req.into(),
features: dep.features.into_iter().map(|x| x.into()).collect(),
optional: dep.optional,
default_features: dep.default_features,
target: dep.target.map(|x| x.into()),
kind: Some(dep.kind.into()),
registry: dep.registry.map(|x| x.into()),
package: package,
public: None,
artifact: dep
.artifact
.map(|xs| xs.into_iter().map(|x| x.into()).collect()),
bindep_target: dep.bindep_target.map(|x| x.into()),
lib: dep.lib,
}
})
.collect();

View File

@ -6492,6 +6492,110 @@ fn workspace_with_capitalized_member() {
.run();
}
#[cargo_test]
fn workspace_with_renamed_member() {
let reg = registry::init();
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["crates/*"]
"#,
)
.file(
"crates/val-json/Cargo.toml",
r#"
[package]
name = "obeli-sk-val-json"
version = "0.16.2"
edition = "2015"
authors = []
license = "MIT"
description = "main"
repository = "bar"
[dependencies]
"#,
)
.file("crates/val-json/src/lib.rs", "pub fn foo() {}")
.file(
"crates/concepts/Cargo.toml",
r#"
[package]
name = "obeli-sk-concepts"
version = "0.16.2"
edition = "2015"
authors = []
license = "MIT"
description = "main"
repository = "bar"
[dependencies]
val-json = { package = "obeli-sk-val-json", path = "../val-json", version = "0.16.2" }
"#,
)
.file(
"crates/concepts/src/lib.rs",
"pub fn foo() { val_json::foo() }",
)
.file(
"crates/utils/Cargo.toml",
r#"
[package]
name = "obeli-sk-utils"
version = "0.16.2"
edition = "2015"
authors = []
license = "MIT"
description = "main"
repository = "bar"
[dependencies]
concepts = { package = "obeli-sk-concepts", path = "../concepts", version = "0.16.2" }
val-json = { package = "obeli-sk-val-json", path = "../val-json", version = "0.16.2" }
"#,
)
.file(
"crates/utils/src/lib.rs",
"pub fn foo() { val_json::foo(); concepts::foo(); }",
)
.build();
p.cargo("package -Zpackage-workspace")
.masquerade_as_nightly_cargo(&["package-workspace"])
.replace_crates_io(reg.index_url())
.with_stderr_data(
str![[r#"
[UPDATING] crates.io index
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[PACKAGING] obeli-sk-val-json v0.16.2 ([ROOT]/foo/crates/val-json)
[PACKAGING] obeli-sk-concepts v0.16.2 ([ROOT]/foo/crates/concepts)
[PACKAGING] obeli-sk-utils v0.16.2 ([ROOT]/foo/crates/utils)
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[VERIFYING] obeli-sk-val-json v0.16.2 ([ROOT]/foo/crates/val-json)
[COMPILING] obeli-sk-val-json v0.16.2 ([ROOT]/foo/target/package/obeli-sk-val-json-0.16.2)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[VERIFYING] obeli-sk-concepts v0.16.2 ([ROOT]/foo/crates/concepts)
[UNPACKING] obeli-sk-val-json v0.16.2 (registry `[ROOT]/foo/target/package/tmp-registry`)
[COMPILING] obeli-sk-val-json v0.16.2
[COMPILING] obeli-sk-concepts v0.16.2 ([ROOT]/foo/target/package/obeli-sk-concepts-0.16.2)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[VERIFYING] obeli-sk-utils v0.16.2 ([ROOT]/foo/crates/utils)
[UNPACKING] obeli-sk-concepts v0.16.2 (registry `[ROOT]/foo/target/package/tmp-registry`)
[COMPILING] obeli-sk-val-json v0.16.2
[COMPILING] obeli-sk-concepts v0.16.2
[COMPILING] obeli-sk-utils v0.16.2 ([ROOT]/foo/target/package/obeli-sk-utils-0.16.2)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]]
.unordered(),
)
.run();
}
#[cargo_test]
fn registry_not_in_publish_list() {
let p = project()