Skip to content

Commit

Permalink
New --no-workspace cli arg
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiegurari committed Jul 16, 2017
1 parent 988be69 commit 70e84dd
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 37 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.24"
version = "0.3.25"
authors = ["Sagie Gur-Ari <sagiegurari@gmail.com>"]
description = "Rust task runner and build tool."
license = "Apache-2.0"
Expand Down
37 changes: 33 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,33 @@ The order of the members is defined by the member attribute in the workspace Car

We can use this capability to run same functionality on all workspace member crates, for example if we want to format all crates, we can run in the workspace directory: ````cargo make format````.

In case you wish to run the tasks on the workspace level and not on the members, use the ````--no-workspace```` cli flag when running cargo make, for example:

````sh
cargo make --no-workspace mytask
````

You can define a composite flow that runs both workspace level tasks and member level tasks using this flag.<br>
This is an example of a workspace level Makefile.toml which enables to run such a flow:

````toml
[tasks.composite]
dependencies = ["member_flow", "workspace_flow"]

[tasks.member_flow]
command = "cargo"
args = ["make", "member_task"]

[tasks.workspace_flow]
#run some workspace level command or flow
````

You can start this composite flow as follows:

````sh
cargo make --no-workspace composite
````

<a name="usage-init-end-tasks"></a>
### Init and End tasks
Every task or flow that is executed by the cargo-make has additional 2 tasks.<br>
Expand Down Expand Up @@ -544,10 +571,11 @@ USAGE:
cargo make [FLAGS] [OPTIONS] [TASK]

FLAGS:
-h, --help Prints help information
--print-steps Only prints the steps of the build in the order they will be invoked but without invoking them
-v, --verbose Sets the log level to verbose (shorthand for --loglevel verbose)
-V, --version Prints version information
-h, --help Prints help information
--no-workspace Disable workspace support (tasks are triggered on workspace and not on members)
--print-steps Only prints the steps of the build in the order they will be invoked but without invoking them
-v, --verbose Sets the log level to verbose (shorthand for --loglevel verbose)
-V, --version Prints version information

OPTIONS:
--cwd <DIRECTORY> Will set the current working directory. The search for the makefile will be from this directory if defined.
Expand Down Expand Up @@ -728,6 +756,7 @@ See [contributing guide](.github/CONTRIBUTING.md)

| Date | Version | Description |
| ----------- | ------- | ----------- |
| 2017-07-16 | v0.3.25 | New --no-workspace cli arg |
| 2017-07-15 | v0.3.24 | Workspace support |
| 2017-07-14 | v0.3.23 | Added codecov task in default toml |
| 2017-07-14 | v0.3.20 | Added coverage task in default toml |
Expand Down
37 changes: 33 additions & 4 deletions docs/_includes/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,33 @@ The order of the members is defined by the member attribute in the workspace Car

We can use this capability to run same functionality on all workspace member crates, for example if we want to format all crates, we can run in the workspace directory: ````cargo make format````.

In case you wish to run the tasks on the workspace level and not on the members, use the ````--no-workspace```` cli flag when running cargo make, for example:

````sh
cargo make --no-workspace mytask
````

You can define a composite flow that runs both workspace level tasks and member level tasks using this flag.<br>
This is an example of a workspace level Makefile.toml which enables to run such a flow:

````toml
[tasks.composite]
dependencies = ["member_flow", "workspace_flow"]

[tasks.member_flow]
command = "cargo"
args = ["make", "member_task"]

[tasks.workspace_flow]
#run some workspace level command or flow
````

You can start this composite flow as follows:

````sh
cargo make --no-workspace composite
````

<a name="usage-init-end-tasks"></a>
### Init and End tasks
Every task or flow that is executed by the cargo-make has additional 2 tasks.<br>
Expand Down Expand Up @@ -515,10 +542,11 @@ USAGE:
cargo make [FLAGS] [OPTIONS] [TASK]

FLAGS:
-h, --help Prints help information
--print-steps Only prints the steps of the build in the order they will be invoked but without invoking them
-v, --verbose Sets the log level to verbose (shorthand for --loglevel verbose)
-V, --version Prints version information
-h, --help Prints help information
--no-workspace Disable workspace support (tasks are triggered on workspace and not on members)
--print-steps Only prints the steps of the build in the order they will be invoked but without invoking them
-v, --verbose Sets the log level to verbose (shorthand for --loglevel verbose)
-V, --version Prints version information

