fix(cli): Warn on stable for precedence changes

This will give us a window to collect feedback on if this affects
anyone.
This commit is contained in:
Ed Page 2023-06-07 16:50:38 -05:00
parent 1a30fc8319
commit 3c15d24960
2 changed files with 26 additions and 5 deletions

View File

@ -306,7 +306,16 @@ For more information, see issue #10049 <https://github.com/rust-lang/cargo/issue
}
}
if commands::run::is_manifest_command(cmd) {
return Ok((args, GlobalArgs::default()));
if config.cli_unstable().script {
return Ok((args, GlobalArgs::default()));
} else {
config.shell().warn(format_args!(
"\
user-defined alias `{cmd}` has the appearance of a manfiest-command
This was previously accepted but will be phased out when `-Zscript` is stabilized.
For more information, see issue #12207 <https://github.com/rust-lang/cargo/issues/12207>."
))?;
}
}
let mut alias = alias
@ -411,7 +420,18 @@ fn execute_subcommand(config: &mut Config, cmd: &str, subcommand_args: &ArgMatch
.map(OsString::as_os_str),
);
if commands::run::is_manifest_command(cmd) {
commands::run::exec_manifest_command(config, cmd, &ext_args)
let ext_path = super::find_external_subcommand(config, cmd);
if !config.cli_unstable().script && ext_path.is_some() {
config.shell().warn(format_args!(
"\
external subcommand `{cmd}` has the appearance of a manfiest-command
This was previously accepted but will be phased out when `-Zscript` is stabilized.
For more information, see issue #12207 <https://github.com/rust-lang/cargo/issues/12207>.",
))?;
super::execute_external_subcommand(config, cmd, &ext_args)
} else {
commands::run::exec_manifest_command(config, cmd, &ext_args)
}
} else {
super::execute_external_subcommand(config, cmd, &ext_args)
}

View File

@ -100,7 +100,7 @@ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
#[cargo_test]
#[cfg(unix)]
fn manifest_precedence_over_plugins_stable() {
fn warn_when_plugin_masks_manifest_on_stable() {
let p = cargo_test_support::project()
.file("echo.rs", ECHO_SCRIPT)
.executable(std::path::Path::new("path-test").join("cargo-echo.rs"), "")
@ -113,11 +113,12 @@ fn manifest_precedence_over_plugins_stable() {
p.cargo("echo.rs")
.arg("--help") // An arg that, if processed by cargo, will cause problems
.env("PATH", &path)
.with_status(101)
.with_stdout("")
.with_stderr(
"\
error: running `echo.rs` requires `-Zscript`
warning: external subcommand `echo.rs` has the appearance of a manfiest-command
This was previously accepted but will be phased out when `-Zscript` is stabilized.
For more information, see issue #12207 <https://github.com/rust-lang/cargo/issues/12207>.
",
)
.run();