Skip to content

Commit 4f7494c

Browse files
committed
feat(publish): workspace publish skips publish=false
This changes how cargo-publish works with the unstable `-Zpackage-workspace` feature. Before this, when publishing the entire workspace, like `cargo publish --workspace`, if there is a package with `package.pulibsh=false, it'll fail the entire publish process. After this, when `--workspace` is passed, or when publishing the virtual workspace, the intent is more like “publish all publishable in this workspace”, so skip `publish=false` packages and proceed to publish others. The new overall behavior looks like this: - `cargo publish` (inside a `package.publish = false` package): error - `cargo publish -p publishable -p unpublishable`: error - `cargo publish --workspace`: skips `package.publish = false See rust-lang#15006 (comment)
1 parent 6f81364 commit 4f7494c

File tree

2 files changed

+72
-19
lines changed

2 files changed

+72
-19
lines changed

src/cargo/ops/registry/publish.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,17 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
9696
let (unpublishable, pkgs): (Vec<_>, Vec<_>) = pkgs
9797
.into_iter()
9898
.partition(|(pkg, _)| pkg.publish() == &Some(vec![]));
99-
if !unpublishable.is_empty() {
99+
// If `--workspace` is passed,
100+
// the intent is more like "publish all publisable packages in this workspace",
101+
// so skip `publish=false` packages.
102+
let allow_unpublishable = multi_package_mode
103+
&& match &opts.to_publish {
104+
Packages::Default => ws.is_virtual(),
105+
Packages::All(_) => true,
106+
Packages::OptOut(_) => true,
107+
Packages::Packages(_) => false,
108+
};
109+
if !unpublishable.is_empty() && !allow_unpublishable {
100110
bail!(
101111
"{} cannot be published.\n\
102112
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.",

tests/testsuite/publish.rs

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4037,10 +4037,18 @@ fn one_unpublishable_package() {
40374037
p.cargo("publish -Zpackage-workspace")
40384038
.masquerade_as_nightly_cargo(&["package-workspace"])
40394039
.replace_crates_io(registry.index_url())
4040-
.with_status(101)
40414040
.with_stderr_data(str![[r#"
4042-
[ERROR] `main` cannot be published.
4043-
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.
4041+
[UPDATING] crates.io index
4042+
[PACKAGING] dep v0.1.0 ([ROOT]/foo/dep)
4043+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
4044+
[VERIFYING] dep v0.1.0 ([ROOT]/foo/dep)
4045+
[COMPILING] dep v0.1.0 ([ROOT]/foo/target/package/dep-0.1.0)
4046+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
4047+
[UPLOADING] dep v0.1.0 ([ROOT]/foo/dep)
4048+
[UPLOADED] dep v0.1.0 to registry `crates-io`
4049+
[NOTE] waiting for `dep v0.1.0` to be available at registry `crates-io`.
4050+
You may press ctrl-c to skip waiting; the crate should be available shortly.
4051+
[PUBLISHED] dep v0.1.0 at registry `crates-io`
40444052
40454053
"#]])
40464054
.run();
@@ -4109,10 +4117,18 @@ fn virtual_ws_with_multiple_unpublishable_package() {
41094117
p.cargo("publish -Zpackage-workspace")
41104118
.masquerade_as_nightly_cargo(&["package-workspace"])
41114119
.replace_crates_io(registry.index_url())
4112-
.with_status(101)
41134120
.with_stderr_data(str![[r#"
4114-
[ERROR] `dep`, `main` cannot be published.
4115-
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.
4121+
[UPDATING] crates.io index
4122+
[PACKAGING] publishable v0.1.0 ([ROOT]/foo/publishable)
4123+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
4124+
[VERIFYING] publishable v0.1.0 ([ROOT]/foo/publishable)
4125+
[COMPILING] publishable v0.1.0 ([ROOT]/foo/target/package/publishable-0.1.0)
4126+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
4127+
[UPLOADING] publishable v0.1.0 ([ROOT]/foo/publishable)
4128+
[UPLOADED] publishable v0.1.0 to registry `crates-io`
4129+
[NOTE] waiting for `publishable v0.1.0` to be available at registry `crates-io`.
4130+
You may press ctrl-c to skip waiting; the crate should be available shortly.
4131+
[PUBLISHED] publishable v0.1.0 at registry `crates-io`
41164132
41174133
"#]])
41184134
.run();
@@ -4173,10 +4189,18 @@ fn workspace_flag_with_unpublishable_packages() {
41734189
p.cargo("publish --workspace -Zpackage-workspace")
41744190
.masquerade_as_nightly_cargo(&["package-workspace"])
41754191
.replace_crates_io(registry.index_url())
4176-
.with_status(101)
41774192
.with_stderr_data(str![[r#"
4178-
[ERROR] `non-publishable`, `cwd` cannot be published.
4179-
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.
4193+
[UPDATING] crates.io index
4194+
[PACKAGING] publishable v0.0.0 ([ROOT]/foo/publishable)
4195+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
4196+
[VERIFYING] publishable v0.0.0 ([ROOT]/foo/publishable)
4197+
[COMPILING] publishable v0.0.0 ([ROOT]/foo/target/package/publishable-0.0.0)
4198+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
4199+
[UPLOADING] publishable v0.0.0 ([ROOT]/foo/publishable)
4200+
[UPLOADED] publishable v0.0.0 to registry `crates-io`
4201+
[NOTE] waiting for `publishable v0.0.0` to be available at registry `crates-io`.
4202+
You may press ctrl-c to skip waiting; the crate should be available shortly.
4203+
[PUBLISHED] publishable v0.0.0 at registry `crates-io`
41804204
41814205
"#]])
41824206
.run();
@@ -4233,8 +4257,15 @@ fn unpublishable_package_as_versioned_dev_dep() {
42334257
.replace_crates_io(registry.index_url())
42344258
.with_status(101)
42354259
.with_stderr_data(str![[r#"
4236-
[ERROR] `dep` cannot be published.
4237-
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.
4260+
[UPDATING] crates.io index
4261+
[PACKAGING] main v0.0.1 ([ROOT]/foo/main)
4262+
[UPDATING] crates.io index
4263+
[ERROR] failed to prepare local package for uploading
4264+
4265+
Caused by:
4266+
no matching package named `dep` found
4267+
location searched: crates.io index
4268+
required by package `main v0.0.1 ([ROOT]/foo/main)`
42384269
42394270
"#]])
42404271
.run();
@@ -4244,8 +4275,15 @@ fn unpublishable_package_as_versioned_dev_dep() {
42444275
.replace_crates_io(registry.index_url())
42454276
.with_status(101)
42464277
.with_stderr_data(str![[r#"
4247-
[ERROR] `dep` cannot be published.
4248-
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.
4278+
[UPDATING] crates.io index
4279+
[PACKAGING] main v0.0.1 ([ROOT]/foo/main)
4280+
[UPDATING] crates.io index
4281+
[ERROR] failed to prepare local package for uploading
4282+
4283+
Caused by:
4284+
no matching package named `dep` found
4285+
location searched: crates.io index
4286+
required by package `main v0.0.1 ([ROOT]/foo/main)`
42494287
42504288
"#]])
42514289
.run();
@@ -4255,8 +4293,15 @@ fn unpublishable_package_as_versioned_dev_dep() {
42554293
.replace_crates_io(registry.index_url())
42564294
.with_status(101)
42574295
.with_stderr_data(str![[r#"
4258-
[ERROR] `dep` cannot be published.
4259-
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.
4296+
[UPDATING] crates.io index
4297+
[PACKAGING] main v0.0.1 ([ROOT]/foo/main)
4298+
[UPDATING] crates.io index
4299+
[ERROR] failed to prepare local package for uploading
4300+
4301+
Caused by:
4302+
no matching package named `dep` found
4303+
location searched: crates.io index
4304+
required by package `main v0.0.1 ([ROOT]/foo/main)`
42604305
42614306
"#]])
42624307
.run();
@@ -4307,10 +4352,8 @@ fn all_unpublishable_packages() {
43074352
p.cargo("publish --workspace -Zpackage-workspace")
43084353
.masquerade_as_nightly_cargo(&["package-workspace"])
43094354
.replace_crates_io(registry.index_url())
4310-
.with_status(101)
43114355
.with_stderr_data(str![[r#"
4312-
[ERROR] `non-publishable1`, `non-publishable2` cannot be published.
4313-
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.
4356+
[UPDATING] crates.io index
43144357
43154358
"#]])
43164359
.run();

0 commit comments

Comments
 (0)