summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar_plugins.erl2
-rw-r--r--src/rebar_prv_compile.erl15
-rw-r--r--test/rebar_hooks_SUITE.erl30
3 files changed, 37 insertions, 10 deletions
diff --git a/src/rebar_plugins.erl b/src/rebar_plugins.erl
index d03ada0..6d0a4dc 100644
--- a/src/rebar_plugins.erl
+++ b/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);
diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl
index 1dff4d8..5a2e379 100644
--- a/src/rebar_prv_compile.erl
+++ b/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)
diff --git a/test/rebar_hooks_SUITE.erl b/test/rebar_hooks_SUITE.erl
index a5136e5..7df4ea3 100644
--- a/test/rebar_hooks_SUITE.erl
+++ b/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"])}]}).