summaryrefslogtreecommitdiffstats
path: root/crates/driver/src/recipe.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/driver/src/recipe.rs')
-rw-r--r--crates/driver/src/recipe.rs97
1 files changed, 0 insertions, 97 deletions
diff --git a/crates/driver/src/recipe.rs b/crates/driver/src/recipe.rs
deleted file mode 100644
index c6a06f1..0000000
--- a/crates/driver/src/recipe.rs
+++ /dev/null
@@ -1,97 +0,0 @@
-use std::{collections::HashMap, fs::File, path::Path, result};
-
-use scoped_tls_hkt::scoped_thread_local;
-use serde::{Deserialize, Deserializer};
-use walkdir::WalkDir;
-
-use common::{error::*, types::*};
-
-use crate::task::{RecipeMeta, TaskDef};
-
-scoped_thread_local!(static CURRENT_RECIPE: str);
-
-fn current_recipe() -> String {
- CURRENT_RECIPE.with(|current| current.to_string())
-}
-
-pub fn deserialize_task_id<'de, D>(deserializer: D) -> result::Result<TaskID, D::Error>
-where
- D: Deserializer<'de>,
-{
- #[derive(Deserialize)]
- struct RecipeTaskID {
- recipe: Option<String>,
- task: String,
- }
- let RecipeTaskID { recipe, task } = RecipeTaskID::deserialize(deserializer)?;
- Ok(TaskID {
- recipe: recipe.unwrap_or_else(current_recipe),
- task,
- })
-}
-
-#[derive(Debug, Deserialize)]
-struct Recipe {
- #[serde(default)]
- pub meta: RecipeMeta,
- pub tasks: HashMap<String, TaskDef>,
-}
-
-fn read_recipe(path: &Path) -> Result<Recipe> {
- let f = File::open(path).context("IO error")?;
-
- let recipe: Recipe = serde_yaml::from_reader(f)
- .map_err(Error::new)
- .context("YAML error")?;
-
- Ok(recipe)
-}
-
-fn is_yml(path: &Path) -> bool {
- path.extension() == Some("yml".as_ref())
-}
-
-pub fn read_recipes<P: AsRef<Path>>(path: P) -> Result<HashMap<TaskID, Vec<TaskDef>>> {
- let mut tasks = HashMap::<TaskID, Vec<TaskDef>>::new();
-
- for entry in WalkDir::new(path)
- .sort_by_file_name()
- .into_iter()
- .filter_map(|e| e.ok())
- {
- let path = entry.path();
- if !path.is_file() || !is_yml(path) {
- continue;
- }
-
- let stem: &str = match path.file_stem().map(|n| n.to_str()) {
- Some(Some(v)) => v,
- _ => continue,
- };
- let (basename, version) = match stem.split_once("@") {
- Some((basename, version)) => (basename, Some(version)),
- None => (stem, None),
- };
-
- let recipe = CURRENT_RECIPE.set(basename, || read_recipe(path))?;
-
- let mut meta = recipe.meta;
- if meta.name.is_empty() {
- meta.name = basename.to_string();
- }
- if meta.version.is_none() {
- meta.version = version.map(|v| v.to_string());
- }
-
- for (label, mut task) in recipe.tasks {
- let task_id = TaskID {
- recipe: basename.to_string(),
- task: label,
- };
- task.meta = meta.clone();
- tasks.entry(task_id).or_default().push(task);
- }
- }
-
- Ok(tasks)
-}