From 43e05370ce1c0df0cd76b88a4d209504439c47f3 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 20 Feb 2024 12:05:09 -0600 Subject: [PATCH 1/3] test: Show lockfile behavior --- .github/.cspell/rust-dependencies.txt | 1 + tests/fixtures/rust-version/Cargo.lock | 50 ++++++++++++++++++++++++++ tests/fixtures/rust-version/Cargo.toml | 1 + tests/test.rs | 4 +-- 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/rust-version/Cargo.lock diff --git a/.github/.cspell/rust-dependencies.txt b/.github/.cspell/rust-dependencies.txt index 6e947904..69e5e707 100644 --- a/.github/.cspell/rust-dependencies.txt +++ b/.github/.cspell/rust-dependencies.txt @@ -1,6 +1,7 @@ // This file is @generated by tidy.sh. // It is not intended for manual editing. +argfile easytime lexopt tempfile diff --git a/tests/fixtures/rust-version/Cargo.lock b/tests/fixtures/rust-version/Cargo.lock new file mode 100644 index 00000000..27cf51f4 --- /dev/null +++ b/tests/fixtures/rust-version/Cargo.lock @@ -0,0 +1,50 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "argfile" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "265f5108974489a217d5098cd81666b60480c8dd67302acbbe7cbdd8aa09d638" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "member1" +version = "0.0.0" + +[[package]] +name = "member2" +version = "0.0.0" + +[[package]] +name = "member3" +version = "0.0.0" +dependencies = [ + "member2", +] + +[[package]] +name = "memchr" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" + +[[package]] +name = "os_str_bytes" +version = "6.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" +dependencies = [ + "memchr", +] + +[[package]] +name = "real" +version = "0.0.0" +dependencies = [ + "argfile", + "member1", +] diff --git a/tests/fixtures/rust-version/Cargo.toml b/tests/fixtures/rust-version/Cargo.toml index d6ee8bcc..1f8627eb 100644 --- a/tests/fixtures/rust-version/Cargo.toml +++ b/tests/fixtures/rust-version/Cargo.toml @@ -12,6 +12,7 @@ c = [] [dependencies] member1 = { path = "member1", optional = true } +argfile = "0.1.5" [dev-dependencies] diff --git a/tests/test.rs b/tests/test.rs index 7bc8823a..95e06e6d 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1458,7 +1458,7 @@ fn version_range() { ", ); cargo_hack(["check", "--version-range", "..=1.66", "--version-step", "2", "--workspace"]) - .assert_success("rust-version") + .assert_failure("rust-version") .stderr_contains( " running `rustup run 1.63 cargo check` on member1 (1/7) @@ -1488,7 +1488,7 @@ fn rust_version() { ", ); cargo_hack(["check", "--rust-version", "--workspace"]) - .assert_success("rust-version") + .assert_failure("rust-version") .stderr_contains( " running `rustup run 1.63 cargo check` on member1 (1/4) From 62047296cfcd7a802b47feaabc1fd7bc5d7c22ed Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 20 Feb 2024 12:09:14 -0600 Subject: [PATCH 2/3] test: Show '--locked' isn't respected --- tests/test.rs | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/tests/test.rs b/tests/test.rs index 95e06e6d..7f48e91b 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1457,19 +1457,27 @@ fn version_range() { running `rustup run 1.64 cargo check` on member3 (5/5) ", ); - cargo_hack(["check", "--version-range", "..=1.66", "--version-step", "2", "--workspace"]) - .assert_failure("rust-version") - .stderr_contains( - " - running `rustup run 1.63 cargo check` on member1 (1/7) - running `rustup run 1.63 cargo check` on member2 (2/7) - running `rustup run 1.64 cargo check` on member3 (3/7) - running `rustup run 1.65 cargo check` on member1 (4/7) - running `rustup run 1.65 cargo check` on member2 (5/7) - running `rustup run 1.65 cargo check` on member3 (6/7) - running `rustup run 1.65 cargo check` on real (7/7) + cargo_hack([ + "check", + "--version-range", + "..=1.66", + "--version-step", + "2", + "--workspace", + "--locked", + ]) + .assert_failure("rust-version") + .stderr_contains( + " + running `rustup run 1.63 cargo check --locked` on member1 (1/7) + running `rustup run 1.63 cargo check --locked` on member2 (2/7) + running `rustup run 1.64 cargo check --locked` on member3 (3/7) + running `rustup run 1.65 cargo check --locked` on member1 (4/7) + running `rustup run 1.65 cargo check --locked` on member2 (5/7) + running `rustup run 1.65 cargo check --locked` on member3 (6/7) + running `rustup run 1.65 cargo check --locked` on real (7/7) ", - ); + ); } #[test] @@ -1487,14 +1495,14 @@ fn rust_version() { running `rustup run 1.63 cargo check` on member2 (2/2) ", ); - cargo_hack(["check", "--rust-version", "--workspace"]) + cargo_hack(["check", "--rust-version", "--workspace", "--locked"]) .assert_failure("rust-version") .stderr_contains( " - running `rustup run 1.63 cargo check` on member1 (1/4) - running `rustup run 1.63 cargo check` on member2 (2/4) - running `rustup run 1.64 cargo check` on member3 (3/4) - running `rustup run 1.65 cargo check` on real (4/4) + running `rustup run 1.63 cargo check --locked` on member1 (1/4) + running `rustup run 1.63 cargo check --locked` on member2 (2/4) + running `rustup run 1.64 cargo check --locked` on member3 (3/4) + running `rustup run 1.65 cargo check --locked` on real (4/4) ", ); } From 81c116742b9fe634249a50d9466fe4b4ce56382a Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 19 Feb 2024 13:38:15 -0600 Subject: [PATCH 3/3] fix: Respect --locked flag When using `--rust-version`, the lockfile can be blown away. While that is a problem in of its own, this focuses on an incremental step of not blowing it away if `--locked` is used. This is part of #234 --- .github/workflows/ci.yml | 2 +- README.md | 3 +++ src/cli.rs | 6 ++++++ src/main.rs | 8 +++++++- tests/long-help.txt | 3 +++ tests/short-help.txt | 1 + tests/test.rs | 4 ++-- 7 files changed, 23 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8ebbeb9..2f44b0c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,7 +75,7 @@ jobs: cargo hack check --feature-powerset --workspace --message-format=json cd ../rust-version rustup toolchain remove 1.63 1.64 1.65 - cargo hack check --rust-version --workspace + cargo hack check --rust-version --workspace --locked cargo uninstall cargo-hack - uses: taiki-e/install-action@cargo-hack - uses: taiki-e/install-action@cargo-minimal-versions diff --git a/README.md b/README.md index aff3d69d..60cfe344 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,9 @@ OPTIONS: --manifest-path Path to Cargo.toml. + --locked + Require Cargo.lock is up to date. + -F, --features ... Space or comma separated list of features to activate. diff --git a/src/cli.rs b/src/cli.rs index 928cc298..59d8bf19 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -25,6 +25,8 @@ pub(crate) struct Args { pub(crate) manifest_path: Option, /// --no-manifest-path pub(crate) no_manifest_path: bool, + /// --locked + pub(crate) locked: bool, /// -p, --package ... pub(crate) package: Vec, /// --exclude ... @@ -155,6 +157,7 @@ impl Args { let mut keep_going = false; let mut print_command_list = false; let mut no_manifest_path = false; + let mut locked = false; let mut rust_version = false; let mut version_range = None; let mut version_step = None; @@ -307,6 +310,7 @@ impl Args { Long("keep-going") => parse_flag!(keep_going), Long("print-command-list") => parse_flag!(print_command_list), Long("no-manifest-path") => parse_flag!(no_manifest_path), + Long("locked") => parse_flag!(locked), Long("ignore-unknown-features") => parse_flag!(ignore_unknown_features), Short('v') | Long("verbose") => verbose += 1, @@ -609,6 +613,7 @@ impl Args { subcommand, manifest_path, + locked, package, exclude, workspace, @@ -700,6 +705,7 @@ const HELP: &[HelpText<'_>] = &[ "This flag can only be used together with --workspace", ]), ("", "--manifest-path", "", "Path to Cargo.toml", &[]), + ("", "--locked", "", "Require Cargo.lock is up to date", &[]), ("-F", "--features", "...", "Space or comma separated list of features to activate", &[]), ("", "--each-feature", "", "Perform for each feature of the package", &[ "This also includes runs with just --no-default-features flag, and default features.", diff --git a/src/main.rs b/src/main.rs index dba22086..9668c812 100644 --- a/src/main.rs +++ b/src/main.rs @@ -114,7 +114,7 @@ fn try_main() -> Result<()> { // First, generate the lockfile using the oldest cargo specified. // https://github.com/taiki-e/cargo-hack/issues/105 - let mut generate_lockfile = true; + let mut generate_lockfile = !cx.locked; // Workaround for spurious "failed to select a version" error. // (This does not work around the underlying cargo bug: https://github.com/rust-lang/cargo/issues/10623) let mut regenerate_lockfile_on_51_or_up = false; @@ -392,6 +392,9 @@ fn exec_on_packages( keep_going: &mut KeepGoing, cargo_version: u32, ) -> Result<()> { + if cx.locked { + line.arg("--locked"); + } if cx.target.is_empty() || cargo_version >= 64 { // TODO: We should test that cargo's multi-target build does not break the resolver behavior required for a correct check. for target in &cx.target { @@ -625,6 +628,9 @@ fn exec_cargo_inner( fn cargo_clean(cx: &Context, id: Option<&PackageId>) -> Result<()> { let mut line = cx.cargo(); line.arg("clean"); + if cx.locked { + line.arg("--locked"); + } if let Some(id) = id { line.arg("--package"); line.arg(&cx.packages(id).name); diff --git a/tests/long-help.txt b/tests/long-help.txt index 60623c01..6b8da66b 100644 --- a/tests/long-help.txt +++ b/tests/long-help.txt @@ -24,6 +24,9 @@ OPTIONS: --manifest-path Path to Cargo.toml. + --locked + Require Cargo.lock is up to date. + -F, --features ... Space or comma separated list of features to activate. diff --git a/tests/short-help.txt b/tests/short-help.txt index 1f2b7010..a06b7c67 100644 --- a/tests/short-help.txt +++ b/tests/short-help.txt @@ -12,6 +12,7 @@ OPTIONS: --workspace Perform command for all packages in the workspace --exclude ... Exclude packages from the check --manifest-path Path to Cargo.toml + --locked Require Cargo.lock is up to date -F, --features ... Space or comma separated list of features to activate --each-feature Perform for each feature of the package --feature-powerset Perform for the feature powerset of the package diff --git a/tests/test.rs b/tests/test.rs index 7f48e91b..30ccd5ac 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1466,7 +1466,7 @@ fn version_range() { "--workspace", "--locked", ]) - .assert_failure("rust-version") + .assert_success("rust-version") .stderr_contains( " running `rustup run 1.63 cargo check --locked` on member1 (1/7) @@ -1496,7 +1496,7 @@ fn rust_version() { ", ); cargo_hack(["check", "--rust-version", "--workspace", "--locked"]) - .assert_failure("rust-version") + .assert_success("rust-version") .stderr_contains( " running `rustup run 1.63 cargo check --locked` on member1 (1/4)