summaryrefslogtreecommitdiff
path: root/src/rebar_core.erl
diff options
context:
space:
mode:
authorTuncer Ayaz <tuncer.ayaz@gmail.com>2011-04-05 16:04:03 +0200
committerTuncer Ayaz <tuncer.ayaz@gmail.com>2011-04-21 21:38:16 +0200
commit20dfd32c85a346f8a8bd270c5c02b5900a5832cf (patch)
tree14ff42cef79b90bd0fea06c90ff4390f441faa75 /src/rebar_core.erl
parent85eb2957c3fd908e8250f8d0816d220bcf06bb77 (diff)
Add support for command-specific env for hooks
Diffstat (limited to 'src/rebar_core.erl')
-rw-r--r--src/rebar_core.erl20
1 files changed, 14 insertions, 6 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, []),