diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-04 18:07:12 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-04 18:31:19 +0200 |
commit | e39de9b1dd3b9bf75ef99667fd10badd7908e0df (patch) | |
tree | 118c449f3ad368ce9098281bb11a3f4fc6608811 /crates | |
parent | 1896ea04204b8086a4f25e257dc5605e5505d768 (diff) | |
download | rebel-e39de9b1dd3b9bf75ef99667fd10badd7908e0df.tar rebel-e39de9b1dd3b9bf75ef99667fd10badd7908e0df.zip |
driver: add support for build.<name>.yml subrecipes
Diffstat (limited to 'crates')
-rw-r--r-- | crates/driver/src/parse.rs | 5 | ||||
-rw-r--r-- | crates/driver/src/recipe.rs | 31 |
2 files changed, 29 insertions, 7 deletions
diff --git a/crates/driver/src/parse.rs b/crates/driver/src/parse.rs index f08254a..da85c99 100644 --- a/crates/driver/src/parse.rs +++ b/crates/driver/src/parse.rs @@ -32,8 +32,11 @@ peg::parser! { rule name() -> &'input str = $(name_char()+) + rule recipe_id() -> &'input str + = $(name() ("/" name())?) + rule task_id() -> TaskID<'input> - = recipe:name() ":" task:name() { + = recipe:recipe_id() ":" task:name() { TaskID { recipe, task } } diff --git a/crates/driver/src/recipe.rs b/crates/driver/src/recipe.rs index 3a033f1..f491ff6 100644 --- a/crates/driver/src/recipe.rs +++ b/crates/driver/src/recipe.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, ffi::OsStr, fs::File, path::Path, result}; +use std::{borrow::Cow, collections::HashMap, ffi::OsStr, fs::File, path::Path, result}; use scoped_tls_hkt::scoped_thread_local; use serde::{Deserialize, Deserializer}; @@ -47,8 +47,19 @@ fn read_recipe(path: &Path) -> Result<Recipe> { Ok(recipe) } -fn is_recipe(path: &Path) -> bool { - path.file_name().unwrap_or_default() == "build.yml" +const RECIPE_NAME: &str = "build"; +const RECIPE_PREFIX: &str = "build."; + +fn recipe_name(path: &Path) -> Option<&str> { + if path.extension() != Some("yml".as_ref()) { + return None; + } + + let stem = path.file_stem()?.to_str()?; + if stem == RECIPE_NAME { + return Some(""); + } + stem.strip_prefix(RECIPE_PREFIX) } pub fn read_recipes<P: AsRef<Path>>(path: P) -> Result<HashMap<TaskID, Vec<TaskDef>>> { @@ -60,10 +71,13 @@ pub fn read_recipes<P: AsRef<Path>>(path: P) -> Result<HashMap<TaskID, Vec<TaskD .filter_map(|e| e.ok()) { let path = entry.path(); - if !path.is_file() || !is_recipe(path) { + if !path.is_file() { continue; } + let Some(recipename) = recipe_name(path) else { + continue; + }; let Some(basename) = path .parent() .and_then(Path::file_name) @@ -71,8 +85,13 @@ pub fn read_recipes<P: AsRef<Path>>(path: P) -> Result<HashMap<TaskID, Vec<TaskD else { continue; }; + let base_recipename = if recipename.is_empty() { + Cow::Borrowed(basename) + } else { + Cow::Owned(format!("{basename}/{recipename}")) + }; - let recipe = CURRENT_RECIPE.set(basename, || read_recipe(path))?; + let recipe = CURRENT_RECIPE.set(&base_recipename, || read_recipe(path))?; let mut meta = recipe.meta; if meta.name.is_empty() { @@ -81,7 +100,7 @@ pub fn read_recipes<P: AsRef<Path>>(path: P) -> Result<HashMap<TaskID, Vec<TaskD for (label, mut task) in recipe.tasks { let task_id = TaskID { - recipe: basename.to_string(), + recipe: base_recipename.as_ref().to_owned(), task: label, }; task.meta = meta.clone(); |