Skip to content

Commit

Permalink
cargo-make now defines env vars based on project git repo information
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiegurari committed Jul 9, 2017
1 parent 917cbed commit c5e9d62
Show file tree
Hide file tree
Showing 15 changed files with 560 additions and 16 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.10"
version = "0.3.11"
authors = ["Sagie Gur-Ari <[email protected]>"]
description = "Rust task runner and build tool."
license = "Apache-2.0"
Expand Down
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,22 @@ In addition, cargo-make will also add few environment variables that can be help

* **CARGO_MAKE** - Set to "true" to help sub processes identify they are running from cargo make.
* **CARGO_MAKE_TASK** - Holds the name of the main task being executed.
* **CARGO_MAKE_CRATE_NAME** - Holds the crate name from the Cargo.toml file found in the cwd (only if file exists and value is defined).
* **CARGO_MAKE_CRATE_VERSION** - Holds the crate version from the Cargo.toml file found in the cwd (only if file exists and value is defined).
* **CARGO_MAKE_CRATE_DESCRIPTION** - Holds the crate description from the Cargo.toml file found in the cwd (only if file exists and value is defined).
* **CARGO_MAKE_CRATE_LICENSE** - Holds the crate license from the Cargo.toml file found in the cwd (only if file exists and value is defined).
* **CARGO_MAKE_CRATE_DOCUMENTATION** - Holds the crate documentation link from the Cargo.toml file found in the cwd (only if file exists and value is defined).
* **CARGO_MAKE_CRATE_HOMEPAGE** - Holds the crate homepage link from the Cargo.toml file found in the cwd (only if file exists and value is defined).
* **CARGO_MAKE_CRATE_REPOSITORY** - Holds the crate repository link from the Cargo.toml file found in the cwd (only if file exists and value is defined).

The following environment variables will be set by cargo-make if Cargo.toml file exists and the relevant value is defined:

* **CARGO_MAKE_CRATE_NAME** - Holds the crate name from the Cargo.toml file found in the cwd.
* **CARGO_MAKE_CRATE_VERSION** - Holds the crate version from the Cargo.toml file found in the cwd.
* **CARGO_MAKE_CRATE_DESCRIPTION** - Holds the crate description from the Cargo.toml file found in the cwd.
* **CARGO_MAKE_CRATE_LICENSE** - Holds the crate license from the Cargo.toml file found in the cwd.
* **CARGO_MAKE_CRATE_DOCUMENTATION** - Holds the crate documentation link from the Cargo.toml file found in the cwd.
* **CARGO_MAKE_CRATE_HOMEPAGE** - Holds the crate homepage link from the Cargo.toml file found in the cwd.
* **CARGO_MAKE_CRATE_REPOSITORY** - Holds the crate repository link from the Cargo.toml file found in the cwd.

The following environment variables will be set by cargo-make if the project is part of a git repo:

* **CARGO_MAKE_GIT_BRANCH** - The current branch name.
* **CARGO_MAKE_GIT_USER_NAME** - The user name pulled from the give config user.name key.
* **CARGO_MAKE_GIT_USER_EMAIL** - The user email pulled from the give config user.email key.

<a name="usage-ci"></a>
### Continuous Integration
Expand Down Expand Up @@ -646,6 +655,7 @@ See [contributing guide](.github/CONTRIBUTING.md)

| Date | Version | Description |
| ----------- | ------- | ----------- |
| 2017-07-09 | v0.3.11 | cargo-make now defines env vars based on project git repo information |
| 2017-07-06 | v0.3.10 | cargo-make now defines env vars based on project Cargo.toml |
| 2017-07-05 | v0.3.6 | Added --cwd cli arg to enable setting working directory |
| 2017-07-04 | v0.3.5 | Added clippy task |
Expand Down
24 changes: 17 additions & 7 deletions docs/_includes/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,22 @@ In addition, cargo-make will also add few environment variables that can be help

* **CARGO_MAKE** - Set to "true" to help sub processes identify they are running from cargo make.
* **CARGO_MAKE_TASK** - Holds the name of the main task being executed.
* **CARGO_MAKE_CRATE_NAME** - Holds the crate name from the Cargo.toml file found in the cwd (only if file exists and value is defined).
* **CARGO_MAKE_CRATE_VERSION** - Holds the crate version from the Cargo.toml file found in the cwd (only if file exists and value is defined).
* **CARGO_MAKE_CRATE_DESCRIPTION** - Holds the crate description from the Cargo.toml file found in the cwd (only if file exists and value is defined).
* **CARGO_MAKE_CRATE_LICENSE** - Holds the crate license from the Cargo.toml file found in the cwd (only if file exists and value is defined).
* **CARGO_MAKE_CRATE_DOCUMENTATION** - Holds the crate documentation link from the Cargo.toml file found in the cwd (only if file exists and value is defined).
* **CARGO_MAKE_CRATE_HOMEPAGE** - Holds the crate homepage link from the Cargo.toml file found in the cwd (only if file exists and value is defined).
* **CARGO_MAKE_CRATE_REPOSITORY** - Holds the crate repository link from the Cargo.toml file found in the cwd (only if file exists and value is defined).

The following environment variables will be set by cargo-make if Cargo.toml file exists and the relevant value is defined:

