@@ -9,10 +9,19 @@ pub(crate) struct Manifest {
99 pub ( crate ) manifest_version : String ,
1010 pub ( crate ) date : String ,
1111 pub ( crate ) pkg : BTreeMap < String , Package > ,
12+ pub ( crate ) artifacts : BTreeMap < String , Artifact > ,
1213 pub ( crate ) renames : BTreeMap < String , Rename > ,
1314 pub ( crate ) profiles : BTreeMap < String , Vec < String > > ,
1415}
1516
17+ impl Manifest {
18+ pub ( crate ) fn add_artifact ( & mut self , name : & str , f : impl FnOnce ( & mut Artifact ) ) {
19+ let mut artifact = Artifact { target : BTreeMap :: new ( ) } ;
20+ f ( & mut artifact) ;
21+ self . artifacts . insert ( name. to_string ( ) , artifact) ;
22+ }
23+ }
24+
1625#[ derive( Serialize ) ]
1726pub ( crate ) struct Package {
1827 pub ( crate ) version : String ,
@@ -25,6 +34,42 @@ pub(crate) struct Rename {
2534 pub ( crate ) to : String ,
2635}
2736
37+ #[ derive( Serialize ) ]
38+ pub ( crate ) struct Artifact {
39+ pub ( crate ) target : BTreeMap < String , Vec < ArtifactFile > > ,
40+ }
41+
42+ impl Artifact {
43+ pub ( crate ) fn add_file ( & mut self , builder : & mut Builder , target : & str , path : & str ) {
44+ if let Some ( path) = record_shipped_file ( builder, builder. input . join ( path) ) {
45+ self . target . entry ( target. into ( ) ) . or_insert_with ( Vec :: new) . push ( ArtifactFile {
46+ url : builder. url ( & path) ,
47+ hash_sha256 : FileHash :: Missing ( path) ,
48+ } ) ;
49+ }
50+ }
51+
52+ pub ( crate ) fn add_tarball ( & mut self , builder : & mut Builder , target : & str , base_path : & str ) {
53+ let files = self . target . entry ( target. into ( ) ) . or_insert_with ( Vec :: new) ;
54+ let base_path = builder. input . join ( base_path) ;
55+ for compression in & [ "gz" , "xz" ] {
56+ if let Some ( tarball) = tarball_variant ( builder, & base_path, compression) {
57+ files. push ( ArtifactFile {
58+ url : builder. url ( & tarball) ,
59+ hash_sha256 : FileHash :: Missing ( tarball) ,
60+ } ) ;
61+ }
62+ }
63+ }
64+ }
65+
66+ #[ derive( Serialize ) ]
67+ #[ serde( rename_all = "kebab-case" ) ]
68+ pub ( crate ) struct ArtifactFile {
69+ pub ( crate ) url : String ,
70+ pub ( crate ) hash_sha256 : FileHash ,
71+ }
72+
2873#[ derive( Serialize , Default ) ]
2974pub ( crate ) struct Target {
3075 pub ( crate ) available : bool ,
@@ -39,8 +84,8 @@ pub(crate) struct Target {
3984impl Target {
4085 pub ( crate ) fn from_compressed_tar ( builder : & mut Builder , base_path : & str ) -> Self {
4186 let base_path = builder. input . join ( base_path) ;
42- let gz = Self :: tarball_variant ( builder, & base_path, "gz" ) ;
43- let xz = Self :: tarball_variant ( builder, & base_path, "xz" ) ;
87+ let gz = tarball_variant ( builder, & base_path, "gz" ) ;
88+ let xz = tarball_variant ( builder, & base_path, "xz" ) ;
4489
4590 if gz. is_none ( ) {
4691 return Self :: unavailable ( ) ;
@@ -59,23 +104,6 @@ impl Target {
59104 }
60105 }
61106
62- fn tarball_variant ( builder : & mut Builder , base : & Path , ext : & str ) -> Option < PathBuf > {
63- let mut path = base. to_path_buf ( ) ;
64- path. set_extension ( ext) ;
65- if path. is_file ( ) {
66- builder. shipped_files . insert (
67- path. file_name ( )
68- . expect ( "missing filename" )
69- . to_str ( )
70- . expect ( "non-utf-8 filename" )
71- . to_string ( ) ,
72- ) ;
73- Some ( path)
74- } else {
75- None
76- }
77- }
78-
79107 pub ( crate ) fn unavailable ( ) -> Self {
80108 Self :: default ( )
81109 }
@@ -111,6 +139,27 @@ impl Serialize for FileHash {
111139 }
112140}
113141
142+ fn tarball_variant ( builder : & mut Builder , base : & Path , ext : & str ) -> Option < PathBuf > {
143+ let mut path = base. to_path_buf ( ) ;
144+ path. set_extension ( ext) ;
145+ record_shipped_file ( builder, path)
146+ }
147+
148+ fn record_shipped_file ( builder : & mut Builder , path : PathBuf ) -> Option < PathBuf > {
149+ if path. is_file ( ) {
150+ builder. shipped_files . insert (
151+ path. file_name ( )
152+ . expect ( "missing filename" )
153+ . to_str ( )
154+ . expect ( "non-utf-8 filename" )
155+ . to_string ( ) ,
156+ ) ;
157+ Some ( path)
158+ } else {
159+ None
160+ }
161+ }
162+
114163pub ( crate ) fn visit_file_hashes ( manifest : & mut Manifest , mut f : impl FnMut ( & mut FileHash ) ) {
115164 for pkg in manifest. pkg . values_mut ( ) {
116165 for target in pkg. target . values_mut ( ) {
@@ -122,4 +171,12 @@ pub(crate) fn visit_file_hashes(manifest: &mut Manifest, mut f: impl FnMut(&mut
122171 }
123172 }
124173 }
174+
175+ for artifact in manifest. artifacts . values_mut ( ) {
176+ for target in artifact. target . values_mut ( ) {
177+ for file in target {
178+ f ( & mut file. hash_sha256 ) ;
179+ }
180+ }
181+ }
125182}
0 commit comments