diff --git a/src/bin/cargo/commands/package.rs b/src/bin/cargo/commands/package.rs index ac6b1fe27f0..cef530fdc6c 100644 --- a/src/bin/cargo/commands/package.rs +++ b/src/bin/cargo/commands/package.rs @@ -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( diff --git a/src/bin/cargo/commands/pkgid.rs b/src/bin/cargo/commands/pkgid.rs index 664db75bd0a..cd92e9998db 100644 --- a/src/bin/cargo/commands/pkgid.rs +++ b/src/bin/cargo/commands/pkgid.rs @@ -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)? } diff --git a/src/bin/cargo/commands/publish.rs b/src/bin/cargo/commands/publish.rs index c831d399f59..e550e1544c0 100644 --- a/src/bin/cargo/commands/publish.rs +++ b/src/bin/cargo/commands/publish.rs @@ -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( diff --git a/tests/testsuite/script.rs b/tests/testsuite/script.rs index fcf58de6981..1065b3bc47e 100644 --- a/tests/testsuite/script.rs +++ b/tests/testsuite/script.rs @@ -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(); +}