-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Turn the new lock file format on by default #7579
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
use std::borrow::Borrow; | ||
use std::cmp; | ||
use std::collections::{HashMap, HashSet}; | ||
use std::fmt; | ||
use std::iter::FromIterator; | ||
|
@@ -15,7 +16,6 @@ use super::encode::Metadata; | |
/// | ||
/// Each instance of `Resolve` also understands the full set of features used | ||
/// for each package. | ||
#[derive(PartialEq)] | ||
pub struct Resolve { | ||
/// A graph, whose vertices are packages and edges are dependency specifications | ||
/// from `Cargo.toml`. We need a `Vec` here because the same package | ||
|
@@ -59,9 +59,12 @@ pub struct Resolve { | |
/// | ||
/// It's theorized that we can add more here over time to track larger changes | ||
/// to the `Cargo.lock` format, but we've yet to see how that strategy pans out. | ||
#[derive(PartialEq, Clone, Debug)] | ||
#[derive(PartialEq, Eq, Clone, Copy, Debug, PartialOrd, Ord)] | ||
pub enum ResolveVersion { | ||
// Historical baseline for when this abstraction was added. | ||
V1, | ||
// Update around 2019 where `dependencies` arrays got compressed and | ||
// checksums are listed inline. | ||
V2, | ||
} | ||
|
||
|
@@ -210,21 +213,35 @@ unable to verify that `{0}` is the same as when the lockfile was generated | |
// Be sure to just copy over any unknown metadata. | ||
self.metadata = previous.metadata.clone(); | ||
|
||
// The goal of Cargo is largely to preserve the encoding of | ||
// `Cargo.lock` that it finds on the filesystem. Sometimes `Cargo.lock` | ||
// changes are in the works where they haven't been set as the default | ||
// yet but will become the default soon. We want to preserve those | ||
// features if we find them. | ||
// The goal of Cargo is largely to preserve the encoding of `Cargo.lock` | ||
// that it finds on the filesystem. Sometimes `Cargo.lock` changes are | ||
// in the works where they haven't been set as the default yet but will | ||
// become the default soon. | ||
// | ||
// For this reason if the previous `Cargo.lock` is from the future, or | ||
// otherwise it looks like it's produced with future features we | ||
// understand, then the new resolve will be encoded with the same | ||
// version. Note that new instances of `Resolve` always use the default | ||
// encoding, and this is where we switch it to a future encoding if the | ||
// future encoding isn't yet the default. | ||
if previous.version.from_the_future() { | ||
self.version = previous.version.clone(); | ||
} | ||
// The scenarios we could be in are: | ||
// | ||
// * This is a brand new lock file with nothing previous. In that case | ||
// this method isn't actually called at all, but instead | ||
// `default_for_new_lockfiles` called below was encoded during the | ||
// resolution step, so that's what we're gonna use. | ||
// | ||
// * We have an old lock file. In this case we want to switch the | ||
// version to `default_for_old_lockfiles`. That puts us in one of | ||
// three cases: | ||
// | ||
// * Our version is older than the default. This means that we're | ||
// migrating someone forward, so we switch the encoding. | ||
// * Our version is equal to the default, nothing to do! | ||
// * Our version is *newer* than the default. This is where we | ||
// critically keep the new version of encoding. | ||
// | ||
// This strategy should get new lockfiles into the pipeline more quickly | ||
// while ensuring that any time an old cargo sees a future lock file it | ||
// keeps the future lockfile encoding. | ||
self.version = cmp::max( | ||
previous.version, | ||
ResolveVersion::default_for_old_lockfiles(), | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
@@ -358,6 +375,26 @@ unable to verify that `{0}` is the same as when the lockfile was generated | |
} | ||
} | ||
|
||
impl PartialEq for Resolve { | ||
fn eq(&self, other: &Resolve) -> bool { | ||
macro_rules! compare { | ||
($($fields:ident)* | $($ignored:ident)*) => { | ||
let Resolve { $($fields,)* $($ignored,)* } = self; | ||
$(drop($ignored);)* | ||
$($fields == &other.$fields)&&* | ||
} | ||
} | ||
compare! { | ||
// fields to compare | ||
graph replacements reverse_replacements empty_features features | ||
checksums metadata unused_patches public_dependencies | ||
| | ||
// fields to ignore | ||
version | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Debug for Resolve { | ||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
writeln!(fmt, "graph: {:?}", self.graph)?; | ||
|
@@ -370,23 +407,26 @@ impl fmt::Debug for Resolve { | |
} | ||
|
||
impl ResolveVersion { | ||
/// The default way to encode `Cargo.lock`. | ||
/// The default way to encode new `Cargo.lock` files. | ||
/// | ||
/// This is used for new `Cargo.lock` files that are generated without a | ||
/// previous `Cargo.lock` files, and generally matches with what we want to | ||
/// encode. | ||
pub fn default() -> ResolveVersion { | ||
ResolveVersion::V1 | ||
/// It's important that if a new version of `ResolveVersion` is added that | ||
/// this is not updated until *at least* the support for the version is in | ||
/// the stable release of Rust. It's ok for this to be newer than | ||
/// `default_for_old_lockfiles` below. | ||
pub fn default_for_new_lockfiles() -> ResolveVersion { | ||
ResolveVersion::V2 | ||
} | ||
|
||
/// Returns whether this encoding version is "from the future". | ||
/// The default way to encode old preexisting `Cargo.lock` files. This is | ||
/// often trailing the new lockfiles one above to give older projects a | ||
/// longer time to catch up. | ||
/// | ||
/// This means that this encoding version is not currently the default but | ||
/// intended to become the default "soon". | ||
pub fn from_the_future(&self) -> bool { | ||
match self { | ||
ResolveVersion::V2 => true, | ||
ResolveVersion::V1 => false, | ||
} | ||
/// It's important that this trails behind `default_for_new_lockfiles` for | ||
/// quite some time. This gives projects a quite large window to update in | ||
/// where we don't force updates, so if projects span many versions of Cargo | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could there be a config param for this? Somewhere in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A flag to |
||
/// all those versions of Cargo will have support for a new version of the | ||
/// lock file. | ||
pub fn default_for_old_lockfiles() -> ResolveVersion { | ||
ResolveVersion::V1 | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doccomment for this still says
V1
is the default.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#7637