Skip to content

Commit

Permalink
Auto merge of #14659 - tweag:publish-workspace-cli-args, r=<try>
Browse files Browse the repository at this point in the history
Support package selection options like `--exclude` in `cargo publish`

Fixes #14652.

Is there a way to make the help text depend on whether nightly/unstable features are enabled? I couldn't find one...
  • Loading branch information
bors committed Oct 9, 2024
2 parents 15fbd2f + 3e1a989 commit 12caaff
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 23 deletions.
6 changes: 5 additions & 1 deletion src/bin/cargo/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ pub fn cli() -> Command {
"Allow dirty working directories to be packaged",
))
.arg_silent_suggestion()
.arg_package("Package to publish")
.arg_package_spec_no_all(
"Package(s) to publish",
"Publish all packages in the workspace (requires nightly)",
"Don't publish specified packages (requires nightly)",
)
.arg_features()
.arg_parallel()
.arg_target_triple("Build for the target triple")
Expand Down
48 changes: 26 additions & 22 deletions tests/testsuite/cargo_publish/help/stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3364,6 +3364,94 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
.run();
}

#[cargo_test]
fn package_selection() {
let registry = registry::RegistryBuilder::new().http_api().build();
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["a", "b"]
"#,
)
.file("a/Cargo.toml", &basic_manifest("a", "0.1.0"))
.file("a/src/lib.rs", "#[test] fn a() {}")
.file("b/Cargo.toml", &basic_manifest("b", "0.1.0"))
.file("b/src/lib.rs", "#[test] fn b() {}")
.build();

p.cargo("publish --no-verify --dry-run -Zpackage-workspace --workspace")
.replace_crates_io(registry.index_url())
.masquerade_as_nightly_cargo(&["package-workspace"])
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
[PACKAGING] a v0.1.0 ([ROOT]/foo/a)
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
[PACKAGING] b v0.1.0 ([ROOT]/foo/b)
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[UPLOADING] a v0.1.0 ([ROOT]/foo/a)
[WARNING] aborting upload due to dry run
[UPLOADING] b v0.1.0 ([ROOT]/foo/b)
[WARNING] aborting upload due to dry run
"#]])
.with_stdout_data(str![[r#""#]])
.run();

p.cargo("publish --no-verify --dry-run -Zpackage-workspace --package a --package b")
.replace_crates_io(registry.index_url())
.masquerade_as_nightly_cargo(&["package-workspace"])
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
[PACKAGING] a v0.1.0 ([ROOT]/foo/a)
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
[PACKAGING] b v0.1.0 ([ROOT]/foo/b)
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[UPLOADING] a v0.1.0 ([ROOT]/foo/a)
[WARNING] aborting upload due to dry run
[UPLOADING] b v0.1.0 ([ROOT]/foo/b)
[WARNING] aborting upload due to dry run
"#]])
.with_stdout_data(str![[r#""#]])
.run();

p.cargo("publish --no-verify --dry-run -Zpackage-workspace --workspace --exclude b")
.replace_crates_io(registry.index_url())
.masquerade_as_nightly_cargo(&["package-workspace"])
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
[PACKAGING] a v0.1.0 ([ROOT]/foo/a)
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[UPLOADING] a v0.1.0 ([ROOT]/foo/a)
[WARNING] aborting upload due to dry run
"#]])
.with_stdout_data(str![[r#""#]])
.run();

p.cargo("publish --no-verify --dry-run --package a --package b")
.replace_crates_io(registry.index_url())
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] the `-p` argument must be specified to select a single package to publish
"#]])
.with_stdout_data(str![[r#""#]])
.run();
}

#[cargo_test]
fn wait_for_git_publish() {
// Slow publish to an index with a git index.
Expand Down

0 comments on commit 12caaff

Please sign in to comment.