Skip to content

Commit

Permalink
Respect lockfile except when necessary to work around old cargo bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Mar 31, 2024
1 parent 8c684c4 commit c8e6133
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com

## [Unreleased]

- Respect the existing `Cargo.lock` with `--version-range`/`--rust-version` except when necessary to work around old cargo bugs. ([#242](https://github.com/taiki-e/cargo-hack/pull/242))
If you want to ensure that lockfile is respected in all cases, please use `--locked`.

## [0.6.23] - 2024-03-27

- Fix ignoring optional dependencies when namespaced dependencies are used. ([#241](https://github.com/taiki-e/cargo-hack/pull/241), thanks @xStrom)
Expand Down
14 changes: 12 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ fn try_main() -> Result<()> {
}
}
}
let versions = versions; // make immutable
if versions.is_empty() {
// TODO: emit warning
return Ok(());
}

for (cargo_version, packages) in &versions {
for package in packages {
Expand All @@ -114,7 +119,12 @@ 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 = !cx.locked;
// For now, only generate lockfile if min version is pre-1.60.
// (If future cargo introduces compatibility issues, the number of
// versions requiring generate-lockfile will probably increase.)
// https://github.com/taiki-e/cargo-hack/issues/234#issuecomment-2028517197
let mut generate_lockfile =
!cx.locked && versions.first_key_value().unwrap().0.minor < 60;
// 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 @@ -381,7 +391,7 @@ fn versioned_cargo_exec_on_packages(
*generate_lockfile = false;
*regenerate_lockfile_on_51_or_up = false;
}
if cargo_version < 51 {
if !cx.locked && cargo_version < 51 {
*regenerate_lockfile_on_51_or_up = true;
}

Expand Down

0 comments on commit c8e6133

Please sign in to comment.