@@ -3,7 +3,7 @@ use crate::core::compiler::{CompileKind, RustcTargetData};
3
3
use crate :: core:: dependency:: DepKind ;
4
4
use crate :: core:: package:: SerializedPackage ;
5
5
use crate :: core:: resolver:: { features:: CliFeatures , HasDevUnits , Resolve } ;
6
- use crate :: core:: { Package , PackageId , Workspace } ;
6
+ use crate :: core:: { Package , PackageId , PackageIdSpec , Workspace } ;
7
7
use crate :: ops:: { self , Packages } ;
8
8
use crate :: util:: interning:: InternedString ;
9
9
use crate :: util:: CargoResult ;
@@ -42,8 +42,14 @@ pub fn output_metadata(ws: &Workspace<'_>, opt: &OutputMetadataOptions) -> Cargo
42
42
43
43
Ok ( ExportInfo {
44
44
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
46
+ . members ( )
47
+ . map ( |pkg| PackageIdSpec :: from_package_id ( pkg. package_id ( ) ) )
48
+ . collect ( ) ,
49
+ workspace_default_members : ws
50
+ . default_members ( )
51
+ . map ( |pkg| PackageIdSpec :: from_package_id ( pkg. package_id ( ) ) )
52
+ . collect ( ) ,
47
53
resolve,
48
54
target_directory : ws. target_dir ( ) . into_path_unlocked ( ) ,
49
55
version : VERSION ,
@@ -58,8 +64,8 @@ pub fn output_metadata(ws: &Workspace<'_>, opt: &OutputMetadataOptions) -> Cargo
58
64
#[ derive( Serialize ) ]
59
65
pub struct ExportInfo {
60
66
packages : Vec < SerializedPackage > ,
61
- workspace_members : Vec < PackageId > ,
62
- workspace_default_members : Vec < PackageId > ,
67
+ workspace_members : Vec < PackageIdSpec > ,
68
+ workspace_default_members : Vec < PackageIdSpec > ,
63
69
resolve : Option < MetadataResolve > ,
64
70
target_directory : PathBuf ,
65
71
version : u32 ,
@@ -70,13 +76,13 @@ pub struct ExportInfo {
70
76
#[ derive( Serialize ) ]
71
77
struct MetadataResolve {
72
78
nodes : Vec < MetadataResolveNode > ,
73
- root : Option < PackageId > ,
79
+ root : Option < PackageIdSpec > ,
74
80
}
75
81
76
82
#[ derive( Serialize ) ]
77
83
struct MetadataResolveNode {
78
- id : PackageId ,
79
- dependencies : Vec < PackageId > ,
84
+ id : PackageIdSpec ,
85
+ dependencies : Vec < PackageIdSpec > ,
80
86
deps : Vec < Dep > ,
81
87
features : Vec < InternedString > ,
82
88
}
@@ -86,7 +92,9 @@ struct Dep {
86
92
// TODO(bindeps): after -Zbindeps gets stabilized,
87
93
// mark this field as deprecated in the help manual of cargo-metadata
88
94
name : InternedString ,
89
- pkg : PackageId ,
95
+ pkg : PackageIdSpec ,
96
+ #[ serde( skip) ]
97
+ pkg_id : PackageId ,
90
98
dep_kinds : Vec < DepKindInfo > ,
91
99
}
92
100
@@ -179,7 +187,9 @@ fn build_resolve_graph(
179
187
180
188
let mr = MetadataResolve {
181
189
nodes : node_map. into_iter ( ) . map ( |( _pkg_id, node) | node) . collect ( ) ,
182
- root : ws. current_opt ( ) . map ( |pkg| pkg. package_id ( ) ) ,
190
+ root : ws
191
+ . current_opt ( )
192
+ . map ( |pkg| PackageIdSpec :: from_package_id ( pkg. package_id ( ) ) ) ,
183
193
} ;
184
194
Ok ( ( actual_packages, mr) )
185
195
}
@@ -301,18 +311,20 @@ fn build_resolve_graph_r(
301
311
302
312
dep_kinds. sort ( ) ;
303
313
304
- let pkg = normalize_id ( dep_id) ;
314
+ let pkg_id = normalize_id ( dep_id) ;
305
315
306
316
let dep = match ( lib_target, dep_kinds. len ( ) ) {
307
317
( Some ( target) , _) => Dep {
308
318
name : extern_name ( target) ?,
309
- pkg,
319
+ pkg : PackageIdSpec :: from_package_id ( pkg_id. clone ( ) ) ,
320
+ pkg_id,
310
321
dep_kinds,
311
322
} ,
312
323
// No lib target exists but contains artifact deps.
313
324
( None , 1 ..) => Dep {
314
325
name : InternedString :: new ( "" ) ,
315
- pkg,
326
+ pkg : PackageIdSpec :: from_package_id ( pkg_id. clone ( ) ) ,
327
+ pkg_id,
316
328
dep_kinds,
317
329
} ,
318
330
// No lib or artifact dep exists.
@@ -325,11 +337,13 @@ fn build_resolve_graph_r(
325
337
dep_metadatas
326
338
} ;
327
339
328
- let dumb_deps: Vec < PackageId > = deps. iter ( ) . map ( |dep| dep. pkg ) . collect ( ) ;
329
- let to_visit = dumb_deps. clone ( ) ;
340
+ let to_visit: Vec < PackageId > = deps. iter ( ) . map ( |dep| dep. pkg_id ) . collect ( ) ;
330
341
let node = MetadataResolveNode {
331
- id : normalize_id ( pkg_id) ,
332
- dependencies : dumb_deps,
342
+ id : PackageIdSpec :: from_package_id ( normalize_id ( pkg_id) ) ,
343
+ dependencies : to_visit
344
+ . iter ( )
345
+ . map ( |id| PackageIdSpec :: from_package_id ( id. clone ( ) ) )
346
+ . collect ( ) ,
333
347
deps,
334
348
features,
335
349
} ;
0 commit comments