Skip to content

Commit 580dbc6

Browse files
committed
Auto merge of #13971 - heisen-li:ignore_release, r=weihanglo
fix: using `--release/debug` and `--profile` together becomes an error ### What does this PR try to resolve? part of #13629 issue #13629 (comment)
2 parents ab85225 + 5d8022c commit 580dbc6

File tree

7 files changed

+54
-110
lines changed

7 files changed

+54
-110
lines changed

src/bin/cargo/commands/bench.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
6363
args.compile_options(gctx, CompileMode::Bench, Some(&ws), ProfileChecking::Custom)?;
6464

6565
compile_opts.build_config.requested_profile =
66-
args.get_profile_name(gctx, "bench", ProfileChecking::Custom)?;
66+
args.get_profile_name("bench", ProfileChecking::Custom)?;
6767

6868
let ops = TestOptions {
6969
no_run: args.flag("no-run"),

src/bin/cargo/commands/clean.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
146146
gctx,
147147
spec: values(args, "package"),
148148
targets: args.targets()?,
149-
requested_profile: args.get_profile_name(gctx, "dev", ProfileChecking::Custom)?,
149+
requested_profile: args.get_profile_name("dev", ProfileChecking::Custom)?,
150150
profile_specified: args.contains_id("profile") || args.flag("release"),
151151
doc: args.flag("doc"),
152152
dry_run: args.dry_run(),

src/bin/cargo/commands/install.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,13 @@ pub fn cli() -> Command {
8585
)
8686
.arg_features()
8787
.arg_parallel()
88-
.arg(flag(
89-
"debug",
90-
"Build in debug mode (with the 'dev' profile) instead of release mode",
91-
))
88+
.arg(
89+
flag(
90+
"debug",
91+
"Build in debug mode (with the 'dev' profile) instead of release mode",
92+
)
93+
.conflicts_with("profile"),
94+
)
9295
.arg_redundant_default_mode("release", "install", "debug")
9396
.arg_profile("Install artifacts with the specified profile")
9497
.arg_target_triple("Build for the target triple")
@@ -196,7 +199,7 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
196199
)?;
197200

198201
compile_opts.build_config.requested_profile =
199-
args.get_profile_name(gctx, "release", ProfileChecking::Custom)?;
202+
args.get_profile_name("release", ProfileChecking::Custom)?;
200203

