]> git.lizzy.rs Git - rust.git/commitdiff
Add an optional condition to constrain defaults.
authorMark Simulacrum <mark.simulacrum@gmail.com>
Thu, 20 Jul 2017 23:24:11 +0000 (17:24 -0600)
committerMark Simulacrum <mark.simulacrum@gmail.com>
Thu, 20 Jul 2017 23:24:11 +0000 (17:24 -0600)
Utilized primarily to not be a default rule unless some configuration is
given (e.g., compiler docs are enabled).

src/bootstrap/builder.rs
src/bootstrap/check.rs
src/bootstrap/dist.rs
src/bootstrap/doc.rs
src/bootstrap/install.rs
src/bootstrap/tool.rs

index dd24e8705beb38c7f7865c5976884dd5559bc1f0..bb68ba15ebc5793b8deb14763c638389b94a8b8e 100644 (file)
@@ -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::<Vec<_>>();
         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<PathBuf>,
+
+    // 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));
index 16f14638b51c5bf21ae6268d5e456b572487c17b..7e9c83d1f76be9ecf564c3efe940f61b2b581927 100644 (file)
@@ -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<String>,
         _target: Interned<String>,
     ) {
-        if path.is_some() {
-            builder.ensure(Linkcheck { host });
-        } else {
-            if builder.build.config.docs {
-                builder.ensure(Linkcheck { host });
-            }
-        }
+        builder.ensure(Linkcheck { host });
     }
 }
 
index bceae8dad9794c557b081b3b8f76bb89947aeb88..b6ab4540ff42b5e3536698ad9345aa166288c6e3 100644 (file)
@@ -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<String>,
         target: Interned<String>
     ) {
-        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<String>, _target: Interned<String>
     ) {
-        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<String>, target: Interned<String>
     ) {
-        if path.is_none() && !builder.build.config.extended {
-            return;
-        }
         builder.ensure(Extended {
             stage: builder.top_stage,
             target: target,
index 3d8d9e50b20ea66bd840bcc3031dc271455c3859..59991e7798ed263a30f22caafd1dd04ce7ad8942 100644 (file)
@@ -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<String>, target: Interned<String>
     ) {
-        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<String>, target: Interned<String>
     ) {
-        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<String>, target: Interned<String>
     ) {
-        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<String>, target: Interned<String>
     ) {
-        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<String>, target: Interned<String>
     ) {
-        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<String>, target: Interned<String>
     ) {
-        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<String>, target: Interned<String>,
     ) {
-        if path.is_none() && !builder.build.config.docs {
-            // Not a default rule if docs are disabled.
-            return;
-        }
-
         builder.ensure(UnstableBookGen {
             target,
         });
index 7b2d644c7696d44f56ff254e00c9aab98703fbdb..d2870832086e8d6ee9c47919c88b8d1301a505f4 100644 (file)
@@ -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<String>,
                 target: Interned<String>,
             ) {
-                if path.is_none() && !($default_cond) {
-                    return;
-                }
                 $builder.ensure($name {
                     stage: $builder.top_stage,
                     target,
index 9db6493ba3172335e0a2b32efac750e332500800..07763d519c8801452c68808c75c9848e859f4654 100644 (file)
@@ -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<String>, target: Interned<String>
     ) {
-        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<String>, target: Interned<String>
     ) {
-        if path.is_none() && !builder.build.config.extended {
-            return;
-        }
         builder.ensure(Rls {
             stage: builder.top_stage,
             target,