Skip to content

Commit e7a4f1e

Browse files
authored
Rollup merge of #86152 - the8472:lazify-npm-queries, r=Mark-Simulacrum
Lazify is_really_default condition in the RustdocGUI bootstrap step The `RustdocGUI::should_run` condition spawns `npm list` several times which adds up to seconds of wall-time. Evaluate the condition lazily to to keep `./x.py test tidy` and similar short-running tasks fast. Fixes #86147
2 parents e6732e0 + bde9570 commit e7a4f1e

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ dependencies = [
179179
"libc",
180180
"merge",
181181
"num_cpus",
182+
"once_cell",
182183
"opener",
183184
"pretty_assertions",
184185
"serde",

src/bootstrap/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ time = "0.1"
5050
ignore = "0.4.10"
5151
opener = "0.4"
5252
merge = "0.1.0"
53+
once_cell = "1.7.2"
5354

5455
[target.'cfg(windows)'.dependencies.winapi]
5556
version = "0.3"

src/bootstrap/builder.rs

+23-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ use crate::util::{self, add_dylib_path, add_link_lib_path, exe, libdir};
2929
use crate::{Build, DocTests, GitRepo, Mode};
3030

3131
pub use crate::Compiler;
32+
// FIXME: replace with std::lazy after it gets stabilized and reaches beta
33+
use once_cell::sync::Lazy;
3234

3335
pub 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+
232238
pub 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

242248
impl<'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
///

src/bootstrap/test.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -806,15 +806,15 @@ impl Step for RustdocGUI {
806806
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
807807
let builder = run.builder;
808808
let run = run.suite_path("src/test/rustdoc-gui");
809-
run.default_condition(
809+
run.lazy_default_condition(Box::new(move || {
810810
builder.config.nodejs.is_some()
811811
&& builder
812812
.config
813813
.npm
814814
.as_ref()
815815
.map(|p| check_if_browser_ui_test_is_installed(p))
816-
.unwrap_or(false),
817-
)
816+
.unwrap_or(false)
817+
}))
818818
}
819819

820820
fn make_run(run: RunConfig<'_>) {

0 commit comments

Comments
 (0)