* **CARGO_MAKE_CRATE_NAME** - Holds the crate name from the Cargo.toml file found in the cwd.
* **CARGO_MAKE_CRATE_VERSION** - Holds the crate version from the Cargo.toml file found in the cwd.
* **CARGO_MAKE_CRATE_DESCRIPTION** - Holds the crate description from the Cargo.toml file found in the cwd.
* **CARGO_MAKE_CRATE_LICENSE** - Holds the crate license from the Cargo.toml file found in the cwd.
* **CARGO_MAKE_CRATE_DOCUMENTATION** - Holds the crate documentation link from the Cargo.toml file found in the cwd.
* **CARGO_MAKE_CRATE_HOMEPAGE** - Holds the crate homepage link from the Cargo.toml file found in the cwd.
* **CARGO_MAKE_CRATE_REPOSITORY** - Holds the crate repository link from the Cargo.toml file found in the cwd.

The following environment variables will be set by cargo-make if the project is part of a git repo:

* **CARGO_MAKE_GIT_BRANCH** - The current branch name.
* **CARGO_MAKE_GIT_USER_NAME** - The user name pulled from the give config user.name key.
* **CARGO_MAKE_GIT_USER_EMAIL** - The user email pulled from the give config user.email key.

<a name="usage-ci"></a>
### Continuous Integration
Expand Down Expand Up @@ -619,6 +628,7 @@ See [contributing guide](https://github.com/sagiegurari/cargo-make/blob/master/.

| Date | Version | Description |
| ----------- | ------- | ----------- |
| 2017-07-09 | v0.3.11 | cargo-make now defines env vars based on project git repo information |
| 2017-07-06 | v0.3.10 | cargo-make now defines env vars based on project Cargo.toml |
| 2017-07-05 | v0.3.6 | Added --cwd cli arg to enable setting working directory |
| 2017-07-04 | v0.3.5 | Added clippy task |
Expand Down
2 changes: 1 addition & 1 deletion docs/api/cargo_make/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h1 class='fqn'><span class='in-band'>Crate <a class="mod" href=''>cargo_make</a
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
[<span class='inner'>&#x2212;</span>]
</a>
</span><a class='srclink' href='../src/cargo_make/main.rs.html#1-119' title='goto source code'>[src]</a></span></h1>
</span><a class='srclink' href='../src/cargo_make/main.rs.html#1-120' title='goto source code'>[src]</a></span></h1>
<div class='docblock'>
<h1 id='cargo-make' class='section-header'><a href='#cargo-make'>cargo-make</a></h1>
<p>Rust task runner and build tool.<br>
Expand Down
40 changes: 40 additions & 0 deletions docs/api/src/cargo_make/environment.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,26 @@
<span id="113">113</span>
<span id="114">114</span>
<span id="115">115</span>
<span id="116">116</span>
<span id="117">117</span>
<span id="118">118</span>
<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>
<span id="127">127</span>
<span id="128">128</span>
<span id="129">129</span>
<span id="130">130</span>
<span id="131">131</span>
<span id="132">132</span>
<span id="133">133</span>
<span id="134">134</span>
<span id="135">135</span>
</pre><pre class="rust ">
<span class="doccomment">//! # env</span>
<span class="doccomment">//!</span>
Expand All @@ -168,6 +188,7 @@
<span class="attribute">#[<span class="ident">path</span> <span class="op">=</span> <span class="string">&quot;./environment_test.rs&quot;</span>]</span>
<span class="kw">mod</span> <span class="ident">environment_test</span>;

<span class="kw">use</span> <span class="ident">gitinfo</span>;
<span class="kw">use</span> <span class="ident">log</span>::<span class="ident">Logger</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">env</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">fs</span>::<span class="ident">File</span>;
Expand Down Expand Up @@ -242,6 +263,22 @@
};
}

<span class="kw">fn</span> <span class="ident">setup_env_for_git_repo</span>(<span class="ident">logger</span>: <span class="kw-2">&amp;</span><span class="ident">Logger</span>) {
<span class="kw">let</span> <span class="ident">git_info</span> <span class="op">=</span> <span class="ident">gitinfo</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">git_info</span>.<span class="ident">branch</span>.<span class="ident">is_some</span>() {
<span class="ident">env</span>::<span class="ident">set_var</span>(<span class="string">&quot;CARGO_MAKE_GIT_BRANCH&quot;</span>, <span class="kw-2">&amp;</span><span class="ident">git_info</span>.<span class="ident">branch</span>.<span class="ident">unwrap</span>());
}

<span class="kw">if</span> <span class="ident">git_info</span>.<span class="ident">user_name</span>.<span class="ident">is_some</span>() {
<span class="ident">env</span>::<span class="ident">set_var</span>(<span class="string">&quot;CARGO_MAKE_GIT_USER_NAME&quot;</span>, <span class="kw-2">&amp;</span><span class="ident">git_info</span>.<span class="ident">user_name</span>.<span class="ident">unwrap</span>());
}

<span class="kw">if</span> <span class="ident">git_info</span>.<span class="ident">user_email</span>.<span class="ident">is_some</span>() {
<span class="ident">env</span>::<span class="ident">set_var</span>(<span class="string">&quot;CARGO_MAKE_GIT_USER_EMAIL&quot;</span>, <span class="kw-2">&amp;</span><span class="ident">git_info</span>.<span class="ident">user_email</span>.<span class="ident">unwrap</span>());
}
}

<span class="doccomment">/// Sets up the env before the tasks execution.</span>
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">setup_env</span>(
<span class="ident">logger</span>: <span class="kw-2">&amp;</span><span class="ident">Logger</span>,
Expand All @@ -255,6 +292,9 @@

<span class="comment">// load crate info</span>
<span class="ident">setup_env_for_crate</span>(<span class="kw-2">&amp;</span><span class="ident">logger</span>);

<span class="comment">// load git info</span>
<span class="ident">setup_env_for_git_repo</span>(<span class="kw-2">&amp;</span><span class="ident">logger</span>);
}

<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">setup_cwd</span>(
Expand Down
Loading

0 comments on commit c5e9d62

Please sign in to comment.