From c3043c53c1ef28ed7aa9b73e11ed9c08cb8ae32d Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Mon, 19 Aug 2024 12:07:40 +0700 Subject: [PATCH] Allow unpublishable crates to be packaged --- src/cargo/ops/cargo_package.rs | 9 +++++-- src/cargo/ops/registry/mod.rs | 18 ++++++++++---- tests/testsuite/package.rs | 43 +++++++++++++++++++++++++++++----- 3 files changed, 58 insertions(+), 12 deletions(-) diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index a744af7ca1c1..1232a543a6b6 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -249,7 +249,9 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult CargoResult> { - if pkgs[1..].iter().all(|p| p.publish() == pkgs[0].publish()) { - // If all packages have the same publish settings, we take that as the default. - match pkgs[0].publish().as_deref() { + // Ignore "publish = false" packages while inferring the registry. + let publishable_pkgs: Vec<_> = pkgs + .iter() + .filter(|p| p.publish() != &Some(Vec::new())) + .collect(); + + let Some((first, rest)) = publishable_pkgs.split_first() else { + return Ok(None); + }; + + // If all packages have the same publish settings, we take that as the default. + if rest.iter().all(|p| p.publish() == first.publish()) { + match publishable_pkgs[0].publish().as_deref() { Some([unique_pkg_reg]) => { Ok(Some(RegistryOrIndex::Registry(unique_pkg_reg.to_owned()))) } @@ -346,7 +356,7 @@ pub(crate) fn infer_registry(pkgs: &[&Package]) -> CargoResult