Skip to content

Commit

Permalink
Added disabled task attribute support
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiegurari committed Jun 25, 2017
1 parent 9b96645 commit 8aae2fa
Show file tree
Hide file tree
Showing 9 changed files with 653 additions and 14 deletions.
8 changes: 2 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ addons:
- cmake
- gcc
- binutils-dev
- gdb
script:
- cargo install --debug cargo-make
- cargo make --task ci-flow
Expand All @@ -38,9 +37,6 @@ after_script:
- rm -rf kcov-$KCOV_VERSION
- ls ./target/debug/deps
- mkdir -p ./target/coverage
- for file in target/debug/deps/cargo_make*; do if "$file" ; then echo "Running $file"; kcov --verify --skip-solibs --debug=4 --exclude-pattern=main.rs --include-pattern=${TRAVIS_BUILD_DIR}/src/ "target/coverage" "$file" || true; COREFILE=$(find . -maxdepth 1 -name "core*" | head -n 1); echo "Core file location:"; echo $COREFILE; if [[ -f "$COREFILE" ]]; then gdb -c "$COREFILE" kcov -ex "thread apply all bt" -ex "set pagination 0" -batch; fi; fi; done
- ls -ls ./target/coverage/cargo_make*
- for file in target/debug/deps/cargo_make*; do if "$file" ; then kcov --include-pattern=${TRAVIS_BUILD_DIR}/src/ "target/coverage" "$file" || true; fi; done
- bash <(curl -s https://codecov.io/bash)
- echo "Uploaded code coverage"
before_script:
- ulimit -c unlimited -S
- echo "Uploaded code coverage"
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-make"
version = "0.2.1"
version = "0.2.2"
authors = ["Sagie Gur-Ari <[email protected]>"]
description = "Rust task runner and build tool."
license = "Apache-2.0"
Expand Down
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* [Continues Integration](#usage-ci)
* [Environment Variables](#usage-env)
* [Cli Options](#usage-cli)
* [Task Definition](#usage-task-def)
* [Badge](#badge)
* [Roadmap](#roadmap)
* [API Documentation](https://sagiegurari.github.io/cargo-make/api.html)
Expand Down Expand Up @@ -283,6 +284,13 @@ If for example, you would like to add verbose output to it, you would just need
args = ["build", "--verbose"]
````

If you want to disable some existing task (will not disable its dependencies), you can do it as follows:

````toml
[tasks.build]
disabled = true
````

There is no need to redefine existing properties of the task, only what needs to be added or overwritten.<br>
The default toml file comes with many steps and flows already built in, so it is worth to check it first.

Expand Down Expand Up @@ -338,6 +346,32 @@ OPTIONS:
-t, --task <TASK NAME> The task name to execute (default: default)
````

### Task Definition
The following is the task definition:

````rs
#[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, depedencies however will be
pub disabled: Option<bool>,
/// if defined, task points to another task and all other properties are ignored
pub 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>>
}
````

<a name="badge"></a>
## Badge
If you are using cargo-make in your project and want to display it in your project README or website, you can embed the "Built with cargo-make" badge.<br>
Expand Down Expand Up @@ -374,7 +408,7 @@ See [contributing guide](.github/CONTRIBUTING.md)

| Date | Version | Description |
| ----------- | ------- | ----------- |
| 2017-06-25 | v0.2.1 | Docs |
| 2017-06-25 | v0.2.2 | Added disabled task attribute support |
| 2017-06-24 | v0.2.0 | Internal fixes (renamed dependencies attribute) |
| 2017-06-24 | v0.1.2 | Print build time, added internal docs, unit tests and coverage |
| 2017-06-24 | v0.1.1 | Added support for env vars, task alias and crate installation |
Expand Down
390 changes: 389 additions & 1 deletion docs/api/src/cargo_make/descriptor.rs.html

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions docs/api/src/cargo_make/runner.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@
<span id="151">151</span>
<span id="152">152</span>
<span id="153">153</span>
<span id="154">154</span>
<span id="155">155</span>
<span id="156">156</span>
<span id="157">157</span>
<span id="158">158</span>
<span id="159">159</span>
<span id="160">160</span>
</pre><pre class="rust ">
<span class="doccomment">//! # runner</span>
<span class="doccomment">//!</span>
Expand Down Expand Up @@ -280,8 +287,15 @@
};

<span class="kw">if</span> <span class="op">!</span><span class="ident">task_names</span>.<span class="ident">contains</span>(<span class="ident">task</span>) {
<span class="ident">steps</span>.<span class="ident">push</span>(<span class="ident">Step</span> { <span class="ident">name</span>: <span class="ident">task</span>.<span class="ident">to_string</span>(), <span class="ident">config</span>: <span class="ident">task_config</span>.<span class="ident">clone</span>() });
<span class="ident">task_names</span>.<span class="ident">insert</span>(<span class="ident">task</span>.<span class="ident">to_string</span>());
<span class="kw">let</span> <span class="ident">add</span> <span class="op">=</span> <span class="kw">match</span> <span class="ident">task_config</span>.<span class="ident">disabled</span> {
<span class="prelude-val">Some</span>(<span class="kw-2">ref</span> <span class="ident">disabled</span>) <span class="op">=&gt;</span> <span class="op">!</span><span class="ident">disabled</span>,
<span class="prelude-val">None</span> <span class="op">=&gt;</span> <span class="bool-val">true</span>,
};

<span class="kw">if</span> <span class="ident">add</span> {
<span class="ident">steps</span>.<span class="ident">push</span>(<span class="ident">Step</span> { <span class="ident">name</span>: <span class="ident">task</span>.<span class="ident">to_string</span>(), <span class="ident">config</span>: <span class="ident">task_config</span>.<span class="ident">clone</span>() });
<span class="ident">task_names</span>.<span class="ident">insert</span>(<span class="ident">task</span>.<span class="ident">to_string</span>());
}
} <span class="kw">else</span> <span class="kw">if</span> <span class="ident">root</span> {
<span class="ident">logger</span>.<span class="ident">error</span>::<span class="op">&lt;</span>()<span class="op">&gt;</span>(<span class="string">&quot;Circular reference found for task: &quot;</span>, <span class="kw-2">&amp;</span>[<span class="kw-2">&amp;</span><span class="ident">task</span>], <span class="prelude-val">None</span>);
}
Expand Down
4 changes: 4 additions & 0 deletions docs/api/src/cargo_make/types.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
<span id="57">57</span>
<span id="58">58</span>
<span id="59">59</span>
<span id="60">60</span>
<span id="61">61</span>
</pre><pre class="rust ">
<span class="doccomment">//! # types</span>
<span class="doccomment">//!</span>
Expand All @@ -113,6 +115,8 @@
<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Serialize</span>, <span class="ident">Deserialize</span>, <span class="ident">Debug</span>, <span class="ident">Clone</span>)]</span>
<span class="doccomment">/// Holds a single task configuration such as command and dependencies list</span>
<span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">Task</span> {
<span class="doccomment">/// if true, the command/script of this task will not be invoked, depedencies however will be</span>
<span class="kw">pub</span> <span class="ident">disabled</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">bool</span><span class="op">&gt;</span>,
<span class="doccomment">/// if defined, task points to another task and all other properties are ignored</span>
<span class="kw">pub</span> <span class="ident">alias</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">String</span><span class="op">&gt;</span>,
<span class="doccomment">/// if defined, the provided crate will be installed (if needed) before running the task</span>
Expand Down
196 changes: 195 additions & 1 deletion src/descriptor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! # log
//! # descriptor
//!
//! Loads the tasks descriptor.<br>
//! It will first load the default descriptor which is defined in cargo-make internally and
Expand Down Expand Up @@ -124,3 +124,197 @@ pub fn load(

config
}

#[cfg(test)]
mod tests {
use super::*;
use log;

#[test]
fn merge_maps_both_empty() {
let mut map1 = HashMap::<String, String>::new();
let mut map2 = HashMap::<String, String>::new();

let output = merge_maps(&mut map1, &mut map2);
assert_eq!(output.len(), 0);
}

#[test]
fn merge_maps_first_empty() {
let mut map1 = HashMap::<String, String>::new();
let mut map2 = HashMap::<String, String>::new();

map2.insert("test".to_string(), "value".to_string());

let output = merge_maps(&mut map1, &mut map2);
assert_eq!(output.len(), 1);
assert_eq!(output.get("test").unwrap(), &"value".to_string());
}

#[test]
fn merge_maps_second_empty() {
let mut map1 = HashMap::<String, String>::new();
let mut map2 = HashMap::<String, String>::new();

map1.insert("test".to_string(), "value".to_string());

let output = merge_maps(&mut map1, &mut map2);
assert_eq!(output.len(), 1);
assert_eq!(output.get("test").unwrap(), &"value".to_string());
}

#[test]
fn merge_maps_both_with_values() {
let mut map1 = HashMap::<String, String>::new();
let mut map2 = HashMap::<String, String>::new();

map1.insert("test1".to_string(), "value1".to_string());
map2.insert("test21".to_string(), "value21".to_string());
map2.insert("test22".to_string(), "value22".to_string());

let output = merge_maps(&mut map1, &mut map2);
assert_eq!(output.len(), 3);
assert_eq!(output.get("test1").unwrap(), &"value1".to_string());
assert_eq!(output.get("test21").unwrap(), &"value21".to_string());
assert_eq!(output.get("test22").unwrap(), &"value22".to_string());
}

#[test]
fn merge_tasks_both_empty() {
let mut map1 = HashMap::<String, Task>::new();
let mut map2 = HashMap::<String, Task>::new();

let output = merge_tasks(&mut map1, &mut map2);
assert_eq!(output.len(), 0);
}

#[test]
fn merge_tasks_first_empty() {
let mut map1 = HashMap::<String, Task>::new();
let mut map2 = HashMap::<String, Task>::new();

map2.insert(
"test".to_string(),
Task {
disabled: None,
alias: None,
install_crate: Some("my crate".to_string()),
install_script: None,
command: Some("test".to_string()),
args: None,
script: None,
dependencies: None
}
);

let output = merge_tasks(&mut map1, &mut map2);
assert_eq!(output.len(), 1);
let task = output.get("test").unwrap();
assert!(task.disabled.is_none());
assert!(task.alias.is_none());
assert!(task.install_crate.is_some());
assert!(task.install_script.is_none());
assert!(task.command.is_some());
assert!(task.args.is_none());
assert!(task.script.is_none());
assert!(task.dependencies.is_none());
}

#[test]
fn merge_tasks_second_empty() {
let mut map1 = HashMap::<String, Task>::new();
let mut map2 = HashMap::<String, Task>::new();

map1.insert(
"test".to_string(),
Task {
disabled: None,
alias: None,
install_crate: Some("my crate".to_string()),
install_script: None,
command: Some("test".to_string()),
args: None,
script: None,
dependencies: None
}
);

let output = merge_tasks(&mut map1, &mut map2);
assert_eq!(output.len(), 1);
let task = output.get("test").unwrap();
assert!(task.disabled.is_none());
assert!(task.alias.is_none());
assert!(task.install_crate.is_some());
assert!(task.install_script.is_none());
assert!(task.command.is_some());
assert!(task.args.is_none());
assert!(task.script.is_none());
assert!(task.dependencies.is_none());
}

#[test]
fn merge_tasks_both_with_values() {
let mut map1 = HashMap::<String, Task>::new();
let mut map2 = HashMap::<String, Task>::new();

map1.insert(
"test".to_string(),
Task {
disabled: None,
alias: None,
install_crate: Some("my crate".to_string()),
install_script: None,
command: Some("test".to_string()),
args: None,
script: None,
dependencies: None
}
);

map2.insert(
"test2".to_string(),
Task {
disabled: None,
alias: None,
install_crate: None,
install_script: None,
command: Some("test".to_string()),
args: None,
script: None,
dependencies: None
}
);

let output = merge_tasks(&mut map1, &mut map2);
assert_eq!(output.len(), 2);

let mut task = output.get("test").unwrap();
assert!(task.disabled.is_none());
assert!(task.alias.is_none());
assert!(task.install_crate.is_some());
assert!(task.install_script.is_none());
assert!(task.command.is_some());
assert!(task.args.is_none());
assert!(task.script.is_none());
assert!(task.dependencies.is_none());

task = output.get("test2").unwrap();
assert!(task.disabled.is_none());
assert!(task.alias.is_none());
assert!(task.install_crate.is_none());
assert!(task.install_script.is_none());
assert!(task.command.is_some());
assert!(task.args.is_none());
assert!(task.script.is_none());
assert!(task.dependencies.is_none());
}

#[test]
fn load_external_descriptor_no_file() {
let logger = log::create("error");
let config = load_external_descriptor("bad_file.toml2", &logger);

assert!(config.env.is_none());
assert!(config.tasks.is_none());
}
}
11 changes: 9 additions & 2 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,15 @@ fn create_execution_plan_for_step(
};

if !task_names.contains(task) {
steps.push(Step { name: task.to_string(), config: task_config.clone() });
task_names.insert(task.to_string());
let add = match task_config.disabled {
Some(ref disabled) => !disabled,
None => true,
};

if add {
steps.push(Step { name: task.to_string(), config: task_config.clone() });
task_names.insert(task.to_string());
}
} else if root {
logger.error::<()>("Circular reference found for task: ", &[&task], None);
}
Expand Down
2 changes: 2 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ 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, depedencies however will be
pub disabled: Option<bool>,
/// if defined, task points to another task and all other properties are ignored
pub alias: Option<String>,
/// if defined, the provided crate will be installed (if needed) before running the task
Expand Down

0 comments on commit 8aae2fa

Please sign in to comment.