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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
//! # types
//!
//! Defines the various types and aliases used by cargo-make.
//!
#[cfg(test)]
#[path = "./types_test.rs"]
mod types_test;
use std::collections::HashMap;
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Holds a single task configuration such as command and dependencies list
pub struct Task {
/// if true, the command/script of this task will not be invoked, dependencies however will be
pub disabled: Option<bool>,
/// if defined, task points to another task and all other properties are ignored
pub alias: Option<String>,
/// acts like alias if runtime OS is Linux (takes precedence over alias)
pub linux_alias: Option<String>,
/// acts like alias if runtime OS is Windows (takes precedence over alias)
pub windows_alias: Option<String>,
/// acts like alias if runtime OS is Mac (takes precedence over alias)
pub mac_alias: Option<String>,
/// if defined, the provided crate will be installed (if needed) before running the task
pub install_crate: Option<String>,
/// if defined, the provided script will be executed before running the task
pub install_script: Option<Vec<String>>,
/// The command to execute
pub command: Option<String>,
/// The command args
pub args: Option<Vec<String>>,
/// If command is not defined, and script is defined, the provided script will be executed
pub script: Option<Vec<String>>,
/// A list of tasks to execute before this task
pub dependencies: Option<Vec<String>>,
/// override task if runtime OS is Linux (takes precedence over alias)
pub linux: Option<PlatformOverrideTask>,
/// override task if runtime OS is Windows (takes precedence over alias)
pub windows: Option<PlatformOverrideTask>,
/// override task if runtime OS is Mac (takes precedence over alias)
pub mac: Option<PlatformOverrideTask>
}
impl Task {
pub fn extend(
self: &mut Task,
task: &Task,
) {
if task.disabled.is_some() {
self.disabled = task.disabled.clone();
}
if task.alias.is_some() {
self.alias = task.alias.clone();
}
if task.linux_alias.is_some() {
self.linux_alias = task.linux_alias.clone();
}
if task.windows_alias.is_some() {
self.windows_alias = task.windows_alias.clone();
}
if task.mac_alias.is_some() {
self.mac_alias = task.mac_alias.clone();
}
if task.install_crate.is_some() {
self.install_crate = task.install_crate.clone();
}
if task.install_script.is_some() {
self.install_script = task.install_script.clone();
}
if task.command.is_some() {
self.command = task.command.clone();
}
if task.args.is_some() {
self.args = task.args.clone();
}
if task.script.is_some() {
self.script = task.script.clone();
}
if task.dependencies.is_some() {
self.dependencies = task.dependencies.clone();
}
if task.linux.is_some() {
self.linux = task.linux.clone();
}
if task.windows.is_some() {
self.windows = task.windows.clone();
}
if task.mac.is_some() {
self.mac = task.mac.clone();
}
}
fn get_override(self: &Task) -> Option<PlatformOverrideTask> {
if cfg!(windows) {
match self.windows {
Some(ref value) => Some(value.clone()),
_ => None,
}
} else if cfg!(target_os = "macos") || cfg!(target_os = "ios") {
match self.mac {
Some(ref value) => Some(value.clone()),
_ => None,
}
} else {
match self.linux {
Some(ref value) => Some(value.clone()),
_ => None,
}
}
}
pub fn get_normalized_task(self: &mut Task) -> Task {
match self.get_override() {
Some(ref mut override_task) => {
override_task.extend(self);
Task {
disabled: override_task.disabled.clone(),
alias: None,
linux_alias: None,
windows_alias: None,
mac_alias: None,
install_crate: override_task.install_crate.clone(),
install_script: override_task.install_script.clone(),
command: override_task.command.clone(),
args: override_task.args.clone(),
script: override_task.script.clone(),
dependencies: override_task.dependencies.clone(),
linux: None,
windows: None,
mac: None
}
}
None => self.clone(),
}
}
pub fn get_alias(self: &Task) -> Option<String> {
let alias = if cfg!(windows) {
match self.windows_alias {
Some(ref value) => Some(value),
_ => None,
}
} else if cfg!(target_os = "macos") || cfg!(target_os = "ios") {
match self.mac_alias {
Some(ref value) => Some(value),
_ => None,
}
} else {
match self.linux_alias {
Some(ref value) => Some(value),
_ => None,
}
};
match alias {
Some(os_alias) => Some(os_alias.clone()),
_ => {
match self.alias {
Some(ref alias) => Some(alias.clone()),
_ => None,
}
}
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Holds a single task configuration for a specific platform as an override of another task
pub struct PlatformOverrideTask {
/// if true, it should ignore all data in base task
clear: Option<bool>,
/// if true, the command/script of this task will not be invoked, dependencies however will be
disabled: Option<bool>,
/// if defined, the provided crate will be installed (if needed) before running the task
install_crate: Option<String>,
/// if defined, the provided script will be executed before running the task
install_script: Option<Vec<String>>,
/// The command to execute
command: Option<String>,
/// The command args
args: Option<Vec<String>>,
/// If command is not defined, and script is defined, the provided script will be executed
script: Option<Vec<String>>,
/// A list of tasks to execute before this task
dependencies: Option<Vec<String>>
}
impl PlatformOverrideTask {
pub fn extend(
self: &mut PlatformOverrideTask,
task: &mut Task,
) {
let copy_values = match self.clear {
Some(value) => !value,
None => true,
};
if copy_values {
if self.disabled.is_none() && task.disabled.is_some() {
self.disabled = task.disabled.clone();
}
if self.install_crate.is_none() && task.install_crate.is_some() {
self.install_crate = task.install_crate.clone();
}
if self.install_script.is_none() && task.install_script.is_some() {
self.install_script = task.install_script.clone();
}
if self.command.is_none() && task.command.is_some() {
self.command = task.command.clone();
}
if self.args.is_none() && task.args.is_some() {
self.args = task.args.clone();
}
if self.script.is_none() && task.script.is_some() {
self.script = task.script.clone();
}
if self.dependencies.is_none() && task.dependencies.is_some() {
self.dependencies = task.dependencies.clone();
}
}
}
}
#[derive(Serialize, Deserialize, Debug)]
/// Holds the entire configuration such as task definitions and env vars
pub struct Config {
/// The env vars to setup before running the tasks
pub env: HashMap<String, String>,
/// All task definitions
pub tasks: HashMap<String, Task>
}
#[derive(Serialize, Deserialize, Debug)]
/// Same as the config struct but all memebers are optional
pub struct ExternalConfig {
/// The env vars to setup before running the tasks
pub env: Option<HashMap<String, String>>,
/// All task definitions
pub tasks: Option<HashMap<String, Task>>
}
#[derive(Debug)]
/// Execution plan step to execute
pub struct Step {
/// The task name
pub name: String,
/// The task config
pub config: Task
}
#[derive(Debug)]
/// Execution plan which defines all steps to run and the order to run them
pub struct ExecutionPlan {
/// A list of steps to execute
pub steps: Vec<Step>
}