@@ -29,6 +29,8 @@ use crate::util::{self, add_dylib_path, add_link_lib_path, exe, libdir};
29
29
use crate :: { Build , DocTests , GitRepo , Mode } ;
30
30
31
31
pub use crate :: Compiler ;
32
+ // FIXME: replace with std::lazy after it gets stabilized and reaches beta
33
+ use once_cell:: sync:: Lazy ;
32
34
33
35
pub struct Builder < ' a > {
34
36
pub build : & ' a Build ,
@@ -195,7 +197,7 @@ impl StepDescription {
195
197
196
198
if paths. is_empty ( ) || builder. config . include_default_paths {
197
199
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 ( ) {
199
201
for pathset in & should_run. paths {
200
202
desc. maybe_run ( builder, pathset) ;
201
203
}
@@ -228,31 +230,47 @@ impl StepDescription {
228
230
}
229
231
}
230
232
231
- #[ derive( Clone ) ]
233
+ enum ReallyDefault < ' a > {
234
+ Bool ( bool ) ,
235
+ Lazy ( Lazy < bool , Box < dyn Fn ( ) -> bool + ' a > > ) ,
236
+ }
237
+
232
238
pub struct ShouldRun < ' a > {
233
239
pub builder : & ' a Builder < ' a > ,
234
240
// use a BTreeSet to maintain sort order
235
241
paths : BTreeSet < PathSet > ,
236
242
237
243
// If this is a default rule, this is an additional constraint placed on
238
244
// its run. Generally something like compiler docs being enabled.
239
- is_really_default : bool ,
245
+ is_really_default : ReallyDefault < ' a > ,
240
246
}
241
247
242
248
impl < ' a > ShouldRun < ' a > {
243
249
fn new ( builder : & ' a Builder < ' _ > ) -> ShouldRun < ' a > {
244
250
ShouldRun {
245
251
builder,
246
252
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
248
254
}
249
255
}
250
256
251
257
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) ) ;
253
264
self
254
265
}
255
266
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
+
256
274
/// Indicates it should run if the command-line selects the given crate or
257
275
/// any of its (local) dependencies.
258
276
///
0 commit comments