diff options
author | Fred Hebert <mononcqc@ferd.ca> | 2015-07-07 22:04:13 -0400 |
---|---|---|
committer | Fred Hebert <mononcqc@ferd.ca> | 2015-07-07 22:04:13 -0400 |
commit | d584fa304a0a35ec030ff8ed58cc429cae0dbd97 (patch) | |
tree | c848a81ed19bb532eb3e6f5f136505739e5bf2cb /src/rebar_hooks.erl | |
parent | 7a65d4ec75ce9e16741a340dfcca75894ec44c6b (diff) | |
parent | a5569f00e04d0ed7b3899ee8cc25469280ba3e11 (diff) |
Merge pull request #596 from tsloughter/run_hooks_empty
don't run unnecessary code if hooks are empty list
Diffstat (limited to 'src/rebar_hooks.erl')
-rw-r--r-- | src/rebar_hooks.erl | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/src/rebar_hooks.erl b/src/rebar_hooks.erl index 56c4e91..857336c 100644 --- a/src/rebar_hooks.erl +++ b/src/rebar_hooks.erl @@ -14,12 +14,21 @@ run_all_hooks(Dir, Type, Command, Providers, State) -> run_hooks(Dir, Type, Command, State). run_provider_hooks(Dir, Type, Command, Providers, State) -> + case rebar_state:get(State, provider_hooks, []) of + [] -> + ok; + AllHooks -> + TypeHooks = proplists:get_value(Type, AllHooks, []), + run_provider_hooks(Dir, Type, Command, Providers, TypeHooks, State) + end. + +run_provider_hooks(_Dir, _Type, _Command, _Providers, [], _State) -> + ok; +run_provider_hooks(Dir, Type, Command, Providers, TypeHooks, State) -> PluginDepsPaths = rebar_state:code_paths(State, all_plugin_deps), code:add_pathsa(PluginDepsPaths), Providers1 = rebar_state:providers(State), State1 = rebar_state:providers(rebar_state:dir(State, Dir), Providers++Providers1), - AllHooks = rebar_state:get(State1, provider_hooks, []), - TypeHooks = proplists:get_value(Type, AllHooks, []), HookProviders = proplists:get_all_values(Command, TypeHooks), case rebar_core:do(HookProviders, State1) of @@ -58,24 +67,24 @@ format_error({bad_provider, Type, Command, Name}) -> %% ERL = ERLANG_ROOT_DIR/bin/erl %% ERLC = ERLANG_ROOT_DIR/bin/erl %% +run_hooks(Dir, pre, Command, State) -> + run_hooks(Dir, pre_hooks, Command, State); +run_hooks(Dir, post, Command, State) -> + run_hooks(Dir, post_hooks, Command, State); run_hooks(Dir, Type, Command, State) -> - Hooks = case Type of - pre -> - rebar_state:get(State, pre_hooks, []); - post -> - rebar_state:get(State, post_hooks, []); - _ -> - [] - end, - - Env = create_env(State), - lists:foreach(fun({_, C, _}=Hook) when C =:= Command -> - apply_hook(Dir, Env, Hook); - ({C, _}=Hook) when C =:= Command -> - apply_hook(Dir, Env, Hook); - (_) -> - continue - end, Hooks). + case rebar_state:get(State, Type, []) of + [] -> + ok; + Hooks -> + Env = create_env(State), + lists:foreach(fun({_, C, _}=Hook) when C =:= Command -> + apply_hook(Dir, Env, Hook); + ({C, _}=Hook) when C =:= Command -> + apply_hook(Dir, Env, Hook); + (_) -> + continue + end, Hooks) + end. apply_hook(Dir, Env, {Arch, Command, Hook}) -> case rebar_utils:is_arch(Arch) of |