summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2021-06-20 20:57:15 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2021-06-20 20:57:15 +0200
commitd486a774540c27ba8c06f8cdd3a95326cbdb0028 (patch)
tree4bc02193cd78a9919b34bc821c606c1942d2a1be
parent79a60833a6f7c856818afc0b0ef7a51bbf158072 (diff)
downloadrebel-d486a774540c27ba8c06f8cdd3a95326cbdb0028.tar
rebel-d486a774540c27ba8c06f8cdd3a95326cbdb0028.zip
executor: generate and print task output information
-rw-r--r--Cargo.lock10
-rw-r--r--Cargo.toml1
-rw-r--r--src/executor.rs35
-rw-r--r--src/recipe.rs2
-rw-r--r--src/runner/runc.rs2
-rw-r--r--src/runner/runc/run.rs6
-rw-r--r--src/types.rs35
7 files changed, 76 insertions, 15 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 971fa43..9c353d9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -162,6 +162,15 @@ dependencies = [
]
[[package]]
+name = "hex"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
+dependencies = [
+ "serde",
+]
+
+[[package]]
name = "iovec"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -427,6 +436,7 @@ dependencies = [
name = "rebel"
version = "0.1.0"
dependencies = [
+ "hex",
"ipc-channel",
"libc",
"nix",
diff --git a/Cargo.toml b/Cargo.toml
index dd9f7fe..074267d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,6 +8,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+hex = { version = "0.4.3", features = ["std", "serde"] }
ipc-channel = { git = "https://github.com/servo/ipc-channel.git" }
libc = "0.2.84"
nix = "0.21.0"
diff --git a/src/executor.rs b/src/executor.rs
index c616c0b..350acc3 100644
--- a/src/executor.rs
+++ b/src/executor.rs
@@ -7,7 +7,7 @@ pub struct Executor<'a> {
tasks: &'a TaskMap,
tasks_blocked: HashSet<TaskRef>,
tasks_runnable: Vec<TaskRef>,
- tasks_done: HashSet<TaskRef>,
+ tasks_done: HashMap<TaskRef, TaskOutput>,
rdeps: HashMap<TaskRef, Vec<TaskRef>>,
}
@@ -17,7 +17,7 @@ impl<'a> Executor<'a> {
tasks,
tasks_blocked: HashSet::new(),
tasks_runnable: Vec::new(),
- tasks_done: HashSet::new(),
+ tasks_done: HashMap::new(),
rdeps: HashMap::new(),
};
@@ -44,17 +44,39 @@ impl<'a> Executor<'a> {
task_def
.depends
.iter()
- .all(|dep| self.tasks_done.contains(dep))
+ .all(|dep| self.tasks_done.contains_key(dep))
+ }
+
+ fn task_deps(&self, task: &TaskRef) -> HashMap<TaskRef, OutputHash> {
+ let task_def = self.tasks.get(&task).expect("Invalid TaskRef");
+ task_def
+ .depends
+ .iter()
+ .map(|dep| {
+ (
+ dep.clone(),
+ self.tasks_done
+ .get(dep)
+ .expect("Invalid dependency")
+ .output_hash,
+ )
+ })
+ .collect()
}
fn run_one(&mut self, runner: &impl runner::Runner) -> runner::Result<()> {
let task = self.tasks_runnable.pop().expect("No runnable tasks left");
+ let task_deps = self.task_deps(&task);
- let _hash = runner.run(self.tasks, &task)?;
+ let hash = runner.run(self.tasks, &task)?;
+ let output = TaskOutput {
+ task_ref: task.clone(),
+ depends: task_deps,
+ output_hash: hash,
+ };
let rdeps = self.rdeps.get(&task);
-
- self.tasks_done.insert(task);
+ self.tasks_done.insert(task, output);
for rdep in rdeps.unwrap_or(&Vec::new()) {
if !self.tasks_blocked.contains(rdep) {
@@ -75,6 +97,7 @@ impl<'a> Executor<'a> {
}
assert!(self.tasks_blocked.is_empty(), "No runnable tasks left");
+ println!("{}", serde_json::to_string_pretty(&self.tasks_done)?);
Ok(())
}
}
diff --git a/src/recipe.rs b/src/recipe.rs
index 20bca6d..f088e9b 100644
--- a/src/recipe.rs
+++ b/src/recipe.rs
@@ -6,7 +6,7 @@ use crate::types::*;
#[derive(Clone, Debug, Deserialize)]
pub struct Recipe {
- pub tasks: HashMap<String, Task>,
+ pub tasks: HashMap<String, TaskDef>,
}
#[derive(Debug)]
diff --git a/src/runner/runc.rs b/src/runner/runc.rs
index ae61013..9725d92 100644
--- a/src/runner/runc.rs
+++ b/src/runner/runc.rs
@@ -15,7 +15,7 @@ use crate::util::ipc::CheckDisconnect;
#[derive(Debug, Deserialize, Serialize)]
struct Request(
TaskRef,
- Task,
+ TaskDef,
ipc::IpcSender<Result<OutputHash, run::Error>>,
);
diff --git a/src/runner/runc/run.rs b/src/runner/runc/run.rs
index dc62159..9eb5bc0 100644
--- a/src/runner/runc/run.rs
+++ b/src/runner/runc/run.rs
@@ -69,7 +69,7 @@ fn output_filename(task: TaskRef) -> PathBuf {
Path::new("build/state").join(format!("{}.tar", task))
}
-fn collect_output(task: TaskRef, task_def: Task) -> Result<OutputHash, io::Error> {
+fn collect_output(task: TaskRef, task_def: TaskDef) -> Result<OutputHash, io::Error> {
let file = util::unix::create_as(
output_filename(task),
Some(unshare::BUILD_UID),
@@ -83,10 +83,10 @@ fn collect_output(task: TaskRef, task_def: Task) -> Result<OutputHash, io::Error
file.sync_all()?;
- Ok(hasher.finalize().into())
+ Ok(StringHash(hasher.finalize().into()))
}
-pub fn handle_task(task: TaskRef, task_def: Task) -> Result<OutputHash, Error> {
+pub fn handle_task(task: TaskRef, task_def: TaskDef) -> Result<OutputHash, Error> {
init_task()?;
spec::generate_spec(task_def.run.as_str())
diff --git a/src/types.rs b/src/types.rs
index afee0e3..3cf4826 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -5,7 +5,7 @@ use std::collections::HashMap;
pub type TaskRef = String;
#[derive(Clone, Debug, Deserialize, Serialize)]
-pub struct Task {
+pub struct TaskDef {
#[serde(default)]
pub depends: Vec<TaskRef>,
#[serde(default)]
@@ -14,13 +14,40 @@ pub struct Task {
}
#[derive(Debug, Default)]
-pub struct TaskMap(pub HashMap<String, Task>);
+pub struct TaskMap(pub HashMap<String, TaskDef>);
impl TaskMap {
- pub fn get(&self, task: &TaskRef) -> Option<&Task> {
+ pub fn get(&self, task: &TaskRef) -> Option<&TaskDef> {
self.0.get(task)
}
}
+#[derive(Clone, Copy, Debug)]
+pub struct StringHash(pub [u8; 32]);
+
+impl Serialize for StringHash {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: serde::Serializer,
+ {
+ hex::serde::serialize(self.0, serializer)
+ }
+}
+impl<'de> Deserialize<'de> for StringHash {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: serde::Deserializer<'de>,
+ {
+ Ok(StringHash(hex::serde::deserialize(deserializer)?))
+ }
+}
+
pub type OutputHasher = Sha256;
-pub type OutputHash = [u8; 32];
+pub type OutputHash = StringHash;
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+pub struct TaskOutput {
+ pub task_ref: TaskRef,
+ pub depends: HashMap<TaskRef, OutputHash>,
+ pub output_hash: OutputHash,
+}