Skip to content

Commit 7dc84a2

Browse files
committed
Auto merge of #13742 - epage:msrv-update, r=Muscraft
feat(cli): Add --ignore-rust-version to update/generate-lockfile ### What does this PR try to resolve? This is part of #9930 and extends `--ignore-rust-version` to `cargo update` and `cargo generate-lockfile` ### How should we test and review this PR? First commit sets up tests ### Additional information
2 parents 7ac5d58 + c7d89c6 commit 7dc84a2

File tree

14 files changed

+195
-21
lines changed

14 files changed

+195
-21
lines changed

src/bin/cargo/commands/generate_lockfile.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,23 @@ pub fn cli() -> Command {
77
.about("Generate the lockfile for a package")
88
.arg_silent_suggestion()
99
.arg_manifest_path()
10+
.arg_ignore_rust_version_with_help(
11+
"Ignore `rust-version` specification in packages (unstable)",
12+
)
1013
.after_help(color_print::cstr!(
1114
"Run `<cyan,bold>cargo help generate-lockfile</>` for more detailed information.\n"
1215
))
1316
}
1417

1518
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
19+
if args.honor_rust_version().is_some() {
20+
gctx.cli_unstable().fail_if_stable_opt_custom_z(
21+
"--ignore-rust-version",
22+
9930,
23+
"msrv-policy",
24+
gctx.cli_unstable().msrv_policy,
25+
)?;
26+
}
1627
let ws = args.workspace(gctx)?;
1728
ops::generate_lockfile(&ws)?;
1829
Ok(())

src/bin/cargo/commands/update.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,23 @@ pub fn cli() -> Command {
4242
.help_heading(heading::PACKAGE_SELECTION),
4343
)
4444
.arg_manifest_path()
45+
.arg_ignore_rust_version_with_help(
46+
"Ignore `rust-version` specification in packages (unstable)",
47+
)
4548
.after_help(color_print::cstr!(
4649
"Run `<cyan,bold>cargo help update</>` for more detailed information.\n"
4750
))
4851
}
4952

5053
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
54+
if args.honor_rust_version().is_some() {
55+
gctx.cli_unstable().fail_if_stable_opt_custom_z(
56+
"--ignore-rust-version",
57+
9930,
58+
"msrv-policy",
59+
gctx.cli_unstable().msrv_policy,
60+
)?;
61+
}
5162
let ws = args.workspace(gctx)?;
5263

