Skip to content

Commit e64975c

Browse files
committed
Auto merge of #12350 - epage:invalid, r=weihanglo
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
2 parents 7d9498d + 10fbb47 commit e64975c

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,3 +1182,57 @@ fn cmd_verify_project_with_embedded() {
11821182
)
11831183
.run();
11841184
}
1185+
1186+
#[cargo_test]
1187+
fn cmd_pkgid_with_embedded() {
1188+
let p = cargo_test_support::project()
1189+
.file("script.rs", ECHO_SCRIPT)
1190+
.build();
1191+
1192+
p.cargo("-Zscript pkgid --manifest-path script.rs")
1193+
.masquerade_as_nightly_cargo(&["script"])
1194+
.with_status(101)
1195+
.with_stderr(
1196+
"\
1197+
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
1198+
[ERROR] [ROOT]/foo/script.rs is unsupported by `cargo pkgid`
1199+
",
1200+
)
1201+
.run();
1202+
}
1203+
1204+
#[cargo_test]
1205+
fn cmd_package_with_embedded() {
1206+
let p = cargo_test_support::project()
1207+
.file("script.rs", ECHO_SCRIPT)
1208+
.build();
1209+
1210+
p.cargo("-Zscript package --manifest-path script.rs")
1211+
.masquerade_as_nightly_cargo(&["script"])
1212+
.with_status(101)
1213+
.with_stderr(
1214+
"\
1215+
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
1216+
[ERROR] [ROOT]/foo/script.rs is unsupported by `cargo package`
1217+
",
1218+
)
1219+
.run();
1220+
}
1221+
1222+
#[cargo_test]
1223+
fn cmd_publish_with_embedded() {
1224+
let p = cargo_test_support::project()
1225+
.file("script.rs", ECHO_SCRIPT)
1226+
.build();
1227+
1228+
p.cargo("-Zscript publish --manifest-path script.rs")
1229+
.masquerade_as_nightly_cargo(&["script"])
1230+
.with_status(101)
1231+
.with_stderr(
1232+
"\
1233+
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
1234+
[ERROR] [ROOT]/foo/script.rs is unsupported by `cargo publish`
1235+
",
1236+
)
1237+
.run();
1238+
}

0 commit comments

Comments
 (0)