@@ -21,7 +21,7 @@ use super::Metadata;
21
21
const USER_AGENT : & str = "docs.rs builder (https://github.com/rust-lang/docs.rs)" ;
22
22
const DEFAULT_RUSTWIDE_WORKSPACE : & str = ".rustwide" ;
23
23
24
- const DEFAULT_TARGET : & str = "x86_64-unknown-linux-gnu" ;
24
+ pub ( super ) const DEFAULT_TARGET : & str = "x86_64-unknown-linux-gnu" ;
25
25
pub ( super ) const TARGETS : & [ & str ] = & [
26
26
"i686-pc-windows-msvc" ,
27
27
"i686-unknown-linux-gnu" ,
@@ -190,7 +190,8 @@ impl RustwideBuilder {
190
190
. build ( & self . toolchain , & krate, sandbox)
191
191
. run ( |build| {
192
192
let metadata = Metadata :: from_source_dir ( & build. host_source_dir ( ) ) ?;
193
- let res = self . execute_build ( None , build, & limits, & metadata) ?;
193
+
194
+ let res = self . execute_build ( DEFAULT_TARGET , true , build, & limits, & metadata) ?;
194
195
if !res. result . successful {
195
196
bail ! ( "failed to build dummy crate for {}" , self . rustc_version) ;
196
197
}
@@ -314,9 +315,10 @@ impl RustwideBuilder {
314
315
let mut has_docs = false ;
315
316
let mut successful_targets = Vec :: new ( ) ;
316
317
let metadata = Metadata :: from_source_dir ( & build. host_source_dir ( ) ) ?;
318
+ let ( default_target, other_targets) = metadata. select_extra_targets ( ) ;
317
319
318
320
// Do an initial build and then copy the sources in the database
319
- let res = self . execute_build ( None , & build, & limits, & metadata) ?;
321
+ let res = self . execute_build ( default_target , true , & build, & limits, & metadata) ?;
320
322
if res. result . successful {
321
323
debug ! ( "adding sources into database" ) ;
322
324
let prefix = format ! ( "sources/{}/{}" , name, version) ;
@@ -342,10 +344,9 @@ impl RustwideBuilder {
342
344
) ?;
343
345
344
346
successful_targets. push ( res. target . clone ( ) ) ;
345
- let targets = metadata. select_extra_targets ( & res. target ) ;
346
347
347
348
// Then build the documentation for all the targets
348
- for target in targets {
349
+ for target in other_targets {
349
350
debug ! ( "building package {} {} for {}" , name, version, target) ;
350
351
self . build_target (
351
352
target,
@@ -400,7 +401,7 @@ impl RustwideBuilder {
400
401
successful_targets : & mut Vec < String > ,
401
402
metadata : & Metadata ,
402
403
) -> Result < ( ) > {
403
- let target_res = self . execute_build ( Some ( target) , build, limits, metadata) ?;
404
+ let target_res = self . execute_build ( target, false , build, limits, metadata) ?;
404
405
if target_res. result . successful {
405
406
// Cargo is not giving any error and not generating documentation of some crates
406
407
// when we use a target compile options. Check documentation exists before
@@ -416,17 +417,15 @@ impl RustwideBuilder {
416
417
417
418
fn execute_build (
418
419
& self ,
419
- target : Option < & str > ,
420
+ target : & str ,
421
+ is_default_target : bool ,
420
422
build : & Build ,
421
423
limits : & Limits ,
422
424
metadata : & Metadata ,
423
425
) -> Result < FullBuildResult > {
424
426
let cargo_metadata =
425
427
CargoMetadata :: load ( & self . workspace , & self . toolchain , & build. host_source_dir ( ) ) ?;
426
428
427
- let is_default_target = target. is_none ( ) ;
428
- let target = target. or_else ( || metadata. default_target . as_ref ( ) . map ( |s| s. as_str ( ) ) ) ;
429
-
430
429
let mut rustdoc_flags: Vec < String > = vec ! [
431
430
"-Z" . to_string( ) ,
432
431
"unstable-options" . to_string( ) ,
@@ -448,9 +447,9 @@ impl RustwideBuilder {
448
447
rustdoc_flags. append ( & mut package_rustdoc_args. iter ( ) . map ( |s| s. to_owned ( ) ) . collect ( ) ) ;
449
448
}
450
449
let mut cargo_args = vec ! [ "doc" . to_owned( ) , "--lib" . to_owned( ) , "--no-deps" . to_owned( ) ] ;
451
- if let Some ( explicit_target ) = target {
450
+ if target != DEFAULT_TARGET {
452
451
cargo_args. push ( "--target" . to_owned ( ) ) ;
453
- cargo_args. push ( explicit_target . to_owned ( ) ) ;
452
+ cargo_args. push ( target . to_owned ( ) ) ;
454
453
} ;
455
454
if let Some ( features) = & metadata. features {
456
455
cargo_args. push ( "--features" . to_owned ( ) ) ;
@@ -488,15 +487,13 @@ impl RustwideBuilder {
488
487
// cargo will put the output in `target/<target>/doc`.
489
488
// However, if this is the default build, we don't want it there,
490
489
// we want it in `target/doc`.
491
- if let Some ( explicit_target) = target {
492
- if is_default_target {
493
- // mv target/$explicit_target/doc target/doc
494
- let target_dir = build. host_target_dir ( ) ;
495
- let old_dir = target_dir. join ( explicit_target) . join ( "doc" ) ;
496
- let new_dir = target_dir. join ( "doc" ) ;
497
- debug ! ( "rename {} to {}" , old_dir. display( ) , new_dir. display( ) ) ;
498
- std:: fs:: rename ( old_dir, new_dir) ?;
499
- }
490
+ if target != DEFAULT_TARGET && is_default_target {
491
+ // mv target/target/doc target/doc
492
+ let target_dir = build. host_target_dir ( ) ;
493
+ let old_dir = target_dir. join ( target) . join ( "doc" ) ;
494
+ let new_dir = target_dir. join ( "doc" ) ;
495
+ debug ! ( "rename {} to {}" , old_dir. display( ) , new_dir. display( ) ) ;
496
+ std:: fs:: rename ( old_dir, new_dir) ?;
500
497
}
501
498
502
499
Ok ( FullBuildResult {
@@ -507,7 +504,7 @@ impl RustwideBuilder {
507
504
successful,
508
505
} ,
509
506
cargo_metadata,
510
- target : target. unwrap_or ( DEFAULT_TARGET ) . to_string ( ) ,
507
+ target : target. to_string ( ) ,
511
508
} )
512
509
}
513
510
0 commit comments