From 595384ffdad5a95b7a86e7c5c94ff71fbc9ce2f6 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 24 Sep 2021 10:59:00 -0700 Subject: [PATCH] Add future compatibility warning on mixture of --release with --profile. This was historically allowed, but it silently ignores the --release flag. --- src/cargo/util/command_prelude.rs | 16 +++++-- tests/testsuite/profile_custom.rs | 78 ++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 4 deletions(-) diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index afe3d68abff..d0cf17824b1 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -353,7 +353,7 @@ pub trait ArgMatchesExt { fn get_profile_name( &self, - _config: &Config, + config: &Config, default: &str, profile_checking: ProfileChecking, ) -> CargoResult { @@ -363,9 +363,19 @@ pub trait ArgMatchesExt { // This is an early exit, since it allows combination with `--release`. match (specified_profile, profile_checking) { // `cargo rustc` has legacy handling of these names - (Some(name @ ("dev" | "test" | "bench" | "check")), ProfileChecking::LegacyRustc) | + (Some(name @ ("dev" | "test" | "bench" | "check")), ProfileChecking::LegacyRustc) // `cargo fix` and `cargo check` has legacy handling of this profile name - (Some(name @ "test"), ProfileChecking::LegacyTestOnly) => return Ok(InternedString::new(name)), + | (Some(name @ "test"), ProfileChecking::LegacyTestOnly) => { + if self._is_present("release") { + config.shell().warn( + "the `--release` flag should not be specified with the `--profile` flag\n\ + The `--release` flag will be ignored.\n\ + This was historically accepted, but will become an error \ + in a future release." + )?; + } + return Ok(InternedString::new(name)); + } _ => {} } diff --git a/tests/testsuite/profile_custom.rs b/tests/testsuite/profile_custom.rs index e7961f373c6..889665baf87 100644 --- a/tests/testsuite/profile_custom.rs +++ b/tests/testsuite/profile_custom.rs @@ -360,7 +360,7 @@ fn conflicting_usage() { authors = [] "#, ) - .file("src/lib.rs", "") + .file("src/main.rs", "fn main() {}") .build(); p.cargo("build --profile=dev --release") @@ -381,6 +381,82 @@ Remove one flag or the other to continue. error: conflicting usage of --profile=release and --debug The `--debug` flag is the same as `--profile=dev`. Remove one flag or the other to continue. +", + ) + .run(); + + p.cargo("rustc --profile=dev --release") + .with_stderr( + "\ +warning: the `--release` flag should not be specified with the `--profile` flag +The `--release` flag will be ignored. +This was historically accepted, but will become an error in a future release. +[COMPILING] foo [..] +[FINISHED] dev [..] +", + ) + .run(); + + p.cargo("check --profile=dev --release") + .with_status(101) + .with_stderr( + "\ +error: conflicting usage of --profile=dev and --release +The `--release` flag is the same as `--profile=release`. +Remove one flag or the other to continue. +", + ) + .run(); + + p.cargo("check --profile=test --release") + .with_stderr( + "\ +warning: the `--release` flag should not be specified with the `--profile` flag +The `--release` flag will be ignored. +This was historically accepted, but will become an error in a future release. +[CHECKING] foo [..] +[FINISHED] test [..] +", + ) + .run(); + + // This is OK since the two are the same. + p.cargo("rustc --profile=release --release") + .with_stderr( + "\ +[COMPILING] foo [..] +[FINISHED] release [..] +", + ) + .run(); + + p.cargo("build --profile=release --release") + .with_stderr( + "\ +[FINISHED] release [..] +", + ) + .run(); + + p.cargo("install --path . --profile=dev --debug") + .with_stderr( + "\ +[INSTALLING] foo [..] +[FINISHED] dev [..] +[INSTALLING] [..] +[INSTALLED] [..] +[WARNING] be sure to add [..] +", + ) + .run(); + + p.cargo("install --path . --profile=release --debug") + .with_status(101) + .with_stderr( + "\ +error: conflicting usage of --profile=release and --debug +The `--debug` flag is the same as `--profile=dev`. +Remove one flag or the other to continue. ", ) .run();