Skip to content

Commit 872b92e

Browse files
authored
fix(unit-graph): switch to Package ID Spec (#15447)
### What does this PR try to resolve? Fixes #15445, where there were still differences between the format of package ids of "`cargo metadata` and build JSON messages", and `--unit-graph` package ids. ### How should we test and review this PR? Everything compiles correctly (and outputs what's expected). I also fixed the testcases
2 parents 0865ee8 + 55952a3 commit 872b92e

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/cargo/core/compiler/unit_graph.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
//!
33
//! [`--unit-graph`]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#unit-graph
44
5+
use cargo_util_schemas::core::PackageIdSpec;
6+
57
use crate::core::compiler::Unit;
68
use crate::core::compiler::{CompileKind, CompileMode};
79
use crate::core::profiles::{Profile, UnitFor};
8-
use crate::core::{PackageId, Target};
10+
use crate::core::Target;
911
use crate::util::interning::InternedString;
1012
use crate::util::CargoResult;
1113
use crate::GlobalContext;
@@ -47,7 +49,7 @@ struct SerializedUnitGraph<'a> {
4749

4850
#[derive(serde::Serialize)]
4951
struct SerializedUnit<'a> {
50-
pkg_id: PackageId,
52+
pkg_id: PackageIdSpec,
5153
target: &'a Target,
5254
profile: &'a Profile,
5355
platform: CompileKind,
@@ -109,7 +111,7 @@ pub fn emit_serialized_unit_graph(
109111
})
110112
.collect();
111113
SerializedUnit {
112-
pkg_id: unit.pkg.package_id(),
114+
pkg_id: unit.pkg.package_id().to_spec(),
113115
target: &unit.target,
114116
profile: &unit.profile,
115117
platform: unit.kind,

tests/testsuite/unit_graph.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn simple() {
6868
"feata"
6969
],
7070
"mode": "build",
71-
"pkg_id": "a 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
71+
"pkg_id": "registry+https://github.com/rust-lang/crates.io-index#[email protected]",
7272
"platform": null,
7373
"profile": {
7474
"codegen_backend": null,
@@ -113,7 +113,7 @@ fn simple() {
113113
"featb"
114114
],
115115
"mode": "build",
116-
"pkg_id": "b 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
116+
"pkg_id": "registry+https://github.com/rust-lang/crates.io-index#[email protected]",
117117
"platform": null,
118118
"profile": {
119119
"codegen_backend": null,
@@ -151,7 +151,7 @@ fn simple() {
151151
"featc"
152152
],
153153
"mode": "build",
154-
"pkg_id": "c 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
154+
"pkg_id": "registry+https://github.com/rust-lang/crates.io-index#[email protected]",
155155
"platform": null,
156156
"profile": {
157157
"codegen_backend": null,
@@ -194,7 +194,7 @@ fn simple() {
194194
],
195195
"features": [],
196196
"mode": "build",
197-
"pkg_id": "foo 0.1.0 (path+[ROOTURL]/foo)",
197+
"pkg_id": "path+[ROOTURL]/foo#0.1.0",
198198
"platform": null,
199199
"profile": {
200200
"codegen_backend": null,

0 commit comments

Comments
 (0)