浏览代码

run hooks when building plugins

pull/458/head
Tristan Sloughter 10 年前
父节点
当前提交
e65ad8c2ca
共有 3 个文件被更改,包括 37 次插入10 次删除
  1. +1
    -1
      src/rebar_plugins.erl
  2. +7
    -8
      src/rebar_prv_compile.erl
  3. +29
    -1
      test/rebar_hooks_SUITE.erl

+ 1
- 1
src/rebar_plugins.erl 查看文件

@ -63,7 +63,7 @@ build_plugin(AppInfo) ->
AppDir = rebar_app_info:dir(AppInfo),
C = rebar_config:consult(AppDir),
S = rebar_state:new(rebar_state:new(), C, AppDir),
rebar_prv_compile:compile(S, AppInfo).
rebar_prv_compile:compile(S, [], AppInfo).
plugin_providers({Plugin, _, _}) when is_atom(Plugin) ->
validate_plugin(Plugin);

+ 7
- 8
src/rebar_prv_compile.erl 查看文件

@ -6,7 +6,7 @@
do/1,
format_error/1]).
-export([compile/2]).
-export([compile/3]).
-include("rebar.hrl").
@ -82,18 +82,17 @@ build_app(State, Providers, AppInfo) ->
AppState
end,
%% Legacy hook support
rebar_hooks:run_all_hooks(AppDir, pre, ?PROVIDER, Providers, S),
AppInfo1 = compile(S, AppInfo),
rebar_hooks:run_all_hooks(AppDir, post, ?PROVIDER, Providers, S),
compile(S, Providers, AppInfo).
AppInfo1.
compile(State, AppInfo) ->
compile(State, Providers, AppInfo) ->
?INFO("Compiling ~s", [rebar_app_info:name(AppInfo)]),
AppDir = rebar_app_info:dir(AppInfo),
rebar_hooks:run_all_hooks(AppDir, pre, ?PROVIDER, Providers, State),
rebar_erlc_compiler:compile(State, ec_cnv:to_list(rebar_app_info:out_dir(AppInfo))),
case rebar_otp_app:compile(State, AppInfo) of
{ok, AppInfo1} ->
rebar_hooks:run_all_hooks(AppDir, post, ?PROVIDER, Providers, State),
AppInfo1;
Error ->
throw(Error)

+ 29
- 1
test/rebar_hooks_SUITE.erl 查看文件

@ -4,9 +4,11 @@
init_per_suite/1,
end_per_suite/1,
init_per_testcase/2,
end_per_testcase/2,
all/0,
build_and_clean_app/1,
run_hooks_once/1,
run_hooks_for_plugins/1,
deps_hook_namespace/1]).
-include_lib("common_test/include/ct.hrl").
@ -25,9 +27,12 @@ end_per_suite(_Config) ->
init_per_testcase(_, Config) ->
rebar_test_utils:init_rebar_state(Config).
end_per_testcase(_, _Config) ->
catch meck:unload().
all() ->
[build_and_clean_app, run_hooks_once,
deps_hook_namespace].
run_hooks_for_plugins, deps_hook_namespace].
%% Test post provider hook cleans compiled project app, leaving it invalid
build_and_clean_app(Config) ->
@ -71,3 +76,26 @@ deps_hook_namespace(Config) ->
Config, RebarConfig, ["compile"],
{ok, [{dep, "some_dep"}]}
).
run_hooks_for_plugins(Config) ->
AppDir = ?config(apps, Config),
Name = rebar_test_utils:create_random_name("app1_"),
Vsn = rebar_test_utils:create_random_vsn(),
rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
PluginName = rebar_test_utils:create_random_name("plugin1_"),
mock_git_resource:mock([{config, [{pre_hooks, [{compile, "touch randomfile"}]}]}]),
RConfFile = rebar_test_utils:create_config(AppDir,
[{plugins, [
{list_to_atom(PluginName),
{git, "http://site.com/user/"++PluginName++".git",
{tag, Vsn}}}
]}]),
{ok, RConf} = file:consult(RConfFile),
rebar_test_utils:run_and_check(Config, RConf, ["compile"], {ok, [{app, Name, valid},
{plugin, PluginName},
{file, filename:join([AppDir, "_build", "default", "plugins", PluginName, "randomfile"])}]}).

正在加载...
取消
保存