Selaa lähdekoodia

don't store global state variables in opts dict

pull/46/head
Tristan Sloughter 10 vuotta sitten
vanhempi
commit
a390419247
3 muutettua tiedostoa jossa 31 lisäystä ja 15 poistoa
  1. +1
    -1
      src/rebar3.erl
  2. +29
    -13
      src/rebar_state.erl
  3. +1
    -1
      src/rebar_templater.erl

+ 1
- 1
src/rebar3.erl Näytä tiedosto

@ -167,7 +167,7 @@ init_config() ->
%% resources out of the escript %% resources out of the escript
State1 = try State1 = try
ScriptName = filename:absname(escript:script_name()), ScriptName = filename:absname(escript:script_name()),
rebar_state:set(State, escript, ScriptName)
rebar_state:escript_path(State, ScriptName)
catch catch
_:_ -> _:_ ->
State State

+ 29
- 13
src/rebar_state.erl Näytä tiedosto

@ -6,6 +6,8 @@
opts/1, opts/1,
default/1, default/2, default/1, default/2,
escript_path/1, escript_path/2,
lock/1, lock/2, lock/1, lock/2,
current_profile/1, current_profile/1,
@ -34,6 +36,8 @@
opts = dict:new() :: rebar_dict(), opts = dict:new() :: rebar_dict(),
default = dict:new() :: rebar_dict(), default = dict:new() :: rebar_dict(),
escript_path :: undefined | file:filename_all(),
lock = [], lock = [],
current_profile = default :: atom(), current_profile = default :: atom(),
@ -129,6 +133,12 @@ lock(#state_t{lock=Lock}) ->
lock(State=#state_t{lock=Lock}, App) -> lock(State=#state_t{lock=Lock}, App) ->
State#state_t{lock=[App | Lock]}. State#state_t{lock=[App | Lock]}.
escript_path(#state_t{escript_path=EscriptPath}) ->
EscriptPath.
escript_path(State, EscriptPath) ->
State#state_t{escript_path=EscriptPath}.
command_args(#state_t{command_args=CmdArgs}) -> command_args(#state_t{command_args=CmdArgs}) ->
CmdArgs. CmdArgs.
@ -149,22 +159,28 @@ apply_profile(State=#state_t{default=Opts}, Profile) ->
ProfileOpts = dict:from_list(proplists:get_value(Profile, ConfigProfiles, [])), ProfileOpts = dict:from_list(proplists:get_value(Profile, ConfigProfiles, [])),
State#state_t{opts=merge_opts(Profile, ProfileOpts, Opts1)}. State#state_t{opts=merge_opts(Profile, ProfileOpts, Opts1)}.
merge_opts(Profile, Opts1, Opts2) ->
dict:fold(fun(deps, Value, OptsAcc) ->
dict:store({deps, Profile}, Value, OptsAcc);
(Key, Value, OptsAcc) ->
case dict:fetch(Key, Opts2) of
OldValue when is_list(OldValue) ->
case io_lib:printable_list(Value) of
merge_opts(Profile, NewOpts, OldOpts) ->
io:format("Keys ~p~n", [dict:fetch_keys(NewOpts)]),
io:format("Keys ~p~n", [dict:fetch_keys(OldOpts)]),
Dict = dict:merge(fun(_Key, NewValue, OldValue) when is_list(NewValue) ->
case io_lib:printable_list(NewValue) of
true -> true ->
dict:store(Key, Value, OptsAcc);
NewValue;
false -> false ->
dict:store(Key, lists:keymerge(1, lists:keysort(1, OldValue), lists:keysort(1, Value)), OptsAcc)
lists:keymerge(1
,lists:keysort(1, OldValue)
,lists:keysort(1, NewValue))
end; end;
_ ->
dict:store(Key, Value, OptsAcc)
end
end, Opts2, Opts1).
(_Key, NewValue, _OldValue) ->
NewValue
end, NewOpts, OldOpts),
case dict:find(deps, NewOpts) of
error ->
dict:store({deps, Profile}, [], Dict);
Deps ->
dict:store({deps, Profile}, Deps, Dict)
end.
dir(#state_t{dir=Dir}) -> dir(#state_t{dir=Dir}) ->
Dir. Dir.

+ 1
- 1
src/rebar_templater.erl Näytä tiedosto

@ -258,7 +258,7 @@ cache_escript_files(State) ->
fun(Name, _, GetBin, Acc) -> fun(Name, _, GetBin, Acc) ->
[{Name, GetBin()} | Acc] [{Name, GetBin()} | Acc]
end, end,
[], rebar_state:get(State, escript)),
[], rebar_state:escript_path(State)),
Files. Files.
%% Find all the template indexes hiding in the rebar3 escript. %% Find all the template indexes hiding in the rebar3 escript.

Ladataan…
Peruuta
Tallenna