@@ -11,6 +11,12 @@ use once_cell::sync::Lazy;
1111use sha2:: { Digest , Sha256 } ;
1212use url:: Url ;
1313
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+
1420use super :: clitools:: hard_link;
1521use super :: MockInstallerBuilder ;
1622
@@ -118,14 +124,14 @@ pub struct MockHashes {
118124 pub zst : Option < String > ,
119125}
120126
121- pub enum ManifestVersion {
127+ pub enum MockManifestVersion {
122128 V1 ,
123129 V2 ,
124130}
125131
126132impl MockDistServer {
127133 #[ 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 ) {
129135 fs:: create_dir_all ( & self . path ) . unwrap ( ) ;
130136
131137 for channel in self . channels . iter ( ) {
@@ -136,8 +142,8 @@ impl MockDistServer {
136142 }
137143 for v in vs {
138144 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) ,
141147 }
142148 }
143149 }
@@ -306,136 +312,118 @@ impl MockDistServer {
306312 channel : & MockChannel ,
307313 hashes : & HashMap < MockComponent , MockHashes > ,
308314 ) {
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+ } ;
319323
320324 // [pkg.*]
321- let mut toml_packages = toml:: value:: Table :: new ( ) ;
322325 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 ( ) ;
328327
329328 // [pkg.*.target.*]
330- let mut toml_targets = toml:: value:: Table :: new ( ) ;
331329 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+ } ;
337334
338335 let package_file_name = if target. target != "*" {
339336 format ! ( "{}-{}-{}.tar.gz" , package. name, channel. name, target. target)
340337 } else {
341338 format ! ( "{}-{}.tar.gz" , package. name, channel. name)
342339 } ;
340+
343341 let path = self
344342 . path
345343 . join ( "dist" )
346344 . join ( & channel. date )
347345 . 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 ( ) ) ) ;
350346
351347 let component = MockComponent {
352348 name : package. name . to_owned ( ) ,
353349 target : target. target . to_owned ( ) ,
354350 is_extension : false ,
355351 } ;
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+ }
372377 }
373378
374379 // [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 ( ) ;
377380 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+ } ) ;
392386 }
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) ;
403389 }
404- toml_package. insert ( String :: from ( "target" ) , toml:: Value :: Table ( toml_targets) ) ;
405390
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+ ) ;
407398 }
408- toml_manifest. insert ( String :: from ( "pkg" ) , toml:: Value :: Table ( toml_packages) ) ;
409399
410- let mut toml_renames = toml:: value:: Table :: new ( ) ;
411400 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 ( ) } ) ;
415404 }
416- toml_manifest. insert ( String :: from ( "renames" ) , toml:: Value :: Table ( toml_renames) ) ;
417405
418- let mut toml_profiles = toml:: value:: Table :: new ( ) ;
419406 let profiles = & [
420- ( "minimal" , vec ! [ "rustc" ] ) ,
421- ( "default" , vec ! [ "rustc" , "cargo" , "rust-std" , "rust-docs" ] ) ,
407+ ( Profile :: Minimal , & [ "rustc" ] [ ..] ) ,
422408 (
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" ] ,
425415 ) ,
426416 ] ;
417+
427418 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 ( ) ) ;
433422 }
434- toml_manifest. insert ( String :: from ( "profiles" ) , toml:: Value :: Table ( toml_profiles) ) ;
435423
436424 let manifest_name = format ! ( "dist/channel-rust-{}" , channel. name) ;
437425 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 ( ) ;
439427 write_file ( & manifest_path, & manifest_content) ;
440428
441429 let hash_path = self . path . join ( format ! ( "{manifest_name}.toml.sha256" ) ) ;
0 commit comments