Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(embedded): Error on intentionally unsupported commands #12350

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}