Skip to content

Commit

Permalink
Auto merge of rust-lang#13742 - epage:msrv-update, r=Muscraft
Browse files Browse the repository at this point in the history
feat(cli): Add --ignore-rust-version to update/generate-lockfile

### What does this PR try to resolve?

This is part of rust-lang#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
  • Loading branch information
bors committed Apr 12, 2024
2 parents 7ac5d58 + c7d89c6 commit 7dc84a2
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 21 deletions.
11 changes: 11 additions & 0 deletions src/bin/cargo/commands/generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,23 @@ pub fn cli() -> Command {
.about("Generate the lockfile for a package")
.arg_silent_suggestion()
.arg_manifest_path()
.arg_ignore_rust_version_with_help(
"Ignore `rust-version` specification in packages (unstable)",
)
.after_help(color_print::cstr!(
"Run `<cyan,bold>cargo help generate-lockfile</>` for more detailed information.\n"
))
}

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)?;
ops::generate_lockfile(&ws)?;
Ok(())
Expand Down
11 changes: 11 additions & 0 deletions src/bin/cargo/commands/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,23 @@ pub fn cli() -> Command {
.help_heading(heading::PACKAGE_SELECTION),
)
.arg_manifest_path()
.arg_ignore_rust_version_with_help(
"Ignore `rust-version` specification in packages (unstable)",
)
.after_help(color_print::cstr!(
"Run `<cyan,bold>cargo help update</>` for more detailed information.\n"
))
}

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)?;

if args.is_present_with_zero_values("package") {
Expand Down
12 changes: 5 additions & 7 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,11 @@ pub trait CommandExt: Sized {
}

fn arg_ignore_rust_version(self) -> Self {
self._arg(
flag(
"ignore-rust-version",
"Ignore `rust-version` specification in packages",
)
.help_heading(heading::MANIFEST_OPTIONS),
)
self.arg_ignore_rust_version_with_help("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))
}

fn arg_future_incompat_report(self) -> Self {
Expand Down
2 changes: 2 additions & 0 deletions src/doc/man/cargo-generate-lockfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ lockfile and has more options for controlling update behavior.
{{#options}}
{{> options-manifest-path }}

{{> options-ignore-rust-version }}

{{> options-locked }}
{{/options}}

Expand Down
2 changes: 2 additions & 0 deletions src/doc/man/cargo-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ Displays what would be updated, but doesn't actually write the lockfile.

{{> options-manifest-path }}

{{> options-ignore-rust-version }}

{{> options-locked }}

{{/options}}
Expand Down
3 changes: 3 additions & 0 deletions src/doc/man/generated_txt/cargo-generate-lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ OPTIONS
Path to the Cargo.toml file. By default, Cargo searches for the
Cargo.toml file in the current directory or any parent directory.

--ignore-rust-version
Ignore rust-version specification in packages.

--locked
Asserts that the exact same dependencies and versions are used as
when the existing Cargo.lock file was originally generated. Cargo
Expand Down
3 changes: 3 additions & 0 deletions src/doc/man/generated_txt/cargo-update.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ OPTIONS
Path to the Cargo.toml file. By default, Cargo searches for the
Cargo.toml file in the current directory or any parent directory.

--ignore-rust-version
Ignore rust-version specification in packages.

--locked
Asserts that the exact same dependencies and versions are used as
when the existing Cargo.lock file was originally generated. Cargo
Expand Down
4 changes: 4 additions & 0 deletions src/doc/src/commands/cargo-generate-lockfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ terminal.</li>
<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>
<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
Expand Down
4 changes: 4 additions & 0 deletions src/doc/src/commands/cargo-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ terminal.</li>
<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>
<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
Expand Down
5 changes: 5 additions & 0 deletions src/etc/man/cargo-generate-lockfile.1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
.RE
.sp
\fB\-\-ignore\-rust\-version\fR
.RS 4
Ignore \fBrust\-version\fR specification in packages.
.RE
.sp
\fB\-\-locked\fR
.RS 4
Asserts that the exact same dependencies and versions are used as when the
Expand Down
5 changes: 5 additions & 0 deletions src/etc/man/cargo-update.1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
.RE
.sp
\fB\-\-ignore\-rust\-version\fR
.RS 4
Ignore \fBrust\-version\fR specification in packages.
.RE
.sp
\fB\-\-locked\fR
.RS 4
Asserts that the exact same dependencies and versions are used as when the
Expand Down
16 changes: 9 additions & 7 deletions tests/testsuite/cargo_generate_lockfile/help/stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 9 additions & 7 deletions tests/testsuite/cargo_update/help/stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
122 changes: 122 additions & 0 deletions tests/testsuite/rust_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,128 @@ fn workspace_with_mixed_rust_version() {
.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]
fn rust_version_older_than_edition() {
project()
Expand Down

0 comments on commit 7dc84a2

Please sign in to comment.