Skip to content

Commit

Permalink
refactor: make clear which resolve versions are stable
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Oct 20, 2023
1 parent 3790a62 commit 4ddacef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
11 changes: 11 additions & 0 deletions src/cargo/core/resolver/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ pub enum ResolveVersion {
V4,
}

impl ResolveVersion {
/// The maximum version of lockfile made into the stable channel.
///
/// Any version larger than this needs `-Znext-lockfile-bump` to enable. ⋮ 97 │ /// ⋮ 98 │ /// Update this when you're going to stabilize a new lockfile version.
///
/// Update this when you're going to stabilize a new lockfile version
pub fn max_stable() -> ResolveVersion {
ResolveVersion::V3
}
}

impl Resolve {
pub fn new(
graph: Graph<PackageId, HashSet<Dependency>>,
Expand Down
17 changes: 8 additions & 9 deletions src/cargo/ops/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,16 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoRes
// out lock file updates as they're otherwise already updated, and changes
// which don't touch dependencies won't seemingly spuriously update the lock
// file.
if resolve.version() < ResolveVersion::default() {
resolve.set_version(ResolveVersion::default());
let default_version = ResolveVersion::default();
let current_version = resolve.version();
let next_lockfile_bump = ws.config().cli_unstable().next_lockfile_bump;

if current_version < default_version {
resolve.set_version(default_version);
out = serialize_resolve(resolve, orig.as_deref());
} else if resolve.version() > ResolveVersion::default()
&& !ws.config().cli_unstable().next_lockfile_bump
{
} else if current_version > ResolveVersion::max_stable() && !next_lockfile_bump {
// The next version hasn't yet stabilized.
anyhow::bail!(
"lock file version `{:?}` requires `-Znext-lockfile-bump`",
resolve.version()
)
anyhow::bail!("lock file version `{current_version:?}` requires `-Znext-lockfile-bump`")
}

// Ok, if that didn't work just write it out
Expand Down

0 comments on commit 4ddacef

Please sign in to comment.