summaryrefslogtreecommitdiffstats
path: root/crates/rebel-resolve/src/task.rs
blob: 1220d452c7f0ac78a9fcb17af35d207df566b5d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use std::collections::{HashMap, HashSet};

use serde::Deserialize;

use rebel_common::{string_hash::StringHash, types::TaskIDRef};

use crate::args::{ArgMapping, ArgType, TaskArgs};

#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash)]
pub struct TaskDep {
	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,
	pub sha256: StringHash,
}

fn default_output_name() -> String {
	"default".to_string()
}

#[derive(Clone, Debug, Deserialize)]
pub struct ParentDep {
	#[serde(flatten)]
	pub dep: TaskDep,
}

#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash)]
pub struct OutputDep {
	#[serde(flatten)]
	pub dep: TaskDep,
	#[serde(default)]
	pub noinherit: bool,
	#[serde(default = "default_output_name")]
	pub output: String,
}

#[derive(Clone, Debug, Deserialize, Default)]
pub struct Output {
	pub path: Option<String>,
	#[serde(default)]
	pub runtime_depends: HashSet<OutputDep>,
}

#[derive(Clone, Debug, Deserialize, Default)]
pub struct Action {
	#[serde(default)]
	pub run: String,
}

impl Action {
	pub fn is_empty(&self) -> bool {
		self.run.is_empty()
	}
}

#[derive(Clone, Debug, Default)]
pub struct TaskMeta {
	pub basename: String,
	pub recipename: String,
	pub recipe: String,
	pub name: String,
	pub version: Option<String>,
}

#[derive(Clone, Debug, Deserialize, Default)]
pub struct TaskDef {
	#[serde(skip)]
	pub meta: TaskMeta,
	#[serde(default)]
	pub args: HashMap<String, ArgType>,
	#[serde(default)]
	pub parent: Option<ParentDep>,
	#[serde(default)]
	pub fetch: HashSet<Fetch>,
	#[serde(default)]
	pub build_depends: HashSet<OutputDep>,
	#[serde(default)]
	pub depends: HashSet<OutputDep>,
	#[serde(default)]
	pub output: HashMap<String, Output>,
	#[serde(flatten)]
	pub action: Action,
	#[serde(default)]
	pub priority: i32,
	#[serde(skip)]
	pub arg_match: TaskArgs,
}