Skip to content

Commit

Permalink
Auto merge of #12350 - epage:invalid, r=weihanglo
Browse files Browse the repository at this point in the history
fix(embedded): Error on unsupported commands

### What does this PR try to resolve?

We had talked about de-prioritizing some commands in the cargo team meeting today.  Looking through `cargo --list` and trying them out, the important ones to defer seemed to be:

- `cargo pkgid` is unsupported because we can't (yet) generate valid
  pkgids for embedded manifests.  Adding support for this would be a
  step towards workspace support
- `cargo package` and `cargo publish` are being deferred.  These would
  be more important for `[lib]` support.  `cargo install` for `[[bin]]`s
  is a small case and As single-file packages are fairly restrictive, a
  `[[bin]]` is a lower priority.

### How should we test and review this PR?

Per-commit
  • Loading branch information
bors committed Jul 11, 2023
2 parents 7d9498d + 10fbb47 commit e64975c
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/bin/cargo/commands/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ pub fn cli() -> Command {

pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
let ws = args.workspace(config)?;
if ws.root_maybe().is_embedded() {
return Err(anyhow::format_err!(
"{} is unsupported by `cargo package`",
ws.root_manifest().display()
)
.into());
}
let specs = args.packages_from_flags()?;

ops::package(
Expand Down
7 changes: 7 additions & 0 deletions src/bin/cargo/commands/pkgid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ pub fn cli() -> Command {

pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
let ws = args.workspace(config)?;
if ws.root_maybe().is_embedded() {
return Err(anyhow::format_err!(
"{} is unsupported by `cargo pkgid`",
ws.root_manifest().display()
)
.into());
}
if args.is_present_with_zero_values("package") {
print_available_packages(&ws)?
}
Expand Down
7 changes: 7 additions & 0 deletions src/bin/cargo/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ pub fn cli() -> Command {
pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
let registry = args.registry(config)?;
let ws = args.workspace(config)?;
if ws.root_maybe().is_embedded() {
return Err(anyhow::format_err!(
"{} is unsupported by `cargo publish`",
ws.root_manifest().display()
)
.into());
}
let index = args.index()?;

ops::publish(
Expand Down
54 changes: 54 additions & 0 deletions tests/testsuite/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1182,3 +1182,57 @@ fn cmd_verify_project_with_embedded() {
)
.run();
}

#[cargo_test]
fn cmd_pkgid_with_embedded() {
let p = cargo_test_support::project()
.file("script.rs", ECHO_SCRIPT)
.build();

p.cargo("-Zscript pkgid --manifest-path script.rs")
.masquerade_as_nightly_cargo(&["script"])
.with_status(101)
.with_stderr(
"\
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[ERROR] [ROOT]/foo/script.rs is unsupported by `cargo pkgid`
",
)
.run();
}

#[cargo_test]
fn cmd_package_with_embedded() {
let p = cargo_test_support::project()
.file("script.rs", ECHO_SCRIPT)
.build();

p.cargo("-Zscript package --manifest-path script.rs")
.masquerade_as_nightly_cargo(&["script"])
.with_status(101)
.with_stderr(
"\
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[ERROR] [ROOT]/foo/script.rs is unsupported by `cargo package`
",
)
.run();
}

#[cargo_test]
fn cmd_publish_with_embedded() {
let p = cargo_test_support::project()
.file("script.rs", ECHO_SCRIPT)
.build();

p.cargo("-Zscript publish --manifest-path script.rs")
.masquerade_as_nightly_cargo(&["script"])
.with_status(101)
.with_stderr(
"\
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[ERROR] [ROOT]/foo/script.rs is unsupported by `cargo publish`
",
)
.run();
}

0 comments on commit e64975c

Please sign in to comment.