From a282233ae4274072097330fd3e2682bb85f6e142 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 15 Jan 2025 20:23:19 -0600 Subject: [PATCH 1/2] test(publish): Check with multiple unpublishable packages --- tests/testsuite/publish.rs | 62 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/testsuite/publish.rs b/tests/testsuite/publish.rs index 4bcb9194416..d4d5fef7e2b 100644 --- a/tests/testsuite/publish.rs +++ b/tests/testsuite/publish.rs @@ -4049,3 +4049,65 @@ fn one_unpublishable_package() { "#]]) .run(); } + +#[cargo_test] +fn multiple_unpublishable_package() { + let _alt_reg = registry::RegistryBuilder::new() + .http_api() + .http_index() + .alternative() + .build(); + + let p = project() + .file( + "Cargo.toml", + r#" + [workspace] + members = ["dep", "main"] + "#, + ) + .file( + "main/Cargo.toml", + r#" + [package] + name = "main" + version = "0.0.1" + edition = "2015" + authors = [] + license = "MIT" + description = "main" + repository = "bar" + publish = false + + [dependencies] + dep = { path = "../dep", version = "0.1.0" } + "#, + ) + .file("main/src/main.rs", "fn main() {}") + .file( + "dep/Cargo.toml", + r#" + [package] + name = "dep" + version = "0.1.0" + edition = "2015" + authors = [] + license = "MIT" + description = "dep" + repository = "bar" + publish = false + "#, + ) + .file("dep/src/lib.rs", "") + .build(); + + p.cargo("publish -Zpackage-workspace") + .masquerade_as_nightly_cargo(&["package-workspace"]) + .with_status(101) + .with_stderr_data(str![[r#" +[ERROR] `dep` cannot be published. +`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish. + +"#]]) + .run(); +} From 1eafdb2656e33b21f4bfeb60f197b50a4a64fc1c Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 15 Jan 2025 20:24:52 -0600 Subject: [PATCH 2/2] fix(publish): Report all unpublishable packages I didn't extend this to multiple packages restricted to specific registries. It seems less likely to be a problem and more complex to gather and report. This was inspired by feedback left at #10948 --- src/cargo/ops/registry/publish.rs | 19 +++++++++++-------- tests/testsuite/publish.rs | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/cargo/ops/registry/publish.rs b/src/cargo/ops/registry/publish.rs index de0f9ac4e0a..0d1d22e8f14 100644 --- a/src/cargo/ops/registry/publish.rs +++ b/src/cargo/ops/registry/publish.rs @@ -703,14 +703,17 @@ fn package_list(pkgs: impl IntoIterator, final_sep: &str) -> S } fn validate_registry(pkgs: &[&Package], reg_or_index: Option<&RegistryOrIndex>) -> CargoResult<()> { - for pkg in pkgs { - if pkg.publish() == &Some(Vec::new()) { - bail!( - "`{}` cannot be published.\n\ - `package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.", - pkg.name(), - ); - } + let unpublishable = pkgs + .iter() + .filter(|pkg| pkg.publish() == &Some(Vec::new())) + .map(|pkg| format!("`{}`", pkg.name())) + .collect::>(); + if !unpublishable.is_empty() { + bail!( + "{} cannot be published.\n\ + `package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.", + unpublishable.join(", ") + ); } let reg_name = match reg_or_index { diff --git a/tests/testsuite/publish.rs b/tests/testsuite/publish.rs index d4d5fef7e2b..4e322431bd0 100644 --- a/tests/testsuite/publish.rs +++ b/tests/testsuite/publish.rs @@ -4105,7 +4105,7 @@ fn multiple_unpublishable_package() { .masquerade_as_nightly_cargo(&["package-workspace"]) .with_status(101) .with_stderr_data(str![[r#" -[ERROR] `dep` cannot be published. +[ERROR] `dep`, `main` cannot be published. `package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish. "#]])