Skip to content

Commit 10fbb47

Browse files
committed
fix(embedded): Error on unsupported commands
- `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.
1 parent aaaa37f commit 10fbb47

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

src/bin/cargo/commands/package.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ pub fn cli() -> Command {
4040

4141
pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
4242
let ws = args.workspace(config)?;
43+
if ws.root_maybe().is_embedded() {
44+
return Err(anyhow::format_err!(
45+
"{} is unsupported by `cargo package`",
46+
ws.root_manifest().display()
47+
)
48+
.into());
49+
}
4350
let specs = args.packages_from_flags()?;
4451

4552
ops::package(

src/bin/cargo/commands/pkgid.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ pub fn cli() -> Command {
1515

1616
pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
1717
let ws = args.workspace(config)?;
18+
if ws.root_maybe().is_embedded() {
19+
return Err(anyhow::format_err!(
20+
"{} is unsupported by `cargo pkgid`",
21+
ws.root_manifest().display()
22+
)
23+
.into());
24+
}
1825
if args.is_present_with_zero_values("package") {
1926
print_available_packages(&ws)?
2027
}

src/bin/cargo/commands/publish.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ pub fn cli() -> Command {
3030
pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
3131
let registry = args.registry(config)?;
3232
let ws = args.workspace(config)?;
33+
if ws.root_maybe().is_embedded() {
34+
return Err(anyhow::format_err!(
35+
"{} is unsupported by `cargo publish`",
36+
ws.root_manifest().display()
37+
)
38+
.into());
39+
}
3340
let index = args.index()?;
3441

3542
ops::publish(

tests/testsuite/script.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ fn cmd_pkgid_with_embedded() {
11951195
.with_stderr(
11961196
"\
11971197
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
1198-
[ERROR] a Cargo.lock must exist for this command
1198+
[ERROR] [ROOT]/foo/script.rs is unsupported by `cargo pkgid`
11991199
",
12001200
)
12011201
.run();
@@ -1213,11 +1213,7 @@ fn cmd_package_with_embedded() {
12131213
.with_stderr(
12141214
"\
12151215
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
1216-
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
1217-
1218-
Caused by:
1219-
no targets specified in the manifest
1220-
either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present
1216+
[ERROR] [ROOT]/foo/script.rs is unsupported by `cargo package`
12211217
",
12221218
)
12231219
.run();
@@ -1235,8 +1231,7 @@ fn cmd_publish_with_embedded() {
12351231
.with_stderr(
12361232
"\
12371233
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
1238-
[ERROR] `script` cannot be published.
1239-
`package.publish` is set to `false` or an empty list in Cargo.toml and prevents publishing.
1234+
[ERROR] [ROOT]/foo/script.rs is unsupported by `cargo publish`
12401235
",
12411236
)
12421237
.run();

0 commit comments

Comments
 (0)