diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8ebbeb..2f44b0c 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 aff3d69..60cfe34 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 928cc29..59d8bf1 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 dba2208..9668c81 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 60623c0..6b8da66 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 1f2b701..a06b7c6 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 7f48e91..30ccd5a 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)