diff options
Diffstat (limited to 'src/rebar_core.erl')
-rw-r--r-- | src/rebar_core.erl | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/rebar_core.erl b/src/rebar_core.erl index d92af34..42f301f 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -223,7 +223,7 @@ execute(Command, Modules, Config, ModuleFile) -> case select_modules(Modules, Command, []) of [] -> ?WARN("'~p' command does not apply to directory ~s\n", - [Command, rebar_utils:get_cwd()]); + [Command, rebar_utils:get_cwd()]); TargetModules -> %% Provide some info on where we are @@ -235,9 +235,11 @@ execute(Command, Modules, Config, ModuleFile) -> erlang:put(operations, erlang:get(operations) + 1), %% Run the available modules + apply_hooks(pre_hooks, Config, Command), case catch(run_modules(TargetModules, Command, Config, ModuleFile)) of ok -> + apply_hooks(post_hooks, Config, Command), ok; {error, failed} -> ?FAIL; @@ -302,6 +304,14 @@ run_modules([Module | Rest], Command, Config, File) -> {Module, Error} end. +apply_hooks(Mode, Config, Command) -> + Hooks = rebar_config:get_local(Config, Mode, []), + lists:foreach(fun apply_hook/1, + [Hook || Hook <- Hooks, element(1, Hook) =:= Command]). + +apply_hook({Command, Hook}) -> + Msg = lists:flatten(io_lib:format("Command [~p] failed!~n", [Command])), + rebar_utils:sh(Hook, [{abort_on_error, Msg}]). acc_modules(Modules, Command, Config, File) -> acc_modules(select_modules(Modules, Command, []), |