@@ -71,12 +71,23 @@ impl DocBuilder {
71
71
72
72
// copy sources and documentation
73
73
let file_list = try!( self . add_sources_into_database ( & conn, & pkg) ) ;
74
- if res. have_doc {
75
- try!( self . copy_documentation ( & pkg, & res. rustc_version ) ) ;
74
+ let successfully_targets = if res. have_doc {
75
+ try!( self . copy_documentation ( & pkg, & res. rustc_version , None ) ) ;
76
+ let successfully_targets = self . build_package_for_all_targets ( & pkg) ;
77
+ for target in & successfully_targets {
78
+ try!( self . copy_documentation ( & pkg, & res. rustc_version , Some ( target) ) ) ;
79
+ }
76
80
try!( self . add_documentation_into_database ( & conn, & pkg) ) ;
77
- }
78
-
79
- let release_id = try!( add_package_into_database ( & conn, & pkg, & res, Some ( file_list) ) ) ;
81
+ successfully_targets
82
+ } else {
83
+ Vec :: new ( )
84
+ } ;
85
+
86
+ let release_id = try!( add_package_into_database ( & conn,
87
+ & pkg,
88
+ & res,
89
+ Some ( file_list) ,
90
+ successfully_targets) ) ;
80
91
try!( add_build_into_database ( & conn, & release_id, & res) ) ;
81
92
82
93
// remove documentation, source and build directory after we are done
@@ -121,13 +132,70 @@ impl DocBuilder {
121
132
}
122
133
123
134
135
+
136
+ /// Builds documentation of crate for every target and returns Vec of successfully targets
137
+ fn build_package_for_all_targets ( & self , package : & Package ) -> Vec < String > {
138
+ let targets = [ "aarch64-apple-ios" ,
139
+ "aarch64-linux-android" ,
140
+ "aarch64-unknown-linux-gnu" ,
141
+ "arm-linux-androideabi" ,
142
+ "arm-unknown-linux-gnueabi" ,
143
+ "arm-unknown-linux-gnueabihf" ,
144
+ "armv7-apple-ios" ,
145
+ "armv7-linux-androideabi" ,
146
+ "armv7-unknown-linux-gnueabihf" ,
147
+ "armv7s-apple-ios" ,
148
+ "i386-apple-ios" ,
149
+ "i586-pc-windows-msvc" ,
150
+ "i586-unknown-linux-gnu" ,
151
+ "i686-apple-darwin" ,
152
+ "i686-linux-android" ,
153
+ "i686-pc-windows-gnu" ,
154
+ "i686-pc-windows-msvc" ,
155
+ "i686-unknown-freebsd" ,
156
+ "i686-unknown-linux-gnu" ,
157
+ "i686-unknown-linux-musl" ,
158
+ "mips-unknown-linux-gnu" ,
159
+ "mips-unknown-linux-musl" ,
160
+ "mipsel-unknown-linux-gnu" ,
161
+ "mipsel-unknown-linux-musl" ,
162
+ "powerpc-unknown-linux-gnu" ,
163
+ "powerpc64-unknown-linux-gnu" ,
164
+ "powerpc64le-unknown-linux-gnu" ,
165
+ "x86_64-apple-darwin" ,
166
+ "x86_64-apple-ios" ,
167
+ "x86_64-pc-windows-gnu" ,
168
+ "x86_64-pc-windows-msvc" ,
169
+ "x86_64-rumprun-netbsd" ,
170
+ "x86_64-unknown-freebsd" ,
171
+ "x86_64-unknown-linux-gnu" ,
172
+ "x86_64-unknown-linux-musl" ,
173
+ "x86_64-unknown-netbsd" ] ;
174
+
175
+ let mut successfuly_targets = Vec :: new ( ) ;
176
+
177
+ for target in targets. iter ( ) {
178
+ debug ! ( "Building {} for {}" , canonical_name( & package) , target) ;
179
+ let cmd = format ! ( "cratesfyi doc {} ={} {}" ,
180
+ package. manifest( ) . name( ) ,
181
+ package. manifest( ) . version( ) ,
182
+ target) ;
183
+ if let Ok ( _) = self . chroot_command ( cmd) {
184
+ successfuly_targets. push ( target. to_string ( ) ) ;
185
+ }
186
+ }
187
+ successfuly_targets
188
+ }
189
+
190
+
124
191
/// Copies source files of a package into source_path
125
192
#[ allow( dead_code) ] // I've been using this function before storing files in database
126
193
fn copy_sources ( & self , package : & Package ) -> Result < ( ) , DocBuilderError > {
127
194
debug ! ( "Copying sources" ) ;
128
- let destination = PathBuf :: from ( & self . options . sources_path ) . join ( format ! ( "{}/{}" ,
129
- package. manifest( ) . name( ) ,
130
- package. manifest( ) . version( ) ) ) ;
195
+ let destination =
196
+ PathBuf :: from ( & self . options . sources_path ) . join ( format ! ( "{}/{}" ,
197
+ package. manifest( ) . name( ) ,
198
+ package. manifest( ) . version( ) ) ) ;
131
199
// unwrap is safe here, this function will be always called after get_package
132
200
match copy_dir ( source_path ( & package) . unwrap ( ) , & destination) {
133
201
Ok ( _) => Ok ( ( ) ) ,
@@ -139,19 +207,23 @@ impl DocBuilder {
139
207
/// Copies documentation to destination directory
140
208
fn copy_documentation ( & self ,
141
209
package : & Package ,
142
- rustc_version : & str )
210
+ rustc_version : & str ,
211
+ target : Option < & str > )
143
212
-> Result < ( ) , DocBuilderError > {
144
- debug ! ( "Copying documentation" ) ;
145
213
let crate_doc_path = PathBuf :: from ( & self . options . chroot_path )
146
- . join ( "home" )
147
- . join ( & self . options . chroot_user )
148
- . join ( canonical_name ( & package) ) ;
149
- let destination = PathBuf :: from ( & self . options . destination ) . join ( format ! ( "{}/{}" ,
214
+ . join ( "home" )
215
+ . join ( & self . options . chroot_user )
216
+ . join ( canonical_name ( & package) )
217
+ . join ( target. unwrap_or ( "" ) ) ;
218
+ let destination = PathBuf :: from ( & self . options . destination )
219
+ . join ( format ! ( "{}/{}" ,
150
220
package. manifest( ) . name( ) ,
151
- package. manifest( ) . version( ) ) ) ;
221
+ package. manifest( ) . version( ) ) )
222
+ . join ( target. unwrap_or ( "" ) ) ;
152
223
copy_doc_dir ( crate_doc_path,
153
224
destination,
154
- parse_rustc_version ( rustc_version) . trim ( ) )
225
+ parse_rustc_version ( rustc_version) . trim ( ) ,
226
+ target. is_some ( ) )
155
227
. map_err ( DocBuilderError :: Io )
156
228
}
157
229
@@ -168,7 +240,7 @@ impl DocBuilder {
168
240
debug ! ( "Cleaning package" ) ;
169
241
use std:: fs:: remove_dir_all;
170
242
let documentation_path = PathBuf :: from ( & self . options . destination )
171
- . join ( package. manifest ( ) . name ( ) ) ;
243
+ . join ( package. manifest ( ) . name ( ) ) ;
172
244
let source_path = source_path ( & package) . unwrap ( ) ;
173
245
// Some crates don't have documentation, so we don't care if removing_dir_all fails
174
246
let _ = self . remove_build_dir ( & package) ;
@@ -181,17 +253,17 @@ impl DocBuilder {
181
253
/// Runs a command in a chroot environment
182
254
fn chroot_command < T : AsRef < str > > ( & self , cmd : T ) -> CommandResult {
183
255
command_result ( Command :: new ( "sudo" )
184
- . arg ( "lxc-attach" )
185
- . arg ( "-n" )
186
- . arg ( & self . options . container_name )
187
- . arg ( "--" )
188
- . arg ( "su" )
189
- . arg ( "-" )
190
- . arg ( & self . options . chroot_user )
191
- . arg ( "-c" )
192
- . arg ( cmd. as_ref ( ) )
193
- . output ( )
194
- . unwrap ( ) )
256
+ . arg ( "lxc-attach" )
257
+ . arg ( "-n" )
258
+ . arg ( & self . options . container_name )
259
+ . arg ( "--" )
260
+ . arg ( "su" )
261
+ . arg ( "-" )
262
+ . arg ( & self . options . chroot_user )
263
+ . arg ( "-c" )
264
+ . arg ( cmd. as_ref ( ) )
265
+ . output ( )
266
+ . unwrap ( ) )
195
267
}
196
268
197
269
@@ -201,11 +273,11 @@ impl DocBuilder {
201
273
/// crate. Package must be successfully built in chroot environment first.
202
274
fn have_documentation ( & self , package : & Package ) -> bool {
203
275
let crate_doc_path = PathBuf :: from ( & self . options . chroot_path )
204
- . join ( "home" )
205
- . join ( & self . options . chroot_user )
206
- . join ( canonical_name ( & package) )
207
- . join ( "doc" )
208
- . join ( package. targets ( ) [ 0 ] . name ( ) . to_string ( ) ) ;
276
+ . join ( "home" )
277
+ . join ( & self . options . chroot_user )
278
+ . join ( canonical_name ( & package) )
279
+ . join ( "doc" )
280
+ . join ( package. targets ( ) [ 0 ] . name ( ) . to_string ( ) ) ;
209
281
crate_doc_path. exists ( )
210
282
}
211
283
@@ -222,11 +294,11 @@ impl DocBuilder {
222
294
// It is safe to use expect here
223
295
// chroot environment must always have rustc and cratesfyi installed
224
296
( String :: from ( self . chroot_command ( "rustc --version" )
225
- . expect ( "Failed to get rustc version" )
226
- . trim ( ) ) ,
297
+ . expect ( "Failed to get rustc version" )
298
+ . trim ( ) ) ,
227
299
String :: from ( self . chroot_command ( "cratesfyi --version" )
228
- . expect ( "Failed to get cratesfyi version" )
229
- . trim ( ) ) )
300
+ . expect ( "Failed to get cratesfyi version" )
301
+ . trim ( ) ) )
230
302
}
231
303
232
304
0 commit comments