From: Mark Simulacrum Date: Thu, 20 Jul 2017 23:24:11 +0000 (-0600) Subject: Add an optional condition to constrain defaults. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=b05af49086d50bf9f325070746975868f8c16f0f;p=rust.git Add an optional condition to constrain defaults. Utilized primarily to not be a default rule unless some configuration is given (e.g., compiler docs are enabled). --- diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index dd24e8705be..bb68ba15ebc 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -152,17 +152,20 @@ fn maybe_run(&self, builder: &Builder, path: Option<&Path>) { } fn run(v: &[StepDescription], builder: &Builder, paths: &[PathBuf]) { + let should_runs = v.iter().map(|desc| { + (desc.should_run)(ShouldRun::new(builder)) + }).collect::>(); if paths.is_empty() { - for desc in v { - if desc.default { + for (desc, should_run) in v.iter().zip(should_runs) { + if desc.default && should_run.is_really_default { desc.maybe_run(builder, None); } } } else { for path in paths { let mut attempted_run = false; - for desc in v { - if (desc.should_run)(ShouldRun::new(builder)).run(path) { + for (desc, should_run) in v.iter().zip(&should_runs) { + if should_run.run(path) { attempted_run = true; desc.maybe_run(builder, Some(path)); } @@ -178,9 +181,13 @@ fn run(v: &[StepDescription], builder: &Builder, paths: &[PathBuf]) { #[derive(Clone)] pub struct ShouldRun<'a> { - builder: &'a Builder<'a>, + pub builder: &'a Builder<'a>, // use a BTreeSet to maintain sort order paths: BTreeSet, + + // If this is a default rule, this is an additional constraint placed on + // it's run. Generally something like compiler docs being enabled. + is_really_default: bool, } impl<'a> ShouldRun<'a> { @@ -188,9 +195,15 @@ fn new(builder: &'a Builder) -> ShouldRun<'a> { ShouldRun { builder: builder, paths: BTreeSet::new(), + is_really_default: true, // by default no additional conditions } } + pub fn default_condition(mut self, cond: bool) -> Self { + self.is_really_default = cond; + self + } + pub fn krate(mut self, name: &str) -> Self { for (_, krate_path) in self.builder.crates(name) { self.paths.insert(PathBuf::from(krate_path)); diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index 16f14638b51..7e9c83d1f76 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -115,7 +115,8 @@ fn run(self, builder: &Builder) { } fn should_run(run: ShouldRun) -> ShouldRun { - run.path("src/tools/linkchecker") + let builder = run.builder; + run.path("src/tools/linkchecker").default_condition(builder.build.config.docs) } fn make_run( @@ -124,13 +125,7 @@ fn make_run( host: Interned, _target: Interned, ) { - if path.is_some() { - builder.ensure(Linkcheck { host }); - } else { - if builder.build.config.docs { - builder.ensure(Linkcheck { host }); - } - } + builder.ensure(Linkcheck { host }); } } diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index bceae8dad97..b6ab4540ff4 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -607,7 +607,8 @@ impl Step for Analysis { const ONLY_BUILD_TARGETS: bool = true; fn should_run(run: ShouldRun) -> ShouldRun { - run.path("analysis") + let builder = run.builder; + run.path("analysis").default_condition(builder.build.config.extended) } fn make_run( @@ -616,9 +617,6 @@ fn make_run( host: Interned, target: Interned ) { - if path.is_none() && !builder.build.config.extended { - return; - } builder.ensure(Analysis { compiler: builder.compiler(builder.top_stage, host), target: target, @@ -818,16 +816,13 @@ impl Step for PlainSourceTarball { const ONLY_BUILD: bool = true; fn should_run(run: ShouldRun) -> ShouldRun { - run.path("src") + let builder = run.builder; + run.path("src").default_condition(builder.config.rust_dist_src) } fn make_run( builder: &Builder, path: Option<&Path>, _host: Interned, _target: Interned ) { - if path.is_none() && !builder.build.config.rust_dist_src { - return; - } - builder.ensure(PlainSourceTarball); } @@ -1138,15 +1133,13 @@ impl Step for Extended { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun) -> ShouldRun { - run.path("cargo") + let builder = run.builder; + run.path("cargo").default_condition(builder.config.extended) } fn make_run( builder: &Builder, path: Option<&Path>, _host: Interned, target: Interned ) { - if path.is_none() && !builder.build.config.extended { - return; - } builder.ensure(Extended { stage: builder.top_stage, target: target, diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 3d8d9e50b20..59991e7798e 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -45,7 +45,8 @@ impl Step for $name { const DEFAULT: bool = true; fn should_run(run: ShouldRun) -> ShouldRun { - run.path($path) + let builder = run.builder; + run.path($path).default_condition(builder.build.config.docs) } fn make_run( @@ -119,17 +120,13 @@ impl Step for UnstableBook { const DEFAULT: bool = true; fn should_run(run: ShouldRun) -> ShouldRun { - run.path("src/doc/unstable-book") + let builder = run.builder; + run.path("src/doc/unstable-book").default_condition(builder.build.config.docs) } fn make_run( builder: &Builder, path: Option<&Path>, _host: Interned, target: Interned ) { - if path.is_none() && !builder.build.config.docs { - // Not a default rule if docs are disabled. - return; - } - builder.ensure(UnstableBook { target, }); @@ -201,17 +198,13 @@ impl Step for TheBook { const DEFAULT: bool = true; fn should_run(run: ShouldRun) -> ShouldRun { - run.path("src/doc/book") + let builder = run.builder; + run.path("src/doc/book").default_condition(builder.build.config.docs) } fn make_run( builder: &Builder, path: Option<&Path>, _host: Interned, target: Interned ) { - if path.is_none() && !builder.build.config.docs { - // Not a default rule if docs are disabled. - return; - } - builder.ensure(TheBook { target, name: "book", @@ -417,31 +410,17 @@ impl Step for Std { const DEFAULT: bool = true; fn should_run(run: ShouldRun) -> ShouldRun { - run.krate("std") + let builder = run.builder; + run.krate("std").default_condition(builder.build.config.docs) } - fn make_run( builder: &Builder, path: Option<&Path>, _host: Interned, target: Interned ) { - let run = || { - builder.ensure(Std { - stage: builder.top_stage, - target - }); - }; - - if let Some(path) = path { - for (_, krate_path) in builder.crates("std") { - if path.ends_with(krate_path) { - run(); - } - } - } else { - if builder.build.config.docs { - run(); - } - } + builder.ensure(Std { + stage: builder.top_stage, + target + }); } /// Compile all standard library documentation. @@ -520,30 +499,17 @@ impl Step for Test { const DEFAULT: bool = true; fn should_run(run: ShouldRun) -> ShouldRun { - run.krate("test") + let builder = run.builder; + run.krate("test").default_condition(builder.config.compiler_docs) } fn make_run( builder: &Builder, path: Option<&Path>, _host: Interned, target: Interned ) { - let run = || { - builder.ensure(Test { - stage: builder.top_stage, - target - }); - }; - - if let Some(path) = path { - for (_, krate_path) in builder.crates("test") { - if path.ends_with(krate_path) { - run(); - } - } - } else { - if builder.build.config.compiler_docs { - run(); - } - } + builder.ensure(Test { + stage: builder.top_stage, + target + }); } /// Compile all libtest documentation. @@ -597,30 +563,17 @@ impl Step for Rustc { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun) -> ShouldRun { - run.krate("rustc-main") + let builder = run.builder; + run.krate("rustc-main").default_condition(builder.build.config.docs) } fn make_run( builder: &Builder, path: Option<&Path>, _host: Interned, target: Interned ) { - let run = || { - builder.ensure(Rustc { - stage: builder.top_stage, - target - }); - }; - - if let Some(path) = path { - for (_, krate_path) in builder.crates("rustc-main") { - if path.ends_with(krate_path) { - run(); - } - } - } else { - if builder.build.config.docs { - run(); - } - } + builder.ensure(Rustc { + stage: builder.top_stage, + target + }); } /// Generate all compiler documentation. @@ -690,17 +643,13 @@ impl Step for ErrorIndex { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun) -> ShouldRun { - run.path("src/tools/error_index_generator") + let builder = run.builder; + run.path("src/tools/error_index_generator").default_condition(builder.build.config.docs) } fn make_run( builder: &Builder, path: Option<&Path>, _host: Interned, target: Interned ) { - if path.is_none() && !builder.build.config.docs { - // Not a default rule if docs are disabled. - return; - } - builder.ensure(ErrorIndex { target, }); @@ -742,17 +691,13 @@ impl Step for UnstableBookGen { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun) -> ShouldRun { - run.path("src/tools/unstable-book-gen") + let builder = run.builder; + run.path("src/tools/unstable-book-gen").default_condition(builder.build.config.docs) } fn make_run( builder: &Builder, path: Option<&Path>, _host: Interned, target: Interned, ) { - if path.is_none() && !builder.build.config.docs { - // Not a default rule if docs are disabled. - return; - } - builder.ensure(UnstableBookGen { target, }); diff --git a/src/bootstrap/install.rs b/src/bootstrap/install.rs index 7b2d644c769..d2870832086 100644 --- a/src/bootstrap/install.rs +++ b/src/bootstrap/install.rs @@ -150,7 +150,8 @@ impl Step for $name { $(const $c: bool = true;)* fn should_run(run: ShouldRun) -> ShouldRun { - run.path($path) + let $builder = run.builder; + run.path($path).default_condition($default_cond) } fn make_run( @@ -159,9 +160,6 @@ fn make_run( host: Interned, target: Interned, ) { - if path.is_none() && !($default_cond) { - return; - } $builder.ensure($name { stage: $builder.top_stage, target, diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 9db6493ba31..07763d519c8 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -248,15 +248,13 @@ impl Step for Cargo { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun) -> ShouldRun { - run.path("src/tools/cargo") + let builder = run.builder; + run.path("src/tools/cargo").default_condition(builder.build.config.extended) } fn make_run( builder: &Builder, path: Option<&Path>, _host: Interned, target: Interned ) { - if path.is_none() && !builder.build.config.extended { - return; - } builder.ensure(Cargo { stage: builder.top_stage, target, @@ -294,15 +292,13 @@ impl Step for Rls { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun) -> ShouldRun { - run.path("src/tools/rls") + let builder = run.builder; + run.path("src/tools/rls").default_condition(builder.build.config.extended) } fn make_run( builder: &Builder, path: Option<&Path>, _host: Interned, target: Interned ) { - if path.is_none() && !builder.build.config.extended { - return; - } builder.ensure(Rls { stage: builder.top_stage, target,