Skip to content

Commit

Permalink
Add future compatibility warning on mixture of --release with --profile.
Browse files Browse the repository at this point in the history
This was historically allowed, but it silently ignores the --release flag.
  • Loading branch information
ehuss committed Sep 24, 2021
1 parent 56b9ce3 commit 595384f
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ pub trait ArgMatchesExt {

fn get_profile_name(
&self,
_config: &Config,
config: &Config,
default: &str,
profile_checking: ProfileChecking,
) -> CargoResult<InternedString> {
Expand All @@ -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));
}
_ => {}
}

Expand Down
78 changes: 77 additions & 1 deletion tests/testsuite/profile_custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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();
Expand Down

0 comments on commit 595384f

Please sign in to comment.