5364
if args.is_present_with_zero_values("package") {

src/cargo/util/command_prelude.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,11 @@ pub trait CommandExt: Sized {
352352
}
353353

354354
fn arg_ignore_rust_version(self) -> Self {
355-
self._arg(
356-
flag(
357-
"ignore-rust-version",
358-
"Ignore `rust-version` specification in packages",
359-
)
360-
.help_heading(heading::MANIFEST_OPTIONS),
361-
)
355+
self.arg_ignore_rust_version_with_help("Ignore `rust-version` specification in packages")
356+
}
357+
358+
fn arg_ignore_rust_version_with_help(self, help: &'static str) -> Self {
359+
self._arg(flag("ignore-rust-version", help).help_heading(heading::MANIFEST_OPTIONS))
362360
}
363361

364362
fn arg_future_incompat_report(self) -> Self {

src/doc/man/cargo-generate-lockfile.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ lockfile and has more options for controlling update behavior.
3030
{{#options}}
3131
{{> options-manifest-path }}
3232

33+
{{> options-ignore-rust-version }}
34+
3335
{{> options-locked }}
3436
{{/options}}
3537

src/doc/man/cargo-update.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ Displays what would be updated, but doesn't actually write the lockfile.
7575

7676
{{> options-manifest-path }}
7777

78+
{{> options-ignore-rust-version }}
79+
7880
{{> options-locked }}
7981

8082
{{/options}}

src/doc/man/generated_txt/cargo-generate-lockfile.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ OPTIONS
4646
Path to the Cargo.toml file. By default, Cargo searches for the
4747
Cargo.toml file in the current directory or any parent directory.
4848

49+
--ignore-rust-version
50+
Ignore rust-version specification in packages.
51+
4952
--locked
5053
Asserts that the exact same dependencies and versions are used as
5154
when the existing Cargo.lock file was originally generated. Cargo

src/doc/man/generated_txt/cargo-update.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ OPTIONS
8585
Path to the Cargo.toml file. By default, Cargo searches for the
8686
Cargo.toml file in the current directory or any parent directory.
8787

88+
--ignore-rust-version
89+
Ignore rust-version specification in packages.
90+
8891
--locked
8992
Asserts that the exact same dependencies and versions are used as
9093
when the existing Cargo.lock file was originally generated. Cargo

src/doc/src/commands/cargo-generate-lockfile.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ terminal.</li>
5858
<code>Cargo.toml</code> file in the current directory or any parent directory.</dd>
5959

6060

61+
<dt class="option-term" id="option-cargo-generate-lockfile---ignore-rust-version"><a class="option-anchor" href="#option-cargo-generate-lockfile---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
62+
<dd class="option-desc">Ignore <code>rust-version</code> specification in packages.</dd>
63+
64+
6165
<dt class="option-term" id="option-cargo-generate-lockfile---locked"><a class="option-anchor" href="#option-cargo-generate-lockfile---locked"></a><code>--locked</code></dt>
6266
<dd class="option-desc">Asserts that the exact same dependencies and versions are used as when the
6367
existing <code>Cargo.lock</code> file was originally generated. Cargo will exit with an

src/doc/src/commands/cargo-update.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ terminal.</li>
100100
<code>Cargo.toml</code> file in the current directory or any parent directory.</dd>
101101

102102

103+
<dt class="option-term" id="option-cargo-update---ignore-rust-version"><a class="option-anchor" href="#option-cargo-update---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
104+
<dd class="option-desc">Ignore <code>rust-version</code> specification in packages.</dd>
105+
106+
103107
<dt class="option-term" id="option-cargo-update---locked"><a class="option-anchor" href="#option-cargo-update---locked"></a><code>--locked</code></dt>
104108
<dd class="option-desc">Asserts that the exact same dependencies and versions are used as when the
105109
existing <code>Cargo.lock</code> file was originally generated. Cargo will exit with an

src/etc/man/cargo-generate-lockfile.1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ Path to the \fBCargo.toml\fR file. By default, Cargo searches for the
6262
\fBCargo.toml\fR file in the current directory or any parent directory.
6363
.RE
6464
.sp
65+
\fB\-\-ignore\-rust\-version\fR
66+
.RS 4
67+
Ignore \fBrust\-version\fR specification in packages.
68+
.RE
69+
.sp
6570
\fB\-\-locked\fR
6671
.RS 4
6772
Asserts that the exact same dependencies and versions are used as when the

src/etc/man/cargo-update.1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ Path to the \fBCargo.toml\fR file. By default, Cargo searches for the
107107
\fBCargo.toml\fR file in the current directory or any parent directory.
108108
.RE
109109
.sp
110+
\fB\-\-ignore\-rust\-version\fR
111+
.RS 4
112+
Ignore \fBrust\-version\fR specification in packages.
113+
.RE
114+
.sp
110115
\fB\-\-locked\fR
111116
.RS 4
112117
Asserts that the exact same dependencies and versions are used as when the

tests/testsuite/cargo_generate_lockfile/help/stdout.term.svg

Lines changed: 9 additions & 7 deletions
Loading

tests/testsuite/cargo_update/help/stdout.term.svg

Lines changed: 9 additions & 7 deletions
Loading

tests/testsuite/rust_version.rs

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,128 @@ fn workspace_with_mixed_rust_version() {
504504
.run();
505505
}
506506

507+
#[cargo_test]
508+
fn generate_lockfile_msrv_resolve() {
509+
Package::new("bar", "1.5.0")
510+
.rust_version("1.55.0")
511+
.file("src/lib.rs", "fn other_stuff() {}")
512+
.publish();
513+
Package::new("bar", "1.6.0")
514+
.rust_version("1.65.0")
515+
.file("src/lib.rs", "fn other_stuff() {}")
516+
.publish();
517+
518+
let p = project()
519+
.file(
520+
"Cargo.toml",
521+
r#"
522+
[package]
523+
name = "foo"
524+
version = "0.0.1"
525+
edition = "2015"
526+
authors = []
527+
rust-version = "1.60.0"
528+
[dependencies]
529+
bar = "1.0.0"
530+
"#,
531+
)
532+
.file("src/main.rs", "fn main(){}")
533+
.build();
534+
535+
p.cargo("generate-lockfile --ignore-rust-version")
536+
.with_status(101)
537+
.with_stderr(
538+
"\
539+
[ERROR] the `--ignore-rust-version` flag is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel
540+
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
541+
See https://github.com/rust-lang/cargo/issues/9930 for more information about the `--ignore-rust-version` flag.
542+
",
543+
)
544+
.run();
545+
p.cargo("generate-lockfile --ignore-rust-version")
546+
.arg("-Zmsrv-policy")
547+
.masquerade_as_nightly_cargo(&["msrv-policy"])
548+
.with_stderr(
549+
"\
550+
[UPDATING] `dummy-registry` index
551+
[LOCKING] 2 packages
552+
",
553+
)
554+
.run();
555+
p.cargo("generate-lockfile")
556+
.arg("-Zmsrv-policy")
557+
.masquerade_as_nightly_cargo(&["msrv-policy"])
558+
.with_stderr(
559+
"\
560+
[UPDATING] `dummy-registry` index
561+
[LOCKING] 2 packages
562+
[ADDING] bar v1.5.0 (latest: v1.6.0)
563+
",
564+
)
565+
.run();
566+
}
567+
568+
#[cargo_test]
569+
fn update_msrv_resolve() {
570+
Package::new("bar", "1.5.0")
571+
.rust_version("1.55.0")
572+
.file("src/lib.rs", "fn other_stuff() {}")
573+
.publish();
574+
Package::new("bar", "1.6.0")
575+
.rust_version("1.65.0")
576+
.file("src/lib.rs", "fn other_stuff() {}")
577+
.publish();
578+
579+
let p = project()
580+
.file(
581+
"Cargo.toml",
582+
r#"
583+
[package]
584+
name = "foo"
585+
version = "0.0.1"
586+
edition = "2015"
587+
authors = []
588+
rust-version = "1.60.0"
589+
[dependencies]
590+
bar = "1.0.0"
591+
"#,
592+
)
593+
.file("src/main.rs", "fn main(){}")
594+
.build();
595+
596+
p.cargo("update")
597+
.arg("-Zmsrv-policy")
598+
.masquerade_as_nightly_cargo(&["msrv-policy"])
599+
.with_stderr(
600+
"\
601+
[UPDATING] `dummy-registry` index
602+
[LOCKING] 2 packages
603+
[ADDING] bar v1.5.0 (latest: v1.6.0)
604+
",
605+
)
606+
.run();
607+
p.cargo("update --ignore-rust-version")
608+
.with_status(101)
609+
.with_stderr(
610+
"\
611+
[ERROR] the `--ignore-rust-version` flag is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel
612+
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
613+
See https://github.com/rust-lang/cargo/issues/9930 for more information about the `--ignore-rust-version` flag.
614+
",
615+
)
616+
.run();
617+
p.cargo("update --ignore-rust-version")
618+
.arg("-Zmsrv-policy")
619+
.masquerade_as_nightly_cargo(&["msrv-policy"])
620+
.with_stderr(
621+
"\
622+
[UPDATING] `dummy-registry` index
623+
[UPDATING] bar v1.5.0 -> v1.6.0
624+
",
625+
)
626+
.run();
627+
}
628+
507629
#[cargo_test]
508630
fn rust_version_older_than_edition() {
509631
project()

0 commit comments

Comments
 (0)