mirror of
https://github.com/correl/rebar.git
synced 2024-12-18 11:06:20 +00:00
Allow plugins to run before/after a rebar command.
This patch makes a small change in rebar_core that checks the list of valid plugins to see if any of them export a pre/post processing function for the current command. This logic is applied only to the plugins and allows plugin authors to hook into rebar's execution by using a naming convention that matches the one used for scripting hooks. Example: ```erlang -module(my_rebar_plugin). -export([pre_compile/2]). pre_compile(Config, AppFile) -> rebar_log:log(debug, "PRECOMPILE: ~p:~p~n", [AppFile, Config]), ok. ```
This commit is contained in:
parent
892dc48a86
commit
c07b0954eb
1 changed files with 20 additions and 1 deletions
|
@ -148,9 +148,17 @@ process_dir(Dir, ParentConfig, Command, DirSet) ->
|
||||||
%% in preprocess.
|
%% in preprocess.
|
||||||
{ok, PluginModules} = plugin_modules(Config),
|
{ok, PluginModules} = plugin_modules(Config),
|
||||||
|
|
||||||
|
%% Execute any before_command plugins on this directory
|
||||||
|
execute_pre(Command, PluginModules,
|
||||||
|
Config, ModuleSetFile),
|
||||||
|
|
||||||
%% Execute the current command on this directory
|
%% Execute the current command on this directory
|
||||||
execute(Command, Modules ++ PluginModules,
|
execute(Command, Modules ++ PluginModules,
|
||||||
Config, ModuleSetFile)
|
Config, ModuleSetFile),
|
||||||
|
|
||||||
|
%% Execute any after_command plugins on this directory
|
||||||
|
execute_post(Command, PluginModules,
|
||||||
|
Config, ModuleSetFile)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
%% Mark the current directory as processed
|
%% Mark the current directory as processed
|
||||||
|
@ -215,6 +223,17 @@ is_dir_type(rel_dir, Dir) ->
|
||||||
is_dir_type(_, _) ->
|
is_dir_type(_, _) ->
|
||||||
false.
|
false.
|
||||||
|
|
||||||
|
execute_pre(Command, Modules, Config, ModuleFile) ->
|
||||||
|
execute_plugin_hook("pre_", Command, Modules,
|
||||||
|
Config, ModuleFile).
|
||||||
|
|
||||||
|
execute_post(Command, Modules, Config, ModuleFile) ->
|
||||||
|
execute_plugin_hook("post_", Command, Modules,
|
||||||
|
Config, ModuleFile).
|
||||||
|
|
||||||
|
execute_plugin_hook(Hook, Command, Modules, Config, ModuleFile) ->
|
||||||
|
HookFunction = list_to_atom(Hook ++ atom_to_list(Command)),
|
||||||
|
execute(HookFunction, Modules, Config, ModuleFile).
|
||||||
|
|
||||||
%%
|
%%
|
||||||
%% Execute a command across all applicable modules
|
%% Execute a command across all applicable modules
|
||||||
|
|
Loading…
Reference in a new issue