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
This commit is contained in:
bors 2024-04-12 16:57:51 +00:00
commit 7dc84a2d31
14 changed files with 195 additions and 21 deletions

View File

@ -7,12 +7,23 @@ pub fn cli() -> Command {
.about("Generate the lockfile for a package") .about("Generate the lockfile for a package")
.arg_silent_suggestion() .arg_silent_suggestion()
.arg_manifest_path() .arg_manifest_path()
.arg_ignore_rust_version_with_help(
"Ignore `rust-version` specification in packages (unstable)",
)
.after_help(color_print::cstr!( .after_help(color_print::cstr!(
"Run `<cyan,bold>cargo help generate-lockfile</>` for more detailed information.\n" "Run `<cyan,bold>cargo help generate-lockfile</>` for more detailed information.\n"
)) ))
} }
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult { pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
if args.honor_rust_version().is_some() {
gctx.cli_unstable().fail_if_stable_opt_custom_z(
"--ignore-rust-version",
9930,
"msrv-policy",
gctx.cli_unstable().msrv_policy,
)?;
}
let ws = args.workspace(gctx)?; let ws = args.workspace(gctx)?;
ops::generate_lockfile(&ws)?; ops::generate_lockfile(&ws)?;
Ok(()) Ok(())

View File

@ -42,12 +42,23 @@ pub fn cli() -> Command {
.help_heading(heading::PACKAGE_SELECTION), .help_heading(heading::PACKAGE_SELECTION),
) )
.arg_manifest_path() .arg_manifest_path()
.arg_ignore_rust_version_with_help(
"Ignore `rust-version` specification in packages (unstable)",
)
.after_help(color_print::cstr!( .after_help(color_print::cstr!(
"Run `<cyan,bold>cargo help update</>` for more detailed information.\n" "Run `<cyan,bold>cargo help update</>` for more detailed information.\n"
)) ))
} }
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult { pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
if args.honor_rust_version().is_some() {
gctx.cli_unstable().fail_if_stable_opt_custom_z(
"--ignore-rust-version",
9930,
"msrv-policy",
gctx.cli_unstable().msrv_policy,
)?;
}
let ws = args.workspace(gctx)?; let ws = args.workspace(gctx)?;
if args.is_present_with_zero_values("package") { if args.is_present_with_zero_values("package") {

View File

@ -352,13 +352,11 @@ pub trait CommandExt: Sized {
} }
fn arg_ignore_rust_version(self) -> Self { fn arg_ignore_rust_version(self) -> Self {
self._arg( self.arg_ignore_rust_version_with_help("Ignore `rust-version` specification in packages")
flag( }
"ignore-rust-version",
"Ignore `rust-version` specification in packages", fn arg_ignore_rust_version_with_help(self, help: &'static str) -> Self {
) self._arg(flag("ignore-rust-version", help).help_heading(heading::MANIFEST_OPTIONS))
.help_heading(heading::MANIFEST_OPTIONS),
)
} }
fn arg_future_incompat_report(self) -> Self { fn arg_future_incompat_report(self) -> Self {

View File

@ -30,6 +30,8 @@ lockfile and has more options for controlling update behavior.
{{#options}} {{#options}}
{{> options-manifest-path }} {{> options-manifest-path }}
{{> options-ignore-rust-version }}
{{> options-locked }} {{> options-locked }}
{{/options}} {{/options}}

View File

@ -75,6 +75,8 @@ Displays what would be updated, but doesn't actually write the lockfile.
{{> options-manifest-path }} {{> options-manifest-path }}
{{> options-ignore-rust-version }}
{{> options-locked }} {{> options-locked }}
{{/options}} {{/options}}

View File

@ -46,6 +46,9 @@ OPTIONS
Path to the Cargo.toml file. By default, Cargo searches for the Path to the Cargo.toml file. By default, Cargo searches for the
Cargo.toml file in the current directory or any parent directory. Cargo.toml file in the current directory or any parent directory.
--ignore-rust-version
Ignore rust-version specification in packages.
--locked --locked
Asserts that the exact same dependencies and versions are used as Asserts that the exact same dependencies and versions are used as
when the existing Cargo.lock file was originally generated. Cargo when the existing Cargo.lock file was originally generated. Cargo

View File

@ -85,6 +85,9 @@ OPTIONS
Path to the Cargo.toml file. By default, Cargo searches for the Path to the Cargo.toml file. By default, Cargo searches for the
Cargo.toml file in the current directory or any parent directory. Cargo.toml file in the current directory or any parent directory.
--ignore-rust-version
Ignore rust-version specification in packages.
--locked --locked
Asserts that the exact same dependencies and versions are used as Asserts that the exact same dependencies and versions are used as
when the existing Cargo.lock file was originally generated. Cargo when the existing Cargo.lock file was originally generated. Cargo

View File

@ -58,6 +58,10 @@ terminal.</li>
<code>Cargo.toml</code> file in the current directory or any parent directory.</dd> <code>Cargo.toml</code> file in the current directory or any parent directory.</dd>
<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>
<dd class="option-desc">Ignore <code>rust-version</code> specification in packages.</dd>
<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> <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>
<dd class="option-desc">Asserts that the exact same dependencies and versions are used as when the <dd class="option-desc">Asserts that the exact same dependencies and versions are used as when the
existing <code>Cargo.lock</code> file was originally generated. Cargo will exit with an existing <code>Cargo.lock</code> file was originally generated. Cargo will exit with an

View File

@ -100,6 +100,10 @@ terminal.</li>
<code>Cargo.toml</code> file in the current directory or any parent directory.</dd> <code>Cargo.toml</code> file in the current directory or any parent directory.</dd>
<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>
<dd class="option-desc">Ignore <code>rust-version</code> specification in packages.</dd>
<dt class="option-term" id="option-cargo-update---locked"><a class="option-anchor" href="#option-cargo-update---locked"></a><code>--locked</code></dt> <dt class="option-term" id="option-cargo-update---locked"><a class="option-anchor" href="#option-cargo-update---locked"></a><code>--locked</code></dt>
<dd class="option-desc">Asserts that the exact same dependencies and versions are used as when the <dd class="option-desc">Asserts that the exact same dependencies and versions are used as when the
existing <code>Cargo.lock</code> file was originally generated. Cargo will exit with an existing <code>Cargo.lock</code> file was originally generated. Cargo will exit with an

View File

@ -62,6 +62,11 @@ Path to the \fBCargo.toml\fR file. By default, Cargo searches for the
\fBCargo.toml\fR file in the current directory or any parent directory. \fBCargo.toml\fR file in the current directory or any parent directory.
.RE .RE
.sp .sp
\fB\-\-ignore\-rust\-version\fR
.RS 4
Ignore \fBrust\-version\fR specification in packages.
.RE
.sp
\fB\-\-locked\fR \fB\-\-locked\fR
.RS 4 .RS 4
Asserts that the exact same dependencies and versions are used as when the Asserts that the exact same dependencies and versions are used as when the

View File

@ -107,6 +107,11 @@ Path to the \fBCargo.toml\fR file. By default, Cargo searches for the
\fBCargo.toml\fR file in the current directory or any parent directory. \fBCargo.toml\fR file in the current directory or any parent directory.
.RE .RE
.sp .sp
\fB\-\-ignore\-rust\-version\fR
.RS 4
Ignore \fBrust\-version\fR specification in packages.
.RE
.sp
\fB\-\-locked\fR \fB\-\-locked\fR
.RS 4 .RS 4
Asserts that the exact same dependencies and versions are used as when the Asserts that the exact same dependencies and versions are used as when the

View File

@ -1,4 +1,4 @@
<svg width="852px" height="380px" xmlns="http://www.w3.org/2000/svg"> <svg width="852px" height="398px" xmlns="http://www.w3.org/2000/svg">
<style> <style>
.fg { fill: #AAAAAA } .fg { fill: #AAAAAA }
.bg { background: #000000 } .bg { background: #000000 }
@ -47,17 +47,19 @@
</tspan> </tspan>
<tspan x="10px" y="262px"><tspan> </tspan><tspan class="fg-cyan bold">--manifest-path</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;PATH&gt;</tspan><tspan> Path to Cargo.toml</tspan> <tspan x="10px" y="262px"><tspan> </tspan><tspan class="fg-cyan bold">--manifest-path</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;PATH&gt;</tspan><tspan> Path to Cargo.toml</tspan>
</tspan> </tspan>
<tspan x="10px" y="280px"><tspan> </tspan><tspan class="fg-cyan bold">--locked</tspan><tspan> Assert that `Cargo.lock` will remain unchanged</tspan> <tspan x="10px" y="280px"><tspan> </tspan><tspan class="fg-cyan bold">--ignore-rust-version</tspan><tspan> Ignore `rust-version` specification in packages (unstable)</tspan>
</tspan> </tspan>
<tspan x="10px" y="298px"><tspan> </tspan><tspan class="fg-cyan bold">--offline</tspan><tspan> Run without accessing the network</tspan> <tspan x="10px" y="298px"><tspan> </tspan><tspan class="fg-cyan bold">--locked</tspan><tspan> Assert that `Cargo.lock` will remain unchanged</tspan>
</tspan> </tspan>
<tspan x="10px" y="316px"><tspan> </tspan><tspan class="fg-cyan bold">--frozen</tspan><tspan> Equivalent to specifying both --locked and --offline</tspan> <tspan x="10px" y="316px"><tspan> </tspan><tspan class="fg-cyan bold">--offline</tspan><tspan> Run without accessing the network</tspan>
</tspan> </tspan>
<tspan x="10px" y="334px"> <tspan x="10px" y="334px"><tspan> </tspan><tspan class="fg-cyan bold">--frozen</tspan><tspan> Equivalent to specifying both --locked and --offline</tspan>
</tspan> </tspan>
<tspan x="10px" y="352px"><tspan>Run `</tspan><tspan class="fg-cyan bold">cargo help generate-lockfile</tspan><tspan class="bold">` for more detailed information.</tspan> <tspan x="10px" y="352px">
</tspan> </tspan>
<tspan x="10px" y="370px"> <tspan x="10px" y="370px"><tspan>Run `</tspan><tspan class="fg-cyan bold">cargo help generate-lockfile</tspan><tspan class="bold">` for more detailed information.</tspan>
</tspan>
<tspan x="10px" y="388px">
</tspan> </tspan>
</text> </text>

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -1,4 +1,4 @@
<svg width="852px" height="506px" xmlns="http://www.w3.org/2000/svg"> <svg width="852px" height="524px" xmlns="http://www.w3.org/2000/svg">
<style> <style>
.fg { fill: #AAAAAA } .fg { fill: #AAAAAA }
.bg { background: #000000 } .bg { background: #000000 }
@ -61,17 +61,19 @@
</tspan> </tspan>
<tspan x="10px" y="388px"><tspan> </tspan><tspan class="fg-cyan bold">--manifest-path</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;PATH&gt;</tspan><tspan> Path to Cargo.toml</tspan> <tspan x="10px" y="388px"><tspan> </tspan><tspan class="fg-cyan bold">--manifest-path</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;PATH&gt;</tspan><tspan> Path to Cargo.toml</tspan>
</tspan> </tspan>
<tspan x="10px" y="406px"><tspan> </tspan><tspan class="fg-cyan bold">--locked</tspan><tspan> Assert that `Cargo.lock` will remain unchanged</tspan> <tspan x="10px" y="406px"><tspan> </tspan><tspan class="fg-cyan bold">--ignore-rust-version</tspan><tspan> Ignore `rust-version` specification in packages (unstable)</tspan>
</tspan> </tspan>
<tspan x="10px" y="424px"><tspan> </tspan><tspan class="fg-cyan bold">--offline</tspan><tspan> Run without accessing the network</tspan> <tspan x="10px" y="424px"><tspan> </tspan><tspan class="fg-cyan bold">--locked</tspan><tspan> Assert that `Cargo.lock` will remain unchanged</tspan>
</tspan> </tspan>
<tspan x="10px" y="442px"><tspan> </tspan><tspan class="fg-cyan bold">--frozen</tspan><tspan> Equivalent to specifying both --locked and --offline</tspan> <tspan x="10px" y="442px"><tspan> </tspan><tspan class="fg-cyan bold">--offline</tspan><tspan> Run without accessing the network</tspan>
</tspan> </tspan>
<tspan x="10px" y="460px"> <tspan x="10px" y="460px"><tspan> </tspan><tspan class="fg-cyan bold">--frozen</tspan><tspan> Equivalent to specifying both --locked and --offline</tspan>
</tspan> </tspan>
<tspan x="10px" y="478px"><tspan>Run `</tspan><tspan class="fg-cyan bold">cargo help update</tspan><tspan class="bold">` for more detailed information.</tspan> <tspan x="10px" y="478px">
</tspan> </tspan>
<tspan x="10px" y="496px"> <tspan x="10px" y="496px"><tspan>Run `</tspan><tspan class="fg-cyan bold">cargo help update</tspan><tspan class="bold">` for more detailed information.</tspan>
</tspan>
<tspan x="10px" y="514px">
</tspan> </tspan>
</text> </text>

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

@ -504,6 +504,128 @@ fn workspace_with_mixed_rust_version() {
.run(); .run();
} }
#[cargo_test]
fn generate_lockfile_msrv_resolve() {
Package::new("bar", "1.5.0")
.rust_version("1.55.0")
.file("src/lib.rs", "fn other_stuff() {}")
.publish();
Package::new("bar", "1.6.0")
.rust_version("1.65.0")
.file("src/lib.rs", "fn other_stuff() {}")
.publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
rust-version = "1.60.0"
[dependencies]
bar = "1.0.0"
"#,
)
.file("src/main.rs", "fn main(){}")
.build();
p.cargo("generate-lockfile --ignore-rust-version")
.with_status(101)
.with_stderr(
"\
[ERROR] the `--ignore-rust-version` flag is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
See https://github.com/rust-lang/cargo/issues/9930 for more information about the `--ignore-rust-version` flag.
",
)
.run();
p.cargo("generate-lockfile --ignore-rust-version")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages
",
)
.run();
p.cargo("generate-lockfile")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages
[ADDING] bar v1.5.0 (latest: v1.6.0)
",
)
.run();
}
#[cargo_test]
fn update_msrv_resolve() {
Package::new("bar", "1.5.0")
.rust_version("1.55.0")
.file("src/lib.rs", "fn other_stuff() {}")
.publish();
Package::new("bar", "1.6.0")
.rust_version("1.65.0")
.file("src/lib.rs", "fn other_stuff() {}")
.publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
rust-version = "1.60.0"
[dependencies]
bar = "1.0.0"
"#,
)
.file("src/main.rs", "fn main(){}")
.build();
p.cargo("update")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages
[ADDING] bar v1.5.0 (latest: v1.6.0)
",
)
.run();
p.cargo("update --ignore-rust-version")
.with_status(101)
.with_stderr(
"\
[ERROR] the `--ignore-rust-version` flag is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
See https://github.com/rust-lang/cargo/issues/9930 for more information about the `--ignore-rust-version` flag.
",
)
.run();
p.cargo("update --ignore-rust-version")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[UPDATING] bar v1.5.0 -> v1.6.0
",
)
.run();
}
#[cargo_test] #[cargo_test]
fn rust_version_older_than_edition() { fn rust_version_older_than_edition() {
project() project()