summaryrefslogtreecommitdiff
path: root/src/rebar_state.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_state.erl')
-rw-r--r--src/rebar_state.erl47
1 files changed, 38 insertions, 9 deletions
diff --git a/src/rebar_state.erl b/src/rebar_state.erl
index 0c07b2a..a613a00 100644
--- a/src/rebar_state.erl
+++ b/src/rebar_state.erl
@@ -36,9 +36,12 @@
deps_names/1,
+ to_list/1,
resources/1, resources/2, add_resource/2,
- providers/1, providers/2, add_provider/2]).
+ providers/1, providers/2, add_provider/2,
+ allow_provider_overrides/1, allow_provider_overrides/2
+ ]).
-include("rebar.hrl").
-include_lib("providers/include/providers.hrl").
@@ -63,7 +66,8 @@
all_deps = [] :: [rebar_app_info:t()],
resources = [],
- providers = []}).
+ providers = [],
+ allow_provider_overrides = false :: boolean()}).
-export_type([t/0]).
@@ -103,7 +107,8 @@ new(ParentState, Config, Dir) ->
new(ParentState, Config, Deps, Dir) ->
Opts = ParentState#state_t.opts,
Plugins = proplists:get_value(plugins, Config, []),
- Terms = Deps++[{{plugins, default}, Plugins} | Config],
+ ProjectPlugins = proplists:get_value(project_plugins, Config, []),
+ Terms = Deps++[{{project_plugins, default}, ProjectPlugins}, {{plugins, default}, Plugins} | Config],
true = rebar_config:verify_config_format(Terms),
LocalOpts = dict:from_list(Terms),
@@ -115,13 +120,13 @@ new(ParentState, Config, Deps, Dir) ->
deps_from_config(Dir, Config) ->
case rebar_config:consult_lock_file(filename:join(Dir, ?LOCK_FILE)) of
- [D] ->
+ [] ->
+ [{{deps, default}, proplists:get_value(deps, Config, [])}];
+ D ->
%% We want the top level deps only from the lock file.
%% This ensures deterministic overrides for configs.
Deps = [X || X <- D, element(3, X) =:= 0],
- [{{locks, default}, D}, {{deps, default}, Deps}];
- _ ->
- [{{deps, default}, proplists:get_value(deps, Config, [])}]
+ [{{locks, default}, D}, {{deps, default}, Deps}]
end.
base_state() ->
@@ -136,7 +141,8 @@ base_state() ->
base_opts(Config) ->
Deps = proplists:get_value(deps, Config, []),
Plugins = proplists:get_value(plugins, Config, []),
- Terms = [{{deps, default}, Deps}, {{plugins, default}, Plugins} | Config],
+ ProjectPlugins = proplists:get_value(project_plugins, Config, []),
+ Terms = [{{deps, default}, Deps}, {{plugins, default}, Plugins}, {{project_plugins, default}, ProjectPlugins} | Config],
true = rebar_config:verify_config_format(Terms),
dict:from_list(Terms).
@@ -368,8 +374,16 @@ providers(#state_t{providers=Providers}) ->
providers(State, NewProviders) ->
State#state_t{providers=NewProviders}.
+allow_provider_overrides(#state_t{allow_provider_overrides=Allow}) ->
+ Allow.
+
+allow_provider_overrides(State, Allow) ->
+ State#state_t{allow_provider_overrides=Allow}.
+
-spec add_provider(t(), providers:t()) -> t().
-add_provider(State=#state_t{providers=Providers}, Provider) ->
+add_provider(State=#state_t{providers=Providers, allow_provider_overrides=true}, Provider) ->
+ State#state_t{providers=[Provider | Providers]};
+add_provider(State=#state_t{providers=Providers, allow_provider_overrides=false}, Provider) ->
Name = providers:impl(Provider),
Namespace = providers:namespace(Provider),
Module = providers:module(Provider),
@@ -406,6 +420,21 @@ create_logic_providers(ProviderModules, State0) ->
throw({error, "Failed creating providers. Run with DEBUG=1 for stacktrace."})
end.
+to_list(#state_t{} = State) ->
+ Fields = record_info(fields, state_t),
+ Values = tl(tuple_to_list(State)),
+ DictSz = tuple_size(dict:new()),
+ lists:zip(Fields, [reformat(I, DictSz) || I <- Values]).
+
+reformat({K,V}, DSz) when is_list(V) ->
+ {K, [reformat(I, DSz) || I <- V]};
+reformat(V, DSz) when is_tuple(V), element(1,V) =:= dict, tuple_size(V) =:= DSz ->
+ [reformat(I, DSz) || I <- dict:to_list(V)];
+reformat({K,V}, DSz) when is_tuple(V), element(1,V) =:= dict, tuple_size(V) =:= DSz ->
+ {K, [reformat(I, DSz) || I <- dict:to_list(V)]};
+reformat(Other, _DSz) ->
+ Other.
+
%% ===================================================================
%% Internal functions
%% ===================================================================