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..f69f78e 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -21,6 +21,8 @@ pub(crate) struct Args { pub(crate) subcommand: Option, + /// --locked + pub(crate) locked: bool, /// --manifest-path pub(crate) manifest_path: Option, /// --no-manifest-path @@ -154,6 +156,7 @@ impl Args { let mut clean_per_version = false; let mut keep_going = false; let mut print_command_list = false; + let mut locked = false; let mut no_manifest_path = false; let mut rust_version = false; let mut version_range = None; @@ -306,6 +309,7 @@ impl Args { Long("clean-per-version") => parse_flag!(clean_per_version), Long("keep-going") => parse_flag!(keep_going), Long("print-command-list") => parse_flag!(print_command_list), + Long("locked") => parse_flag!(locked), Long("no-manifest-path") => parse_flag!(no_manifest_path), Long("ignore-unknown-features") => parse_flag!(ignore_unknown_features), Short('v') | Long("verbose") => verbose += 1, @@ -624,6 +628,7 @@ impl Args { clean_per_version, keep_going, print_command_list, + locked, no_manifest_path, include_features: include_features.into_iter().map(Into::into).collect(), at_least_one_of, @@ -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)