diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/context.rs | 14 | ||||
-rw-r--r-- | src/recipe.rs | 28 | ||||
-rw-r--r-- | src/task.rs | 4 | ||||
-rw-r--r-- | src/types.rs | 7 |
4 files changed, 42 insertions, 11 deletions
diff --git a/src/context.rs b/src/context.rs index 77f1389..bb226f5 100644 --- a/src/context.rs +++ b/src/context.rs @@ -131,7 +131,11 @@ impl Context { } pub fn parse<'ctx>(&'ctx self, s: &str) -> Option<TaskRef> { - let id = TaskID(s.to_string()); + let (recipe, task) = s.split_once(":")?; + let id = TaskID { + recipe: recipe.to_string(), + task: task.to_string(), + }; let (ctx_id, _) = self.tasks.get_key_value(&id)?; self.task_ref(ctx_id, &self.default_args).ok() } @@ -167,8 +171,8 @@ impl Context { } fn inherit_ref<'ctx>(&'ctx self, dep: &'ctx InheritDep, args: &TaskArgs) -> Result<TaskRef> { - let mapped_args = Context::map_args(&dep.dep.task, &dep.dep.args, args, false)?; - self.task_ref(&dep.dep.task, mapped_args.as_ref()) + let mapped_args = Context::map_args(&dep.dep.id, &dep.dep.args, args, false)?; + self.task_ref(&dep.dep.id, mapped_args.as_ref()) } pub fn output_ref<'ctx>( @@ -177,9 +181,9 @@ impl Context { args: &TaskArgs, build_dep: bool, ) -> Result<OutputRef<'ctx>> { - let mapped_args = Context::map_args(&dep.dep.task, &dep.dep.args, args, build_dep)?; + let mapped_args = Context::map_args(&dep.dep.id, &dep.dep.args, args, build_dep)?; Ok(OutputRef { - task: self.task_ref(&dep.dep.task, mapped_args.as_ref())?, + task: self.task_ref(&dep.dep.id, mapped_args.as_ref())?, output: &dep.output, }) } diff --git a/src/recipe.rs b/src/recipe.rs index 15f4c3b..c27d44e 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -1,10 +1,29 @@ -use std::{collections::HashMap, fmt, fs::File, io, path::Path}; +use std::{collections::HashMap, fmt, fs::File, io, path::Path, result}; -use serde::Deserialize; +use serde::{Deserialize, Deserializer}; use walkdir::WalkDir; use crate::{task::TaskDef, types::TaskID}; +pub fn deserialize_task_id<'de, D>(deserializer: D) -> result::Result<TaskID, D::Error> +where + D: Deserializer<'de>, +{ + #[derive(Deserialize)] + struct RecipeTaskID { + task: String, + } + let id = RecipeTaskID::deserialize(deserializer)?; + let (recipe, task) = id + .task + .split_once(":") + .ok_or(serde::de::Error::custom("Invalid task ID"))?; + Ok(TaskID { + recipe: recipe.to_string(), + task: task.to_string(), + }) +} + #[derive(Debug, Deserialize)] struct Recipe { pub tasks: HashMap<String, TaskDef>, @@ -70,7 +89,10 @@ pub fn read_recipes<P: AsRef<Path>>(path: P) -> Result<HashMap<TaskID, TaskDef>> let recipe = read_recipe(path)?; for (label, task) in recipe.tasks { - let task_id = TaskID(format!("{}:{}", basename, label)); + let task_id = TaskID { + recipe: basename.to_string(), + task: label, + }; tasks.insert(task_id, task); } } diff --git a/src/task.rs b/src/task.rs index 1b9b6dc..f921774 100644 --- a/src/task.rs +++ b/src/task.rs @@ -4,12 +4,14 @@ use serde::Deserialize; use crate::{ args::{ArgMapping, ArgType}, + recipe, types::{StringHash, TaskID}, }; #[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash)] pub struct TaskDep { - pub task: TaskID, + #[serde(flatten, deserialize_with = "recipe::deserialize_task_id")] + pub id: TaskID, #[serde(default)] pub args: ArgMapping, } diff --git a/src/types.rs b/src/types.rs index d831aa3..51b9420 100644 --- a/src/types.rs +++ b/src/types.rs @@ -60,11 +60,14 @@ pub type ArchiveHasher = Sha256; stringhash_newtype!(ArchiveHash); #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)] -pub struct TaskID(pub String); +pub struct TaskID { + pub recipe: String, + pub task: String, +} impl Display for TaskID { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - self.0.fmt(f) + write!(f, "{}:{}", self.recipe, self.task) } } |