From c9de6eeeb2f90999bbef03ffc7aba13829da5791 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 11 Apr 2024 14:18:10 -0500 Subject: [PATCH 1/2] test(resolve): Show update/generate-lockfile behavior --- tests/testsuite/rust_version.rs | 112 ++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/tests/testsuite/rust_version.rs b/tests/testsuite/rust_version.rs index 42c265609..9a22fe31c 100644 --- a/tests/testsuite/rust_version.rs +++ b/tests/testsuite/rust_version.rs @@ -504,6 +504,118 @@ 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") + .arg("-Zmsrv-policy") + .masquerade_as_nightly_cargo(&["msrv-policy"]) + .with_status(1) + .with_stderr( + "\ +error: unexpected argument '--ignore-rust-version' found + +Usage: cargo generate-lockfile [OPTIONS] + +For more information, try '--help'. +", + ) + .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") + .arg("-Zmsrv-policy") + .masquerade_as_nightly_cargo(&["msrv-policy"]) + .with_status(1) + .with_stderr( + "\ +error: unexpected argument '--ignore-rust-version' found + + tip: to pass '--ignore-rust-version' as a value, use '-- --ignore-rust-version' + +Usage: cargo update [OPTIONS] [SPEC]... + +For more information, try '--help'. +", + ) + .run(); +} + #[cargo_test] fn rust_version_older_than_edition() { project() From c7d89c64f1467090b93c485a1465b6634582572e Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 11 Apr 2024 14:27:57 -0500 Subject: [PATCH 2/2] feat(cli): Add --ignore-rust-version to update/generate-lockfile --- src/bin/cargo/commands/generate_lockfile.rs | 11 +++++ src/bin/cargo/commands/update.rs | 11 +++++ src/cargo/util/command_prelude.rs | 12 ++--- src/doc/man/cargo-generate-lockfile.md | 2 + src/doc/man/cargo-update.md | 2 + .../generated_txt/cargo-generate-lockfile.txt | 3 ++ src/doc/man/generated_txt/cargo-update.txt | 3 ++ .../src/commands/cargo-generate-lockfile.md | 4 ++ src/doc/src/commands/cargo-update.md | 4 ++ src/etc/man/cargo-generate-lockfile.1 | 5 ++ src/etc/man/cargo-update.1 | 5 ++ .../help/stdout.term.svg | 16 ++++--- .../cargo_update/help/stdout.term.svg | 16 ++++--- tests/testsuite/rust_version.rs | 46 +++++++++++-------- 14 files changed, 101 insertions(+), 39 deletions(-) diff --git a/src/bin/cargo/commands/generate_lockfile.rs b/src/bin/cargo/commands/generate_lockfile.rs index d1a95fda0..a2ddac61d 100644 --- a/src/bin/cargo/commands/generate_lockfile.rs +++ b/src/bin/cargo/commands/generate_lockfile.rs @@ -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 `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(()) diff --git a/src/bin/cargo/commands/update.rs b/src/bin/cargo/commands/update.rs index 43bd32926..fb394e4aa 100644 --- a/src/bin/cargo/commands/update.rs +++ b/src/bin/cargo/commands/update.rs @@ -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 `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") { diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index c269e65ba..0f3d3dc43 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -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 { diff --git a/src/doc/man/cargo-generate-lockfile.md b/src/doc/man/cargo-generate-lockfile.md index 3a2f52b39..956cc58dc 100644 --- a/src/doc/man/cargo-generate-lockfile.md +++ b/src/doc/man/cargo-generate-lockfile.md @@ -30,6 +30,8 @@ lockfile and has more options for controlling update behavior. {{#options}} {{> options-manifest-path }} +{{> options-ignore-rust-version }} + {{> options-locked }} {{/options}} diff --git a/src/doc/man/cargo-update.md b/src/doc/man/cargo-update.md index 0e9ca371a..ce62269f9 100644 --- a/src/doc/man/cargo-update.md +++ b/src/doc/man/cargo-update.md @@ -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}} diff --git a/src/doc/man/generated_txt/cargo-generate-lockfile.txt b/src/doc/man/generated_txt/cargo-generate-lockfile.txt index d1951275e..7c925d384 100644 --- a/src/doc/man/generated_txt/cargo-generate-lockfile.txt +++ b/src/doc/man/generated_txt/cargo-generate-lockfile.txt @@ -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 diff --git a/src/doc/man/generated_txt/cargo-update.txt b/src/doc/man/generated_txt/cargo-update.txt index e6765c680..1d5541042 100644 --- a/src/doc/man/generated_txt/cargo-update.txt +++ b/src/doc/man/generated_txt/cargo-update.txt @@ -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 diff --git a/src/doc/src/commands/cargo-generate-lockfile.md b/src/doc/src/commands/cargo-generate-lockfile.md index ee52d544c..a87e86a62 100644 --- a/src/doc/src/commands/cargo-generate-lockfile.md +++ b/src/doc/src/commands/cargo-generate-lockfile.md @@ -58,6 +58,10 @@ terminal. 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 will exit with an diff --git a/src/doc/src/commands/cargo-update.md b/src/doc/src/commands/cargo-update.md index 3738c7418..27a9f815d 100644 --- a/src/doc/src/commands/cargo-update.md +++ b/src/doc/src/commands/cargo-update.md @@ -100,6 +100,10 @@ terminal. 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 will exit with an diff --git a/src/etc/man/cargo-generate-lockfile.1 b/src/etc/man/cargo-generate-lockfile.1 index a436909f8..732c805a7 100644 --- a/src/etc/man/cargo-generate-lockfile.1 +++ b/src/etc/man/cargo-generate-lockfile.1 @@ -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 diff --git a/src/etc/man/cargo-update.1 b/src/etc/man/cargo-update.1 index 921575fec..56407d023 100644 --- a/src/etc/man/cargo-update.1 +++ b/src/etc/man/cargo-update.1 @@ -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 diff --git a/tests/testsuite/cargo_generate_lockfile/help/stdout.term.svg b/tests/testsuite/cargo_generate_lockfile/help/stdout.term.svg index 80de855fa..d116fb6d5 100644 --- a/tests/testsuite/cargo_generate_lockfile/help/stdout.term.svg +++ b/tests/testsuite/cargo_generate_lockfile/help/stdout.term.svg @@ -1,4 +1,4 @@ - +