diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-05 20:34:16 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-06 00:00:02 +0200 |
commit | dd1dae3d269b9bcae9c0a8b818eca780bc3f86f9 (patch) | |
tree | 3242c3f44cef54421010110b049dbf9271f4c5ba /crates | |
parent | ce1f8acf6ae86d3a09c097f41e2173a7c5ee36e1 (diff) | |
download | rebel-dd1dae3d269b9bcae9c0a8b818eca780bc3f86f9.tar rebel-dd1dae3d269b9bcae9c0a8b818eca780bc3f86f9.zip |
driver: refactor CompletionState::task_deps()
Diffstat (limited to 'crates')
-rw-r--r-- | crates/driver/src/driver.rs | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/crates/driver/src/driver.rs b/crates/driver/src/driver.rs index 8acf50a..58d356b 100644 --- a/crates/driver/src/driver.rs +++ b/crates/driver/src/driver.rs @@ -10,7 +10,7 @@ use common::{error::*, string_hash::*, types::*}; use runner::Runner; use crate::{ - context::{Context, TaskRef}, + context::{Context, OutputRef, TaskRef}, paths, resolve, task::*, template, @@ -58,41 +58,44 @@ impl<'ctx> CompletionState<'ctx> { .collect() } - fn task_deps(&self, task: &TaskRef<'ctx>) -> Result<HashSet<Dependency>> { - Ok(self - .fetch_deps(task)? + fn dep_closure<I>(&self, deps: I, path: &'ctx str) -> impl Iterator<Item = Dependency> + '_ + where + I: IntoIterator<Item = OutputRef<'ctx>>, + { + resolve::runtime_depends(self.ctx, deps) + .expect("invalid runtime depends") .into_iter() - .chain( - resolve::runtime_depends( - self.ctx, - self.ctx - .get_build_depends(task) - .with_context(|| format!("invalid build depends for {}", task))?, - ) - .expect("invalid runtime depends of build_depends") - .into_iter() - .filter_map(|dep| self.tasks_done[&dep.task].outputs.get(dep.output)) - .map(|&output| Dependency::Task { - output, - path: "".to_string(), - }), - ) - .chain( - resolve::runtime_depends( - self.ctx, - self.ctx - .get_host_depends(task) - .with_context(|| format!("invalid depends for {}", task))?, - ) - .expect("invalid runtime depends of host_depends") - .into_iter() - .filter_map(|dep| self.tasks_done[&dep.task].outputs.get(dep.output)) - .map(|&output| Dependency::Task { - output, - path: paths::TASK_SYSROOT.to_string(), - }), - ) - .collect()) + .filter_map(|dep| self.tasks_done[&dep.task].outputs.get(dep.output)) + .map(|&output| Dependency::Task { + output, + path: path.to_string(), + }) + } + + fn build_deps(&self, task: &TaskRef<'ctx>) -> Result<impl Iterator<Item = Dependency> + '_> { + Ok(self.dep_closure( + self.ctx + .get_build_depends(task) + .with_context(|| format!("invalid build depends for {}", task))?, + "", + )) + } + + fn host_deps(&self, task: &TaskRef<'ctx>) -> Result<impl Iterator<Item = Dependency> + '_> { + Ok(self.dep_closure( + self.ctx + .get_host_depends(task) + .with_context(|| format!("invalid depends for {}", task))?, + paths::TASK_SYSROOT, + )) + } + + fn task_deps(&self, task: &TaskRef<'ctx>) -> Result<HashSet<Dependency>> { + let fetch_deps = self.fetch_deps(task)?.into_iter(); + let build_deps = self.build_deps(task)?; + let host_deps = self.host_deps(task)?; + + Ok(fetch_deps.chain(build_deps).chain(host_deps).collect()) } fn task_inherit_chain(&self, task_ref: &TaskRef<'ctx>) -> Vec<LayerHash> { |