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

Stop depending on PackageId format for node ordering #603

Merged
merged 1 commit into from
Apr 2, 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
20 changes: 11 additions & 9 deletions src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,12 @@ pub type PackageIdx = usize;

#[derive(Debug, Clone, Serialize)]
pub struct PackageNode<'a> {
#[serde(skip_serializing_if = "pkgid_unstable")]
#[serde(skip)]
/// The PackageId that cargo uses to uniquely identify this package
///
/// This ID is not guaranteed to be stable across cargo versions, so is not
/// serialized into graph JSON.
///
/// Prefer using a [`DepGraph`] and its memoized [`PackageIdx`]'s.
pub package_id: &'a PackageId,
/// The name of the package
Expand Down Expand Up @@ -211,11 +214,6 @@ pub struct PackageNode<'a> {
pub is_dev_only: bool,
}

/// Don't serialize path package ids, not stable across systems
fn pkgid_unstable(pkgid: &PackageId) -> bool {
pkgid.repr.contains("(path+file:/")
}

/// The dependency graph in a form we can use more easily.
#[derive(Debug, Clone)]
pub struct DepGraph<'a> {
Expand Down Expand Up @@ -449,9 +447,13 @@ impl<'a> DepGraph<'a> {
});
}

// Sort the nodes by package_id to make the graph more stable and to make
// anything sorted by package_idx to also be approximately sorted by name and version.
nodes.sort_by_key(|k| k.package_id);
// Sort the nodes by package name and version to make the graph as
// stable as possible. We avoid sorting by the package_id if possible,
// as for some packages it may not be stable (e.g. file:///), and the
// package_id format can also vary between cargo versions.
nodes.sort_by(|a, b| {
(a.name, &a.version, &a.package_id).cmp(&(b.name, &b.version, &b.package_id))
});

// Populate the interners based on the new ordering
for (idx, node) in nodes.iter_mut().enumerate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ expression: json
"vetted_fully": [
{
"name": "third-core",
"version": "10.0.0"
"version": "5.0.0"
},
{
"name": "third-core",
"version": "5.0.0"
"version": "10.0.0"
},
{
"name": "thirdA",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ expression: json
"vetted_with_exemptions": [
{
"name": "third-core",
"version": "10.0.0"
"version": "5.0.0"
},
{
"name": "third-core",
"version": "5.0.0"
"version": "10.0.0"
},
{
"name": "thirdA",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ expression: json
"vetted_fully": [
{
"name": "third-core",
"version": "10.0.0"
"version": "5.0.0"
},
{
"name": "third-core",
"version": "5.0.0"
"version": "10.0.0"
},
{
"name": "thirdA",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ expression: json
"failures": [
{
"name": "third-core",
"version": "10.0.0",
"version": "5.0.0",
"missing_criteria": [
"safe-to-deploy"
]
},
{
"name": "third-core",
"version": "5.0.0",
"version": "10.0.0",
"missing_criteria": [
"safe-to-deploy"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ expression: json
"vetted_with_exemptions": [
{
"name": "third-core",
"version": "10.0.0"
"version": "5.0.0"
},
{
"name": "third-core",
"version": "5.0.0"
"version": "10.0.0"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ expression: json
"vetted_fully": [
{
"name": "third-core",
"version": "10.0.0"
"version": "5.0.0"
},
{
"name": "third-core",
"version": "5.0.0"
"version": "10.0.0"
},
{
"name": "thirdA",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ expression: json
"vetted_with_exemptions": [
{
"name": "third-core",
"version": "10.0.0"
"version": "5.0.0"
},
{
"name": "third-core",
"version": "5.0.0"
"version": "10.0.0"
},
{
"name": "thirdA",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ expression: json
"failures": [
{
"name": "third-core",
"version": "10.0.0",
"version": "5.0.0",
"missing_criteria": [
"reviewed"
]
},
{
"name": "third-core",
"version": "5.0.0",
"version": "10.0.0",
"missing_criteria": [
"reviewed"
]
Expand Down
Loading
Loading