Skip to content

Commit 150bbc4

Browse files
authored
fix(publish): Report all unpublishable packages (#15070)
### What does this PR try to resolve? 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 ### How should we test and review this PR? ### Additional information
2 parents 1177d2a + 1eafdb2 commit 150bbc4

File tree

2 files changed

+73
-8
lines changed

2 files changed

+73
-8
lines changed

src/cargo/ops/registry/publish.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -703,14 +703,17 @@ fn package_list(pkgs: impl IntoIterator<Item = PackageId>, final_sep: &str) -> S
703703
}
704704

705705
fn validate_registry(pkgs: &[&Package], reg_or_index: Option<&RegistryOrIndex>) -> CargoResult<()> {
706-
for pkg in pkgs {
707-
if pkg.publish() == &Some(Vec::new()) {
708-
bail!(
709-
"`{}` cannot be published.\n\
710-
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.",
711-
pkg.name(),
712-
);
713-
}
706+
let unpublishable = pkgs
707+
.iter()
708+
.filter(|pkg| pkg.publish() == &Some(Vec::new()))
709+
.map(|pkg| format!("`{}`", pkg.name()))
710+
.collect::<Vec<_>>();
711+
if !unpublishable.is_empty() {
712+
bail!(
713+
"{} cannot be published.\n\
714+
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.",
715+
unpublishable.join(", ")
716+
);
714717
}
715718

716719
let reg_name = match reg_or_index {

tests/testsuite/publish.rs

+62
Original file line numberDiff line numberDiff line change
@@ -4049,3 +4049,65 @@ fn one_unpublishable_package() {
40494049
"#]])
40504050
.run();
40514051
}
4052+
4053+
#[cargo_test]
4054+
fn multiple_unpublishable_package() {
4055+
let _alt_reg = registry::RegistryBuilder::new()
4056+
.http_api()
4057+
.http_index()
4058+
.alternative()
4059+
.build();
4060+
4061+
let p = project()
4062+
.file(
4063+
"Cargo.toml",
4064+
r#"
4065+
[workspace]
4066+
members = ["dep", "main"]
4067+
"#,
4068+
)
4069+
.file(
4070+
"main/Cargo.toml",
4071+
r#"
4072+
[package]
4073+
name = "main"
4074+
version = "0.0.1"
4075+
edition = "2015"
4076+
authors = []
4077+
license = "MIT"
4078+
description = "main"
4079+
repository = "bar"
4080+
publish = false
4081+
4082+
[dependencies]
4083+
dep = { path = "../dep", version = "0.1.0" }
4084+
"#,
4085+
)
4086+
.file("main/src/main.rs", "fn main() {}")
4087+
.file(
4088+
"dep/Cargo.toml",
4089+
r#"
4090+
[package]
4091+
name = "dep"
4092+
version = "0.1.0"
4093+
edition = "2015"
4094+
authors = []
4095+
license = "MIT"
4096+
description = "dep"
4097+
repository = "bar"
4098+
publish = false
4099+
"#,
4100+
)
4101+
.file("dep/src/lib.rs", "")
4102+
.build();
4103+
4104+
p.cargo("publish -Zpackage-workspace")
4105+
.masquerade_as_nightly_cargo(&["package-workspace"])
4106+
.with_status(101)
4107+
.with_stderr_data(str![[r#"
4108+
[ERROR] `dep`, `main` cannot be published.
4109+
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.
4110+
4111+
"#]])
4112+
.run();
4113+
}

0 commit comments

Comments
 (0)