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.erl102
1 files changed, 49 insertions, 53 deletions
diff --git a/src/rebar_state.erl b/src/rebar_state.erl
index 59a9588..e31b01b 100644
--- a/src/rebar_state.erl
+++ b/src/rebar_state.erl
@@ -38,9 +38,6 @@
overrides/1, overrides/2,
apply_overrides/2,
- packages/1, packages/2,
- registry/1, registry/2,
-
resources/1, resources/2, add_resource/2,
providers/1, providers/2, add_provider/2]).
@@ -65,8 +62,6 @@
all_plugin_deps = [] :: [rebar_app_info:t()],
all_deps = [] :: [rebar_app_info:t()],
- packages = undefined :: {rebar_dict(), rebar_digraph()} | undefined,
- registry = undefined :: {ok, ets:tid()} | error | undefined,
overrides = [],
resources = [],
providers = []}).
@@ -83,11 +78,7 @@ new() ->
-spec new(list()) -> t().
new(Config) when is_list(Config) ->
BaseState = base_state(),
- Deps = proplists:get_value(deps, Config, []),
- Plugins = proplists:get_value(plugins, Config, []),
- Terms = [{{deps, default}, Deps}, {{plugins, default}, Plugins} | Config],
- true = rebar_config:verify_config_format(Terms),
- Opts = dict:from_list(Terms),
+ Opts = base_opts(Config),
BaseState#state_t { dir = rebar_dir:get_cwd(),
default = Opts,
opts = Opts }.
@@ -96,12 +87,7 @@ new(Config) when is_list(Config) ->
new(Profile, Config) when is_atom(Profile)
, is_list(Config) ->
BaseState = base_state(),
- Deps = proplists:get_value(deps, Config, []),
-
- Plugins = proplists:get_value(plugins, Config, []),
- Terms = [{{deps, default}, Deps}, {{plugins, default}, Plugins} | Config],
- true = rebar_config:verify_config_format(Terms),
- Opts = dict:from_list(Terms),
+ Opts = base_opts(Config),
BaseState#state_t { dir = rebar_dir:get_cwd(),
current_profiles = [Profile],
default = Opts,
@@ -111,25 +97,26 @@ new(ParentState=#state_t{}, Config) ->
Dir = rebar_dir:get_cwd(),
new(ParentState, Config, Dir).
--spec new(t(), list(), file:name()) -> t().
-new(ParentState, Config, Dir) ->
+-spec new(t(), list(), rebar_app_info:t() | file:filename_all()) -> t().
+new(ParentState, Config, Dir) when is_list(Dir) ->
+ new(ParentState, Config, deps_from_config(Dir, Config), Dir);
+new(ParentState, Config, AppInfo) ->
+ Dir = rebar_app_info:dir(AppInfo),
+ DepLocks = case rebar_app_info:resource_type(AppInfo) of
+ pkg ->
+ Deps = rebar_app_info:deps(AppInfo),
+ [{{locks, default}, Deps}, {{deps, default}, Deps}];
+ _ ->
+ deps_from_config(Dir, Config)
+ end,
+ new(ParentState, Config, DepLocks, Dir).
+
+new(ParentState, Config, Deps, Dir) ->
Opts = ParentState#state_t.opts,
- LocalOpts = case rebar_config:consult_lock_file(filename:join(Dir, ?LOCK_FILE)) of
- [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],
- Plugins = proplists:get_value(plugins, Config, []),
- Terms = [{{locks, default}, D}, {{deps, default}, Deps}, {{plugins, default}, Plugins} | Config],
- true = rebar_config:verify_config_format(Terms),
- dict:from_list(Terms);
- _ ->
- D = proplists:get_value(deps, Config, []),
- Plugins = proplists:get_value(plugins, Config, []),
- Terms = [{{deps, default}, D}, {{plugins, default}, Plugins} | Config],
- true = rebar_config:verify_config_format(Terms),
- dict:from_list(Terms)
- end,
+ Plugins = proplists:get_value(plugins, Config, []),
+ Terms = Deps++[{{plugins, default}, Plugins} | Config],
+ true = rebar_config:verify_config_format(Terms),
+ LocalOpts = dict:from_list(Terms),
NewOpts = merge_opts(LocalOpts, Opts),
@@ -137,6 +124,17 @@ new(ParentState, Config, Dir) ->
,opts=NewOpts
,default=NewOpts}.
+deps_from_config(Dir, Config) ->
+ case rebar_config:consult_lock_file(filename:join(Dir, ?LOCK_FILE)) of
+ [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, [])}]
+ end.
+
base_state() ->
case application:get_env(rebar, resources) of
undefined ->
@@ -146,6 +144,13 @@ base_state() ->
end,
#state_t{resources=Resources}.
+base_opts(Config) ->
+ Deps = proplists:get_value(deps, Config, []),
+ Plugins = proplists:get_value(plugins, Config, []),
+ Terms = [{{deps, default}, Deps}, {{plugins, default}, Plugins} | Config],
+ true = rebar_config:verify_config_format(Terms),
+ dict:from_list(Terms).
+
get(State, Key) ->
{ok, Value} = dict:find(Key, State#state_t.opts),
Value.
@@ -253,7 +258,9 @@ apply_overrides(State=#state_t{overrides=Overrides}, AppName) ->
%% Inefficient. We want the order we get here though.
State1 = lists:foldl(fun({override, O}, StateAcc) ->
- lists:foldl(fun({Key, Value}, StateAcc1) ->
+ lists:foldl(fun({deps, Value}, StateAcc1) ->
+ rebar_state:set(StateAcc1, {deps,default}, Value);
+ ({Key, Value}, StateAcc1) ->
rebar_state:set(StateAcc1, Key, Value)
end, StateAcc, O);
(_, StateAcc) ->
@@ -261,7 +268,9 @@ apply_overrides(State=#state_t{overrides=Overrides}, AppName) ->
end, State, Overrides),
State2 = lists:foldl(fun({override, N, O}, StateAcc) when N =:= Name ->
- lists:foldl(fun({Key, Value}, StateAcc1) ->
+ lists:foldl(fun({deps, Value}, StateAcc1) ->
+ rebar_state:set(StateAcc1, {deps,default}, Value);
+ ({Key, Value}, StateAcc1) ->
rebar_state:set(StateAcc1, Key, Value)
end, StateAcc, O);
(_, StateAcc) ->
@@ -269,7 +278,10 @@ apply_overrides(State=#state_t{overrides=Overrides}, AppName) ->
end, State1, Overrides),
State3 = lists:foldl(fun({add, N, O}, StateAcc) when N =:= Name ->
- lists:foldl(fun({Key, Value}, StateAcc1) ->
+ lists:foldl(fun({deps, Value}, StateAcc1) ->
+ OldValue = rebar_state:get(StateAcc1, {deps,default}, []),
+ rebar_state:set(StateAcc1, {deps,default}, Value++OldValue);
+ ({Key, Value}, StateAcc1) ->
OldValue = rebar_state:get(StateAcc1, Key, []),
rebar_state:set(StateAcc1, Key, Value++OldValue)
end, StateAcc, O);
@@ -438,22 +450,6 @@ namespace(#state_t{namespace=Namespace}) ->
namespace(State=#state_t{}, Namespace) ->
State#state_t{namespace=Namespace}.
-packages(State=#state_t{packages=undefined}) ->
- rebar_packages:get_packages(State);
-packages(#state_t{packages=Packages}) ->
- Packages.
-
-packages(State, Packages) ->
- State#state_t{packages=Packages}.
-
-registry(State=#state_t{registry=undefined}) ->
- rebar_packages:registry(State);
-registry(#state_t{registry=Registry}) ->
- Registry.
-
-registry(State, Registry) ->
- State#state_t{registry=Registry}.
-
-spec resources(t()) -> [{rebar_resource:type(), module()}].
resources(#state_t{resources=Resources}) ->
Resources.