Skip to content

Commit ab08e66

Browse files
committed
Stop depending on PackageId format for node ordering
In rust-lang/cargo#12914, the format used for PackageId strings in cargo metadata was changed. This led to a number of test failures due to the ordering of nodes when logging graphs changing relative to earlier versions of cargo. To work around this issue, the ordering of nodes in the graph was changed to be based on package name and version explicitly, rather than implicitly through the PackageId string. This slightly changes the ordering of some crates in outputs. In addition, in order to keep tests passing across all versions, the package_id member has been hidden from the JSON graph dump output. This field was already missing for path dependencies. Fixes mozilla#602
1 parent 9bf5bbe commit ab08e66

13 files changed

+67
-171
lines changed

src/resolver.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,12 @@ pub type PackageIdx = usize;
180180

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

214-
/// Don't serialize path package ids, not stable across systems
215-
fn pkgid_unstable(pkgid: &PackageId) -> bool {
216-
pkgid.repr.contains("(path+file:/")
217-
}
218-
219217
/// The dependency graph in a form we can use more easily.
220218
#[derive(Debug, Clone)]
221219
pub struct DepGraph<'a> {
@@ -449,9 +447,13 @@ impl<'a> DepGraph<'a> {
449447
});
450448
}
451449

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

456458
// Populate the interners based on the new ordering
457459
for (idx, node) in nodes.iter_mut().enumerate() {

src/tests/snapshots/cargo_vet__tests__vet__builtin-complex-full-audited.json.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ expression: json
77
"vetted_fully": [
88
{
99
"name": "third-core",
10-
"version": "10.0.0"
10+
"version": "5.0.0"
1111
},
1212
{
1313
"name": "third-core",
14-
"version": "5.0.0"
14+
"version": "10.0.0"
1515
},
1616
{
1717
"name": "thirdA",

src/tests/snapshots/cargo_vet__tests__vet__builtin-complex-inited.json.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ expression: json
99
"vetted_with_exemptions": [
1010
{
1111
"name": "third-core",
12-
"version": "10.0.0"
12+
"version": "5.0.0"
1313
},
1414
{
1515
"name": "third-core",
16-
"version": "5.0.0"
16+
"version": "10.0.0"
1717
},
1818
{
1919
"name": "thirdA",

src/tests/snapshots/cargo_vet__tests__vet__builtin-complex-minimal-audited.json.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ expression: json
77
"vetted_fully": [
88
{
99
"name": "third-core",
10-
"version": "10.0.0"
10+
"version": "5.0.0"
1111
},
1212
{
1313
"name": "third-core",
14-
"version": "5.0.0"
14+
"version": "10.0.0"
1515
},
1616
{
1717
"name": "thirdA",

src/tests/snapshots/cargo_vet__tests__vet__builtin-complex-no-unaudited.json.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ expression: json
77
"failures": [
88
{
99
"name": "third-core",
10-
"version": "10.0.0",
10+
"version": "5.0.0",
1111
"missing_criteria": [
1212
"safe-to-deploy"
1313
]
1414
},
1515
{
1616
"name": "third-core",
17-
"version": "5.0.0",
17+
"version": "10.0.0",
1818
"missing_criteria": [
1919
"safe-to-deploy"
2020
]

src/tests/snapshots/cargo_vet__tests__vet__builtin-simple-unaudited-twins.json.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ expression: json
1818
"vetted_with_exemptions": [
1919
{
2020
"name": "third-core",
21-
"version": "10.0.0"
21+
"version": "5.0.0"
2222
},
2323
{
2424
"name": "third-core",
25-
"version": "5.0.0"
25+
"version": "10.0.0"
2626
}
2727
]
2828
}

src/tests/snapshots/cargo_vet__tests__vet__mock-complex-full-audited.json.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ expression: json
77
"vetted_fully": [
88
{
99
"name": "third-core",
10-
"version": "10.0.0"
10+
"version": "5.0.0"
1111
},
1212
{
1313
"name": "third-core",
14-
"version": "5.0.0"
14+
"version": "10.0.0"
1515
},
1616
{
1717
"name": "thirdA",

src/tests/snapshots/cargo_vet__tests__vet__mock-complex-inited.json.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ expression: json
99
"vetted_with_exemptions": [
1010
{
1111
"name": "third-core",
12-
"version": "10.0.0"
12+
"version": "5.0.0"
1313
},
1414
{
1515
"name": "third-core",
16-
"version": "5.0.0"
16+
"version": "10.0.0"
1717
},
1818
{
1919
"name": "thirdA",

src/tests/snapshots/cargo_vet__tests__vet__mock-complex-no-unaudited.json.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ expression: json
77
"failures": [
88
{
99
"name": "third-core",
10-
"version": "10.0.0",
10+
"version": "5.0.0",
1111
"missing_criteria": [
1212
"reviewed"
1313
]
1414
},
1515
{
1616
"name": "third-core",
17-
"version": "5.0.0",
17+
"version": "10.0.0",
1818
"missing_criteria": [
1919
"reviewed"
2020
]

0 commit comments

Comments
 (0)