OPTIONS:
--cwd <DIRECTORY> Will set the current working directory. The search for the makefile will be from this directory if defined.
Expand Down Expand Up @@ -699,6 +727,7 @@ See [contributing guide](https://github.com/sagiegurari/cargo-make/blob/master/.

| Date | Version | Description |
| ----------- | ------- | ----------- |
| 2017-07-16 | v0.3.25 | New --no-workspace cli arg |
| 2017-07-15 | v0.3.24 | Workspace support |
| 2017-07-14 | v0.3.23 | Added codecov task in default toml |
| 2017-07-14 | v0.3.20 | Added coverage task in default toml |
Expand Down
16 changes: 13 additions & 3 deletions docs/api/src/cargo_make/cli.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@
<span id="119">119</span>
<span id="120">120</span>
<span id="121">121</span>
<span id="122">122</span>
<span id="123">123</span>
<span id="124">124</span>
<span id="125">125</span>
<span id="126">126</span>
</pre><pre class="rust ">
<span class="doccomment">//! # cli</span>
<span class="doccomment">//!</span>
Expand Down Expand Up @@ -193,6 +198,7 @@
<span class="ident">task</span>: <span class="kw-2">&amp;</span><span class="ident">str</span>,
<span class="ident">log_level</span>: <span class="kw-2">&amp;</span><span class="ident">str</span>,
<span class="ident">cwd</span>: <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span>,
<span class="ident">disable_workspace</span>: <span class="ident">bool</span>,
<span class="ident">print_only</span>: <span class="ident">bool</span>,
) {
<span class="kw">let</span> <span class="ident">logger</span> <span class="op">=</span> <span class="ident">log</span>::<span class="ident">create</span>(<span class="ident">log_level</span>);
Expand All @@ -210,9 +216,9 @@
<span class="ident">environment</span>::<span class="ident">setup_env</span>(<span class="kw-2">&amp;</span><span class="ident">logger</span>, <span class="kw-2">&amp;</span><span class="ident">config</span>, <span class="kw-2">&amp;</span><span class="ident">task</span>);

<span class="kw">if</span> <span class="ident">print_only</span> {
<span class="ident">runner</span>::<span class="ident">print</span>(<span class="kw-2">&amp;</span><span class="ident">logger</span>, <span class="kw-2">&amp;</span><span class="ident">config</span>, <span class="kw-2">&amp;</span><span class="ident">task</span>);
<span class="ident">runner</span>::<span class="ident">print</span>(<span class="kw-2">&amp;</span><span class="ident">logger</span>, <span class="kw-2">&amp;</span><span class="ident">config</span>, <span class="kw-2">&amp;</span><span class="ident">task</span>, <span class="ident">disable_workspace</span>);
} <span class="kw">else</span> {
<span class="ident">runner</span>::<span class="ident">run</span>(<span class="kw-2">&amp;</span><span class="ident">logger</span>, <span class="kw-2">&amp;</span><span class="ident">config</span>, <span class="kw-2">&amp;</span><span class="ident">task</span>);
<span class="ident">runner</span>::<span class="ident">run</span>(<span class="kw-2">&amp;</span><span class="ident">logger</span>, <span class="kw-2">&amp;</span><span class="ident">config</span>, <span class="kw-2">&amp;</span><span class="ident">task</span>, <span class="ident">disable_workspace</span>);
}
}

Expand All @@ -232,8 +238,9 @@
};

<span class="kw">let</span> <span class="ident">print_only</span> <span class="op">=</span> <span class="ident">cmd_matches</span>.<span class="ident">is_present</span>(<span class="string">&quot;print-steps&quot;</span>);
<span class="kw">let</span> <span class="ident">disable_workspace</span> <span class="op">=</span> <span class="ident">cmd_matches</span>.<span class="ident">is_present</span>(<span class="string">&quot;no-workspace&quot;</span>);

