summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar3.erl22
-rw-r--r--src/rebar_core.erl7
-rw-r--r--src/rebar_state.erl27
3 files changed, 37 insertions, 19 deletions
diff --git a/src/rebar3.erl b/src/rebar3.erl
index 9de8236..ebb0ea2 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -106,20 +106,28 @@ run_aux(State, GlobalPluginProviders, RawArgs) ->
application:start(ssl),
inets:start(),
+ State2 = case os:getenv("REBAR_PROFILE") of
+ false ->
+ State;
+ Profile ->
+ State1 = rebar_state:current_profile(State, list_to_atom(Profile)),
+ rebar_state:default(State1, rebar_state:opts(State1))
+ end,
+
%% Process each command, resetting any state between each one
- BaseDir = rebar_utils:base_dir(State),
- State2 = rebar_state:set(State, base_dir,
- filename:join(filename:absname(rebar_state:dir(State)), BaseDir)),
+ BaseDir = rebar_utils:base_dir(State2),
+ State3 = rebar_state:set(State2, base_dir,
+ filename:join(filename:absname(rebar_state:dir(State2)), BaseDir)),
{ok, Providers} = application:get_env(rebar, providers),
- {ok, PluginProviders, State3} = rebar_plugins:install(State2),
- rebar_core:update_code_path(State3),
+ {ok, PluginProviders, State4} = rebar_plugins:install(State3),
+ rebar_core:update_code_path(State4),
AllProviders = Providers++PluginProviders++GlobalPluginProviders,
- State4 = rebar_state:create_logic_providers(AllProviders, State3),
+ State5 = rebar_state:create_logic_providers(AllProviders, State4),
{Task, Args} = parse_args(RawArgs),
- rebar_core:process_command(rebar_state:command_args(State4, Args), list_to_atom(Task)).
+ rebar_core:process_command(rebar_state:command_args(State5, Args), list_to_atom(Task)).
init_config() ->
%% Initialize logging system
diff --git a/src/rebar_core.erl b/src/rebar_core.erl
index 7dacc50..a79414a 100644
--- a/src/rebar_core.erl
+++ b/src/rebar_core.erl
@@ -42,15 +42,14 @@ process_command(State, Command) ->
CommandProvider ->
Profile = providers:profile(CommandProvider),
State1 = rebar_state:current_profile(State, Profile),
- State2 = rebar_state:apply_profile(State1, Profile),
Opts = providers:opts(CommandProvider)++rebar3:global_option_spec_list(),
case Command of
do ->
- do(TargetProviders, State2);
+ do(TargetProviders, State1);
_ ->
- case getopt:parse(Opts, rebar_state:command_args(State2)) of
+ case getopt:parse(Opts, rebar_state:command_args(State1)) of
{ok, Args} ->
- State3 = rebar_state:command_parsed_args(State2, Args),
+ State3 = rebar_state:command_parsed_args(State1, Args),
do(TargetProviders, State3);
{error, {invalid_option, Option}} ->
{error, io_lib:format("Invalid option ~s on task ~p", [Option, Command])}
diff --git a/src/rebar_state.erl b/src/rebar_state.erl
index bfcc1e7..e3408ec 100644
--- a/src/rebar_state.erl
+++ b/src/rebar_state.erl
@@ -3,8 +3,10 @@
-export([new/0, new/1, new/2, new/3,
get/2, get/3, set/3,
- lock/1,
- lock/2,
+ opts/1,
+ default/1, default/2,
+
+ lock/1, lock/2,
current_profile/1,
current_profile/2,
@@ -104,11 +106,20 @@ get(State, Key, Default) ->
set(State=#state_t{opts=Opts}, Key, Value) ->
State#state_t{ opts = dict:store(Key, Value, Opts) }.
+default(#state_t{default=Opts}) ->
+ Opts.
+
+default(State, Opts) ->
+ State#state_t{default=Opts}.
+
+opts(#state_t{opts=Opts}) ->
+ Opts.
+
current_profile(#state_t{current_profile=Profile}) ->
Profile.
current_profile(State, Profile) ->
- State#state_t{current_profile=Profile}.
+ apply_profile(State#state_t{current_profile=Profile}, Profile).
lock(#state_t{lock=Lock}) ->
Lock.
@@ -140,15 +151,15 @@ merge_opts(Profile, Opts1, Opts2) ->
dict:fold(fun(deps, Value, OptsAcc) ->
dict:store({deps, Profile}, Value, OptsAcc);
(Key, Value, OptsAcc) ->
- case dict:fetch(Key, 1, Opts2) of
- {_, OldValue} when is_list(OldValue) ->
+ case dict:fetch(Key, Opts2) of
+ OldValue when is_list(OldValue) ->
case io_lib:printable_list(Value) of
true ->
- dict:store(Key, OptsAcc, {Key, Value});
+ dict:store(Key, Value, OptsAcc);
false ->
- dict:store(Key, OptsAcc, {Key, lists:keymerge(1, lists:keysort(1, OldValue), lists:keysort(1, Value))})
+ dict:store(Key, lists:keymerge(1, lists:keysort(1, OldValue), lists:keysort(1, Value)), OptsAcc)
end;
- error ->
+ _ ->
dict:store(Key, Value, OptsAcc)
end
end, Opts2, Opts1).