@@ -11,6 +11,12 @@ use once_cell::sync::Lazy;
11
11
use sha2:: { Digest , Sha256 } ;
12
12
use url:: Url ;
13
13
14
+ use crate :: dist:: dist:: { Profile , TargetTriple } ;
15
+ use crate :: dist:: manifest:: {
16
+ Component , CompressionKind , HashedBinary , Manifest , ManifestVersion , Package , PackageTargets ,
17
+ Renamed , TargetedPackage ,
18
+ } ;
19
+
14
20
use super :: clitools:: hard_link;
15
21
use super :: MockInstallerBuilder ;
16
22
@@ -118,14 +124,14 @@ pub struct MockHashes {
118
124
pub zst : Option < String > ,
119
125
}
120
126
121
- pub enum ManifestVersion {
127
+ pub enum MockManifestVersion {
122
128
V1 ,
123
129
V2 ,
124
130
}
125
131
126
132
impl MockDistServer {
127
133
#[ cfg_attr( feature = "otel" , tracing:: instrument( skip_all) ) ]
128
- pub fn write ( & self , vs : & [ ManifestVersion ] , enable_xz : bool , enable_zst : bool ) {
134
+ pub fn write ( & self , vs : & [ MockManifestVersion ] , enable_xz : bool , enable_zst : bool ) {
129
135
fs:: create_dir_all ( & self . path ) . unwrap ( ) ;
130
136
131
137
for channel in self . channels . iter ( ) {
@@ -136,8 +142,8 @@ impl MockDistServer {
136
142
}
137
143
for v in vs {
138
144
match * v {
139
- ManifestVersion :: V1 => self . write_manifest_v1 ( channel) ,
140
- ManifestVersion :: V2 => self . write_manifest_v2 ( channel, & hashes) ,
145
+ MockManifestVersion :: V1 => self . write_manifest_v1 ( channel) ,
146
+ MockManifestVersion :: V2 => self . write_manifest_v2 ( channel, & hashes) ,
141
147
}
142
148
}
143
149
}
@@ -306,136 +312,118 @@ impl MockDistServer {
306
312
channel : & MockChannel ,
307
313
hashes : & HashMap < MockComponent , MockHashes > ,
308
314
) {
309
- let mut toml_manifest = toml:: value:: Table :: new ( ) ;
310
-
311
- toml_manifest. insert (
312
- String :: from ( "manifest-version" ) ,
313
- toml:: Value :: String ( MOCK_MANIFEST_VERSION . to_owned ( ) ) ,
314
- ) ;
315
- toml_manifest. insert (
316
- String :: from ( "date" ) ,
317
- toml:: Value :: String ( channel. date . to_owned ( ) ) ,
318
- ) ;
315
+ let mut manifest = Manifest {
316
+ manifest_version : ManifestVersion :: V2 ,
317
+ date : channel. date . clone ( ) ,
318
+ renames : HashMap :: default ( ) ,
319
+ packages : HashMap :: default ( ) ,
320
+ reverse_renames : HashMap :: default ( ) ,
321
+ profiles : HashMap :: default ( ) ,
322
+ } ;
319
323
320
324
// [pkg.*]
321
- let mut toml_packages = toml:: value:: Table :: new ( ) ;
322
325
for package in & channel. packages {
323
- let mut toml_package = toml:: value:: Table :: new ( ) ;
324
- toml_package. insert (
325
- String :: from ( "version" ) ,
326
- toml:: Value :: String ( package. version . to_owned ( ) ) ,
327
- ) ;
326
+ let mut targets = HashMap :: default ( ) ;
328
327
329
328
// [pkg.*.target.*]
330
- let mut toml_targets = toml:: value:: Table :: new ( ) ;
331
329
for target in & package. targets {
332
- let mut toml_target = toml:: value:: Table :: new ( ) ;
333
- toml_target. insert (
334
- String :: from ( "available" ) ,
335
- toml:: Value :: Boolean ( target. available ) ,
336
- ) ;
330
+ let mut tpkg = TargetedPackage {
331
+ bins : Vec :: new ( ) ,
332
+ components : Vec :: new ( ) ,
333
+ } ;
337
334
338
335
let package_file_name = if target. target != "*" {
339
336
format ! ( "{}-{}-{}.tar.gz" , package. name, channel. name, target. target)
340
337
} else {
341
338
format ! ( "{}-{}.tar.gz" , package. name, channel. name)
342
339
} ;
340
+
343
341
let path = self
344
342
. path
345
343
. join ( "dist" )
346
344
. join ( & channel. date )
347
345
. join ( package_file_name) ;
348
- let url = format ! ( "file://{}" , path. to_string_lossy( ) ) ;
349
- toml_target. insert ( String :: from ( "url" ) , toml:: Value :: String ( url. clone ( ) ) ) ;
350
346
351
347
let component = MockComponent {
352
348
name : package. name . to_owned ( ) ,
353
349
target : target. target . to_owned ( ) ,
354
350
is_extension : false ,
355
351
} ;
356
- let hash = hashes[ & component] . clone ( ) ;
357
- toml_target. insert ( String :: from ( "hash" ) , toml:: Value :: String ( hash. gz ) ) ;
358
-
359
- if let Some ( xz_hash) = hash. xz {
360
- toml_target. insert (
361
- String :: from ( "xz_url" ) ,
362
- toml:: Value :: String ( url. replace ( ".tar.gz" , ".tar.xz" ) ) ,
363
- ) ;
364
- toml_target. insert ( String :: from ( "xz_hash" ) , toml:: Value :: String ( xz_hash) ) ;
365
- }
366
- if let Some ( zst_hash) = hash. zst {
367
- toml_target. insert (
368
- String :: from ( "zst_url" ) ,
369
- toml:: Value :: String ( url. replace ( ".tar.gz" , ".tar.zst" ) ) ,
370
- ) ;
371
- toml_target. insert ( String :: from ( "zst_hash" ) , toml:: Value :: String ( zst_hash) ) ;
352
+
353
+ if target. available {
354
+ let hash = hashes[ & component] . clone ( ) ;
355
+ let url = format ! ( "file://{}" , path. to_string_lossy( ) ) ;
356
+ tpkg. bins . push ( HashedBinary {
357
+ url : url. clone ( ) ,
358
+ hash : hash. gz ,
359
+ compression : CompressionKind :: GZip ,
360
+ } ) ;
361
+
362
+ if let Some ( xz_hash) = hash. xz {
363
+ tpkg. bins . push ( HashedBinary {
364
+ url : url. replace ( ".tar.gz" , ".tar.xz" ) ,
365
+ hash : xz_hash,
366
+ compression : CompressionKind :: XZ ,
367
+ } ) ;
368
+ }
369
+
370
+ if let Some ( zst_hash) = hash. zst {
371
+ tpkg. bins . push ( HashedBinary {
372
+ url : url. replace ( ".tar.gz" , ".tar.zst" ) ,
373
+ hash : zst_hash,
374
+ compression : CompressionKind :: ZStd ,
375
+ } ) ;
376
+ }
372
377
}
373
378
374
379
// [pkg.*.target.*.components.*] and [pkg.*.target.*.extensions.*]
375
- let mut toml_components = toml:: value:: Array :: new ( ) ;
376
- let mut toml_extensions = toml:: value:: Array :: new ( ) ;
377
380
for component in & target. components {
378
- let mut toml_component = toml:: value:: Table :: new ( ) ;
379
- toml_component. insert (
380
- String :: from ( "pkg" ) ,
381
- toml:: Value :: String ( component. name . to_owned ( ) ) ,
382
- ) ;
383
- toml_component. insert (
384
- String :: from ( "target" ) ,
385
- toml:: Value :: String ( component. target . to_owned ( ) ) ,
386
- ) ;
387
- if component. is_extension {
388
- toml_extensions. push ( toml:: Value :: Table ( toml_component) ) ;
389
- } else {
390
- toml_components. push ( toml:: Value :: Table ( toml_component) ) ;
391
- }
381
+ tpkg. components . push ( Component {
382
+ pkg : component. name . to_owned ( ) ,
383
+ target : Some ( TargetTriple :: new ( & component. target ) ) ,
384
+ is_extension : component. is_extension ,
385
+ } ) ;
392
386
}
393
- toml_target. insert (
394
- String :: from ( "components" ) ,
395
- toml:: Value :: Array ( toml_components) ,
396
- ) ;
397
- toml_target. insert (
398
- String :: from ( "extensions" ) ,
399
- toml:: Value :: Array ( toml_extensions) ,
400
- ) ;
401
-
402
- toml_targets. insert ( target. target . clone ( ) , toml:: Value :: Table ( toml_target) ) ;
387
+
388
+ targets. insert ( TargetTriple :: new ( & target. target ) , tpkg) ;
403
389
}
404
- toml_package. insert ( String :: from ( "target" ) , toml:: Value :: Table ( toml_targets) ) ;
405
390
406
- toml_packages. insert ( String :: from ( package. name ) , toml:: Value :: Table ( toml_package) ) ;
391
+ manifest. packages . insert (
392
+ package. name . to_owned ( ) ,
393
+ Package {
394
+ version : package. version . clone ( ) ,
395
+ targets : PackageTargets :: Targeted ( targets) ,
396
+ } ,
397
+ ) ;
407
398
}
408
- toml_manifest. insert ( String :: from ( "pkg" ) , toml:: Value :: Table ( toml_packages) ) ;
409
399
410
- let mut toml_renames = toml:: value:: Table :: new ( ) ;
411
400
for ( from, to) in & channel. renames {
412
- let mut toml_rename = toml :: value :: Table :: new ( ) ;
413
- toml_rename . insert ( String :: from ( "to" ) , toml :: Value :: String ( to . to_owned ( ) ) ) ;
414
- toml_renames . insert ( from. to_owned ( ) , toml :: Value :: Table ( toml_rename ) ) ;
401
+ manifest
402
+ . renames
403
+ . insert ( from. to_owned ( ) , Renamed { to : to . to_owned ( ) } ) ;
415
404
}
416
- toml_manifest. insert ( String :: from ( "renames" ) , toml:: Value :: Table ( toml_renames) ) ;
417
405
418
- let mut toml_profiles = toml:: value:: Table :: new ( ) ;
419
406
let profiles = & [
420
- ( "minimal" , vec ! [ "rustc" ] ) ,
421
- ( "default" , vec ! [ "rustc" , "cargo" , "rust-std" , "rust-docs" ] ) ,
407
+ ( Profile :: Minimal , & [ "rustc" ] [ ..] ) ,
422
408
(
423
- "complete" ,
424
- vec ! [ "rustc" , "cargo" , "rust-std" , "rust-docs" , "rls" ] ,
409
+ Profile :: Default ,
410
+ & [ "rustc" , "cargo" , "rust-std" , "rust-docs" ] ,
411
+ ) ,
412
+ (
413
+ Profile :: Complete ,
414
+ & [ "rustc" , "cargo" , "rust-std" , "rust-docs" , "rls" ] ,
425
415
) ,
426
416
] ;
417
+
427
418
for ( profile, values) in profiles {
428
- let array = values
429
- . iter ( )
430
- . map ( |v| toml:: Value :: String ( ( * * v) . to_owned ( ) ) )
431
- . collect ( ) ;
432
- toml_profiles. insert ( ( * profile) . to_string ( ) , toml:: Value :: Array ( array) ) ;
419
+ manifest
420
+ . profiles
421
+ . insert ( * profile, values. iter ( ) . map ( |& v| v. to_owned ( ) ) . collect ( ) ) ;
433
422
}
434
- toml_manifest. insert ( String :: from ( "profiles" ) , toml:: Value :: Table ( toml_profiles) ) ;
435
423
436
424
let manifest_name = format ! ( "dist/channel-rust-{}" , channel. name) ;
437
425
let manifest_path = self . path . join ( format ! ( "{manifest_name}.toml" ) ) ;
438
- let manifest_content = toml :: to_string ( & toml_manifest ) . unwrap ( ) ;
426
+ let manifest_content = manifest . stringify ( ) . unwrap ( ) ;
439
427
write_file ( & manifest_path, & manifest_content) ;
440
428
441
429
let hash_path = self . path . join ( format ! ( "{manifest_name}.toml.sha256" ) ) ;
0 commit comments