diff options
author | Tristan Sloughter <t@crashfast.com> | 2015-01-25 11:26:48 -0600 |
---|---|---|
committer | Tristan Sloughter <t@crashfast.com> | 2015-01-31 10:42:30 -0600 |
commit | 37b79ff2b78b7ed0df65f8eaf30105692711f74b (patch) | |
tree | 0668c92d74d95dfb04e7844574ca2ac7d7d0cb29 /src | |
parent | 89d3ef6e0d2225ea195b6ef1207c4c438792b2d1 (diff) |
support for provider_hooks in config
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_core.erl | 23 | ||||
-rw-r--r-- | src/rebar_prv_erlydtl_compiler.erl | 1 | ||||
-rw-r--r-- | src/rebar_state.erl | 56 |
3 files changed, 50 insertions, 30 deletions
diff --git a/src/rebar_core.erl b/src/rebar_core.erl index 9d9262c..4497825 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -37,17 +37,18 @@ process_command(State, Command) -> Providers = rebar_state:providers(State), Namespace = rebar_state:namespace(State), {TargetProviders, CommandProvider} = - case Namespace of - undefined -> - %% undefined namespace means 'default', but on the first run; - %% it is used as an implicit counter for the first vs. subsequent - %% runs. - {providers:get_target_providers(Command, Providers, default), - providers:get_provider(Command, Providers, default)}; - _ -> - {providers:get_target_providers(Command, Providers, Namespace), - providers:get_provider(Command, Providers, Namespace)} - end, + case Namespace of + undefined -> + %% undefined namespace means 'default', but on the first run; + %% it is used as an implicit counter for the first vs. subsequent + %% runs. + {providers:get_target_providers(Command, Providers, default), + providers:get_provider(Command, Providers, default)}; + _ -> + {providers:get_target_providers(Command, Providers, Namespace), + providers:get_provider(Command, Providers, Namespace)} + end, + case CommandProvider of not_found -> case Namespace of diff --git a/src/rebar_prv_erlydtl_compiler.erl b/src/rebar_prv_erlydtl_compiler.erl index a922404..f4b4eb0 100644 --- a/src/rebar_prv_erlydtl_compiler.erl +++ b/src/rebar_prv_erlydtl_compiler.erl @@ -126,6 +126,7 @@ init(State) -> {ok, State1}. do(Config) -> + ?INFO("Running erlydtl...", []), MultiDtlOpts = erlydtl_opts(Config), Result = lists:foldl(fun(DtlOpts, _) -> diff --git a/src/rebar_state.erl b/src/rebar_state.erl index 0bf26e2..42caa5b 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -30,7 +30,6 @@ overrides/1, overrides/2, apply_overrides/2, - prepend_hook/3, append_hook/3, hooks/2, providers/1, providers/2, add_provider/2]). -include("rebar.hrl"). @@ -279,15 +278,43 @@ add_provider(State=#state_t{providers=Providers}, Provider) -> State#state_t{providers=[Provider | Providers]}. create_logic_providers(ProviderModules, State0) -> - lists:foldl(fun(ProviderMod, Acc) -> - case providers:new(ProviderMod, Acc) of - {error, Reason} -> - ?ERROR(Reason++"~n", []), - Acc; - {ok, State1} -> - State1 - end - end, State0, ProviderModules). + State1 = try + lists:foldl(fun(ProviderMod, StateAcc) -> + case providers:new(ProviderMod, StateAcc) of + {error, Reason} -> + ?ERROR(Reason++"~n", []), + StateAcc; + {ok, StateAcc1} -> + StateAcc1 + end + end, State0, ProviderModules) + catch + C:T -> + ?DEBUG("~p: ~p ~p", [C, T, erlang:get_stacktrace()]), + throw({error, "Failed creating providers. Run with DEBUG=1 for stacktrace."}) + end, + apply_hooks(State1). + +apply_hooks(State0) -> + try + Hooks = rebar_state:get(State0, provider_hooks, []), + PreHooks = proplists:get_value(pre, Hooks, []), + PostHooks = proplists:get_value(post, Hooks, []), + State1 = lists:foldl(fun({Target, Hook}, StateAcc) -> + prepend_hook(StateAcc, Target, Hook) + end, State0, PreHooks), + lists:foldl(fun({Target, Hook}, StateAcc) -> + append_hook(StateAcc, Target, Hook) + end, State1, PostHooks) + catch + C:T -> + ?DEBUG("~p: ~p ~p", [C, T, erlang:get_stacktrace()]), + throw({error, "Failed parsing provider hooks. Run with DEBUG=1 for stacktrace."}) + end. + +%% =================================================================== +%% Internal functions +%% =================================================================== prepend_hook(State=#state_t{providers=Providers}, Target, Hook) -> State#state_t{providers=add_hook(pre, Providers, Target, Hook)}. @@ -295,15 +322,6 @@ prepend_hook(State=#state_t{providers=Providers}, Target, Hook) -> append_hook(State=#state_t{providers=Providers}, Target, Hook) -> State#state_t{providers=add_hook(post, Providers, Target, Hook)}. --spec hooks(t(), atom()) -> {[providers:t()], [providers:t()]}. -hooks(_State=#state_t{providers=Providers}, Target) -> - Provider = providers:get_provider(Target, Providers), - providers:hooks(Provider). - -%% =================================================================== -%% Internal functions -%% =================================================================== - add_hook(Which, Providers, Target, Hook) -> Provider = providers:get_provider(Target, Providers), Hooks = providers:hooks(Provider), |