summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar_core.erl20
-rw-r--r--src/rebar_port_compiler.erl23
2 files changed, 26 insertions, 17 deletions
diff --git a/src/rebar_core.erl b/src/rebar_core.erl
index 42f301f..f17ed0b 100644
--- a/src/rebar_core.erl
+++ b/src/rebar_core.erl
@@ -234,12 +234,15 @@ execute(Command, Modules, Config, ModuleFile) ->
%% responds to this command
erlang:put(operations, erlang:get(operations) + 1),
+ %% Check for and get command specific environments
+ Env = setup_envs(Config, Modules),
+
%% Run the available modules
- apply_hooks(pre_hooks, Config, Command),
+ apply_hooks(pre_hooks, Config, Command, Env),
case catch(run_modules(TargetModules, Command,
Config, ModuleFile)) of
ok ->
- apply_hooks(post_hooks, Config, Command),
+ apply_hooks(post_hooks, Config, Command, Env),
ok;
{error, failed} ->
?FAIL;
@@ -304,14 +307,19 @@ run_modules([Module | Rest], Command, Config, File) ->
{Module, Error}
end.
-apply_hooks(Mode, Config, Command) ->
+apply_hooks(Mode, Config, Command, Env) ->
Hooks = rebar_config:get_local(Config, Mode, []),
lists:foreach(fun apply_hook/1,
- [Hook || Hook <- Hooks, element(1, Hook) =:= Command]).
+ [{Env, Hook} || Hook <- Hooks, element(1, Hook) =:= Command]).
-apply_hook({Command, Hook}) ->
+apply_hook({Env, {Command, Hook}}) ->
Msg = lists:flatten(io_lib:format("Command [~p] failed!~n", [Command])),
- rebar_utils:sh(Hook, [{abort_on_error, Msg}]).
+ rebar_utils:sh(Hook, [{env, Env}, {abort_on_error, Msg}]).
+
+setup_envs(Config, Modules) ->
+ lists:flatten([M:setup_env(Config) ||
+ M <- Modules,
+ erlang:function_exported(M, setup_env, 1)]).
acc_modules(Modules, Command, Config, File) ->
acc_modules(select_modules(Modules, Command, []),
diff --git a/src/rebar_port_compiler.erl b/src/rebar_port_compiler.erl
index 9f859e8..57df199 100644
--- a/src/rebar_port_compiler.erl
+++ b/src/rebar_port_compiler.erl
@@ -27,7 +27,8 @@
-module(rebar_port_compiler).
-export([compile/2,
- clean/2]).
+ clean/2,
+ setup_env/1]).
-include("rebar.hrl").
@@ -94,14 +95,7 @@ compile(Config, AppFile) ->
[] ->
ok;
_ ->
- %% Extract environment values from the config (if specified) and
- %% merge with the default for this operating system. This enables
- %% max flexibility for users.
- DefaultEnvs = filter_envs(default_env(), []),
- PortEnvs = rebar_config:get_list(Config, port_envs, []),
- OverrideEnvs = filter_envs(PortEnvs, []),
- RawEnv = DefaultEnvs ++ OverrideEnvs ++ os_env(),
- Env = expand_vars_loop(merge_each_var(RawEnv, [])),
+ Env = setup_env(Config),
%% One or more files are available for building.
%% Run the pre-compile hook, if necessary.
@@ -152,8 +146,15 @@ clean(Config, AppFile) ->
%% Run the cleanup script, if it exists
run_cleanup_hook(Config).
-
-
+setup_env(Config) ->
+ %% Extract environment values from the config (if specified) and
+ %% merge with the default for this operating system. This enables
+ %% max flexibility for users.
+ DefaultEnvs = filter_envs(default_env(), []),
+ PortEnvs = rebar_config:get_list(Config, port_envs, []),
+ OverrideEnvs = filter_envs(PortEnvs, []),
+ RawEnv = DefaultEnvs ++ OverrideEnvs ++ os_env(),
+ expand_vars_loop(merge_each_var(RawEnv, [])).
%% ===================================================================
%% Internal functions