Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Respect --locked flag #236

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/.cspell/rust-dependencies.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ OPTIONS:
--manifest-path <PATH>
Path to Cargo.toml.

--locked
Require Cargo.lock is up to date.

-F, --features <FEATURES>...
Space or comma separated list of features to activate.

Expand Down
6 changes: 6 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub(crate) struct Args {
pub(crate) manifest_path: Option<String>,
/// --no-manifest-path
pub(crate) no_manifest_path: bool,
/// --locked
pub(crate) locked: bool,
/// -p, --package <SPEC>...
pub(crate) package: Vec<String>,
/// --exclude <SPEC>...
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -609,6 +613,7 @@ impl Args {
subcommand,

manifest_path,
locked,
package,
exclude,
workspace,
Expand Down Expand Up @@ -700,6 +705,7 @@ const HELP: &[HelpText<'_>] = &[
"This flag can only be used together with --workspace",
]),
("", "--manifest-path", "<PATH>", "Path to Cargo.toml", &[]),
("", "--locked", "", "Require Cargo.lock is up to date", &[]),
("-F", "--features", "<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.",
Expand Down
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
50 changes: 50 additions & 0 deletions tests/fixtures/rust-version/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/fixtures/rust-version/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ c = []

[dependencies]
member1 = { path = "member1", optional = true }
argfile = "0.1.5"

[dev-dependencies]

Expand Down
3 changes: 3 additions & 0 deletions tests/long-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ OPTIONS:
--manifest-path <PATH>
Path to Cargo.toml.

--locked
Require Cargo.lock is up to date.

-F, --features <FEATURES>...
Space or comma separated list of features to activate.

Expand Down
1 change: 1 addition & 0 deletions tests/short-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ OPTIONS:
--workspace Perform command for all packages in the workspace
--exclude <SPEC>... Exclude packages from the check
--manifest-path <PATH> Path to Cargo.toml
--locked Require Cargo.lock is up to date
-F, --features <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
Expand Down
42 changes: 25 additions & 17 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_success("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_success("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]
Expand All @@ -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_success("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)
",
);
}
Expand Down