summaryrefslogtreecommitdiffstats
path: root/crates/driver/src/task.rs
blob: 6b9083bd623af264b177e296c5c52c2a6637ee31 (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
use std::collections::{HashMap, HashSet};

use serde::Deserialize;

use common::{string_hash::StringHash, types::TaskID};

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

#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash, Default)]
pub struct RecipeMeta {
	#[serde(default)]
	pub name: String,
	pub version: Option<String>,
}

#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash)]
pub struct TaskDep {
	#[serde(flatten, deserialize_with = "recipe::deserialize_task_id")]
	pub id: TaskID,
	#[serde(default)]
	pub args: ArgMapping,
}

#[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 InheritDep {
	#[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)]
pub struct Output {
	pub path: Option<String>,
	#[serde(default)]
	pub runtime_depends: HashSet<OutputDep>,
}

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

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

#[derive(Clone, Debug, Deserialize)]
pub struct TaskDef {
	#[serde(skip)]
	pub meta: RecipeMeta,
	#[serde(default)]
	pub args: HashMap<String, ArgType>,
	#[serde(default)]
	pub inherit: Option<InheritDep>,
	#[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,
}