@@ -22,6 +22,20 @@ use crate::compile;
2222use crate :: cache:: { INTERNER , Interned } ;
2323use crate :: config:: Config ;
2424
25+ fn doc_dir (
26+ builder : & Builder < ' _ > ,
27+ compiler : Compiler ,
28+ target : Interned < String > ,
29+ mode : Mode ,
30+ ) -> PathBuf {
31+ let compiler = if builder. force_use_stage1 ( compiler, target) {
32+ builder. compiler ( 1 , compiler. host )
33+ } else {
34+ compiler
35+ } ;
36+ builder. stage_out ( compiler, mode) . join ( target) . join ( "doc" )
37+ }
38+
2539macro_rules! book {
2640 ( $( $name: ident, $path: expr, $book_name: expr, $book_ver: expr; ) +) => {
2741 $(
@@ -476,15 +490,9 @@ impl Step for Std {
476490 let out = builder. doc_out ( target) ;
477491 t ! ( fs:: create_dir_all( & out) ) ;
478492 let compiler = builder. compiler ( stage, builder. config . build ) ;
479- let compiler = if builder. force_use_stage1 ( compiler, target) {
480- builder. compiler ( 1 , compiler. host )
481- } else {
482- compiler
483- } ;
484493
485494 builder. ensure ( compile:: Std { compiler, target } ) ;
486- let out_dir = builder. stage_out ( compiler, Mode :: Std )
487- . join ( target) . join ( "doc" ) ;
495+ let out_dir = doc_dir ( builder, compiler, target, Mode :: Std ) ;
488496
489497 // Here what we're doing is creating a *symlink* (directory junction on
490498 // Windows) to the final output location. This is not done as an
@@ -564,18 +572,12 @@ impl Step for Test {
564572 let out = builder. doc_out ( target) ;
565573 t ! ( fs:: create_dir_all( & out) ) ;
566574 let compiler = builder. compiler ( stage, builder. config . build ) ;
567- let compiler = if builder. force_use_stage1 ( compiler, target) {
568- builder. compiler ( 1 , compiler. host )
569- } else {
570- compiler
571- } ;
572575
573576 // Build libstd docs so that we generate relative links
574577 builder. ensure ( Std { stage, target } ) ;
575578
576579 builder. ensure ( compile:: Test { compiler, target } ) ;
577- let out_dir = builder. stage_out ( compiler, Mode :: Test )
578- . join ( target) . join ( "doc" ) ;
580+ let out_dir = doc_dir ( builder, compiler, target, Mode :: Test ) ;
579581
580582 // See docs in std above for why we symlink
581583 let my_out = builder. crate_doc_out ( target) ;
@@ -633,18 +635,12 @@ impl Step for WhitelistedRustc {
633635 let out = builder. doc_out ( target) ;
634636 t ! ( fs:: create_dir_all( & out) ) ;
635637 let compiler = builder. compiler ( stage, builder. config . build ) ;
636- let compiler = if builder. force_use_stage1 ( compiler, target) {
637- builder. compiler ( 1 , compiler. host )
638- } else {
639- compiler
640- } ;
641638
642639 // Build libstd docs so that we generate relative links
643640 builder. ensure ( Std { stage, target } ) ;
644641
645642 builder. ensure ( compile:: Rustc { compiler, target } ) ;
646- let out_dir = builder. stage_out ( compiler, Mode :: Rustc )
647- . join ( target) . join ( "doc" ) ;
643+ let out_dir = doc_dir ( builder, compiler, target, Mode :: Rustc ) ;
648644
649645 // See docs in std above for why we symlink
650646 let my_out = builder. crate_doc_out ( target) ;
@@ -707,11 +703,6 @@ impl Step for Rustc {
707703
708704 // Get the correct compiler for this stage.
709705 let compiler = builder. compiler ( stage, builder. config . build ) ;
710- let compiler = if builder. force_use_stage1 ( compiler, target) {
711- builder. compiler ( 1 , compiler. host )
712- } else {
713- compiler
714- } ;
715706
716707 if !builder. config . compiler_docs {
717708 builder. info ( "\t skipping - compiler/librustdoc docs disabled" ) ;
@@ -723,7 +714,7 @@ impl Step for Rustc {
723714
724715 // We do not symlink to the same shared folder that already contains std library
725716 // documentation from previous steps as we do not want to include that.
726- let out_dir = builder . stage_out ( compiler, Mode :: Rustc ) . join ( target ) . join ( "doc" ) ;
717+ let out_dir = doc_dir ( builder , compiler, target , Mode :: Rustc ) ;
727718 t ! ( symlink_dir_force( & builder. config, & out, & out_dir) ) ;
728719
729720 // Build cargo command.
@@ -808,11 +799,6 @@ impl Step for Rustdoc {
808799
809800 // Get the correct compiler for this stage.
810801 let compiler = builder. compiler ( stage, builder. config . build ) ;
811- let compiler = if builder. force_use_stage1 ( compiler, target) {
812- builder. compiler ( 1 , compiler. host )
813- } else {
814- compiler
815- } ;
816802
817803 if !builder. config . compiler_docs {
818804 builder. info ( "\t skipping - compiler/librustdoc docs disabled" ) ;
@@ -826,9 +812,7 @@ impl Step for Rustdoc {
826812 builder. ensure ( tool:: Rustdoc { compiler : compiler } ) ;
827813
828814 // Symlink compiler docs to the output directory of rustdoc documentation.
829- let out_dir = builder. stage_out ( compiler, Mode :: ToolRustc )
830- . join ( target)
831- . join ( "doc" ) ;
815+ let out_dir = doc_dir ( builder, compiler, target, Mode :: ToolRustc ) ;
832816 t ! ( fs:: create_dir_all( & out_dir) ) ;
833817 t ! ( symlink_dir_force( & builder. config, & out, & out_dir) ) ;
834818
0 commit comments