Browse Source

in providers that don't run per app run all available hooks

pull/1091/head
Tristan Sloughter 9 years ago
parent
commit
3ad65d8304
4 changed files with 16 additions and 9 deletions
  1. +6
    -0
      src/rebar_hooks.erl
  2. +5
    -4
      src/rebar_prv_common_test.erl
  3. +3
    -3
      src/rebar_prv_eunit.erl
  4. +2
    -2
      src/rebar_relx.erl

+ 6
- 0
src/rebar_hooks.erl View File

@ -2,6 +2,7 @@
-export([run_all_hooks/5
,run_all_hooks/6
,run_project_and_app_hooks/5
,format_error/1]).
-include("rebar.hrl").
@ -20,6 +21,11 @@ run_all_hooks(Dir, Type, Command, Providers, State) ->
run_provider_hooks(Dir, Type, Command, Providers, rebar_state:opts(State), State),
run_hooks(Dir, Type, Command, rebar_state:opts(State), State).
run_project_and_app_hooks(Dir, Type, Command, Providers, State) ->
ProjectApps = rebar_state:project_apps(State),
[rebar_hooks:run_all_hooks(Dir, Type, Command, Providers, AppInfo, State) || AppInfo <- ProjectApps],
run_all_hooks(Dir, Type, Command, Providers, State).
run_provider_hooks(Dir, Type, Command, Providers, Opts, State) ->
case rebar_opts:get(Opts, provider_hooks, []) of
[] ->

+ 5
- 4
src/rebar_prv_common_test.erl View File

@ -52,14 +52,16 @@ do(State, Tests) ->
%% Run ct provider prehooks
Providers = rebar_state:providers(State),
Cwd = rebar_dir:get_cwd(),
rebar_hooks:run_all_hooks(Cwd, pre, ?PROVIDER, Providers, State),
%% Run ct provider pre hooks for all project apps and top level project hooks
rebar_hooks:run_project_and_app_hooks(Cwd, pre, ?PROVIDER, Providers, State),
case Tests of
{ok, T} ->
case run_tests(State, T) of
ok ->
%% Run ct provider posthooks
rebar_hooks:run_all_hooks(Cwd, post, ?PROVIDER, Providers, State),
%% Run ct provider post hooks for all project apps and top level project hooks
rebar_hooks:run_project_and_app_hooks(Cwd, post, ?PROVIDER, Providers, State),
rebar_utils:cleanup_code_path(rebar_state:code_paths(State, default)),
{ok, State};
Error ->
@ -653,4 +655,3 @@ help(verbose) ->
"Verbose output";
help(_) ->
"".

+ 3
- 3
src/rebar_prv_eunit.erl View File

@ -56,14 +56,14 @@ do(State, Tests) ->
%% Run eunit provider prehooks
Providers = rebar_state:providers(State),
Cwd = rebar_dir:get_cwd(),
rebar_hooks:run_all_hooks(Cwd, pre, ?PROVIDER, Providers, State),
rebar_hooks:run_project_and_app_hooks(Cwd, pre, ?PROVIDER, Providers, State),
case validate_tests(State, Tests) of
{ok, T} ->
case run_tests(State, T) of
{ok, State1} ->
%% Run eunit provider posthooks
rebar_hooks:run_all_hooks(Cwd, post, ?PROVIDER, Providers, State1),
rebar_hooks:run_project_and_app_hooks(Cwd, post, ?PROVIDER, Providers, State1),
rebar_utils:cleanup_code_path(rebar_state:code_paths(State, default)),
{ok, State1};
Error ->
@ -190,7 +190,7 @@ dedupe_tests({AppMods, TestMods}) ->
%% in AppMods that will trigger it
F = fun(Mod) ->
M = filename:basename(Mod, ".erl"),
MatchesTest = fun(Dir) -> filename:basename(Dir, ".erl") ++ "_tests" == M end,
MatchesTest = fun(Dir) -> filename:basename(Dir, ".erl") ++ "_tests" == M end,
case lists:any(MatchesTest, AppMods) of
false -> {true, {module, list_to_atom(M)}};
true -> false

+ 2
- 2
src/rebar_relx.erl View File

@ -25,7 +25,7 @@ do(Module, Command, Provider, State) ->
AllOptions = string:join([Command | Options], " "),
Cwd = rebar_state:dir(State),
Providers = rebar_state:providers(State),
rebar_hooks:run_all_hooks(Cwd, pre, Provider, Providers, State),
rebar_hooks:run_project_and_app_hooks(Cwd, pre, Provider, Providers, State),
try
case rebar_state:get(State, relx, []) of
[] ->
@ -37,7 +37,7 @@ do(Module, Command, Provider, State) ->
,{config, Config1}
,{caller, api} | output_dir(OutputDir, Options)], AllOptions)
end,
rebar_hooks:run_all_hooks(Cwd, post, Provider, Providers, State),
rebar_hooks:run_project_and_app_hooks(Cwd, post, Provider, Providers, State),
{ok, State}
catch
throw:T ->

Loading…
Cancel
Save