summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2015-03-06 10:39:39 -0500
committerFred Hebert <mononcqc@ferd.ca>2015-03-06 10:39:39 -0500
commitbc5d1cb155ad99d6e605cc80952bd34d8a3de17e (patch)
tree5a4e2f90b26ca3ef3cc92b87a1377b3faa3c2915 /src
parent9903b5271f5a27faf5485bfc32944b8969a2f4e9 (diff)
parent0399b0eeb30d531360faa888c7d64b5d0b2f09ce (diff)
Merge pull request #233 from tsloughter/base_opts
apply profiles and overrides for an app's opts to the base opts
Diffstat (limited to 'src')
-rw-r--r--src/rebar3.erl9
-rw-r--r--src/rebar_app_discover.erl9
-rw-r--r--src/rebar_core.erl9
-rw-r--r--src/rebar_state.erl7
4 files changed, 21 insertions, 13 deletions
diff --git a/src/rebar3.erl b/src/rebar3.erl
index d7597cd..5b7db24 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -115,8 +115,7 @@ run_aux(State, GlobalPluginProviders, RawArgs) ->
false ->
State;
Profile ->
- State1 = rebar_state:apply_profiles(State, [list_to_atom(Profile)]),
- rebar_state:default(State1, rebar_state:opts(State1))
+ rebar_state:apply_profiles(State, [list_to_atom(Profile)])
end,
%% Process each command, resetting any state between each one
@@ -127,11 +126,15 @@ run_aux(State, GlobalPluginProviders, RawArgs) ->
{ok, Providers} = application:get_env(rebar, providers),
{ok, PluginProviders, State4} = rebar_plugins:install(State3),
rebar_core:update_code_path(State4),
+
+ %% Providers can modify profiles stored in opts, so set default after initializing providers
AllProviders = Providers++PluginProviders++GlobalPluginProviders,
State5 = rebar_state:create_logic_providers(AllProviders, State4),
+ State6 = rebar_state:default(State5, rebar_state:opts(State5)),
+
{Task, Args} = parse_args(RawArgs),
- rebar_core:process_command(rebar_state:command_args(State5, Args), Task).
+ rebar_core:process_command(rebar_state:command_args(State6, Args), Task).
init_config() ->
%% Initialize logging system
diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl
index 553947a..63cf703 100644
--- a/src/rebar_app_discover.erl
+++ b/src/rebar_app_discover.erl
@@ -34,13 +34,15 @@ format_error({missing_module, Module}) ->
io_lib:format("Module defined in app file missing: ~p~n", [Module]).
merge_deps(AppInfo, State) ->
- Profiles = rebar_state:current_profiles(State),
+ Default = rebar_state:default(State),
+ CurrentProfiles = rebar_state:current_profiles(State),
Name = rebar_app_info:name(AppInfo),
C = rebar_config:consult(rebar_app_info:dir(AppInfo)),
+ %% We reset the opts here to default so no profiles are applied multiple times
AppState = rebar_state:apply_overrides(
rebar_state:apply_profiles(
- rebar_state:new(State, C, rebar_app_info:dir(AppInfo)), Profiles), Name),
+ rebar_state:new(rebar_state:opts(State, Default), C, rebar_app_info:dir(AppInfo)), CurrentProfiles), Name),
AppInfo1 = rebar_app_info:state(AppInfo, AppState),
State1 = lists:foldl(fun(Profile, StateAcc) ->
@@ -48,8 +50,7 @@ merge_deps(AppInfo, State) ->
TopLevelProfDeps = rebar_state:get(StateAcc, {deps, Profile}, []),
ProfDeps2 = lists:keymerge(1, TopLevelProfDeps, AppProfDeps),
rebar_state:set(StateAcc, {deps, Profile}, ProfDeps2)
- end, State, lists:reverse(Profiles)),
-
+ end, State, lists:reverse(CurrentProfiles)),
{AppInfo1, State1}.
diff --git a/src/rebar_core.erl b/src/rebar_core.erl
index 205258a..f0d9b3d 100644
--- a/src/rebar_core.erl
+++ b/src/rebar_core.erl
@@ -78,12 +78,13 @@ process_command(State, Command) ->
Command when Command =:= do; Command =:= as ->
do(TargetProviders, State);
_ ->
+ Profiles = providers:profiles(CommandProvider),
+ State1 = rebar_state:apply_profiles(State, Profiles),
Opts = providers:opts(CommandProvider)++rebar3:global_option_spec_list(),
-
- case getopt:parse(Opts, rebar_state:command_args(State)) of
+ case getopt:parse(Opts, rebar_state:command_args(State1)) of
{ok, Args} ->
- State1 = rebar_state:command_parsed_args(State, Args),
- do(TargetProviders, State1);
+ State2 = rebar_state:command_parsed_args(State1, Args),
+ do(TargetProviders, State2);
{error, {invalid_option, Option}} ->
{error, io_lib:format("Invalid option ~s on task ~p", [Option, Command])}
end
diff --git a/src/rebar_state.erl b/src/rebar_state.erl
index 8170b8d..e77a259 100644
--- a/src/rebar_state.erl
+++ b/src/rebar_state.erl
@@ -3,7 +3,7 @@
-export([new/0, new/1, new/2, new/3,
get/2, get/3, set/3,
- opts/1,
+ opts/1, opts/2,
default/1, default/2,
escript_path/1, escript_path/2,
@@ -37,7 +37,6 @@
-record(state_t, {dir :: file:name(),
opts = dict:new() :: rebar_dict(),
default = dict:new() :: rebar_dict(),
-
escript_path :: undefined | file:filename_all(),
lock = [],
@@ -97,6 +96,7 @@ new(ParentState, Config, Dir) ->
D = proplists:get_value(deps, Config, []),
dict:from_list([{{deps, default}, D} | Config])
end,
+
NewOpts = dict:merge(fun(_Key, Value1, _Value2) ->
Value1
end, LocalOpts, Opts),
@@ -129,6 +129,9 @@ default(State, Opts) ->
opts(#state_t{opts=Opts}) ->
Opts.
+opts(State, Opts) ->
+ State#state_t{opts=Opts}.
+
current_profiles(#state_t{current_profiles=Profiles}) ->
Profiles.