Skip to content

Commit

Permalink
Enable task attributes override
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiegurari committed Jun 26, 2017
1 parent afd42f4 commit 8b224c7
Show file tree
Hide file tree
Showing 6 changed files with 677 additions and 65 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.2.5"
version = "0.2.6"
authors = ["Sagie Gur-Ari <[email protected]>"]
description = "Rust task runner and build tool."
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ See [contributing guide](.github/CONTRIBUTING.md)

| Date | Version | Description |
| ----------- | ------- | ----------- |
| 2017-06-25 | v0.2.5 | More tests |
| 2017-06-26 | v0.2.6 | Enable task attributes override |
| 2017-06-25 | v0.2.3 | 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 |
Expand Down
152 changes: 151 additions & 1 deletion docs/api/src/cargo_make/descriptor.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,81 @@
<span id="318">318</span>
<span id="319">319</span>
<span id="320">320</span>
<span id="321">321</span>
<span id="322">322</span>
<span id="323">323</span>
<span id="324">324</span>
<span id="325">325</span>
<span id="326">326</span>
<span id="327">327</span>
<span id="328">328</span>
<span id="329">329</span>
<span id="330">330</span>
<span id="331">331</span>
<span id="332">332</span>
<span id="333">333</span>
<span id="334">334</span>
<span id="335">335</span>
<span id="336">336</span>
<span id="337">337</span>
<span id="338">338</span>
<span id="339">339</span>
<span id="340">340</span>
<span id="341">341</span>
<span id="342">342</span>
<span id="343">343</span>
<span id="344">344</span>
<span id="345">345</span>
<span id="346">346</span>
<span id="347">347</span>
<span id="348">348</span>
<span id="349">349</span>
<span id="350">350</span>
<span id="351">351</span>
<span id="352">352</span>
<span id="353">353</span>
<span id="354">354</span>
<span id="355">355</span>
<span id="356">356</span>
<span id="357">357</span>
<span id="358">358</span>
<span id="359">359</span>
<span id="360">360</span>
<span id="361">361</span>
<span id="362">362</span>
<span id="363">363</span>
<span id="364">364</span>
<span id="365">365</span>
<span id="366">366</span>
<span id="367">367</span>
<span id="368">368</span>
<span id="369">369</span>
<span id="370">370</span>
<span id="371">371</span>
<span id="372">372</span>
<span id="373">373</span>
<span id="374">374</span>
<span id="375">375</span>
<span id="376">376</span>
<span id="377">377</span>
<span id="378">378</span>
<span id="379">379</span>
<span id="380">380</span>
<span id="381">381</span>
<span id="382">382</span>
<span id="383">383</span>
<span id="384">384</span>
<span id="385">385</span>
<span id="386">386</span>
<span id="387">387</span>
<span id="388">388</span>
<span id="389">389</span>
<span id="390">390</span>
<span id="391">391</span>
<span id="392">392</span>
<span id="393">393</span>
<span id="394">394</span>
<span id="395">395</span>
</pre><pre class="rust ">
<span class="doccomment">//! # descriptor</span>
<span class="doccomment">//!</span>
Expand Down Expand Up @@ -415,7 +490,30 @@

<span class="kw">for</span> (<span class="ident">key</span>, <span class="ident">value</span>) <span class="kw">in</span> <span class="ident">extended</span>.<span class="ident">iter</span>() {
<span class="kw">let</span> <span class="ident">key_str</span> <span class="op">=</span> <span class="ident">key</span>.<span class="ident">to_string</span>();
<span class="ident">merged</span>.<span class="ident">insert</span>(<span class="ident">key_str</span>, <span class="ident">value</span>.<span class="ident">clone</span>());
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">task</span> <span class="op">=</span> <span class="ident">value</span>.<span class="ident">clone</span>();

<span class="ident">task</span> <span class="op">=</span> <span class="kw">match</span> <span class="ident">base</span>.<span class="ident">get</span>(<span class="ident">key</span>) {
<span class="prelude-val">Some</span>(<span class="kw-2">ref</span> <span class="ident">value</span>) <span class="op">=&gt;</span> {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">merged_task</span> <span class="op">=</span> <span class="ident">Task</span> {
<span class="ident">disabled</span>: <span class="prelude-val">None</span>,
<span class="ident">alias</span>: <span class="prelude-val">None</span>,
<span class="ident">install_crate</span>: <span class="prelude-val">None</span>,
<span class="ident">install_script</span>: <span class="prelude-val">None</span>,
<span class="ident">command</span>: <span class="prelude-val">None</span>,
<span class="ident">args</span>: <span class="prelude-val">None</span>,
<span class="ident">script</span>: <span class="prelude-val">None</span>,
<span class="ident">dependencies</span>: <span class="prelude-val">None</span>
};

<span class="ident">merged_task</span>.<span class="ident">extend</span>(<span class="ident">value</span>);
<span class="ident">merged_task</span>.<span class="ident">extend</span>(<span class="kw-2">&amp;</span><span class="ident">task</span>);

<span class="ident">merged_task</span>
}
_ <span class="op">=&gt;</span> <span class="ident">task</span>,
};

