diff options
author | Fred Hebert <mononcqc@ferd.ca> | 2016-02-28 11:50:40 -0500 |
---|---|---|
committer | Fred Hebert <mononcqc@ferd.ca> | 2016-02-28 11:50:40 -0500 |
commit | a0b2c743566fcfae543ba758b954ec465db6fcfd (patch) | |
tree | bc05b44242ac7df355194440c7946002e3ee1d7b | |
parent | 47a0a20a3cc649303a31368dee82012983512d72 (diff) | |
parent | c36e9bf791e90b27cb0c9657cf245049a3595572 (diff) |
Merge pull request #1091 from tsloughter/all_hooks
Run all hooks
-rw-r--r-- | src/rebar_hooks.erl | 6 | ||||
-rw-r--r-- | src/rebar_prv_common_test.erl | 9 | ||||
-rw-r--r-- | src/rebar_prv_eunit.erl | 6 | ||||
-rw-r--r-- | src/rebar_relx.erl | 4 | ||||
-rw-r--r-- | test/rebar_hooks_SUITE.erl | 22 |
5 files changed, 37 insertions, 10 deletions
diff --git a/src/rebar_hooks.erl b/src/rebar_hooks.erl index 4e6d486..769890f 100644 --- a/src/rebar_hooks.erl +++ b/src/rebar_hooks.erl @@ -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 [] -> diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index 4be50d8..180061c 100644 --- a/src/rebar_prv_common_test.erl +++ b/src/rebar_prv_common_test.erl @@ -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(_) -> "". - diff --git a/src/rebar_prv_eunit.erl b/src/rebar_prv_eunit.erl index a1a4408..abfab8a 100644 --- a/src/rebar_prv_eunit.erl +++ b/src/rebar_prv_eunit.erl @@ -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 diff --git a/src/rebar_relx.erl b/src/rebar_relx.erl index 45e1c96..125da47 100644 --- a/src/rebar_relx.erl +++ b/src/rebar_relx.erl @@ -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 -> diff --git a/test/rebar_hooks_SUITE.erl b/test/rebar_hooks_SUITE.erl index 188fb34..b121dd5 100644 --- a/test/rebar_hooks_SUITE.erl +++ b/test/rebar_hooks_SUITE.erl @@ -10,6 +10,7 @@ escriptize_artifacts/1, run_hooks_once/1, run_hooks_for_plugins/1, + eunit_app_hooks/1, deps_hook_namespace/1]). -include_lib("common_test/include/ct.hrl"). @@ -33,7 +34,7 @@ end_per_testcase(_, _Config) -> all() -> [build_and_clean_app, run_hooks_once, escriptize_artifacts, - run_hooks_for_plugins, deps_hook_namespace]. + run_hooks_for_plugins, deps_hook_namespace, eunit_app_hooks]. %% Test post provider hook cleans compiled project app, leaving it invalid build_and_clean_app(Config) -> @@ -119,6 +120,25 @@ deps_hook_namespace(Config) -> {ok, [{dep, "some_dep"}]} ). +%% Checks that a hook that is defined on an app (not a top level hook of a project with subapps) is run +eunit_app_hooks(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]), + + RConfFile = + rebar_test_utils:create_config(AppDir, + [ + {escript_name, list_to_atom(Name)} + ,{provider_hooks, [{post, [{eunit, escriptize}]}]} + ]), + {ok, RConf} = file:consult(RConfFile), + + rebar_test_utils:run_and_check(Config, RConf, + ["eunit"], {ok, [{app, Name, valid} + ,{file, filename:join([AppDir, "_build/test/bin", Name])}]}). + run_hooks_for_plugins(Config) -> AppDir = ?config(apps, Config), |