diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2021-10-28 01:01:46 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2021-10-28 01:01:46 +0200 |
commit | 683f0a65fd351bc761e9114bd4bddf11ff9094ec (patch) | |
tree | f1f29665de8d5d0b1aa722ca48888a01a427f124 | |
parent | 0dbd34f31e826d5b33b3688de2486a2cc6a8af3b (diff) | |
download | rebel-683f0a65fd351bc761e9114bd4bddf11ff9094ec.tar rebel-683f0a65fd351bc761e9114bd4bddf11ff9094ec.zip |
executor: use lazy_static for template engine
-rw-r--r-- | crates/executor/src/executor.rs | 15 | ||||
-rw-r--r-- | crates/executor/src/template.rs | 5 |
2 files changed, 12 insertions, 8 deletions
diff --git a/crates/executor/src/executor.rs b/crates/executor/src/executor.rs index ad560e9..e29b5b3 100644 --- a/crates/executor/src/executor.rs +++ b/crates/executor/src/executor.rs @@ -13,7 +13,7 @@ use crate::{ context::{Context, TaskRef}, resolve, task::*, - template::TemplateEngine, + template, }; pub struct Executor<'ctx> { @@ -23,7 +23,6 @@ pub struct Executor<'ctx> { tasks_running: HashMap<RawFd, (UnixStream, TaskRef<'ctx>)>, tasks_done: HashMap<TaskRef<'ctx>, TaskOutput>, rdeps: HashMap<TaskRef<'ctx>, Vec<TaskRef<'ctx>>>, - tpl: TemplateEngine, } impl<'ctx> Executor<'ctx> { @@ -35,7 +34,6 @@ impl<'ctx> Executor<'ctx> { tasks_running: HashMap::new(), tasks_done: HashMap::new(), rdeps: HashMap::new(), - tpl: TemplateEngine::new(), }; for task in taskset { @@ -74,9 +72,11 @@ impl<'ctx> Executor<'ctx> { .iter() .map(|Fetch { name, sha256 }| { Ok(Dependency::Fetch { - name: self.tpl.eval_raw(name, &task.args).with_context(|| { - format!("Failed to evaluate fetch filename for task {}", task) - })?, + name: template::ENGINE + .eval_raw(name, &task.args) + .with_context(|| { + format!("Failed to evaluate fetch filename for task {}", task) + })?, sha256: *sha256, }) }) @@ -225,8 +225,7 @@ impl<'ctx> Executor<'ctx> { let mut run = self.task_setup(task_ref); run.push(&task_def.action.run); - let command = self - .tpl + let command = template::ENGINE .eval(&run.concat(), &task_ref.args) .with_context(|| { format!("Failed to evaluate command template for task {}", task_ref) diff --git a/crates/executor/src/template.rs b/crates/executor/src/template.rs index 0caa30d..b663e7d 100644 --- a/crates/executor/src/template.rs +++ b/crates/executor/src/template.rs @@ -1,4 +1,5 @@ use handlebars::Handlebars; +use lazy_static::lazy_static; use common::error::*; @@ -37,3 +38,7 @@ impl TemplateEngine { self.tpl.render_template(input, args).map_err(Error::new) } } + +lazy_static! { + pub static ref ENGINE: TemplateEngine = TemplateEngine::new(); +} |