From 4213e921caf8f34ded54588ce22b643da501d687 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 21 Feb 2025 08:39:40 -0600 Subject: [PATCH 1/3] test(package): Show behavior with renamed members --- tests/testsuite/package.rs | 112 +++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 4d981890ffb..3edd5fe27bf 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -6492,6 +6492,118 @@ 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_status(101) + .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 +error[E0433]: failed to resolve: use of undeclared crate or module `val_json` + --> [ROOT]/home/.cargo/registry/src/-[HASH]/obeli-sk-concepts-0.16.2/src/lib.rs:1:16 + | +1 | pub fn foo() { val_json::foo() } + | ^^^^^^^^ use of undeclared crate or module `val_json` + +For more information about this error, try `rustc --explain E0433`. +[ERROR] could not compile `obeli-sk-concepts` (lib) due to 1 previous error +[ERROR] failed to verify package tarball + +"#]] + .unordered(), + ) + .run(); +} + #[cargo_test] fn registry_not_in_publish_list() { let p = project() From ca9bf214d0744d9d9fd53d648f3501a9a020b5c2 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 24 Feb 2025 11:27:13 -0600 Subject: [PATCH 2/3] refactor(package): Pull out field initialization --- src/cargo/ops/cargo_package/mod.rs | 36 +++++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/cargo/ops/cargo_package/mod.rs b/src/cargo/ops/cargo_package/mod.rs index 5e5f4ff191d..d86b8491467 100644 --- a/src/cargo/ops/cargo_package/mod.rs +++ b/src/cargo/ops/cargo_package/mod.rs @@ -1032,22 +1032,26 @@ 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.name.into(); + let package = None; + 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(); From e1d61b80805ed4e4f32f1d0eea338602d83a77e4 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 24 Feb 2025 11:21:55 -0600 Subject: [PATCH 3/3] fix(package): Register workspace member renames in overlay This was reported at https://github.com/rust-lang/cargo/issues/10948#issuecomment-2674289330 I suspect there is a second bug here because my debugging only showed us doing this for `val-json` and not `concepts` and only when building `utils`. 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. --- src/cargo/ops/cargo_package/mod.rs | 11 +++++++++-- tests/testsuite/package.rs | 12 ++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/cargo/ops/cargo_package/mod.rs b/src/cargo/ops/cargo_package/mod.rs index d86b8491467..d71e4fd207f 100644 --- a/src/cargo/ops/cargo_package/mod.rs +++ b/src/cargo/ops/cargo_package/mod.rs @@ -1033,8 +1033,15 @@ impl<'a> TmpRegistry<'a> { .deps .into_iter() .map(|dep| { - let name = dep.name.into(); - let package = None; + 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(), diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 3edd5fe27bf..0263607449c 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -6566,7 +6566,6 @@ fn workspace_with_renamed_member() { p.cargo("package -Zpackage-workspace") .masquerade_as_nightly_cargo(&["package-workspace"]) .replace_crates_io(reg.index_url()) - .with_status(101) .with_stderr_data( str![[r#" [UPDATING] crates.io index @@ -6588,15 +6587,8 @@ fn workspace_with_renamed_member() { [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 -error[E0433]: failed to resolve: use of undeclared crate or module `val_json` - --> [ROOT]/home/.cargo/registry/src/-[HASH]/obeli-sk-concepts-0.16.2/src/lib.rs:1:16 - | -1 | pub fn foo() { val_json::foo() } - | ^^^^^^^^ use of undeclared crate or module `val_json` - -For more information about this error, try `rustc --explain E0433`. -[ERROR] could not compile `obeli-sk-concepts` (lib) due to 1 previous error -[ERROR] failed to verify package tarball +[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(),