diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2021-01-28 19:54:37 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2021-01-28 19:54:53 +0100 |
commit | f15e7d4aa6554f5039484c0e03c5641921ff032f (patch) | |
tree | 4ad05129056312b8602f688d9ea0eafaccd02139 /src | |
parent | 8e0ff0e22fc32af2e20c4c4d07a8c4cf11e0e860 (diff) | |
download | rebel-f15e7d4aa6554f5039484c0e03c5641921ff032f.tar rebel-f15e7d4aa6554f5039484c0e03c5641921ff032f.zip |
Prepare for running stuff through buildah
Diffstat (limited to 'src')
-rw-r--r-- | src/executor.rs | 16 | ||||
-rw-r--r-- | src/main.rs | 12 | ||||
-rw-r--r-- | src/runner.rs | 11 | ||||
-rw-r--r-- | src/runner/buildah.rs | 22 |
4 files changed, 52 insertions, 9 deletions
diff --git a/src/executor.rs b/src/executor.rs index 18944cd..e07b4e3 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -1,6 +1,6 @@ use std::collections::{HashMap, HashSet}; -use crate::types::*; +use crate::{runner, types::*}; #[derive(Debug)] pub struct Executor<'a> { @@ -47,10 +47,10 @@ impl<'a> Executor<'a> { .all(|dep| self.tasks_done.contains(dep)) } - fn run_one(&mut self) { + fn run_one(&mut self, runner: &impl runner::Runner) -> runner::Result<()> { let task = self.tasks_runnable.pop().expect("No runnable tasks left"); - println!("Running {}", task); - println!("Running {} done.", task); + + runner.run(&task)?; let rdeps = self.rdeps.get(&task); @@ -65,13 +65,17 @@ impl<'a> Executor<'a> { self.tasks_runnable.push(rdep.clone()); } } + + Ok(()) } - pub fn run(&mut self) { + pub fn run(&mut self) -> runner::Result<()> { + let runner = runner::buildah::RunnerBuildah::new(self.tasks); while !self.tasks_runnable.is_empty() { - self.run_one(); + self.run_one(&runner)?; } assert!(self.tasks_blocked.is_empty(), "No runnable tasks left"); + Ok(()) } } diff --git a/src/main.rs b/src/main.rs index 4ebb2bd..72178be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,11 @@ -use std::path::Path; - mod executor; mod recipe; mod resolve; +mod runner; mod types; +use std::path::Path; + use types::*; fn main() { @@ -29,5 +30,10 @@ fn main() { } let taskset = rsv.to_taskset(); let mut executor = executor::Executor::new(&tasks, taskset); - executor.run(); + + let result = executor.run(); + if let Err(error) = result { + eprintln!("{}", error); + std::process::exit(1); + } } diff --git a/src/runner.rs b/src/runner.rs new file mode 100644 index 0000000..7b94573 --- /dev/null +++ b/src/runner.rs @@ -0,0 +1,11 @@ +pub mod buildah; + +use std::io; + +use crate::types::*; + +pub type Result<T> = io::Result<T>; + +pub trait Runner { + fn run(&self, task: &TaskRef) -> Result<()>; +} diff --git a/src/runner/buildah.rs b/src/runner/buildah.rs new file mode 100644 index 0000000..a4f0d3b --- /dev/null +++ b/src/runner/buildah.rs @@ -0,0 +1,22 @@ +use super::*; +use crate::types::*; + +pub struct RunnerBuildah<'a> { + tasks: &'a TaskMap, +} + +impl<'a> RunnerBuildah<'a> { + pub fn new(tasks: &'a TaskMap) -> Self { + RunnerBuildah { tasks } + } +} + +impl<'a> Runner for RunnerBuildah<'a> { + fn run(&self, task: &TaskRef) -> Result<()> { + let task_def = self.tasks.get(task).expect("Invalid TaskRef"); + + println!("{}: {:?}", task, task_def.run); + + Ok(()) + } +} |