summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTristan Sloughter <t@crashfast.com>2014-11-02 09:05:08 -0600
committerTristan Sloughter <t@crashfast.com>2014-11-02 09:05:08 -0600
commitd549901de4493a8ac8f6f591e885b11816a340e8 (patch)
treeccf314fc9cd3c2bcd8a9b07a2261f98b479e1990 /src
parent920fd533973da9605e498a9db6e44a8f8d734c73 (diff)
add rebar_hooks module
Diffstat (limited to 'src')
-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}]).