summaryrefslogtreecommitdiff
path: root/src/rebar_utils.erl
diff options
context:
space:
mode:
authorTristan Sloughter <tristan.sloughter@gmail.com>2014-06-13 19:25:21 -0500
committerTristan Sloughter <tristan.sloughter@gmail.com>2014-06-13 19:25:21 -0500
commit9380583f6c27b30e1e2a5aa16d681f2e1b6c00c3 (patch)
treed596d93c56aa8304df89ce9e60311be98cb949cd /src/rebar_utils.erl
parent3297ffec2c89c6b7135165b4bfaeaeb07167c33c (diff)
parent9c23dfef72c381d93e3d7843700a2e9949c6e31e (diff)
downloadrebar-9380583f6c27b30e1e2a5aa16d681f2e1b6c00c3.tar.gz
Merge pull request #229 from tolbrino/tb-patch-env
Add REBAR to environment before executing hooks
Diffstat (limited to 'src/rebar_utils.erl')
-rw-r--r--src/rebar_utils.erl20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index c02d200..fa35fed 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -54,7 +54,8 @@
src_dirs/1,
ebin_dir/0,
base_dir/1,
- processing_base_dir/1, processing_base_dir/2]).
+ processing_base_dir/1, processing_base_dir/2,
+ patch_env/2]).
-include("rebar.hrl").
@@ -338,6 +339,23 @@ processing_base_dir(Config, Dir) ->
AbsDir = filename:absname(Dir),
AbsDir =:= base_dir(Config).
+%% @doc Returns the list of environment variables including 'REBAR' which points to the
+%% rebar executable used to execute the currently running command. The environment is
+%% not modified if rebar was invoked programmatically.
+-spec patch_env(rebar_config:config(), [{string(), string()}]) -> [{string(), string()}].
+patch_env(Config, []) ->
+ % if we reached an empty list the env did not contain the REBAR variable
+ case rebar_config:get_xconf(Config, escript, "") of
+ "" -> % rebar was invoked programmatically
+ [];
+ Path ->
+ [{"REBAR", Path}]
+ end;
+patch_env(_Config, [{"REBAR", _} | _]=All) ->
+ All;
+patch_env(Config, [E | Rest]) ->
+ [E | patch_env(Config, Rest)].
+
%% ====================================================================
%% Internal functions
%% ====================================================================