summaryrefslogtreecommitdiff
path: root/src/rebar_hooks.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_hooks.erl')
-rw-r--r--src/rebar_hooks.erl27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/rebar_hooks.erl b/src/rebar_hooks.erl
index 706d6b9..e144a8e 100644
--- a/src/rebar_hooks.erl
+++ b/src/rebar_hooks.erl
@@ -1,9 +1,30 @@
-module(rebar_hooks).
--export([run_compile_hooks/4]).
+-export([run_all_hooks/5]).
-run_compile_hooks(Dir, Type, Command, State) ->
- Hooks = rebar_state:get(State, Type, []),
+-spec run_all_hooks(file:filename_all(), pre | post,
+ atom() | {atom(), atom()} | string(),
+ [providers:t()], rebar_state:t()) -> ok.
+run_all_hooks(Dir, Type, Command, Providers, State) ->
+ run_provider_hooks(Dir, Type, Command, Providers, State),
+ run_hooks(Dir, Type, Command, State).
+
+run_provider_hooks(Dir, Type, Command, Providers, State) ->
+ State1 = rebar_state:providers(rebar_state:dir(State, Dir), Providers),
+ AllHooks = rebar_state:get(State1, provider_hooks, []),
+ TypeHooks = proplists:get_value(Type, AllHooks, []),
+ HookProviders = proplists:get_all_values(Command, TypeHooks),
+ rebar_core:do(HookProviders, State1).
+
+run_hooks(Dir, Type, Command, State) ->
+ Hooks = case Type of
+ pre ->
+ rebar_state:get(State, pre_hooks, []);
+ post ->
+ rebar_state:get(State, post_hooks, []);
+ _ ->
+ []
+ end,
Env = [{"REBAR_DEPS_DIR", filename:absname(rebar_dir:deps_dir(State))}],
lists:foreach(fun({_, C, _}=Hook) when C =:= Command ->
apply_hook(Dir, Env, Hook);