Skip to content

Commit 5276f6e

Browse files
committed
fix:Using --release/debug and --profile together becomes an error
1 parent 2f17770 commit 5276f6e

File tree

7 files changed

+53
-67
lines changed

7 files changed

+53
-67
lines changed

src/bin/cargo/commands/bench.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
196196
)?;
197197

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

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

src/bin/cargo/commands/test.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,6 @@ Run `{cmd}` to see possible targets."
558558

559559
fn get_profile_name(
560560
&self,
561-
gctx: &GlobalContext,
562561
default: &str,
563562
profile_checking: ProfileChecking,
564563
) -> CargoResult<InternedString> {
@@ -572,47 +571,36 @@ Run `{cmd}` to see possible targets."
572571
// `cargo fix` and `cargo check` has legacy handling of this profile name
573572
| (Some(name @ "test"), ProfileChecking::LegacyTestOnly) => {
574573
if self.maybe_flag("release") {
575-
gctx.shell().warn(
576-
"the `--release` flag should not be specified with the `--profile` flag\n\
577-
The `--release` flag will be ignored.\n\
578-
This was historically accepted, but will become an error \
579-
in a future release."
580-
)?;
574+
bail!("\
575+
the `--release` flag can not be specified with the `--profile` flag
576+
Please remove one of the flags.");
581577
}
582578
return Ok(InternedString::new(name));
583579
}
584580
_ => {}
585581
}
586582

587-
let conflict = |flag: &str, equiv: &str, specified: &str| -> anyhow::Error {
588-
anyhow::format_err!(
589-
"conflicting usage of --profile={} and --{flag}\n\
590-
The `--{flag}` flag is the same as `--profile={equiv}`.\n\
591-
Remove one flag or the other to continue.",
592-
specified,
593-
flag = flag,
594-
equiv = equiv
595-
)
596-
};
583+
let err_message = |flag: &str| format!(
584+
"\
585+
the `--{flag}` flag can not be specified with the `--profile` flag
586+
Please remove one of the flags.");
597587

598588
let name = match (
599589
self.maybe_flag("release"),
600590
self.maybe_flag("debug"),
601591
specified_profile,
602592
) {
603593
(false, false, None) => default,
604-
(true, _, None | Some("release")) => "release",
605-
(true, _, Some(name)) => return Err(conflict("release", "release", name)),
606-
(_, true, None | Some("dev")) => "dev",
607-
(_, true, Some(name)) => return Err(conflict("debug", "dev", name)),
594+
(true, _, None) => "release",
595+
(true, _, Some(_)) => bail!(err_message("release")),
596+
(_, true, None) => "dev",
597+
(_, true, Some(_)) => bail!(err_message("debug")),
608598
// `doc` is separate from all the other reservations because
609599
// [profile.doc] was historically allowed, but is deprecated and
610600
// has no effect. To avoid potentially breaking projects, it is a
611601
// warning in Cargo.toml, but since `--profile` is new, we can
612602
// reject it completely here.
613-
(_, _, Some("doc")) => {
614-
bail!("profile `doc` is reserved and not allowed to be explicitly specified")
615-
}
603+
(_, _, Some("doc")) => bail!("profile `doc` is reserved and not allowed to be explicitly specified"),
616604
(_, _, Some(name)) => {
617605
ProfileName::new(name)?;
618606
name
@@ -710,7 +698,7 @@ Run `{cmd}` to see possible targets."
710698
mode,
711699
)?;
712700
build_config.message_format = message_format.unwrap_or(MessageFormat::Human);
713-
build_config.requested_profile = self.get_profile_name(gctx, "dev", profile_checking)?;
701+
build_config.requested_profile = self.get_profile_name("dev", profile_checking)?;
714702
build_config.build_plan = self.flag("build-plan");
715703
build_config.unit_graph = self.flag("unit-graph");
716704
build_config.future_incompat_report = self.flag("future-incompat-report");

tests/testsuite/check.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,21 @@ fn rustc_check() {
289289

290290
// Verify compatible usage of --profile with --release, issue #7488
291291
foo.cargo("rustc --profile check --release -- --emit=metadata")
292+
.with_status(101)
293+
.with_stderr(
294+
"\
295+
error: the `--release` flag can not be specified with the `--profile` flag
296+
Please remove one of the flags.",
297+
)
292298
.run();
299+
293300
foo.cargo("rustc --profile test --release -- --emit=metadata")
301+
.with_status(101)
302+
.with_stderr(
303+
"\
304+
error: the `--release` flag can not be specified with the `--profile` flag
305+
Please remove one of the flags.",
306+
)
294307
.run();
295308
}
296309

tests/testsuite/profile_custom.rs

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -383,32 +383,26 @@ fn conflicting_usage() {
383383
.with_status(101)
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-
",
386+
error: the `--release` flag can not be specified with the `--profile` flag
387+
Please remove one of the flags.",
390388
)
391389
.run();
392390

393391
p.cargo("install --profile=release --debug")
394392
.with_status(101)
395393
.with_stderr(
396394
"\
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-
",
395+
error: the `--debug` flag can not be specified with the `--profile` flag
396+
Please remove one of the flags.",
401397
)
402398
.run();
403399

404400
p.cargo("rustc --profile=dev --release")
401+
.with_status(101)
405402
.with_stderr(
406403
"\
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 [..]
404+
error: the `--release` flag can not be specified with the `--profile` flag
405+
Please remove one of the flags.
412406
",
413407
)
414408
.run();
@@ -417,63 +411,54 @@ This was historically accepted, but will become an error in a future release.
417411
.with_status(101)
418412
.with_stderr(
419413
"\
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-
",
414+
error: the `--release` flag can not be specified with the `--profile` flag
415+
Please remove one of the flags.",
424416
)
425417
.run();
426418

427419
p.cargo("check --profile=test --release")
420+
.with_status(101)
428421
.with_stderr(
429422
"\
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-
",
423+
error: the `--release` flag can not be specified with the `--profile` flag
424+
Please remove one of the flags.",
436425
)
437426
.run();
438427

439428
// This is OK since the two are the same.
440429
p.cargo("rustc --profile=release --release")
430+
.with_status(101)
441431
.with_stderr(
442432
"\
443-
[COMPILING] foo [..]
444-
[FINISHED] `release` profile [..]
445-
",
433+
error: the `--release` flag can not be specified with the `--profile` flag
434+
Please remove one of the flags.",
446435
)
447436
.run();
448437

449438
p.cargo("build --profile=release --release")
439+
.with_status(101)
450440
.with_stderr(
451441
"\
452-
[FINISHED] `release` profile [..]
453-
",
442+
error: the `--release` flag can not be specified with the `--profile` flag
443+
Please remove one of the flags.",
454444
)
455445
.run();
456446

457447
p.cargo("install --path . --profile=dev --debug")
448+
.with_status(101)
458449
.with_stderr(
459450
"\
460-
[INSTALLING] foo [..]
461-
[FINISHED] `dev` profile [..]
462-
[INSTALLING] [..]
463-
[INSTALLED] [..]
464-
[WARNING] be sure to add [..]
465-
",
451+
error: the `--debug` flag can not be specified with the `--profile` flag
452+
Please remove one of the flags.",
466453
)
467454
.run();
468455

469456
p.cargo("install --path . --profile=release --debug")
470457
.with_status(101)
471458
.with_stderr(
472459
"\
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-
",
460+
error: the `--debug` flag can not be specified with the `--profile` flag
461+
Please remove one of the flags.",
477462
)
478463
.run();
479464
}

0 commit comments

Comments
 (0)