1
1
2
2
use super :: DocBuilder ;
3
3
use super :: crates:: crates_from_path;
4
+ use super :: metadata:: Metadata ;
4
5
use utils:: { get_package, source_path, copy_dir, copy_doc_dir,
5
6
update_sources, parse_rustc_version, command_result} ;
6
7
use db:: { connect_db, add_package_into_database, add_build_into_database, add_path_into_database} ;
@@ -79,15 +80,19 @@ impl DocBuilder {
79
80
80
81
// get_package (and cargo) is using semver, add '=' in front of version.
81
82
let pkg = try!( get_package ( name, Some ( & format ! ( "={}" , version) [ ..] ) ) ) ;
82
- let res = self . build_package_in_chroot ( & pkg) ;
83
+ let metadata = Metadata :: from_package ( & pkg) ?;
84
+ let res = self . build_package_in_chroot ( & pkg, metadata. default_target . clone ( ) ) ;
83
85
84
86
// copy sources and documentation
85
87
let file_list = try!( self . add_sources_into_database ( & conn, & pkg) ) ;
86
88
let successfully_targets = if res. have_doc {
87
- try!( self . copy_documentation ( & pkg, & res. rustc_version , None ) ) ;
89
+ try!( self . copy_documentation ( & pkg,
90
+ & res. rustc_version ,
91
+ metadata. default_target . as_ref ( ) . map ( String :: as_str) ,
92
+ true ) ) ;
88
93
let successfully_targets = self . build_package_for_all_targets ( & pkg) ;
89
94
for target in & successfully_targets {
90
- try!( self . copy_documentation ( & pkg, & res. rustc_version , Some ( target) ) ) ;
95
+ try!( self . copy_documentation ( & pkg, & res. rustc_version , Some ( target) , false ) ) ;
91
96
}
92
97
try!( self . add_documentation_into_database ( & conn, & pkg) ) ;
93
98
successfully_targets
@@ -113,18 +118,19 @@ impl DocBuilder {
113
118
114
119
115
120
/// Builds documentation of a package with cratesfyi in chroot environment
116
- fn build_package_in_chroot ( & self , package : & Package ) -> ChrootBuilderResult {
121
+ fn build_package_in_chroot ( & self , package : & Package , default_target : Option < String > ) -> ChrootBuilderResult {
117
122
debug ! ( "Building package in chroot" ) ;
118
123
let ( rustc_version, cratesfyi_version) = self . get_versions ( ) ;
119
- let cmd = format ! ( "cratesfyi doc {} ={}" ,
124
+ let cmd = format ! ( "cratesfyi doc {} ={} {} " ,
120
125
package. manifest( ) . name( ) ,
121
- package. manifest( ) . version( ) ) ;
126
+ package. manifest( ) . version( ) ,
127
+ default_target. as_ref( ) . unwrap_or( & "" . to_string( ) ) ) ;
122
128
match self . chroot_command ( cmd) {
123
129
Ok ( o) => {
124
130
ChrootBuilderResult {
125
131
output : o,
126
132
build_success : true ,
127
- have_doc : self . have_documentation ( & package) ,
133
+ have_doc : self . have_documentation ( & package, default_target ) ,
128
134
have_examples : self . have_examples ( & package) ,
129
135
rustc_version : rustc_version,
130
136
cratesfyi_version : cratesfyi_version,
@@ -192,22 +198,38 @@ impl DocBuilder {
192
198
fn copy_documentation ( & self ,
193
199
package : & Package ,
194
200
rustc_version : & str ,
195
- target : Option < & str > )
201
+ target : Option < & str > ,
202
+ is_default_target : bool )
196
203
-> Result < ( ) > {
197
- let crate_doc_path = PathBuf :: from ( & self . options . chroot_path )
204
+ let mut crate_doc_path = PathBuf :: from ( & self . options . chroot_path )
198
205
. join ( "home" )
199
206
. join ( & self . options . chroot_user )
200
- . join ( "cratesfyi" )
201
- . join ( target. unwrap_or ( "" ) ) ;
202
- let destination = PathBuf :: from ( & self . options . destination )
207
+ . join ( "cratesfyi" ) ;
208
+
209
+ // docs are available in cratesfyi/$TARGET when target is being used
210
+ if let Some ( target) = target {
211
+ crate_doc_path. push ( target) ;
212
+ }
213
+
214
+ let mut destination = PathBuf :: from ( & self . options . destination )
203
215
. join ( format ! ( "{}/{}" ,
204
216
package. manifest( ) . name( ) ,
205
- package. manifest( ) . version( ) ) )
206
- . join ( target. unwrap_or ( "" ) ) ;
217
+ package. manifest( ) . version( ) ) ) ;
218
+
219
+ // only add target name to destination directory when we are copying a non-default target.
220
+ // this is allowing us to host documents in the root of the crate documentation directory.
221
+ // for example winapi will be available in docs.rs/winapi/$version/winapi/ for it's
222
+ // default target: x86_64-pc-windows-msvc. But since it will be built under
223
+ // cratesfyi/x86_64-pc-windows-msvc we still need target in this function.
224
+ if !is_default_target {
225
+ if let Some ( target) = target {
226
+ destination. push ( target) ;
227
+ }
228
+ }
229
+
207
230
copy_doc_dir ( crate_doc_path,
208
231
destination,
209
- parse_rustc_version ( rustc_version) ?. trim ( ) ,
210
- target. is_some ( ) )
232
+ parse_rustc_version ( rustc_version) ?. trim ( ) )
211
233
}
212
234
213
235
@@ -268,13 +290,18 @@ impl DocBuilder {
268
290
///
269
291
/// This function is checking first target in targets to see if documentation exists for a
270
292
/// crate. Package must be successfully built in chroot environment first.
271
- fn have_documentation ( & self , package : & Package ) -> bool {
272
- let crate_doc_path = PathBuf :: from ( & self . options . chroot_path )
293
+ fn have_documentation ( & self , package : & Package , default_target : Option < String > ) -> bool {
294
+ let mut crate_doc_path = PathBuf :: from ( & self . options . chroot_path )
273
295
. join ( "home" )
274
296
. join ( & self . options . chroot_user )
275
- . join ( "cratesfyi" )
276
- . join ( "doc" )
277
- . join ( package. targets ( ) [ 0 ] . name ( ) . replace ( "-" , "_" ) . to_string ( ) ) ;
297
+ . join ( "cratesfyi" ) ;
298
+
299
+ if let Some ( default_doc_path) = default_target {
300
+ crate_doc_path. push ( default_doc_path) ;
301
+ }
302
+
303
+ crate_doc_path. push ( "doc" ) ;
304
+ crate_doc_path. push ( package. targets ( ) [ 0 ] . name ( ) . replace ( "-" , "_" ) . to_string ( ) ) ;
278
305
crate_doc_path. exists ( )
279
306
}
280
307
@@ -350,7 +377,7 @@ impl DocBuilder {
350
377
351
378
// acme-client-0.0.0 is an empty library crate and it will always build
352
379
let pkg = try!( get_package ( "acme-client" , Some ( "=0.0.0" ) ) ) ;
353
- let res = self . build_package_in_chroot ( & pkg) ;
380
+ let res = self . build_package_in_chroot ( & pkg, None ) ;
354
381
let rustc_version = parse_rustc_version ( & res. rustc_version ) ?;
355
382
356
383
if !res. build_success {
0 commit comments