Skip to content

Commit

Permalink
Fixed disabled not checked in platform override task
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiegurari committed Jul 3, 2017
1 parent c87b19e commit 09b531a
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 50 deletions.
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.3.1"
version = "0.3.2"
authors = ["Sagie Gur-Ari <sagiegurari@gmail.com>"]
description = "Rust task runner and build tool."
license = "Apache-2.0"
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -528,23 +528,23 @@ pub struct Task {
/// 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>,
pub clear: Option<bool>,
/// if true, the command/script of this task will not be invoked, dependencies however will be
disabled: Option<bool>,
pub disabled: Option<bool>,
/// if true, any error while executing the task will be printed but will not break the build
force: Option<bool>,
pub force: Option<bool>,
/// if defined, the provided crate will be installed (if needed) before running the task
install_crate: Option<String>,
pub install_crate: Option<String>,
/// if defined, the provided script will be executed before running the task
install_script: Option<Vec<String>>,
pub install_script: Option<Vec<String>>,
/// The command to execute
command: Option<String>,
pub command: Option<String>,
/// The command args
args: Option<Vec<String>>,
pub args: Option<Vec<String>>,
/// If command is not defined, and script is defined, the provided script will be executed
script: Option<Vec<String>>,
pub script: Option<Vec<String>>,
/// A list of tasks to execute before this task
dependencies: Option<Vec<String>>
pub dependencies: Option<Vec<String>>
}
````

Expand Down Expand Up @@ -634,6 +634,7 @@ See [contributing guide](.github/CONTRIBUTING.md)

| Date | Version | Description |
| ----------- | ------- | ----------- |
| 2017-07-03 | v0.3.2 | Fixed disabled not checked in platform override task |
| 2017-07-02 | v0.3.1 | Added CARGO_MAKE_TASK env var holding the main task name |
| 2017-07-02 | v0.3.0 | Renamed few cli options |
| 2017-07-02 | v0.2.20 | Added -v and --verbose cli arg |
Expand Down
19 changes: 10 additions & 9 deletions docs/_includes/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,23 +501,23 @@ pub struct Task {
/// 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>,
pub clear: Option<bool>,
/// if true, the command/script of this task will not be invoked, dependencies however will be
disabled: Option<bool>,
pub disabled: Option<bool>,
/// if true, any error while executing the task will be printed but will not break the build
force: Option<bool>,
pub force: Option<bool>,
/// if defined, the provided crate will be installed (if needed) before running the task
install_crate: Option<String>,
pub install_crate: Option<String>,
/// if defined, the provided script will be executed before running the task
install_script: Option<Vec<String>>,
pub install_script: Option<Vec<String>>,
/// The command to execute
command: Option<String>,
pub command: Option<String>,
/// The command args
args: Option<Vec<String>>,
pub args: Option<Vec<String>>,
/// If command is not defined, and script is defined, the provided script will be executed
script: Option<Vec<String>>,
pub script: Option<Vec<String>>,
/// A list of tasks to execute before this task
dependencies: Option<Vec<String>>
pub dependencies: Option<Vec<String>>
}
````

Expand Down Expand Up @@ -607,6 +607,7 @@ See [contributing guide](https://github.com/sagiegurari/cargo-make/blob/master/.

| Date | Version | Description |
| ----------- | ------- | ----------- |
| 2017-07-03 | v0.3.2 | Fixed disabled not checked in platform override task |
| 2017-07-02 | v0.3.1 | Added CARGO_MAKE_TASK env var holding the main task name |
| 2017-07-02 | v0.3.0 | Renamed few cli options |
| 2017-07-02 | v0.2.20 | Added -v and --verbose cli arg |
Expand Down
14 changes: 8 additions & 6 deletions docs/api/src/cargo_make/runner.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
<span id="169">169</span>
<span id="170">170</span>
<span id="171">171</span>
<span id="172">172</span>
</pre><pre class="rust ">
<span class="doccomment">//! # runner</span>
<span class="doccomment">//!</span>
Expand Down Expand Up @@ -304,17 +305,18 @@
};

<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="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">let</span> <span class="kw-2">mut</span> <span class="ident">add</span> <span class="op">=</span> <span class="op">!</span><span class="ident">task_config</span>.<span class="ident">disabled</span>.<span class="ident">unwrap_or</span>(<span class="bool-val">false</span>);

