about summary refs log tree commit diff
path: root/src/bootstrap/builder.rs
diff options
context:
space:
mode:
authorPietro Albini <pietro.albini@ferrous-systems.com>2021-07-23 16:51:43 +0200
committerPietro Albini <pietro.albini@ferrous-systems.com>2021-07-23 17:56:37 +0200
commitc15e2480908868024f41ac4de92eabf435f5e911 (patch)
tree42c9bde57e7a272a2a702daabbf750315e862edc /src/bootstrap/builder.rs
parent2cfac3f04599ab50f1a7b6e21bb98c02b53bba75 (diff)
downloadrust-c15e2480908868024f41ac4de92eabf435f5e911.tar.gz
rust-c15e2480908868024f41ac4de92eabf435f5e911.zip
refactor extended tarball generaton to use the new ensure_if_default
Diffstat (limited to 'src/bootstrap/builder.rs')
-rw-r--r--src/bootstrap/builder.rs44
1 files changed, 37 insertions, 7 deletions
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
index 56ecc6e68a9..f2d841cb335 100644
--- a/src/bootstrap/builder.rs
+++ b/src/bootstrap/builder.rs
@@ -163,14 +163,8 @@ impl StepDescription {
     }
 
     fn maybe_run(&self, builder: &Builder<'_>, pathset: &PathSet) {
-        if builder.config.exclude.iter().any(|e| pathset.has(e)) {
-            eprintln!("Skipping {:?} because it is excluded", pathset);
+        if self.is_excluded(builder, pathset) {
             return;
-        } else if !builder.config.exclude.is_empty() {
-            eprintln!(
-                "{:?} not skipped for {:?} -- not in {:?}",
-                pathset, self.name, builder.config.exclude
-            );
         }
 
         // Determine the targets participating in this rule.
@@ -182,6 +176,21 @@ impl StepDescription {
         }
     }
 
+    fn is_excluded(&self, builder: &Builder<'_>, pathset: &PathSet) -> bool {
+        if builder.config.exclude.iter().any(|e| pathset.has(e)) {
+            eprintln!("Skipping {:?} because it is excluded", pathset);
+            return true;
+        }
+
+        if !builder.config.exclude.is_empty() {
+            eprintln!(
+                "{:?} not skipped for {:?} -- not in {:?}",
+                pathset, self.name, builder.config.exclude
+            );
+        }
+        false
+    }
+
     fn run(v: &[StepDescription], builder: &Builder<'_>, paths: &[PathBuf]) {
         let should_runs =
             v.iter().map(|desc| (desc.should_run)(ShouldRun::new(builder))).collect::<Vec<_>>();
@@ -1579,6 +1588,27 @@ impl<'a> Builder<'a> {
         self.cache.put(step, out.clone());
         out
     }
+
+    /// Ensure that a given step is built *only if it's supposed to be built by default*, returning
+    /// its output. This will cache the step, so it's safe (and good!) to call this as often as
+    /// needed to ensure that all dependencies are build.
+    pub(crate) fn ensure_if_default<T, S: Step<Output = Option<T>>>(
+        &'a self,
+        step: S,
+    ) -> S::Output {
+        let desc = StepDescription::from::<S>();
+        let should_run = (desc.should_run)(ShouldRun::new(self));
+
+        // Avoid running steps contained in --exclude
+        for pathset in &should_run.paths {
+            if desc.is_excluded(self, pathset) {
+                return None;
+            }
+        }
+
+        // Only execute if it's supposed to run as default
+        if desc.default && should_run.is_really_default() { self.ensure(step) } else { None }
+    }
 }
 
 #[cfg(test)]