@@ -9,10 +9,19 @@ pub(crate) struct Manifest {
9
9
pub ( crate ) manifest_version : String ,
10
10
pub ( crate ) date : String ,
11
11
pub ( crate ) pkg : BTreeMap < String , Package > ,
12
+ pub ( crate ) artifacts : BTreeMap < String , Artifact > ,
12
13
pub ( crate ) renames : BTreeMap < String , Rename > ,
13
14
pub ( crate ) profiles : BTreeMap < String , Vec < String > > ,
14
15
}
15
16
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
+
16
25
#[ derive( Serialize ) ]
17
26
pub ( crate ) struct Package {
18
27
pub ( crate ) version : String ,
@@ -25,6 +34,42 @@ pub(crate) struct Rename {
25
34
pub ( crate ) to : String ,
26
35
}
27
36
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
+
28
73
#[ derive( Serialize , Default ) ]
29
74
pub ( crate ) struct Target {
30
75
pub ( crate ) available : bool ,
@@ -39,8 +84,8 @@ pub(crate) struct Target {
39
84
impl Target {
40
85
pub ( crate ) fn from_compressed_tar ( builder : & mut Builder , base_path : & str ) -> Self {
41
86
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" ) ;
44
89
45
90
if gz. is_none ( ) {
46
91
return Self :: unavailable ( ) ;
@@ -59,23 +104,6 @@ impl Target {
59
104
}
60
105
}
61
106
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
-
79
107
pub ( crate ) fn unavailable ( ) -> Self {
80
108
Self :: default ( )
81
109
}
@@ -111,6 +139,27 @@ impl Serialize for FileHash {
111
139
}
112
140
}
113
141
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
+
114
163
pub ( crate ) fn visit_file_hashes ( manifest : & mut Manifest , mut f : impl FnMut ( & mut FileHash ) ) {
115
164
for pkg in manifest. pkg . values_mut ( ) {
116
165
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
122
171
}
123
172
}
124
173
}
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
+ }
125
182
}
0 commit comments