Skip to content

cargo package --workspace must support publish = false #14364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
63 changes: 63 additions & 0 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2831,6 +2831,69 @@ 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")
.with_stderr_data(str![[r#"
[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();

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()
Expand Down