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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
//! # 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 true, any error while executing the task will be printed but will not break the build
pub force: 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 new() -> Task {
Task {
disabled: None,
force: None,
alias: None,
linux_alias: None,
windows_alias: None,
mac_alias: None,
install_crate: None,
install_script: None,
command: None,
args: None,
script: None,
dependencies: None,
linux: None,
windows: None,
mac: None
}
}
pub fn extend(
self: &mut Task,
task: &Task,
) {
if task.disabled.is_some() {
self.disabled = task.disabled.clone();
}
if task.force.is_some() {
self.force = task.force.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();
}
}
pub fn is_force(self: &Task) -> bool {
self.force.unwrap_or(false)
}
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(),
force: override_task.force.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
pub clear: Option<bool>,
/// if true, the command/script of this task will not be invoked, dependencies however will be
pub disabled: Option<bool>,
/// if true, any error while executing the task will be printed but will not break the build
pub force: Option<bool>,
/// 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>>
}
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.force.is_none() && task.force.is_some() {
self.force = task.force.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, Clone)]
pub struct ConfigSection {
/// Init task name which will be invoked at the start of every run
pub init_task: Option<String>,
/// End task name which will be invoked at the end of every run
pub end_task: Option<String>
}
impl ConfigSection {
pub fn new() -> ConfigSection {
ConfigSection { init_task: None, end_task: None }
}
pub fn extend(
self: &mut ConfigSection,
extended: &mut ConfigSection,
) {
if extended.init_task.is_some() {
self.init_task = extended.init_task.clone();
}
if extended.end_task.is_some() {
self.end_task = extended.end_task.clone();
}
}
}
#[derive(Serialize, Deserialize, Debug)]
/// Holds the entire configuration such as task definitions and env vars
pub struct Config {
/// Runtime config
pub config: ConfigSection,
/// 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)]
/// Holds the entire externally read configuration such as task definitions and env vars where all values are optional
pub struct ExternalConfig {
/// Path to another toml file to extend
pub extend: Option<String>,
/// Runtime config
pub config: Option<ConfigSection>,
/// The env vars to setup before running the tasks
pub env: Option<HashMap<String, String>>,
/// All task definitions
pub tasks: Option<HashMap<String, Task>>
}
impl ExternalConfig {
pub fn new() -> ExternalConfig {
ExternalConfig { extend: None, config: None, env: None, tasks: None }
}
}
#[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>
}
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Holds crate package information loaded from the Cargo.toml file package section.
pub struct PackageInfo {
/// name
pub name: Option<String>,
/// version
pub version: Option<String>,
/// description
pub description: Option<String>,
/// license
pub license: Option<String>,
/// documentation link
pub documentation: Option<String>,
/// homepage link
pub homepage: Option<String>,
/// repository link
pub repository: Option<String>
}
impl PackageInfo {
pub fn new() -> PackageInfo {
PackageInfo {
name: None,
version: None,
description: None,
license: None,
documentation: None,
homepage: None,
repository: None
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Holds crate information loaded from the Cargo.toml file.
pub struct CrateInfo {
/// package info
pub package: Option<PackageInfo>
}