201204
if args.flag("list") {
202205
ops::install_list(root, gctx)?;

src/bin/cargo/commands/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
7474
args.compile_options(gctx, CompileMode::Test, Some(&ws), ProfileChecking::Custom)?;
7575

7676
compile_opts.build_config.requested_profile =
77-
args.get_profile_name(gctx, "test", ProfileChecking::Custom)?;
77+
args.get_profile_name("test", ProfileChecking::Custom)?;
7878

7979
// `TESTNAME` is actually an argument of the test binary, but it's
8080
// important, so we explicitly mention it and reconfigure.

src/cargo/util/command_prelude.rs

+10-26
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ pub trait CommandExt: Sized {
131131
) -> Self {
132132
let msg = format!("`--{default_mode}` is the default for `cargo {command}`; instead `--{supported_mode}` is supported");
133133
let value_parser = UnknownArgumentValueParser::suggest(msg);
134-
self._arg(flag(default_mode, "").value_parser(value_parser).hide(true))
134+
self._arg(
135+
flag(default_mode, "")
136+
.conflicts_with("profile")
137+
.value_parser(value_parser)
138+
.hide(true),
139+
)
135140
}
136141

137142
fn arg_targets_all(
@@ -226,6 +231,7 @@ pub trait CommandExt: Sized {
226231
self._arg(
227232
flag("release", release)
228233
.short('r')
234+
.conflicts_with("profile")
229235
.help_heading(heading::COMPILATION_OPTIONS),
230236
)
231237
}
@@ -568,7 +574,6 @@ Run `{cmd}` to see possible targets."
568574

569575
fn get_profile_name(
570576
&self,
571-
gctx: &GlobalContext,
572577
default: &str,
573578
profile_checking: ProfileChecking,
574579
) -> CargoResult<InternedString> {
@@ -581,40 +586,19 @@ Run `{cmd}` to see possible targets."
581586
(Some(name @ ("dev" | "test" | "bench" | "check")), ProfileChecking::LegacyRustc)
582587
// `cargo fix` and `cargo check` has legacy handling of this profile name
583588
| (Some(name @ "test"), ProfileChecking::LegacyTestOnly) => {
584-
if self.maybe_flag("release") {
585-
gctx.shell().warn(
586-
"the `--release` flag should not be specified with the `--profile` flag\n\
587-
The `--release` flag will be ignored.\n\
588-
This was historically accepted, but will become an error \
589-
in a future release."
590-
)?;
591-
}
592589
return Ok(InternedString::new(name));
593590
}
594591
_ => {}
595592
}
596593

597-
let conflict = |flag: &str, equiv: &str, specified: &str| -> anyhow::Error {
598-
anyhow::format_err!(
599-
"conflicting usage of --profile={} and --{flag}\n\
600-
The `--{flag}` flag is the same as `--profile={equiv}`.\n\
601-
Remove one flag or the other to continue.",
602-
specified,
603-
flag = flag,
604-
equiv = equiv
605-
)
606-
};
607-
608594
let name = match (
609595
self.maybe_flag("release"),
610596
self.maybe_flag("debug"),
611597
specified_profile,
612598
) {
613599
(false, false, None) => default,
614-
(true, _, None | Some("release")) => "release",
615-
(true, _, Some(name)) => return Err(conflict("release", "release", name)),
616-
(_, true, None | Some("dev")) => "dev",
617-
(_, true, Some(name)) => return Err(conflict("debug", "dev", name)),
600+
(true, _, None) => "release",
601+
(_, true, None) => "dev",
618602
// `doc` is separate from all the other reservations because
619603
// [profile.doc] was historically allowed, but is deprecated and
620604
// has no effect. To avoid potentially breaking projects, it is a
@@ -720,7 +704,7 @@ Run `{cmd}` to see possible targets."
720704
mode,
721705
)?;
722706
build_config.message_format = message_format.unwrap_or(MessageFormat::Human);
723-
build_config.requested_profile = self.get_profile_name(gctx, "dev", profile_checking)?;
707+
build_config.requested_profile = self.get_profile_name("dev", profile_checking)?;
724708
build_config.build_plan = self.flag("build-plan");
725709
build_config.unit_graph = self.flag("unit-graph");
726710
build_config.future_incompat_report = self.flag("future-incompat-report");

tests/testsuite/check.rs

+19
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,27 @@ fn rustc_check() {
290290

291291
// Verify compatible usage of --profile with --release, issue #7488
292292
foo.cargo("rustc --profile check --release -- --emit=metadata")
293+
.with_status(1)
294+
.with_stderr(
295+
"\
296+
[ERROR] the argument '--profile <PROFILE-NAME>' cannot be used with '--release'
297+
298+
Usage: cargo[EXE] rustc --profile <PROFILE-NAME> [ARGS]...
299+
300+
For more information, try '--help'.",
301+
)
293302
.run();
303+
294304
foo.cargo("rustc --profile test --release -- --emit=metadata")
305+
.with_status(1)
306+
.with_stderr(
307+
"\
308+
[ERROR] the argument '--profile <PROFILE-NAME>' cannot be used with '--release'
309+
310+
Usage: cargo[EXE] rustc --profile <PROFILE-NAME> [ARGS]...
311+
312+
For more information, try '--help'.",
313+
)
295314
.run();
296315
}
297316

tests/testsuite/profile_custom.rs

+14-76
Original file line numberDiff line numberDiff line change
@@ -380,100 +380,38 @@ fn conflicting_usage() {
380380
.build();
381381

382382
p.cargo("build --profile=dev --release")
383-
.with_status(101)
383+
.with_status(1)
384384
.with_stderr(
385385
"\
386-
error: conflicting usage of --profile=dev and --release
387-
The `--release` flag is the same as `--profile=release`.
388-
Remove one flag or the other to continue.
389-
",
390-
)
391-
.run();
386+
[ERROR] the argument '--profile <PROFILE-NAME>' cannot be used with '--release'
392387
393-
p.cargo("install --profile=release --debug")
394-
.with_status(101)
395-
.with_stderr(
396-
"\
397-
error: conflicting usage of --profile=release and --debug
398-
The `--debug` flag is the same as `--profile=dev`.
399-
Remove one flag or the other to continue.
400-
",
401-
)
402-
.run();
388+
Usage: cargo[EXE] build --profile <PROFILE-NAME>
403389
404-
p.cargo("rustc --profile=dev --release")
405-
.with_stderr(
406-
"\
407-
warning: the `--release` flag should not be specified with the `--profile` flag
408-
The `--release` flag will be ignored.
409-
This was historically accepted, but will become an error in a future release.
410-
[COMPILING] foo [..]
411-
[FINISHED] `dev` profile [..]
412-
",
390+
For more information, try '--help'.",
413391
)
414392
.run();
415393

416-
p.cargo("check --profile=dev --release")
417-
.with_status(101)
394+
p.cargo("install --profile=release --debug")
395+
.with_status(1)
418396
.with_stderr(
419397
"\
420-
error: conflicting usage of --profile=dev and --release
421-
The `--release` flag is the same as `--profile=release`.
422-
Remove one flag or the other to continue.
423-
",
424-
)
425-
.run();
398+
[ERROR] the argument '--profile <PROFILE-NAME>' cannot be used with '--debug'
426399
427-
p.cargo("check --profile=test --release")
428-
.with_stderr(
429-
"\
430-
warning: the `--release` flag should not be specified with the `--profile` flag
431-
The `--release` flag will be ignored.
432-
This was historically accepted, but will become an error in a future release.
433-
[CHECKING] foo [..]
434-
[FINISHED] `test` profile [..]
435-
",
436-
)
437-
.run();
400+
Usage: cargo[EXE] install --profile <PROFILE-NAME> [CRATE[@<VER>]]...
438401
439-
// This is OK since the two are the same.
440-
p.cargo("rustc --profile=release --release")
441-
.with_stderr(
442-
"\
443-
[COMPILING] foo [..]
444-
[FINISHED] `release` profile [..]
445-
",
402+
For more information, try '--help'.",
446403
)
447404
.run();
448405

449-
p.cargo("build --profile=release --release")
406+
p.cargo("check --profile=dev --release")
407+
.with_status(1)
450408
.with_stderr(
451409
"\
452-
[FINISHED] `release` profile [..]
453-
",
454-
)
455-
.run();
410+
[ERROR] the argument '--profile <PROFILE-NAME>' cannot be used with '--release'
456411
457-
p.cargo("install --path . --profile=dev --debug")
458-
.with_stderr(
459-
"\
460-
[INSTALLING] foo [..]
461-
[FINISHED] `dev` profile [..]
462-
[INSTALLING] [..]
463-
[INSTALLED] [..]
464-
[WARNING] be sure to add [..]
465-
",
466-
)
467-
.run();
412+
Usage: cargo[EXE] check --profile <PROFILE-NAME>
468413
469-
p.cargo("install --path . --profile=release --debug")
470-
.with_status(101)
471-
.with_stderr(
472-
"\
473-
error: conflicting usage of --profile=release and --debug
474-
The `--debug` flag is the same as `--profile=dev`.
475-
Remove one flag or the other to continue.
476-
",
414+
For more information, try '--help'.",
477415
)
478416
.run();
479417
}

0 commit comments

Comments
 (0)