99
1010use std:: io:: { self , Write } ;
1111use std:: path:: { Path , PathBuf } ;
12- use std:: { fs, mem} ;
12+ use std:: { env , fs, mem} ;
1313
1414use crate :: core:: build_steps:: compile;
1515use crate :: core:: build_steps:: tool:: { self , prepare_tool_cargo, SourceType , Tool } ;
1616use crate :: core:: builder:: { self , crate_description} ;
1717use crate :: core:: builder:: { Alias , Builder , Compiler , Kind , RunConfig , ShouldRun , Step } ;
1818use crate :: core:: config:: { Config , TargetSelection } ;
19- use crate :: utils:: helpers:: { dir_is_empty , symlink_dir, t, up_to_date} ;
19+ use crate :: utils:: helpers:: { symlink_dir, t, up_to_date} ;
2020use crate :: Mode ;
2121
2222macro_rules! submodule_helper {
@@ -53,15 +53,16 @@ macro_rules! book {
5353
5454 fn run( self , builder: & Builder <' _>) {
5555 $(
56- let path = Path :: new ( submodule_helper!( $path, submodule $( = $submodule ) ? ) ) ;
57- builder. update_submodule ( & path) ;
56+ let path = submodule_helper!( $path, submodule $( = $submodule ) ? ) ;
57+ builder. require_submodule ( path, None ) ;
5858 ) ?
5959 builder. ensure( RustbookSrc {
6060 target: self . target,
6161 name: $book_name. to_owned( ) ,
6262 src: builder. src. join( $path) ,
6363 parent: Some ( self ) ,
6464 languages: $lang. into( ) ,
65+ rustdoc: None ,
6566 } )
6667 }
6768 }
8081 EditionGuide , "src/doc/edition-guide" , "edition-guide" , & [ ] , submodule;
8182 EmbeddedBook , "src/doc/embedded-book" , "embedded-book" , & [ ] , submodule;
8283 Nomicon , "src/doc/nomicon" , "nomicon" , & [ ] , submodule;
83- Reference , "src/doc/reference" , "reference" , & [ ] , submodule;
8484 RustByExample , "src/doc/rust-by-example" , "rust-by-example" , & [ "ja" ] , submodule;
8585 RustdocBook , "src/doc/rustdoc" , "rustdoc" , & [ ] ;
8686 StyleGuide , "src/doc/style-guide" , "style-guide" , & [ ] ;
@@ -112,6 +112,7 @@ impl Step for UnstableBook {
112112 src : builder. md_doc_out ( self . target ) . join ( "unstable-book" ) ,
113113 parent : Some ( self ) ,
114114 languages : vec ! [ ] ,
115+ rustdoc : None ,
115116 } )
116117 }
117118}
@@ -123,6 +124,7 @@ struct RustbookSrc<P: Step> {
123124 src : PathBuf ,
124125 parent : Option < P > ,
125126 languages : Vec < & ' static str > ,
127+ rustdoc : Option < PathBuf > ,
126128}
127129
128130impl < P : Step > Step for RustbookSrc < P > {
@@ -153,13 +155,18 @@ impl<P: Step> Step for RustbookSrc<P> {
153155 builder. info ( & format ! ( "Rustbook ({target}) - {name}" ) ) ;
154156 let _ = fs:: remove_dir_all ( & out) ;
155157
156- builder
157- . tool_cmd ( Tool :: Rustbook )
158- . arg ( "build" )
159- . arg ( & src)
160- . arg ( "-d" )
161- . arg ( & out)
162- . run ( builder) ;
158+ let mut rustbook_cmd = builder. tool_cmd ( Tool :: Rustbook ) ;
159+ if let Some ( mut rustdoc) = self . rustdoc {
160+ rustdoc. pop ( ) ;
161+ let old_path = env:: var_os ( "PATH" ) . unwrap_or_default ( ) ;
162+ let new_path =
163+ env:: join_paths ( std:: iter:: once ( rustdoc) . chain ( env:: split_paths ( & old_path) ) )
164+ . expect ( "could not add rustdoc to PATH" ) ;
165+
166+ rustbook_cmd. env ( "PATH" , new_path) ;
167+ }
168+
169+ rustbook_cmd. arg ( "build" ) . arg ( & src) . arg ( "-d" ) . arg ( & out) . run ( builder) ;
163170
164171 for lang in & self . languages {
165172 let out = out. join ( lang) ;
@@ -217,29 +224,22 @@ impl Step for TheBook {
217224 /// * Index page
218225 /// * Redirect pages
219226 fn run ( self , builder : & Builder < ' _ > ) {
220- let relative_path = Path :: new ( "src" ) . join ( "doc" ) . join ( "book" ) ;
221- builder. update_submodule ( & relative_path) ;
227+ builder. require_submodule ( "src/doc/book" , None ) ;
222228
223229 let compiler = self . compiler ;
224230 let target = self . target ;
225231
226- let absolute_path = builder. src . join ( & relative_path ) ;
232+ let absolute_path = builder. src . join ( "src/doc/book" ) ;
227233 let redirect_path = absolute_path. join ( "redirects" ) ;
228- if !absolute_path. exists ( )
229- || !redirect_path. exists ( )
230- || dir_is_empty ( & absolute_path)
231- || dir_is_empty ( & redirect_path)
232- {
233- eprintln ! ( "Please checkout submodule: {}" , relative_path. display( ) ) ;
234- crate :: exit!( 1 ) ;
235- }
234+
236235 // build book
237236 builder. ensure ( RustbookSrc {
238237 target,
239238 name : "book" . to_owned ( ) ,
240239 src : absolute_path. clone ( ) ,
241240 parent : Some ( self ) ,
242241 languages : vec ! [ ] ,
242+ rustdoc : None ,
243243 } ) ;
244244
245245 // building older edition redirects
@@ -252,6 +252,7 @@ impl Step for TheBook {
252252 // treat the other editions as not having a parent.
253253 parent : Option :: < Self > :: None ,
254254 languages : vec ! [ ] ,
255+ rustdoc : None ,
255256 } ) ;
256257 }
257258
@@ -932,8 +933,8 @@ macro_rules! tool_doc {
932933 let _ = source_type; // silence the "unused variable" warning
933934 let source_type = SourceType :: Submodule ;
934935
935- let path = Path :: new ( submodule_helper!( $path, submodule $( = $submodule ) ? ) ) ;
936- builder. update_submodule ( & path) ;
936+ let path = submodule_helper!( $path, submodule $( = $submodule ) ? ) ;
937+ builder. require_submodule ( path, None ) ;
937938 ) ?
938939
939940 let stage = builder. top_stage;
@@ -1172,12 +1173,6 @@ impl Step for RustcBook {
11721173 /// in the "md-doc" directory in the build output directory. Then
11731174 /// "rustbook" is used to convert it to HTML.
11741175 fn run ( self , builder : & Builder < ' _ > ) {
1175- // These submodules are required to be checked out to build rustbook
1176- // because they have Cargo dependencies that are needed.
1177- #[ allow( clippy:: single_element_loop) ] // This will change soon.
1178- for path in [ "src/doc/book" ] {
1179- builder. update_submodule ( Path :: new ( path) ) ;
1180- }
11811176 let out_base = builder. md_doc_out ( self . target ) . join ( "rustc" ) ;
11821177 t ! ( fs:: create_dir_all( & out_base) ) ;
11831178 let out_listing = out_base. join ( "src/lints" ) ;
@@ -1228,6 +1223,50 @@ impl Step for RustcBook {
12281223 src : out_base,
12291224 parent : Some ( self ) ,
12301225 languages : vec ! [ ] ,
1226+ rustdoc : None ,
1227+ } ) ;
1228+ }
1229+ }
1230+
1231+ #[ derive( Ord , PartialOrd , Debug , Clone , Hash , PartialEq , Eq ) ]
1232+ pub struct Reference {
1233+ pub compiler : Compiler ,
1234+ pub target : TargetSelection ,
1235+ }
1236+
1237+ impl Step for Reference {
1238+ type Output = ( ) ;
1239+ const DEFAULT : bool = true ;
1240+
1241+ fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
1242+ let builder = run. builder ;
1243+ run. path ( "src/doc/reference" ) . default_condition ( builder. config . docs )
1244+ }
1245+
1246+ fn make_run ( run : RunConfig < ' _ > ) {
1247+ run. builder . ensure ( Reference {
1248+ compiler : run. builder . compiler ( run. builder . top_stage , run. builder . config . build ) ,
1249+ target : run. target ,
1250+ } ) ;
1251+ }
1252+
1253+ /// Builds the reference book.
1254+ fn run ( self , builder : & Builder < ' _ > ) {
1255+ builder. require_submodule ( "src/doc/reference" , None ) ;
1256+
1257+ // This is needed for generating links to the standard library using
1258+ // the mdbook-spec plugin.
1259+ builder. ensure ( compile:: Std :: new ( self . compiler , builder. config . build ) ) ;
1260+ let rustdoc = builder. rustdoc ( self . compiler ) ;
1261+
1262+ // Run rustbook/mdbook to generate the HTML pages.
1263+ builder. ensure ( RustbookSrc {
1264+ target : self . target ,
1265+ name : "reference" . to_owned ( ) ,
1266+ src : builder. src . join ( "src/doc/reference" ) ,
1267+ parent : Some ( self ) ,
1268+ languages : vec ! [ ] ,
1269+ rustdoc : Some ( rustdoc) ,
12311270 } ) ;
12321271 }
12331272}
0 commit comments