<span class="ident">merged</span>.<span class="ident">insert</span>(<span class="ident">key_str</span>, <span class="ident">task</span>);
}

<span class="ident">merged</span>
Expand Down Expand Up @@ -675,6 +773,58 @@
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">task</span>.<span class="ident">dependencies</span>.<span class="ident">is_none</span>());
}

<span class="attribute">#[<span class="ident">test</span>]</span>
<span class="kw">fn</span> <span class="ident">merge_tasks_extend_task</span>() {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map1</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="op">&lt;</span><span class="ident">String</span>, <span class="ident">Task</span><span class="op">&gt;</span>::<span class="ident">new</span>();
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map2</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="op">&lt;</span><span class="ident">String</span>, <span class="ident">Task</span><span class="op">&gt;</span>::<span class="ident">new</span>();

<span class="ident">map1</span>.<span class="ident">insert</span>(
<span class="string">&quot;test&quot;</span>.<span class="ident">to_string</span>(),
<span class="ident">Task</span> {
<span class="ident">disabled</span>: <span class="prelude-val">None</span>,
<span class="ident">alias</span>: <span class="prelude-val">None</span>,
<span class="ident">install_crate</span>: <span class="prelude-val">Some</span>(<span class="string">&quot;my crate&quot;</span>.<span class="ident">to_string</span>()),
<span class="ident">install_script</span>: <span class="prelude-val">None</span>,
<span class="ident">command</span>: <span class="prelude-val">Some</span>(<span class="string">&quot;test1&quot;</span>.<span class="ident">to_string</span>()),
<span class="ident">args</span>: <span class="prelude-val">None</span>,
<span class="ident">script</span>: <span class="prelude-val">None</span>,
<span class="ident">dependencies</span>: <span class="prelude-val">None</span>
}
);

<span class="ident">map2</span>.<span class="ident">insert</span>(
<span class="string">&quot;test&quot;</span>.<span class="ident">to_string</span>(),
<span class="ident">Task</span> {
<span class="ident">disabled</span>: <span class="prelude-val">Some</span>(<span class="bool-val">true</span>),
<span class="ident">alias</span>: <span class="prelude-val">None</span>,
<span class="ident">install_crate</span>: <span class="prelude-val">None</span>,
<span class="ident">install_script</span>: <span class="prelude-val">None</span>,
<span class="ident">command</span>: <span class="prelude-val">Some</span>(<span class="string">&quot;test2&quot;</span>.<span class="ident">to_string</span>()),
<span class="ident">args</span>: <span class="prelude-val">None</span>,
<span class="ident">script</span>: <span class="prelude-val">None</span>,
<span class="ident">dependencies</span>: <span class="prelude-val">None</span>
}
);

<span class="kw">let</span> <span class="ident">output</span> <span class="op">=</span> <span class="ident">merge_tasks</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">map1</span>, <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">map2</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">output</span>.<span class="ident">len</span>(), <span class="number">1</span>);

<span class="kw">let</span> <span class="ident">task</span> <span class="op">=</span> <span class="ident">output</span>.<span class="ident">get</span>(<span class="string">&quot;test&quot;</span>).<span class="ident">unwrap</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">task</span>.<span class="ident">disabled</span>.<span class="ident">is_some</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">task</span>.<span class="ident">alias</span>.<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">task</span>.<span class="ident">install_crate</span>.<span class="ident">is_some</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">task</span>.<span class="ident">install_script</span>.<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">task</span>.<span class="ident">command</span>.<span class="ident">is_some</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">task</span>.<span class="ident">args</span>.<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">task</span>.<span class="ident">script</span>.<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">task</span>.<span class="ident">dependencies</span>.<span class="ident">is_none</span>());

<span class="kw">let</span> <span class="ident">task_clone</span> <span class="op">=</span> <span class="ident">task</span>.<span class="ident">clone</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">task_clone</span>.<span class="ident">disabled</span>.<span class="ident">unwrap</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">task_clone</span>.<span class="ident">install_crate</span>.<span class="ident">unwrap</span>(), <span class="string">&quot;my crate&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">task_clone</span>.<span class="ident">command</span>.<span class="ident">unwrap</span>(), <span class="string">&quot;test2&quot;</span>);
}

<span class="attribute">#[<span class="ident">test</span>]</span>
<span class="kw">fn</span> <span class="ident">load_external_descriptor_no_file</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="string">&quot;error&quot;</span>);
Expand Down
Loading

0 comments on commit 8b224c7

Please sign in to comment.