summaryrefslogtreecommitdiffstats
path: root/crates
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2024-04-06 12:02:44 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2024-04-06 12:02:44 +0200
commitfaf1624a19ed0e017e5d4715ce5ced1c516fd30a (patch)
tree0454da5f9637bbcc7abc73cd9bbb460ce6b5a1be /crates
parenta488b37a22b72bdcd7b58102387fea98b82918e1 (diff)
downloadrebel-faf1624a19ed0e017e5d4715ce5ced1c516fd30a.tar
rebel-faf1624a19ed0e017e5d4715ce5ced1c516fd30a.zip
driver: recipe: use separate structs for recipe and subrecipe reading
Subrecipes don't have a meta section.
Diffstat (limited to 'crates')
-rw-r--r--crates/driver/src/recipe.rs17
1 files changed, 11 insertions, 6 deletions
diff --git a/crates/driver/src/recipe.rs b/crates/driver/src/recipe.rs
index 3d3f847..bf8ab99 100644
--- a/crates/driver/src/recipe.rs
+++ b/crates/driver/src/recipe.rs
@@ -1,7 +1,7 @@
use std::{collections::HashMap, ffi::OsStr, fs::File, path::Path, result};
use scoped_tls_hkt::scoped_thread_local;
-use serde::{Deserialize, Deserializer};
+use serde::{de::DeserializeOwned, Deserialize, Deserializer};
use walkdir::WalkDir;
use common::{error::*, types::*};
@@ -37,14 +37,19 @@ struct Recipe {
pub tasks: HashMap<String, TaskDef>,
}
-fn read_recipe(path: &Path) -> Result<Recipe> {
+#[derive(Debug, Deserialize)]
+struct Subrecipe {
+ pub tasks: HashMap<String, TaskDef>,
+}
+
+fn read_yaml<T: DeserializeOwned>(path: &Path) -> Result<T> {
let f = File::open(path).context("IO error")?;
- let recipe: Recipe = serde_yaml::from_reader(f)
+ let value: T = serde_yaml::from_reader(f)
.map_err(Error::new)
.context("YAML error")?;
- Ok(recipe)
+ Ok(value)
}
const RECIPE_NAME: &str = "build";
@@ -82,7 +87,7 @@ fn read_recipe_tasks(
basename: &str,
tasks: &mut HashMap<TaskID, Vec<TaskDef>>,
) -> Result<RecipeMeta> {
- let recipe_def = CURRENT_RECIPE.set(basename, || read_recipe(path))?;
+ let recipe_def = CURRENT_RECIPE.set(basename, || read_yaml::<Recipe>(path))?;
let name = recipe_def
.meta
@@ -112,7 +117,7 @@ fn read_subrecipe_tasks(
tasks: &mut HashMap<TaskID, Vec<TaskDef>>,
) -> Result<()> {
let recipe = format!("{basename}/{recipename}");
- let recipe_def = CURRENT_RECIPE.set(&recipe, || read_recipe(path))?;
+ let recipe_def = CURRENT_RECIPE.set(&recipe, || read_yaml::<Subrecipe>(path))?;
let name = recipe_meta.name.as_deref().unwrap_or(basename).to_string();