9
9
10
10
use std:: io:: { self , Write } ;
11
11
use std:: path:: { Path , PathBuf } ;
12
- use std:: { fs, mem} ;
12
+ use std:: { env , fs, mem} ;
13
13
14
14
use crate :: core:: build_steps:: compile;
15
15
use crate :: core:: build_steps:: tool:: { self , prepare_tool_cargo, SourceType , Tool } ;
16
16
use crate :: core:: builder:: { self , crate_description} ;
17
17
use crate :: core:: builder:: { Alias , Builder , Compiler , Kind , RunConfig , ShouldRun , Step } ;
18
18
use 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} ;
20
20
use crate :: Mode ;
21
21
22
22
macro_rules! submodule_helper {
@@ -53,15 +53,16 @@ macro_rules! book {
53
53
54
54
fn run( self , builder: & Builder <' _>) {
55
55
$(
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 ) ;
58
58
) ?
59
59
builder. ensure( RustbookSrc {
60
60
target: self . target,
61
61
name: $book_name. to_owned( ) ,
62
62
src: builder. src. join( $path) ,
63
63
parent: Some ( self ) ,
64
64
languages: $lang. into( ) ,
65
+ rustdoc: None ,
65
66
} )
66
67
}
67
68
}
80
81
EditionGuide , "src/doc/edition-guide" , "edition-guide" , & [ ] , submodule;
81
82
EmbeddedBook , "src/doc/embedded-book" , "embedded-book" , & [ ] , submodule;
82
83
Nomicon , "src/doc/nomicon" , "nomicon" , & [ ] , submodule;
83
- Reference , "src/doc/reference" , "reference" , & [ ] , submodule;
84
84
RustByExample , "src/doc/rust-by-example" , "rust-by-example" , & [ "ja" ] , submodule;
85
85
RustdocBook , "src/doc/rustdoc" , "rustdoc" , & [ ] ;
86
86
StyleGuide , "src/doc/style-guide" , "style-guide" , & [ ] ;
@@ -112,6 +112,7 @@ impl Step for UnstableBook {
112
112
src : builder. md_doc_out ( self . target ) . join ( "unstable-book" ) ,
113
113
parent : Some ( self ) ,
114
114
languages : vec ! [ ] ,
115
+ rustdoc : None ,
115
116
} )
116
117
}
117
118
}
@@ -123,6 +124,7 @@ struct RustbookSrc<P: Step> {
123
124
src : PathBuf ,
124
125
parent : Option < P > ,
125
126
languages : Vec < & ' static str > ,
127
+ rustdoc : Option < PathBuf > ,
126
128
}
127
129
128
130
impl < P : Step > Step for RustbookSrc < P > {
@@ -153,13 +155,18 @@ impl<P: Step> Step for RustbookSrc<P> {
153
155
builder. info ( & format ! ( "Rustbook ({target}) - {name}" ) ) ;
154
156
let _ = fs:: remove_dir_all ( & out) ;
155
157
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) ;
163
170
164
171
for lang in & self . languages {
165
172
let out = out. join ( lang) ;
@@ -217,29 +224,22 @@ impl Step for TheBook {
217
224
/// * Index page
218
225
/// * Redirect pages
219
226
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 ) ;
222
228
223
229
let compiler = self . compiler ;
224
230
let target = self . target ;
225
231
226
- let absolute_path = builder. src . join ( & relative_path ) ;
232
+ let absolute_path = builder. src . join ( "src/doc/book" ) ;
227
233
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
+
236
235
// build book
237
236
builder. ensure ( RustbookSrc {
238
237
target,
239
238
name : "book" . to_owned ( ) ,
240
239
src : absolute_path. clone ( ) ,
241
240
parent : Some ( self ) ,
242
241
languages : vec ! [ ] ,
242
+ rustdoc : None ,
243
243
} ) ;
244
244
245
245
// building older edition redirects
@@ -252,6 +252,7 @@ impl Step for TheBook {
252
252
// treat the other editions as not having a parent.
253
253
parent : Option :: < Self > :: None ,
254
254
languages : vec ! [ ] ,
255
+ rustdoc : None ,
255
256
} ) ;
256
257
}
257
258
@@ -932,8 +933,8 @@ macro_rules! tool_doc {
932
933
let _ = source_type; // silence the "unused variable" warning
933
934
let source_type = SourceType :: Submodule ;
934
935
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 ) ;
937
938
) ?
938
939
939
940
let stage = builder. top_stage;
@@ -1172,12 +1173,6 @@ impl Step for RustcBook {
1172
1173
/// in the "md-doc" directory in the build output directory. Then
1173
1174
/// "rustbook" is used to convert it to HTML.
1174
1175
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
- }
1181
1176
let out_base = builder. md_doc_out ( self . target ) . join ( "rustc" ) ;
1182
1177
t ! ( fs:: create_dir_all( & out_base) ) ;
1183
1178
let out_listing = out_base. join ( "src/lints" ) ;
@@ -1228,6 +1223,50 @@ impl Step for RustcBook {
1228
1223
src : out_base,
1229
1224
parent : Some ( self ) ,
1230
1225
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) ,
1231
1270
} ) ;
1232
1271
}
1233
1272
}
0 commit comments