From d26cd393ee42ed6c4e8e9c4343a2bc37cc2cfbc5 Mon Sep 17 00:00:00 2001 From: Tor Hovland <55164+torhovland@users.noreply.github.com> Date: Wed, 7 Aug 2024 11:30:59 +0200 Subject: [PATCH 1/2] test: package::in_workspace_with_publish_false --- tests/testsuite/package.rs | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 92a91d41732..032b49f832f 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -2831,6 +2831,60 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for assert!(p.root().join("target/package/bar-0.0.1.crate").is_file()); } +#[cargo_test] +fn in_workspace_with_publish_false() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + authors = [] + license = "MIT" + description = "foo" + + [workspace] + members = ["no-publish"] + "#, + ) + .file("src/main.rs", "fn main() {}") + .file( + "no-publish/Cargo.toml", + r#" + [package] + name = "no-publish" + version = "0.0.1" + edition = "2015" + authors = [] + license = "MIT" + description = "no-publish" + workspace = ".." + publish = false + "#, + ) + .file("no-publish/src/main.rs", "fn main() {}") + .build(); + + p.cargo("package --workspace") + // FIXME: This reproduces https://github.com/rust-lang/cargo/issues/14356 + .with_status(101) + .with_stderr_data(str![[r#" +[ERROR] `no-publish` cannot be packaged. +The registry `crates-io` is not listed in the `package.publish` value in Cargo.toml. + +"#]]) + .run(); + + // FIXME: Enable these + // assert!(p.root().join("target/package/foo-0.0.1.crate").is_file()); + // assert!(p + // .root() + // .join("target/package/no-publish-0.0.1.crate") + // .is_file()); +} + #[cargo_test] fn workspace_noconflict_readme() { let p = project() From 79bab4d0cb5a43f2d7b43a8d489feceb0cfc4beb Mon Sep 17 00:00:00 2001 From: Tor Hovland <55164+torhovland@users.noreply.github.com> Date: Wed, 7 Aug 2024 11:49:11 +0200 Subject: [PATCH 2/2] fix: Don't fail packaging on publish = false. --- src/cargo/ops/cargo_package.rs | 2 +- tests/testsuite/package.rs | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index ab4ceeb4199..c29e5c3ec85 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -207,7 +207,7 @@ fn infer_registry( let reg_name = publish_registry.as_deref().unwrap_or(CRATES_IO_REGISTRY); for pkg in pkgs { if let Some(allowed) = pkg.publish().as_ref() { - if !allowed.iter().any(|a| a == reg_name) { + if !allowed.is_empty() && !allowed.iter().any(|a| a == reg_name) { bail!( "`{}` cannot be packaged.\n\ The registry `{}` is not listed in the `package.publish` value in Cargo.toml.", diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 032b49f832f..0fbc0f2059c 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -2868,21 +2868,30 @@ fn in_workspace_with_publish_false() { .build(); p.cargo("package --workspace") - // FIXME: This reproduces https://github.com/rust-lang/cargo/issues/14356 - .with_status(101) .with_stderr_data(str![[r#" -[ERROR] `no-publish` cannot be packaged. -The registry `crates-io` is not listed in the `package.publish` value in Cargo.toml. +[WARNING] manifest has no documentation, homepage or repository. +See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info. +[PACKAGING] foo v0.0.1 ([ROOT]/foo) +[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) +[WARNING] manifest has no documentation, homepage or repository. +See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info. +[PACKAGING] no-publish v0.0.1 ([ROOT]/foo/no-publish) +[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) +[VERIFYING] foo v0.0.1 ([ROOT]/foo) +[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[VERIFYING] no-publish v0.0.1 ([ROOT]/foo/no-publish) +[COMPILING] no-publish v0.0.1 ([ROOT]/foo/target/package/no-publish-0.0.1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s "#]]) .run(); - // FIXME: Enable these - // assert!(p.root().join("target/package/foo-0.0.1.crate").is_file()); - // assert!(p - // .root() - // .join("target/package/no-publish-0.0.1.crate") - // .is_file()); + assert!(p.root().join("target/package/foo-0.0.1.crate").is_file()); + assert!(p + .root() + .join("target/package/no-publish-0.0.1.crate") + .is_file()); } #[cargo_test]