diff options
author | Tim Watson <watson.timothy@gmail.com> | 2011-01-26 01:50:33 +0000 |
---|---|---|
committer | Tuncer Ayaz <tuncer.ayaz@gmail.com> | 2011-03-12 16:31:41 +0100 |
commit | e76770511a6bae6fe9d23e7821db8d32e897f9a8 (patch) | |
tree | c99b887a4cbb19f2c84977294d2590459468391f /src | |
parent | 2e1b4da71d85122bbb2aabd78fd1b4dbfefddd21 (diff) |
Add pre and post script support for all commands
This change makes it possible to assign pre/post scripts to all
rebar commands. This allows users fine grained control over
when scripts and/or shell commands should be executed, where such
extensions are absolutely needed.
Several examples have been added to the rebar.config.sample file.
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_core.erl | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/rebar_core.erl b/src/rebar_core.erl index d92af34..3f8068a 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,20 @@ run_modules([Module | Rest], Command, Config, File) -> {Module, Error} end. +apply_hooks(Mode, Config, Command) -> + case rebar_config:get_local(Config, Mode, []) of + [] -> + skip; + Hooks when is_list(Hooks) -> + lists:foreach(fun apply_hook/1, + [{Command, Hook} || Hook <- Hooks]) + end. + +apply_hook({Command, {Command, Hook}}) -> + Msg = lists:flatten(io_lib:format("Command [~p] failed!~n", [Command])), + rebar_utils:sh(Hook, [{abort_on_error, Msg}]); +apply_hook({Command, {HookCmd, _}}) when Command =/= HookCmd -> + skip. acc_modules(Modules, Command, Config, File) -> acc_modules(select_modules(Modules, Command, []), |