summaryrefslogtreecommitdiffstats
path: root/src/executor.rs
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2021-07-24 18:12:48 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2021-07-24 18:12:48 +0200
commit0e5d0d5edf8860ed2803b1425dee8573917b2d22 (patch)
treec2267c79707e1230e9bfe3710ba32335e08241f1 /src/executor.rs
parent5e07bcccacbe812019a87045621fc531c2721adf (diff)
downloadrebel-0e5d0d5edf8860ed2803b1425dee8573917b2d22.tar
rebel-0e5d0d5edf8860ed2803b1425dee8573917b2d22.zip
Separate runner input from InputHash input
We need dependencies' actions in the runner to handle sysroot unpacking, but we don't want them in the TaskOutput. To keep TaskInput and TaskOutput similar, a separate definition for passing tasks to the runner is introduced. The TaskInput and TaskOutput structs are simplified, and the depends TaskRef are replaced with the dependencies InputHashes. This allows to walk the dependency chain of TaskOutputs.
Diffstat (limited to 'src/executor.rs')
-rw-r--r--src/executor.rs61
1 files changed, 47 insertions, 14 deletions
diff --git a/src/executor.rs b/src/executor.rs
index a1053b8..35255ab 100644
--- a/src/executor.rs
+++ b/src/executor.rs
@@ -4,6 +4,8 @@ use std::{
path::{Path, PathBuf},
};
+use serde::{Deserialize, Serialize};
+
use crate::{runner, types::*, util::cjson};
fn tmp_filename(hash: &InputHash) -> PathBuf {
@@ -28,6 +30,27 @@ const TASK_ENV: &[(&str, &str)] = &[
("PREFIX", "/opt/sysroot"),
];
+#[derive(Clone, Debug, Serialize)]
+struct TaskInput<'a> {
+ pub id: &'a TaskRef,
+ pub depends: &'a HashMap<OutputHash, InputHash>,
+ pub action: &'a TaskAction,
+}
+
+impl<'a> TaskInput<'a> {
+ fn input_hash(&self) -> InputHash {
+ StringHash(cjson::digest::<InputHasher, _>(self).unwrap().into())
+ }
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+struct TaskOutput {
+ pub id: TaskRef,
+ pub depends: HashMap<OutputHash, InputHash>,
+ pub input_hash: InputHash,
+ pub output_hash: OutputHash,
+}
+
#[derive(Debug)]
pub struct Executor<'a> {
tasks: &'a TaskMap,
@@ -85,17 +108,23 @@ impl<'a> Executor<'a> {
.all(|dep| self.tasks_done.contains_key(dep))
}
- fn task_deps(&self, task: &Task) -> HashMap<OutputHash, TaskRef> {
+ fn task_deps(&self, task: &Task) -> HashMap<OutputHash, InputHash> {
+ task.depends
+ .iter()
+ .map(|dep| {
+ let output = &self.tasks_done[dep];
+ (output.output_hash, output.input_hash)
+ })
+ .collect()
+ }
+
+ fn task_deps_with_actions(&self, task: &Task) -> HashMap<OutputHash, TaskAction> {
task.depends
.iter()
.map(|dep| {
- (
- self.tasks_done
- .get(dep)
- .expect("Invalid dependency")
- .output_hash,
- dep.clone(),
- )
+ let task = &self.tasks[&dep.id];
+ let output = &self.tasks_done[dep];
+ (output.output_hash, task.action.clone())
})
.collect()
}
@@ -105,24 +134,28 @@ impl<'a> Executor<'a> {
let task_def = self.tasks.get(&task_ref.id).expect("Invalid TaskRef");
let task_deps = self.task_deps(&task_def);
+ let input_hash = TaskInput {
+ id: &task_ref,
+ depends: &task_deps,
+ action: &task_def.action,
+ }
+ .input_hash();
+
let TaskAction::Run(run) = &task_def.action;
- let task = RunTaskInput {
+ let task = runner::Task {
id: task_ref.clone(),
run: run.clone(),
- depends: task_deps,
+ depends: self.task_deps_with_actions(&task_def),
env: self.env.clone(),
};
- let input_hash = task.input_hash();
-
let output_hash = runner.run(&task)?;
let output = TaskOutput {
id: task.id.clone(),
- depends: task.depends,
+ depends: task_deps,
input_hash,
output_hash,
- env: task.env,
};
save_output(&output)?;