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

refactor: centralize logic of getting max resolve version #12860

Merged
merged 1 commit into from
Oct 20, 2023
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
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.
///
/// Update this when you're going to stabilize a new lockfile format.
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