summaryrefslogtreecommitdiffstats
path: root/src/executor.rs
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2021-09-22 17:12:37 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2021-09-22 17:21:39 +0200
commit74bfe80bd104fe8e71b4dbffc41e8f15d494f709 (patch)
tree77cf51026df4dd626e7525d669d67ea6dad01bcb /src/executor.rs
parent6a5aea9df9183ea7ee4c7900d7c6f856df2d47b4 (diff)
downloadrebel-74bfe80bd104fe8e71b4dbffc41e8f15d494f709.tar
rebel-74bfe80bd104fe8e71b4dbffc41e8f15d494f709.zip
Use same struct for InputHash and to pass task data to the runner
Diffstat (limited to 'src/executor.rs')
-rw-r--r--src/executor.rs57
1 files changed, 21 insertions, 36 deletions
diff --git a/src/executor.rs b/src/executor.rs
index 39a7cc9..8b7965f 100644
--- a/src/executor.rs
+++ b/src/executor.rs
@@ -19,22 +19,11 @@ const BASE_ARGS: &[(&str, &str)] = &[
("destdir", "/build/dest"),
];
-#[derive(Clone, Debug, Serialize)]
-struct TaskInput<'ctx> {
- pub inherit: Option<&'ctx InputHash>,
- pub depends: &'ctx HashMap<DependencyHash, Dependency>,
- pub output: &'ctx HashMap<String, String>,
- pub command: &'ctx str,
+fn input_hash(task: &runner::TaskInput) -> InputHash {
+ InputHash(StringHash(
+ cjson::digest::<InputHasher, _>(task).unwrap().into(),
+ ))
}
-
-impl<'ctx> TaskInput<'ctx> {
- fn input_hash(&self) -> InputHash {
- InputHash(StringHash(
- cjson::digest::<InputHasher, _>(self).unwrap().into(),
- ))
- }
-}
-
#[derive(Clone, Debug, Deserialize, Serialize)]
struct TaskMeta {
pub id: TaskID,
@@ -167,15 +156,14 @@ impl<'ctx> Executor<'ctx> {
})
.collect();
- let (inherit_chain, inherit_hash) =
- if let Some(inherit_dep) = self.ctx.get_inherit_depend(task_ref) {
+ let inherit_chain = self
+ .ctx
+ .get_inherit_depend(task_ref)
+ .map(|inherit_dep| {
let inherit_meta = &self.tasks_done[&inherit_dep];
- let mut inherit_chain = inherit_meta.inherit.clone();
- inherit_chain.push(inherit_meta.input_hash);
- (inherit_chain, Some(&inherit_meta.input_hash))
- } else {
- (Vec::new(), None)
- };
+ [inherit_meta.inherit.as_slice(), &[inherit_meta.input_hash]].concat()
+ })
+ .unwrap_or_default();
let command = self
.eval_command(&task_def, &task_ref.args)
@@ -183,13 +171,13 @@ impl<'ctx> Executor<'ctx> {
format!("Failed to evaluate command template for task {}", task_ref)
})?;
- let input_hash = TaskInput {
- inherit: inherit_hash,
- depends: &task_deps,
- output: &task_output,
- command: &command,
- }
- .input_hash();
+ let input = runner::TaskInput {
+ command,
+ inherit: inherit_chain,
+ depends: task_deps,
+ output: task_output,
+ };
+ let input_hash = input_hash(&input);
// Use cached result
if let Ok(meta) = TaskMeta::load(&input_hash) {
@@ -205,11 +193,8 @@ impl<'ctx> Executor<'ctx> {
let task = runner::Task {
label: format!("{}{:?}", task_ref.id, task_ref.args.0),
- command,
+ input,
input_hash,
- inherit: inherit_chain.clone(),
- depends: task_deps.clone(),
- output: task_output,
};
let output = runner.run(&task)?;
@@ -217,8 +202,8 @@ impl<'ctx> Executor<'ctx> {
let meta = TaskMeta {
id: task_ref.id.clone(),
args: task_ref.args.clone(),
- inherit: inherit_chain,
- depends: task_deps,
+ inherit: task.input.inherit,
+ depends: task.input.depends,
input_hash,
output,
};