@@ -55,10 +55,19 @@ pub struct PackageBins {
55
55
pub xz_hash : Option < String > ,
56
56
}
57
57
58
- #[ derive( Clone , Debug , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
58
+ #[ derive( Clone , Debug , Eq , Ord , PartialOrd , Hash ) ]
59
59
pub struct Component {
60
60
pkg : String ,
61
61
pub target : Option < TargetTriple > ,
62
+ // Older Rustup distinguished between components (which are essential) and
63
+ // extensions (which are not).
64
+ is_extension : bool ,
65
+ }
66
+
67
+ impl PartialEq for Component {
68
+ fn eq ( & self , other : & Component ) -> bool {
69
+ self . pkg == other. pkg && self . target == other. target
70
+ }
62
71
}
63
72
64
73
impl Manifest {
@@ -165,7 +174,10 @@ impl Manifest {
165
174
path : & str ,
166
175
) -> Result < HashMap < Profile , Vec < String > > > {
167
176
let mut result = HashMap :: new ( ) ;
168
- let profile_table = get_table ( table, "profiles" , path) ?;
177
+ let profile_table = match get_table ( table, "profiles" , path) {
178
+ Ok ( t) => t,
179
+ Err ( _) => return Ok ( result) ,
180
+ } ;
169
181
170
182
for ( k, v) in profile_table {
171
183
if let toml:: Value :: Array ( a) = v {
@@ -201,11 +213,29 @@ impl Manifest {
201
213
self . get_package ( "rust" ) . map ( |p| & * p. version )
202
214
}
203
215
216
+ pub fn get_legacy_components ( & self , target : & TargetTriple ) -> Result < Vec < Component > > {
217
+ // Build a profile from the components/extensions.
218
+ let result = self
219
+ . get_package ( "rust" ) ?
220
+ . get_target ( Some ( target) ) ?
221
+ . components
222
+ . iter ( )
223
+ . filter ( |c| !c. is_extension && c. target . as_ref ( ) . map ( |t| t == target) . unwrap_or ( true ) )
224
+ . map ( |c| c. clone ( ) )
225
+ . collect ( ) ;
226
+
227
+ return Ok ( result) ;
228
+ }
204
229
pub fn get_profile_components (
205
230
& self ,
206
231
profile : Profile ,
207
232
target : & TargetTriple ,
208
- ) -> Result < Vec < String > > {
233
+ ) -> Result < Vec < Component > > {
234
+ // An older manifest with no profiles section.
235
+ if self . profiles . is_empty ( ) {
236
+ return self . get_legacy_components ( target) ;
237
+ }
238
+
209
239
let profile = self
210
240
. profiles
211
241
. get ( & profile)
@@ -214,8 +244,13 @@ impl Manifest {
214
244
let rust_pkg = self . get_package ( "rust" ) ?. get_target ( Some ( target) ) ?;
215
245
let result = profile
216
246
. into_iter ( )
217
- . filter ( |s| rust_pkg. components . iter ( ) . any ( |c| & c. pkg == * s) )
218
- . map ( |s| s. to_owned ( ) )
247
+ . filter ( |s| {
248
+ rust_pkg
249
+ . components
250
+ . iter ( )
251
+ . any ( |c| & c. pkg == * s && c. target . as_ref ( ) . map ( |t| t == target) . unwrap_or ( true ) )
252
+ } )
253
+ . map ( |s| Component :: new ( s. to_owned ( ) , Some ( target. clone ( ) ) , false ) )
219
254
. collect ( ) ;
220
255
Ok ( result)
221
256
}
@@ -357,10 +392,11 @@ impl TargetedPackage {
357
392
let extensions = get_array ( & mut table, "extensions" , path) ?;
358
393
359
394
let mut components =
360
- Self :: toml_to_components ( components, & format ! ( "{}{}." , path, "components" ) ) ?;
395
+ Self :: toml_to_components ( components, & format ! ( "{}{}." , path, "components" ) , false ) ?;
361
396
components. append ( & mut Self :: toml_to_components (
362
397
extensions,
363
398
& format ! ( "{}{}." , path, "extensions" ) ,
399
+ true ,
364
400
) ?) ;
365
401
366
402
if get_bool ( & mut table, "available" , path) ? {
@@ -381,11 +417,14 @@ impl TargetedPackage {
381
417
}
382
418
}
383
419
pub fn into_toml ( self ) -> toml:: value:: Table {
384
- let components = Self :: components_to_toml ( self . components ) ;
385
420
let mut result = toml:: value:: Table :: new ( ) ;
421
+ let ( components, extensions) = Self :: components_to_toml ( self . components ) ;
386
422
if !components. is_empty ( ) {
387
423
result. insert ( "components" . to_owned ( ) , toml:: Value :: Array ( components) ) ;
388
424
}
425
+ if !extensions. is_empty ( ) {
426
+ result. insert ( "extensions" . to_owned ( ) , toml:: Value :: Array ( extensions) ) ;
427
+ }
389
428
if let Some ( bins) = self . bins . clone ( ) {
390
429
result. insert ( "hash" . to_owned ( ) , toml:: Value :: String ( bins. hash ) ) ;
391
430
result. insert ( "url" . to_owned ( ) , toml:: Value :: String ( bins. url ) ) ;
@@ -404,38 +443,56 @@ impl TargetedPackage {
404
443
self . bins . is_some ( )
405
444
}
406
445
407
- fn toml_to_components ( arr : toml:: value:: Array , path : & str ) -> Result < Vec < Component > > {
446
+ fn toml_to_components (
447
+ arr : toml:: value:: Array ,
448
+ path : & str ,
449
+ is_extension : bool ,
450
+ ) -> Result < Vec < Component > > {
408
451
let mut result = Vec :: new ( ) ;
409
452
410
453
for ( i, v) in arr. into_iter ( ) . enumerate ( ) {
411
454
if let toml:: Value :: Table ( t) = v {
412
455
let path = format ! ( "{}[{}]" , path, i) ;
413
- result. push ( Component :: from_toml ( t, & path) ?) ;
456
+ result. push ( Component :: from_toml ( t, & path, is_extension ) ?) ;
414
457
}
415
458
}
416
459
417
460
Ok ( result)
418
461
}
419
- fn components_to_toml ( components : Vec < Component > ) -> toml:: value:: Array {
420
- let mut result = toml:: value:: Array :: new ( ) ;
421
- for v in components {
422
- result. push ( toml:: Value :: Table ( v. into_toml ( ) ) ) ;
462
+ fn components_to_toml ( data : Vec < Component > ) -> ( toml:: value:: Array , toml:: value:: Array ) {
463
+ let mut components = toml:: value:: Array :: new ( ) ;
464
+ let mut extensions = toml:: value:: Array :: new ( ) ;
465
+ for v in data {
466
+ if v. is_extension {
467
+ extensions. push ( toml:: Value :: Table ( v. into_toml ( ) ) ) ;
468
+ } else {
469
+ components. push ( toml:: Value :: Table ( v. into_toml ( ) ) ) ;
470
+ }
423
471
}
424
- result
472
+ ( components , extensions )
425
473
}
426
474
}
427
475
428
476
impl Component {
429
- pub fn new ( pkg : String , target : Option < TargetTriple > ) -> Component {
430
- Component { pkg, target }
477
+ pub fn new ( pkg : String , target : Option < TargetTriple > , is_extension : bool ) -> Component {
478
+ Component {
479
+ pkg,
480
+ target,
481
+ is_extension,
482
+ }
431
483
}
432
484
pub fn wildcard ( & self ) -> Component {
433
485
Component {
434
486
pkg : self . pkg . clone ( ) ,
435
487
target : None ,
488
+ is_extension : false ,
436
489
}
437
490
}
438
- pub fn from_toml ( mut table : toml:: value:: Table , path : & str ) -> Result < Self > {
491
+ pub fn from_toml (
492
+ mut table : toml:: value:: Table ,
493
+ path : & str ,
494
+ is_extension : bool ,
495
+ ) -> Result < Self > {
439
496
Ok ( Component {
440
497
pkg : get_string ( & mut table, "pkg" , path) ?,
441
498
target : get_string ( & mut table, "target" , path) . map ( |s| {
@@ -445,6 +502,7 @@ impl Component {
445
502
Some ( TargetTriple :: new ( & s) )
446
503
}
447
504
} ) ?,
505
+ is_extension,
448
506
} )
449
507
}
450
508
pub fn into_toml ( self ) -> toml:: value:: Table {
0 commit comments