summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar_hooks.erl24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/rebar_hooks.erl b/src/rebar_hooks.erl
new file mode 100644
index 0000000..2599d8e
--- /dev/null
+++ b/src/rebar_hooks.erl
@@ -0,0 +1,24 @@
+-module(rebar_hooks).
+
+-export([run_compile_hooks/4]).
+
+run_compile_hooks(Dir, Type, Command, State) ->
+ Hooks = rebar_state:get(State, Type, []),
+ lists:foreach(fun({_, C, _}=Hook) when C =:= Command ->
+ apply_hook(Dir, [], Hook);
+ ({C, _}=Hook) when C =:= Command ->
+ apply_hook(Dir, [], Hook);
+ (_) ->
+ continue
+ end, Hooks).
+
+apply_hook(Dir, Env, {Arch, Command, Hook}) ->
+ case rebar_utils:is_arch(Arch) of
+ true ->
+ apply_hook(Dir, Env, {Command, Hook});
+ false ->
+ ok
+ end;
+apply_hook(Dir, Env, {Command, Hook}) ->
+ Msg = lists:flatten(io_lib:format("Hook for ~p failed!~n", [Command])),
+ rebar_utils:sh(Hook, [{cd, Dir}, {env, Env}, {abort_on_error, Msg}]).