Skip to content

Commit

Permalink
fix(embedded): Error on unsupported commands
Browse files Browse the repository at this point in the history
- `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.
  • Loading branch information
epage committed Jul 11, 2023
1 parent aaaa37f commit 10fbb47
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 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
11 changes: 3 additions & 8 deletions tests/testsuite/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ fn cmd_pkgid_with_embedded() {
.with_stderr(
"\
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[ERROR] a Cargo.lock must exist for this command
[ERROR] [ROOT]/foo/script.rs is unsupported by `cargo pkgid`
",
)
.run();
Expand All @@ -1213,11 +1213,7 @@ fn cmd_package_with_embedded() {
.with_stderr(
"\
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
Caused by:
no targets specified in the manifest
either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present
[ERROR] [ROOT]/foo/script.rs is unsupported by `cargo package`
",
)
.run();
Expand All @@ -1235,8 +1231,7 @@ fn cmd_publish_with_embedded() {
.with_stderr(
"\
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[ERROR] `script` cannot be published.
`package.publish` is set to `false` or an empty list in Cargo.toml and prevents publishing.
[ERROR] [ROOT]/foo/script.rs is unsupported by `cargo publish`
",
)
.run();
Expand Down

0 comments on commit 10fbb47

Please sign in to comment.