summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2024-04-20 16:19:47 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2024-04-20 16:19:47 +0200
commitedf1d5a5cea4bfb662696f3b5c24dbd95e1733c1 (patch)
tree6616f238cb4eee9a2c11cfe21a6927768f18359e
parent712d356b969540c7f09fad08c141e3c6aadde00f (diff)
downloadrebel-edf1d5a5cea4bfb662696f3b5c24dbd95e1733c1.tar
rebel-edf1d5a5cea4bfb662696f3b5c24dbd95e1733c1.zip
rebel: avoid thread-local for reading recipes
This also disentangles dependencies between modules a bit.
-rw-r--r--Cargo.lock7
-rw-r--r--crates/rebel/Cargo.toml1
-rw-r--r--crates/rebel/src/context.rs18
-rw-r--r--crates/rebel/src/recipe.rs33
-rw-r--r--crates/rebel/src/resolve.rs2
-rw-r--r--crates/rebel/src/task.rs19
6 files changed, 30 insertions, 50 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 3a4c596..df7f3f3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -492,7 +492,6 @@ dependencies = [
"rebel-common",
"rebel-parse",
"rebel-runner",
- "scoped-tls-hkt",
"serde",
"serde_yaml",
"walkdir",
@@ -571,12 +570,6 @@ dependencies = [
]
[[package]]
-name = "scoped-tls-hkt"
-version = "0.1.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3ddc765d3410d9f6c6ca071bf0b67f6b01e3ec4595dc3892f02677e75819dddc"
-
-[[package]]
name = "serde"
version = "1.0.198"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/crates/rebel/Cargo.toml b/crates/rebel/Cargo.toml
index 9f229c8..18f85e1 100644
--- a/crates/rebel/Cargo.toml
+++ b/crates/rebel/Cargo.toml
@@ -19,7 +19,6 @@ handlebars = "5.1.2"
indoc = "2.0.4"
lazy_static = "1.4.0"
nix = { version = "0.28.0", features = ["poll", "signal"] }
-scoped-tls-hkt = "0.1.2"
serde = { version = "1", features = ["derive", "rc"] }
serde_yaml = "0.9"
walkdir = "2"
diff --git a/crates/rebel/src/context.rs b/crates/rebel/src/context.rs
index bf16546..b8090d1 100644
--- a/crates/rebel/src/context.rs
+++ b/crates/rebel/src/context.rs
@@ -437,19 +437,25 @@ impl Context {
Ok(Cow::Owned(ret))
}
- fn parent_ref<'ctx>(&'ctx self, dep: &'ctx ParentDep, args: &TaskArgs) -> Result<TaskRef> {
- let id = dep.dep.id.as_ref();
+ fn parent_ref<'ctx>(
+ &'ctx self,
+ dep_of: TaskIDRef<'ctx>,
+ dep: &'ctx ParentDep,
+ args: &TaskArgs,
+ ) -> Result<TaskRef> {
+ let id = dep.dep.id(dep_of.recipe);
let mapped_args = Context::map_args(id, &dep.dep.args, args, false)?;
self.task_ref(id, mapped_args.as_ref())
}
pub fn output_ref<'ctx>(
&'ctx self,
+ dep_of: TaskIDRef<'ctx>,
dep: &'ctx OutputDep,
args: &TaskArgs,
build_dep: bool,
) -> Result<OutputRef<'ctx>> {
- let id = dep.dep.id.as_ref();
+ let id = dep.dep.id(dep_of.recipe);
let mapped_args = Context::map_args(id, &dep.dep.args, args, build_dep)?;
Ok(OutputRef {
task: self.task_ref(id, mapped_args.as_ref())?,
@@ -465,7 +471,7 @@ impl Context {
let Some(parent) = &task.parent else {
return Ok(None);
};
- Some(self.parent_ref(parent, &task_ref.args)).transpose()
+ Some(self.parent_ref(task_ref.id, parent, &task_ref.args)).transpose()
}
fn ancestor_iter<'ctx>(
@@ -504,7 +510,7 @@ impl Context {
.build_depends
.iter()
.filter(|dep| allow_noinherit || !dep.noinherit)
- .map(|dep| self.output_ref(dep, &current_ref.args, true))
+ .map(|dep| self.output_ref(task_ref.id, dep, &current_ref.args, true))
.collect::<Result<Vec<_>>>()?;
ret.extend(entries);
@@ -528,7 +534,7 @@ impl Context {
.depends
.iter()
.filter(|dep| allow_noinherit || !dep.noinherit)
- .map(|dep| self.output_ref(dep, &current_ref.args, false))
+ .map(|dep| self.output_ref(task_ref.id, dep, &current_ref.args, false))
.collect::<Result<Vec<_>>>()?;
ret.extend(entries);
diff --git a/crates/rebel/src/recipe.rs b/crates/rebel/src/recipe.rs
index 24b4bff..d0bb47e 100644
--- a/crates/rebel/src/recipe.rs
+++ b/crates/rebel/src/recipe.rs
@@ -1,35 +1,12 @@
-use std::{collections::HashMap, ffi::OsStr, fs::File, path::Path, result};
+use std::{collections::HashMap, ffi::OsStr, fs::File, path::Path};
-use scoped_tls_hkt::scoped_thread_local;
-use serde::{de::DeserializeOwned, Deserialize, Deserializer};
+use serde::{de::DeserializeOwned, Deserialize};
use walkdir::WalkDir;
-use rebel_common::{error::*, types::*};
+use rebel_common::error::*;
use crate::task::{TaskDef, TaskMeta};
-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(Clone, Debug, Deserialize, Default)]
pub struct RecipeMeta {
pub name: Option<String>,
@@ -94,7 +71,7 @@ fn read_recipe_tasks(
basename: &str,
tasks: &mut HashMap<String, HashMap<String, Vec<TaskDef>>>,
) -> Result<RecipeMeta> {
- let recipe_def = CURRENT_RECIPE.set(basename, || read_yaml::<Recipe>(path))?;
+ let recipe_def = read_yaml::<Recipe>(path)?;
let name = recipe_def
.meta
@@ -124,7 +101,7 @@ fn read_subrecipe_tasks(
tasks: &mut HashMap<String, HashMap<String, Vec<TaskDef>>>,
) -> Result<()> {
let recipe = format!("{basename}/{recipename}");
- let recipe_def = CURRENT_RECIPE.set(&recipe, || read_yaml::<Subrecipe>(path))?;
+ let recipe_def = read_yaml::<Subrecipe>(path)?;
let name = recipe_meta.name.as_deref().unwrap_or(basename).to_string();
diff --git a/crates/rebel/src/resolve.rs b/crates/rebel/src/resolve.rs
index 27a6d5c..a57263a 100644
--- a/crates/rebel/src/resolve.rs
+++ b/crates/rebel/src/resolve.rs
@@ -162,7 +162,7 @@ where
let mut errors = Vec::new();
for runtime_dep in &output.runtime_depends {
- match ctx.output_ref(runtime_dep, &task.args, false) {
+ match ctx.output_ref(task.id, runtime_dep, &task.args, false) {
Ok(output_ref) => {
for mut error in add_dep(ret, ctx, output_ref) {
error.extend(task);
diff --git a/crates/rebel/src/task.rs b/crates/rebel/src/task.rs
index 7875869..1220d45 100644
--- a/crates/rebel/src/task.rs
+++ b/crates/rebel/src/task.rs
@@ -2,21 +2,26 @@ use std::collections::{HashMap, HashSet};
use serde::Deserialize;
-use rebel_common::{string_hash::StringHash, types::TaskID};
+use rebel_common::{string_hash::StringHash, types::TaskIDRef};
-use crate::{
- args::{ArgMapping, ArgType, TaskArgs},
- recipe,
-};
+use crate::args::{ArgMapping, ArgType, TaskArgs};
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash)]
pub struct TaskDep {
- #[serde(flatten, deserialize_with = "recipe::deserialize_task_id")]
- pub id: TaskID,
+ pub recipe: Option<String>,
+ pub task: String,
#[serde(default)]
pub args: ArgMapping,
}
+impl TaskDep {
+ pub fn id<'a>(&'a self, recipe: &'a str) -> TaskIDRef<'a> {
+ let recipe = self.recipe.as_deref().unwrap_or(recipe);
+ let task = &self.task;
+ TaskIDRef { recipe, task }
+ }
+}
+
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash)]
pub struct Fetch {
pub name: String,