@@ -62,6 +62,7 @@ macro_rules! book {
6262 target: self . target,
6363 name: INTERNER . intern_str( $book_name) ,
6464 src: INTERNER . intern_path( builder. src. join( $path) ) ,
65+ parent: Some ( self ) ,
6566 } )
6667 }
6768 }
@@ -119,18 +120,20 @@ impl Step for UnstableBook {
119120 target : self . target ,
120121 name : INTERNER . intern_str ( "unstable-book" ) ,
121122 src : INTERNER . intern_path ( builder. md_doc_out ( self . target ) . join ( "unstable-book" ) ) ,
123+ parent : Some ( self ) ,
122124 } )
123125 }
124126}
125127
126128#[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
127- struct RustbookSrc {
129+ struct RustbookSrc < P : Step > {
128130 target : TargetSelection ,
129131 name : Interned < String > ,
130132 src : Interned < PathBuf > ,
133+ parent : Option < P > ,
131134}
132135
133- impl Step for RustbookSrc {
136+ impl < P : Step > Step for RustbookSrc < P > {
134137 type Output = ( ) ;
135138
136139 fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
@@ -152,13 +155,18 @@ impl Step for RustbookSrc {
152155 let index = out. join ( "index.html" ) ;
153156 let rustbook = builder. tool_exe ( Tool :: Rustbook ) ;
154157 let mut rustbook_cmd = builder. tool_cmd ( Tool :: Rustbook ) ;
155- if builder. config . dry_run ( ) || up_to_date ( & src, & index) && up_to_date ( & rustbook, & index) {
156- return ;
158+
159+ if !builder. config . dry_run ( ) && !( up_to_date ( & src, & index) || up_to_date ( & rustbook, & index) )
160+ {
161+ builder. info ( & format ! ( "Rustbook ({}) - {}" , target, name) ) ;
162+ let _ = fs:: remove_dir_all ( & out) ;
163+
164+ builder. run ( rustbook_cmd. arg ( "build" ) . arg ( & src) . arg ( "-d" ) . arg ( out) ) ;
157165 }
158- builder. info ( & format ! ( "Rustbook ({}) - {}" , target, name) ) ;
159- let _ = fs:: remove_dir_all ( & out) ;
160166
161- builder. run ( rustbook_cmd. arg ( "build" ) . arg ( & src) . arg ( "-d" ) . arg ( out) ) ;
167+ if self . parent . is_some ( ) {
168+ builder. maybe_open_in_browser :: < P > ( index)
169+ }
162170 }
163171}
164172
@@ -205,6 +213,7 @@ impl Step for TheBook {
205213 target,
206214 name : INTERNER . intern_str ( "book" ) ,
207215 src : INTERNER . intern_path ( builder. src . join ( & relative_path) ) ,
216+ parent : Some ( self ) ,
208217 } ) ;
209218
210219 // building older edition redirects
@@ -213,6 +222,9 @@ impl Step for TheBook {
213222 target,
214223 name : INTERNER . intern_string ( format ! ( "book/{}" , edition) ) ,
215224 src : INTERNER . intern_path ( builder. src . join ( & relative_path) . join ( edition) ) ,
225+ // There should only be one book that is marked as the parent for each target, so
226+ // treat the other editions as not having a parent.
227+ parent : Option :: < Self > :: None ,
216228 } ) ;
217229 }
218230
@@ -228,10 +240,6 @@ impl Step for TheBook {
228240
229241 invoke_rustdoc ( builder, compiler, & shared_assets, target, path) ;
230242 }
231-
232- let out = builder. doc_out ( target) ;
233- let index = out. join ( "book" ) . join ( "index.html" ) ;
234- builder. maybe_open_in_browser :: < Self > ( index) ;
235243 }
236244}
237245
@@ -1032,10 +1040,7 @@ impl Step for RustcBook {
10321040 target : self . target ,
10331041 name : INTERNER . intern_str ( "rustc" ) ,
10341042 src : INTERNER . intern_path ( out_base) ,
1043+ parent : Some ( self ) ,
10351044 } ) ;
1036-
1037- let out = builder. doc_out ( self . target ) ;
1038- let index = out. join ( "rustc" ) . join ( "index.html" ) ;
1039- builder. maybe_open_in_browser :: < Self > ( index) ;
10401045 }
10411046}
0 commit comments