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} ;
@@ -81,15 +82,19 @@ impl DocBuilder {
81
82
82
83
// get_package (and cargo) is using semver, add '=' in front of version.
83
84
let pkg = try!( get_package ( name, Some ( & format ! ( "={}" , version) [ ..] ) ) ) ;
84
- let res = self . build_package_in_chroot ( & pkg) ;
85
+ let metadata = Metadata :: from_package ( & pkg) ?;
86
+ let res = self . build_package_in_chroot ( & pkg, metadata. default_target . clone ( ) ) ;
85
87
86
88
// copy sources and documentation
87
89
let file_list = try!( self . add_sources_into_database ( & conn, & pkg) ) ;
88
90
let successfully_targets = if res. have_doc {
89
- try!( self . copy_documentation ( & pkg, & res. rustc_version , None ) ) ;
91
+ try!( self . copy_documentation ( & pkg,
92
+ & res. rustc_version ,
93
+ metadata. default_target . as_ref ( ) . map ( String :: as_str) ,
94
+ true ) ) ;
90
95
let successfully_targets = self . build_package_for_all_targets ( & pkg) ;
91
96
for target in & successfully_targets {
92
- try!( self . copy_documentation ( & pkg, & res. rustc_version , Some ( target) ) ) ;
97
+ try!( self . copy_documentation ( & pkg, & res. rustc_version , Some ( target) , false ) ) ;
93
98
}
94
99
try!( self . add_documentation_into_database ( & conn, & pkg) ) ;
95
100
successfully_targets
@@ -115,18 +120,19 @@ impl DocBuilder {
115
120
116
121
117
122
/// Builds documentation of a package with cratesfyi in chroot environment
118
- fn build_package_in_chroot ( & self , package : & Package ) -> ChrootBuilderResult {
123
+ fn build_package_in_chroot ( & self , package : & Package , default_target : Option < String > ) -> ChrootBuilderResult {
119
124
debug ! ( "Building package in chroot" ) ;
120
125
let ( rustc_version, cratesfyi_version) = self . get_versions ( ) ;
121
- let cmd = format ! ( "cratesfyi doc {} ={}" ,
126
+ let cmd = format ! ( "cratesfyi doc {} ={} {} " ,
122
127
package. manifest( ) . name( ) ,
123
- package. manifest( ) . version( ) ) ;
128
+ package. manifest( ) . version( ) ,
129
+ default_target. as_ref( ) . unwrap_or( & "" . to_string( ) ) ) ;
124
130
match self . chroot_command ( cmd) {
125
131
Ok ( o) => {
126
132
ChrootBuilderResult {
127
133
output : o,
128
134
build_success : true ,
129
- have_doc : self . have_documentation ( & package) ,
135
+ have_doc : self . have_documentation ( & package, default_target ) ,
130
136
have_examples : self . have_examples ( & package) ,
131
137
rustc_version : rustc_version,
132
138
cratesfyi_version : cratesfyi_version,
@@ -194,22 +200,31 @@ impl DocBuilder {
194
200
fn copy_documentation ( & self ,
195
201
package : & Package ,
196
202
rustc_version : & str ,
197
- target : Option < & str > )
203
+ target : Option < & str > ,
204
+ is_default_target : bool )
198
205
-> Result < ( ) > {
199
206
let crate_doc_path = PathBuf :: from ( & self . options . chroot_path )
200
207
. join ( "home" )
201
208
. join ( & self . options . chroot_user )
202
209
. join ( "cratesfyi" )
203
210
. join ( target. unwrap_or ( "" ) ) ;
204
- let destination = PathBuf :: from ( & self . options . destination )
211
+ let mut destination = PathBuf :: from ( & self . options . destination )
205
212
. join ( format ! ( "{}/{}" ,
206
213
package. manifest( ) . name( ) ,
207
- package. manifest( ) . version( ) ) )
208
- . join ( target. unwrap_or ( "" ) ) ;
214
+ package. manifest( ) . version( ) ) ) ;
215
+
216
+ // only add target name to destination directory when we are copying a non-default target.
217
+ // this is allowing us to host documents in the root of the crate documentation directory.
218
+ // for example win-api will be available in docs.rs/win-api/$version/win-api/ for it's
219
+ // default target: x86_64-pc-windows-msvc. But since it will be built under
220
+ // cratesfyi/x86_64-pc-windows-msvc we still need target in this function.
221
+ if !is_default_target {
222
+ destination. push ( target. unwrap_or ( "" ) ) ;
223
+ }
224
+
209
225
copy_doc_dir ( crate_doc_path,
210
226
destination,
211
- parse_rustc_version ( rustc_version) ?. trim ( ) ,
212
- target. is_some ( ) )
227
+ parse_rustc_version ( rustc_version) ?. trim ( ) )
213
228
}
214
229
215
230
@@ -270,13 +285,18 @@ impl DocBuilder {
270
285
///
271
286
/// This function is checking first target in targets to see if documentation exists for a
272
287
/// crate. Package must be successfully built in chroot environment first.
273
- fn have_documentation ( & self , package : & Package ) -> bool {
274
- let crate_doc_path = PathBuf :: from ( & self . options . chroot_path )
288
+ fn have_documentation ( & self , package : & Package , default_target : Option < String > ) -> bool {
289
+ let mut crate_doc_path = PathBuf :: from ( & self . options . chroot_path )
275
290
. join ( "home" )
276
291
. join ( & self . options . chroot_user )
277
- . join ( "cratesfyi" )
278
- . join ( "doc" )
279
- . join ( package. targets ( ) [ 0 ] . name ( ) . replace ( "-" , "_" ) . to_string ( ) ) ;
292
+ . join ( "cratesfyi" ) ;
293
+
294
+ if let Some ( default_doc_path) = default_target {
295
+ crate_doc_path. push ( default_doc_path) ;
296
+ }
297
+
298
+ crate_doc_path. push ( "doc" ) ;
299
+ crate_doc_path. push ( package. targets ( ) [ 0 ] . name ( ) . replace ( "-" , "_" ) . to_string ( ) ) ;
280
300
crate_doc_path. exists ( )
281
301
}
282
302
@@ -352,7 +372,7 @@ impl DocBuilder {
352
372
353
373
// acme-client-0.0.0 is an empty library crate and it will always build
354
374
let pkg = try!( get_package ( "acme-client" , Some ( "=0.0.0" ) ) ) ;
355
- let res = self . build_package_in_chroot ( & pkg) ;
375
+ let res = self . build_package_in_chroot ( & pkg, None ) ;
356
376
let rustc_version = parse_rustc_version ( & res. rustc_version ) ?;
357
377
358
378
if !res. build_success {
0 commit comments