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
This commit is contained in:
commit
e7a4f1e3fc
4 changed files with 28 additions and 8 deletions
|
@ -179,6 +179,7 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"merge",
|
"merge",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
|
"once_cell",
|
||||||
"opener",
|
"opener",
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
@ -50,6 +50,7 @@ time = "0.1"
|
||||||
ignore = "0.4.10"
|
ignore = "0.4.10"
|
||||||
opener = "0.4"
|
opener = "0.4"
|
||||||
merge = "0.1.0"
|
merge = "0.1.0"
|
||||||
|
once_cell = "1.7.2"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies.winapi]
|
[target.'cfg(windows)'.dependencies.winapi]
|
||||||
version = "0.3"
|
version = "0.3"
|
||||||
|
|
|
@ -29,6 +29,8 @@ use crate::util::{self, add_dylib_path, add_link_lib_path, exe, libdir};
|
||||||
use crate::{Build, DocTests, GitRepo, Mode};
|
use crate::{Build, DocTests, GitRepo, Mode};
|
||||||
|
|
||||||
pub use crate::Compiler;
|
pub use crate::Compiler;
|
||||||
|
// FIXME: replace with std::lazy after it gets stabilized and reaches beta
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
pub struct Builder<'a> {
|
pub struct Builder<'a> {
|
||||||
pub build: &'a Build,
|
pub build: &'a Build,
|
||||||
|
@ -195,7 +197,7 @@ impl StepDescription {
|
||||||
|
|
||||||
if paths.is_empty() || builder.config.include_default_paths {
|
if paths.is_empty() || builder.config.include_default_paths {
|
||||||
for (desc, should_run) in v.iter().zip(&should_runs) {
|
for (desc, should_run) in v.iter().zip(&should_runs) {
|
||||||
if desc.default && should_run.is_really_default {
|
if desc.default && should_run.is_really_default() {
|
||||||
for pathset in &should_run.paths {
|
for pathset in &should_run.paths {
|
||||||
desc.maybe_run(builder, pathset);
|
desc.maybe_run(builder, pathset);
|
||||||
}
|
}
|
||||||
|
@ -228,7 +230,11 @@ impl StepDescription {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
enum ReallyDefault<'a> {
|
||||||
|
Bool(bool),
|
||||||
|
Lazy(Lazy<bool, Box<dyn Fn() -> bool + 'a>>),
|
||||||
|
}
|
||||||
|
|
||||||
pub struct ShouldRun<'a> {
|
pub struct ShouldRun<'a> {
|
||||||
pub builder: &'a Builder<'a>,
|
pub builder: &'a Builder<'a>,
|
||||||
// use a BTreeSet to maintain sort order
|
// use a BTreeSet to maintain sort order
|
||||||
|
@ -236,7 +242,7 @@ pub struct ShouldRun<'a> {
|
||||||
|
|
||||||
// If this is a default rule, this is an additional constraint placed on
|
// If this is a default rule, this is an additional constraint placed on
|
||||||
// its run. Generally something like compiler docs being enabled.
|
// its run. Generally something like compiler docs being enabled.
|
||||||
is_really_default: bool,
|
is_really_default: ReallyDefault<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ShouldRun<'a> {
|
impl<'a> ShouldRun<'a> {
|
||||||
|
@ -244,15 +250,27 @@ impl<'a> ShouldRun<'a> {
|
||||||
ShouldRun {
|
ShouldRun {
|
||||||
builder,
|
builder,
|
||||||
paths: BTreeSet::new(),
|
paths: BTreeSet::new(),
|
||||||
is_really_default: true, // by default no additional conditions
|
is_really_default: ReallyDefault::Bool(true), // by default no additional conditions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_condition(mut self, cond: bool) -> Self {
|
pub fn default_condition(mut self, cond: bool) -> Self {
|
||||||
self.is_really_default = cond;
|
self.is_really_default = ReallyDefault::Bool(cond);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn lazy_default_condition(mut self, lazy_cond: Box<dyn Fn() -> bool + 'a>) -> Self {
|
||||||
|
self.is_really_default = ReallyDefault::Lazy(Lazy::new(lazy_cond));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_really_default(&self) -> bool {
|
||||||
|
match &self.is_really_default {
|
||||||
|
ReallyDefault::Bool(val) => *val,
|
||||||
|
ReallyDefault::Lazy(lazy) => *lazy.deref(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Indicates it should run if the command-line selects the given crate or
|
/// Indicates it should run if the command-line selects the given crate or
|
||||||
/// any of its (local) dependencies.
|
/// any of its (local) dependencies.
|
||||||
///
|
///
|
||||||
|
|
|
@ -806,15 +806,15 @@ impl Step for RustdocGUI {
|
||||||
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
|
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
|
||||||
let builder = run.builder;
|
let builder = run.builder;
|
||||||
let run = run.suite_path("src/test/rustdoc-gui");
|
let run = run.suite_path("src/test/rustdoc-gui");
|
||||||
run.default_condition(
|
run.lazy_default_condition(Box::new(move || {
|
||||||
builder.config.nodejs.is_some()
|
builder.config.nodejs.is_some()
|
||||||
&& builder
|
&& builder
|
||||||
.config
|
.config
|
||||||
.npm
|
.npm
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|p| check_if_browser_ui_test_is_installed(p))
|
.map(|p| check_if_browser_ui_test_is_installed(p))
|
||||||
.unwrap_or(false),
|
.unwrap_or(false)
|
||||||
)
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_run(run: RunConfig<'_>) {
|
fn make_run(run: RunConfig<'_>) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue