浏览代码

add use of REBAR_PROFILE os var to set default profile

pull/31/head
Tristan Sloughter 10 年前
父节点
当前提交
5fdf2f82d5
共有 3 个文件被更改,包括 37 次插入19 次删除
  1. +15
    -7
      src/rebar3.erl
  2. +3
    -4
      src/rebar_core.erl
  3. +19
    -8
      src/rebar_state.erl

+ 15
- 7
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

+ 3
- 4
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])}

+ 19
- 8
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).

正在加载...
取消
保存