<span class="ident">run</span>(<span class="ident">build_file</span>, <span class="ident">task</span>, <span class="ident">log_level</span>, <span class="ident">cwd</span>, <span class="ident">print_only</span>);
<span class="ident">run</span>(<span class="ident">build_file</span>, <span class="ident">task</span>, <span class="ident">log_level</span>, <span class="ident">cwd</span>, <span class="ident">disable_workspace</span>, <span class="ident">print_only</span>);
}
<span class="prelude-val">None</span> <span class="op">=&gt;</span> <span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;cargo-{} not invoked via cargo command.&quot;</span>, <span class="ident">NAME</span>),
}
Expand Down Expand Up @@ -263,6 +270,9 @@
.<span class="ident">arg</span>(<span class="ident">Arg</span>::<span class="ident">with_name</span>(<span class="string">&quot;cwd&quot;</span>).<span class="ident">long</span>(<span class="string">&quot;--cwd&quot;</span>).<span class="ident">value_name</span>(<span class="string">&quot;DIRECTORY&quot;</span>).<span class="ident">help</span>(
<span class="string">&quot;Will set the current working directory. The search for the makefile will be from this directory if defined.&quot;</span>
))
.<span class="ident">arg</span>(<span class="ident">Arg</span>::<span class="ident">with_name</span>(<span class="string">&quot;no-workspace&quot;</span>).<span class="ident">long</span>(<span class="string">&quot;--no-workspace&quot;</span>).<span class="ident">help</span>(
<span class="string">&quot;Disable workspace support (tasks are triggered on workspace and not on members)&quot;</span>
))
.<span class="ident">arg</span>(
<span class="ident">Arg</span>::<span class="ident">from_usage</span>(<span class="string">&quot;-l, --loglevel=[LOG LEVEL] &#39;The log level&#39;&quot;</span>)
.<span class="ident">possible_values</span>(<span class="kw-2">&amp;</span>[<span class="string">&quot;verbose&quot;</span>, <span class="string">&quot;info&quot;</span>, <span class="string">&quot;error&quot;</span>])
Expand Down
16 changes: 11 additions & 5 deletions docs/api/src/cargo_make/runner.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@
<span id="235">235</span>
<span id="236">236</span>
<span id="237">237</span>
<span id="238">238</span>
<span id="239">239</span>
<span id="240">240</span>
</pre><pre class="rust ">
<span class="doccomment">//! # runner</span>
<span class="doccomment">//!</span>
Expand Down Expand Up @@ -420,6 +423,7 @@
<span class="ident">logger</span>: <span class="kw-2">&amp;</span><span class="ident">Logger</span>,
<span class="ident">config</span>: <span class="kw-2">&amp;</span><span class="ident">Config</span>,
<span class="ident">task</span>: <span class="kw-2">&amp;</span><span class="ident">str</span>,
<span class="ident">disable_workspace</span>: <span class="ident">bool</span>,
) <span class="op">-&gt;</span> <span class="ident">ExecutionPlan</span> {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">task_names</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">new</span>();
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">steps</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">new</span>();
Expand All @@ -445,12 +449,12 @@
<span class="comment">// load crate info and look for workspace info</span>
<span class="kw">let</span> <span class="ident">crate_info</span> <span class="op">=</span> <span class="ident">CrateInfo</span>::<span class="ident">load</span>(<span class="kw-2">&amp;</span><span class="ident">logger</span>);

<span class="kw">if</span> <span class="ident">crate_info</span>.<span class="ident">workspace</span>.<span class="ident">is_some</span>() {
<span class="kw">if</span> <span class="ident">disable_workspace</span> <span class="op">||</span> <span class="ident">crate_info</span>.<span class="ident">workspace</span>.<span class="ident">is_none</span>() {
<span class="ident">create_execution_plan_for_step</span>(<span class="kw-2">&amp;</span><span class="ident">logger</span>, <span class="kw-2">&amp;</span><span class="ident">config</span>, <span class="kw-2">&amp;</span><span class="ident">task</span>, <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">steps</span>, <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">task_names</span>, <span class="bool-val">true</span>);
} <span class="kw">else</span> {
<span class="kw">let</span> <span class="ident">workspace_task</span> <span class="op">=</span> <span class="ident">create_workspace_task</span>(<span class="ident">crate_info</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="string">&quot;workspace&quot;</span>.<span class="ident">to_string</span>(), <span class="ident">config</span>: <span class="ident">workspace_task</span> });
} <span class="kw">else</span> {
<span class="ident">create_execution_plan_for_step</span>(<span class="kw-2">&amp;</span><span class="ident">logger</span>, <span class="kw-2">&amp;</span><span class="ident">config</span>, <span class="kw-2">&amp;</span><span class="ident">task</span>, <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">steps</span>, <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">task_names</span>, <span class="bool-val">true</span>);
}

<span class="comment">// always add end task even if already executed due to some depedency</span>
Expand Down Expand Up @@ -484,10 +488,11 @@
<span class="ident">logger</span>: <span class="kw-2">&amp;</span><span class="ident">Logger</span>,
<span class="ident">config</span>: <span class="kw-2">&amp;</span><span class="ident">Config</span>,
<span class="ident">task</span>: <span class="kw-2">&amp;</span><span class="ident">str</span>,
<span class="ident">disable_workspace</span>: <span class="ident">bool</span>,
) {
<span class="kw">let</span> <span class="ident">start_time</span> <span class="op">=</span> <span class="ident">SystemTime</span>::<span class="ident">now</span>();

<span class="kw">let</span> <span class="ident">execution_plan</span> <span class="op">=</span> <span class="ident">create_execution_plan</span>(<span class="kw-2">&amp;</span><span class="ident">logger</span>, <span class="kw-2">&amp;</span><span class="ident">config</span>, <span class="kw-2">&amp;</span><span class="ident">task</span>);
<span class="kw">let</span> <span class="ident">execution_plan</span> <span class="op">=</span> <span class="ident">create_execution_plan</span>(<span class="kw-2">&amp;</span><span class="ident">logger</span>, <span class="kw-2">&amp;</span><span class="ident">config</span>, <span class="kw-2">&amp;</span><span class="ident">task</span>, <span class="ident">disable_workspace</span>);
<span class="ident">logger</span>.<span class="ident">verbose</span>(<span class="string">&quot;Created execution plan: &quot;</span>, <span class="kw-2">&amp;</span>[], <span class="prelude-val">Some</span>(<span class="kw-2">&amp;</span><span class="ident">execution_plan</span>));

<span class="ident">run_task_flow</span>(<span class="ident">logger</span>, <span class="kw-2">&amp;</span><span class="ident">execution_plan</span>);
Expand All @@ -512,8 +517,9 @@
<span class="ident">logger</span>: <span class="kw-2">&amp;</span><span class="ident">Logger</span>,
<span class="ident">config</span>: <span class="kw-2">&amp;</span><span class="ident">Config</span>,
<span class="ident">task</span>: <span class="kw-2">&amp;</span><span class="ident">str</span>,
<span class="ident">disable_workspace</span>: <span class="ident">bool</span>,
) {
<span class="kw">let</span> <span class="ident">execution_plan</span> <span class="op">=</span> <span class="ident">create_execution_plan</span>(<span class="kw-2">&amp;</span><span class="ident">logger</span>, <span class="kw-2">&amp;</span><span class="ident">config</span>, <span class="kw-2">&amp;</span><span class="ident">task</span>);
<span class="kw">let</span> <span class="ident">execution_plan</span> <span class="op">=</span> <span class="ident">create_execution_plan</span>(<span class="kw-2">&amp;</span><span class="ident">logger</span>, <span class="kw-2">&amp;</span><span class="ident">config</span>, <span class="kw-2">&amp;</span><span class="ident">task</span>, <span class="ident">disable_workspace</span>);
<span class="ident">logger</span>.<span class="ident">verbose</span>(<span class="string">&quot;Created execution plan: &quot;</span>, <span class="kw-2">&amp;</span>[], <span class="prelude-val">Some</span>(<span class="kw-2">&amp;</span><span class="ident">execution_plan</span>));

<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:#?}&quot;</span>, <span class="kw-2">&amp;</span><span class="ident">execution_plan</span>);
Expand Down
11 changes: 8 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fn run(
task: &str,
log_level: &str,
cwd: Option<&str>,
disable_workspace: bool,
print_only: bool,
) {
let logger = log::create(log_level);
Expand All @@ -43,9 +44,9 @@ fn run(
environment::setup_env(&logger, &config, &task);

if print_only {
runner::print(&logger, &config, &task);
runner::print(&logger, &config, &task, disable_workspace);
} else {
runner::run(&logger, &config, &task);
runner::run(&logger, &config, &task, disable_workspace);
}
}

Expand All @@ -65,8 +66,9 @@ fn run_for_args(matches: ArgMatches) {
};

let print_only = cmd_matches.is_present("print-steps");
let disable_workspace = cmd_matches.is_present("no-workspace");

run(build_file, task, log_level, cwd, print_only);
run(build_file, task, log_level, cwd, disable_workspace, print_only);
}
None => panic!("cargo-{} not invoked via cargo command.", NAME),
}
Expand Down Expand Up @@ -96,6 +98,9 @@ fn create_cli<'a, 'b>() -> App<'a, 'b> {
.arg(Arg::with_name("cwd").long("--cwd").value_name("DIRECTORY").help(
"Will set the current working directory. The search for the makefile will be from this directory if defined."
))
.arg(Arg::with_name("no-workspace").long("--no-workspace").help(
"Disable workspace support (tasks are triggered on workspace and not on members)"
))
.arg(
Arg::from_usage("-l, --loglevel=[LOG LEVEL] 'The log level'")
.possible_values(&["verbose", "info", "error"])
Expand Down
Loading

0 comments on commit 70e84dd

Please sign in to comment.