@@ -29,6 +29,8 @@ use crate::util::{self, add_dylib_path, add_link_lib_path, exe, libdir};
2929use crate :: { Build , DocTests , GitRepo , Mode } ;
3030
3131pub use crate :: Compiler ;
32+ // FIXME: replace with std::lazy after it gets stabilized and reaches beta
33+ use once_cell:: sync:: Lazy ;
3234
3335pub struct Builder < ' a > {
3436 pub build : & ' a Build ,
@@ -195,7 +197,7 @@ impl StepDescription {
195197
196198 if paths. is_empty ( ) || builder. config . include_default_paths {
197199 for ( desc, should_run) in v. iter ( ) . zip ( & should_runs) {
198- if desc. default && should_run. is_really_default {
200+ if desc. default && should_run. is_really_default ( ) {
199201 for pathset in & should_run. paths {
200202 desc. maybe_run ( builder, pathset) ;
201203 }
@@ -228,31 +230,47 @@ impl StepDescription {
228230 }
229231}
230232
231- #[ derive( Clone ) ]
233+ enum ReallyDefault < ' a > {
234+ Bool ( bool ) ,
235+ Lazy ( Lazy < bool , Box < dyn Fn ( ) -> bool + ' a > > ) ,
236+ }
237+
232238pub struct ShouldRun < ' a > {
233239 pub builder : & ' a Builder < ' a > ,
234240 // use a BTreeSet to maintain sort order
235241 paths : BTreeSet < PathSet > ,
236242
237243 // If this is a default rule, this is an additional constraint placed on
238244 // its run. Generally something like compiler docs being enabled.
239- is_really_default : bool ,
245+ is_really_default : ReallyDefault < ' a > ,
240246}
241247
242248impl < ' a > ShouldRun < ' a > {
243249 fn new ( builder : & ' a Builder < ' _ > ) -> ShouldRun < ' a > {
244250 ShouldRun {
245251 builder,
246252 paths : BTreeSet :: new ( ) ,
247- is_really_default : true , // by default no additional conditions
253+ is_really_default : ReallyDefault :: Bool ( true ) , // by default no additional conditions
248254 }
249255 }
250256
251257 pub fn default_condition ( mut self , cond : bool ) -> Self {
252- self . is_really_default = cond;
258+ self . is_really_default = ReallyDefault :: Bool ( cond) ;
259+ self
260+ }
261+
262+ pub fn lazy_default_condition ( mut self , lazy_cond : Box < dyn Fn ( ) -> bool + ' a > ) -> Self {
263+ self . is_really_default = ReallyDefault :: Lazy ( Lazy :: new ( lazy_cond) ) ;
253264 self
254265 }
255266
267+ pub fn is_really_default ( & self ) -> bool {
268+ match & self . is_really_default {
269+ ReallyDefault :: Bool ( val) => * val,
270+ ReallyDefault :: Lazy ( lazy) => * lazy. deref ( ) ,
271+ }
272+ }
273+
256274 /// Indicates it should run if the command-line selects the given crate or
257275 /// any of its (local) dependencies.
258276 ///
0 commit comments