<span class="kw">if</span> <span class="ident">add</span> {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">clone_task</span> <span class="op">=</span> <span class="ident">task_config</span>.<span class="ident">clone</span>();
<span class="kw">let</span> <span class="ident">normalized_task</span> <span class="op">=</span> <span class="ident">clone_task</span>.<span class="ident">get_normalized_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">normalized_task</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="ident">add</span> <span class="op">=</span> <span class="op">!</span><span class="ident">normalized_task</span>.<span class="ident">disabled</span>.<span class="ident">unwrap_or</span>(<span class="bool-val">false</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">normalized_task</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
18 changes: 9 additions & 9 deletions docs/api/src/cargo_make/types.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -582,23 +582,23 @@
<span class="doccomment">/// Holds a single task configuration for a specific platform as an override of another task</span>
<span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">PlatformOverrideTask</span> {
<span class="doccomment">/// if true, it should ignore all data in base task</span>
<span class="ident">clear</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">bool</span><span class="op">&gt;</span>,
<span class="kw">pub</span> <span class="ident">clear</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 true, the command/script of this task will not be invoked, dependencies however will be</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="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 true, any error while executing the task will be printed but will not break the build</span>
<span class="ident">force</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">bool</span><span class="op">&gt;</span>,
<span class="kw">pub</span> <span class="ident">force</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, the provided crate will be installed (if needed) before running the task</span>
<span class="ident">install_crate</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">String</span><span class="op">&gt;</span>,
<span class="kw">pub</span> <span class="ident">install_crate</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 script will be executed before running the task</span>
<span class="ident">install_script</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">String</span><span class="op">&gt;&gt;</span>,
<span class="kw">pub</span> <span class="ident">install_script</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">String</span><span class="op">&gt;&gt;</span>,
<span class="doccomment">/// The command to execute</span>
<span class="ident">command</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">String</span><span class="op">&gt;</span>,
<span class="kw">pub</span> <span class="ident">command</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">/// The command args</span>
<span class="ident">args</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">String</span><span class="op">&gt;&gt;</span>,
<span class="kw">pub</span> <span class="ident">args</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">String</span><span class="op">&gt;&gt;</span>,
<span class="doccomment">/// If command is not defined, and script is defined, the provided script will be executed</span>
<span class="ident">script</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">String</span><span class="op">&gt;&gt;</span>,
<span class="kw">pub</span> <span class="ident">script</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">String</span><span class="op">&gt;&gt;</span>,
<span class="doccomment">/// A list of tasks to execute before this task</span>
<span class="ident">dependencies</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">String</span><span class="op">&gt;&gt;</span>
<span class="kw">pub</span> <span class="ident">dependencies</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">String</span><span class="op">&gt;&gt;</span>
}

<span class="kw">impl</span> <span class="ident">PlatformOverrideTask</span> {
Expand Down
13 changes: 7 additions & 6 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,18 @@ fn create_execution_plan_for_step(
};

if !task_names.contains(task) {
let add = match task_config.disabled {
Some(ref disabled) => !disabled,
None => true,
};
let mut add = !task_config.disabled.unwrap_or(false);

if add {
let mut clone_task = task_config.clone();
let normalized_task = clone_task.get_normalized_task();

steps.push(Step { name: task.to_string(), config: normalized_task });
task_names.insert(task.to_string());
add = !normalized_task.disabled.unwrap_or(false);

if add {
steps.push(Step { name: task.to_string(), config: normalized_task });
task_names.insert(task.to_string());
}
}
} else if root {
logger.error::<()>("Circular reference found for task: ", &[&task], None);
Expand Down
75 changes: 74 additions & 1 deletion src/runner_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;
use log;
use std::collections::HashMap;
use types::Task;
use types::{PlatformOverrideTask, Task};

#[test]
fn set_env_empty() {
Expand Down Expand Up @@ -83,3 +83,76 @@ fn get_task_name_platform_alias() {

assert_eq!(name, "test2");
}

#[test]
fn create_execution_plan_single() {
let logger = log::create("error");
let mut config = Config { env: HashMap::new(), tasks: HashMap::new() };

let task = Task::new();

config.tasks.insert("test".to_string(), task);

let execution_plan = create_execution_plan(&logger, &config, "test");
assert_eq!(execution_plan.steps.len(), 1);
}

#[test]
fn create_execution_plan_single_disabled() {
let logger = log::create("error");
let mut config = Config { env: HashMap::new(), tasks: HashMap::new() };

let mut task = Task::new();
task.disabled = Some(true);

config.tasks.insert("test".to_string(), task);

let execution_plan = create_execution_plan(&logger, &config, "test");
assert_eq!(execution_plan.steps.len(), 0);
}

#[test]
fn create_execution_plan_platform_disabled() {
let logger = log::create("error");
let mut config = Config { env: HashMap::new(), tasks: HashMap::new() };

let mut task = Task::new();
task.linux = Some(PlatformOverrideTask {
clear: Some(true),
disabled: Some(true),
install_crate: None,
command: None,
force: None,
install_script: None,
args: None,
script: None,
dependencies: None
});
task.windows = Some(PlatformOverrideTask {
clear: Some(true),
disabled: Some(true),
install_crate: None,
command: None,
force: None,
install_script: None,
args: None,
script: None,
dependencies: None
});
task.mac = Some(PlatformOverrideTask {
clear: Some(true),
disabled: Some(true),
install_crate: None,
command: None,
force: None,
install_script: None,
args: None,
script: None,
dependencies: None
});

config.tasks.insert("test".to_string(), task);

let execution_plan = create_execution_plan(&logger, &config, "test");
assert_eq!(execution_plan.steps.len(), 0);
}
18 changes: 9 additions & 9 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,23 +214,23 @@ impl Task {
/// 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>,
pub clear: Option<bool>,
/// if true, the command/script of this task will not be invoked, dependencies however will be
disabled: Option<bool>,
pub disabled: Option<bool>,
/// if true, any error while executing the task will be printed but will not break the build
force: Option<bool>,
pub force: Option<bool>,
/// if defined, the provided crate will be installed (if needed) before running the task
install_crate: Option<String>,
pub install_crate: Option<String>,
/// if defined, the provided script will be executed before running the task
install_script: Option<Vec<String>>,
pub install_script: Option<Vec<String>>,
/// The command to execute
command: Option<String>,
pub command: Option<String>,
/// The command args
args: Option<Vec<String>>,
pub args: Option<Vec<String>>,
/// If command is not defined, and script is defined, the provided script will be executed
script: Option<Vec<String>>,
pub script: Option<Vec<String>>,
/// A list of tasks to execute before this task
dependencies: Option<Vec<String>>
pub dependencies: Option<Vec<String>>
}

impl PlatformOverrideTask {
Expand Down

0 comments on commit 09b531a

Please sign in to comment.