@@ -3,7 +3,7 @@ use crate::core::compiler::{CompileKind, RustcTargetData};
33use crate :: core:: dependency:: DepKind ;
44use crate :: core:: package:: SerializedPackage ;
55use crate :: core:: resolver:: { features:: CliFeatures , HasDevUnits , Resolve } ;
6- use crate :: core:: { Package , PackageId , Workspace } ;
6+ use crate :: core:: { Package , PackageId , PackageIdSpec , Workspace } ;
77use crate :: ops:: { self , Packages } ;
88use crate :: util:: interning:: InternedString ;
99use crate :: util:: CargoResult ;
@@ -42,8 +42,11 @@ pub fn output_metadata(ws: &Workspace<'_>, opt: &OutputMetadataOptions) -> Cargo
4242
4343 Ok ( ExportInfo {
4444 packages,
45- workspace_members : ws. members ( ) . map ( |pkg| pkg. package_id ( ) ) . collect ( ) ,
46- workspace_default_members : ws. default_members ( ) . map ( |pkg| pkg. package_id ( ) ) . collect ( ) ,
45+ workspace_members : ws. members ( ) . map ( |pkg| pkg. package_id ( ) . to_spec ( ) ) . collect ( ) ,
46+ workspace_default_members : ws
47+ . default_members ( )
48+ . map ( |pkg| pkg. package_id ( ) . to_spec ( ) )
49+ . collect ( ) ,
4750 resolve,
4851 target_directory : ws. target_dir ( ) . into_path_unlocked ( ) ,
4952 version : VERSION ,
@@ -58,8 +61,8 @@ pub fn output_metadata(ws: &Workspace<'_>, opt: &OutputMetadataOptions) -> Cargo
5861#[ derive( Serialize ) ]
5962pub struct ExportInfo {
6063 packages : Vec < SerializedPackage > ,
61- workspace_members : Vec < PackageId > ,
62- workspace_default_members : Vec < PackageId > ,
64+ workspace_members : Vec < PackageIdSpec > ,
65+ workspace_default_members : Vec < PackageIdSpec > ,
6366 resolve : Option < MetadataResolve > ,
6467 target_directory : PathBuf ,
6568 version : u32 ,
@@ -70,13 +73,13 @@ pub struct ExportInfo {
7073#[ derive( Serialize ) ]
7174struct MetadataResolve {
7275 nodes : Vec < MetadataResolveNode > ,
73- root : Option < PackageId > ,
76+ root : Option < PackageIdSpec > ,
7477}
7578
7679#[ derive( Serialize ) ]
7780struct MetadataResolveNode {
78- id : PackageId ,
79- dependencies : Vec < PackageId > ,
81+ id : PackageIdSpec ,
82+ dependencies : Vec < PackageIdSpec > ,
8083 deps : Vec < Dep > ,
8184 features : Vec < InternedString > ,
8285}
@@ -86,7 +89,9 @@ struct Dep {
8689 // TODO(bindeps): after -Zbindeps gets stabilized,
8790 // mark this field as deprecated in the help manual of cargo-metadata
8891 name : InternedString ,
89- pkg : PackageId ,
92+ pkg : PackageIdSpec ,
93+ #[ serde( skip) ]
94+ pkg_id : PackageId ,
9095 dep_kinds : Vec < DepKindInfo > ,
9196}
9297
@@ -179,7 +184,7 @@ fn build_resolve_graph(
179184
180185 let mr = MetadataResolve {
181186 nodes : node_map. into_iter ( ) . map ( |( _pkg_id, node) | node) . collect ( ) ,
182- root : ws. current_opt ( ) . map ( |pkg| pkg. package_id ( ) ) ,
187+ root : ws. current_opt ( ) . map ( |pkg| pkg. package_id ( ) . to_spec ( ) ) ,
183188 } ;
184189 Ok ( ( actual_packages, mr) )
185190}
@@ -301,18 +306,20 @@ fn build_resolve_graph_r(
301306
302307 dep_kinds. sort ( ) ;
303308
304- let pkg = normalize_id ( dep_id) ;
309+ let pkg_id = normalize_id ( dep_id) ;
305310
306311 let dep = match ( lib_target, dep_kinds. len ( ) ) {
307312 ( Some ( target) , _) => Dep {
308313 name : extern_name ( target) ?,
309- pkg,
314+ pkg : pkg_id. to_spec ( ) ,
315+ pkg_id,
310316 dep_kinds,
311317 } ,
312318 // No lib target exists but contains artifact deps.
313319 ( None , 1 ..) => Dep {
314320 name : InternedString :: new ( "" ) ,
315- pkg,
321+ pkg : pkg_id. to_spec ( ) ,
322+ pkg_id,
316323 dep_kinds,
317324 } ,
318325 // No lib or artifact dep exists.
@@ -325,11 +332,10 @@ fn build_resolve_graph_r(
325332 dep_metadatas
326333 } ;
327334
328- let dumb_deps: Vec < PackageId > = deps. iter ( ) . map ( |dep| dep. pkg ) . collect ( ) ;
329- let to_visit = dumb_deps. clone ( ) ;
335+ let to_visit: Vec < PackageId > = deps. iter ( ) . map ( |dep| dep. pkg_id ) . collect ( ) ;
330336 let node = MetadataResolveNode {
331- id : normalize_id ( pkg_id) ,
332- dependencies : dumb_deps ,
337+ id : normalize_id ( pkg_id) . to_spec ( ) ,
338+ dependencies : to_visit . iter ( ) . map ( |id| id . to_spec ( ) ) . collect ( ) ,
333339 deps,
334340 features,
335341 } ;
0 commit comments