mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
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
This commit is contained in:
commit
150bbc4d50
@ -703,15 +703,18 @@ fn package_list(pkgs: impl IntoIterator<Item = PackageId>, final_sep: &str) -> S
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn validate_registry(pkgs: &[&Package], reg_or_index: Option<&RegistryOrIndex>) -> CargoResult<()> {
|
fn validate_registry(pkgs: &[&Package], reg_or_index: Option<&RegistryOrIndex>) -> CargoResult<()> {
|
||||||
for pkg in pkgs {
|
let unpublishable = pkgs
|
||||||
if pkg.publish() == &Some(Vec::new()) {
|
.iter()
|
||||||
|
.filter(|pkg| pkg.publish() == &Some(Vec::new()))
|
||||||
|
.map(|pkg| format!("`{}`", pkg.name()))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
if !unpublishable.is_empty() {
|
||||||
bail!(
|
bail!(
|
||||||
"`{}` cannot be published.\n\
|
"{} cannot be published.\n\
|
||||||
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.",
|
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.",
|
||||||
pkg.name(),
|
unpublishable.join(", ")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let reg_name = match reg_or_index {
|
let reg_name = match reg_or_index {
|
||||||
Some(RegistryOrIndex::Registry(r)) => Some(r.as_str()),
|
Some(RegistryOrIndex::Registry(r)) => Some(r.as_str()),
|
||||||
|
@ -4049,3 +4049,65 @@ fn one_unpublishable_package() {
|
|||||||
"#]])
|
"#]])
|
||||||
.run();
|
.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`, `main` cannot be published.
|
||||||
|
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.
|
||||||
|
|
||||||
|
"#]])
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user