Bladeren bron

Get rid of rebar_utils:tup_umerge/2 patching

pull/350/head
Viacheslav Kovalev 10 jaren geleden
bovenliggende
commit
e255529da5
3 gewijzigde bestanden met toevoegingen van 8 en 30 verwijderingen
  1. +4
    -3
      src/rebar_state.erl
  2. +1
    -14
      src/rebar_utils.erl
  3. +3
    -13
      test/rebar_utils_SUITE.erl

+ 4
- 3
src/rebar_state.erl Bestand weergeven

@ -207,7 +207,8 @@ apply_profiles(State, Profile) when not is_list(Profile) ->
apply_profiles(State, [Profile]); apply_profiles(State, [Profile]);
apply_profiles(State, [default]) -> apply_profiles(State, [default]) ->
State; State;
apply_profiles(State=#state_t{opts=Opts, current_profiles=CurrentProfiles}, Profiles) ->
apply_profiles(State=#state_t{default = Defaults, current_profiles=CurrentProfiles}, Profiles) ->
AppliedProfiles = deduplicate(CurrentProfiles ++ Profiles),
ConfigProfiles = rebar_state:get(State, profiles, []), ConfigProfiles = rebar_state:get(State, profiles, []),
NewOpts = NewOpts =
lists:foldl(fun(default, OptsAcc) -> lists:foldl(fun(default, OptsAcc) ->
@ -215,8 +216,8 @@ apply_profiles(State=#state_t{opts=Opts, current_profiles=CurrentProfiles}, Prof
(Profile, OptsAcc) -> (Profile, OptsAcc) ->
ProfileOpts = dict:from_list(proplists:get_value(Profile, ConfigProfiles, [])), ProfileOpts = dict:from_list(proplists:get_value(Profile, ConfigProfiles, [])),
merge_opts(Profile, ProfileOpts, OptsAcc) merge_opts(Profile, ProfileOpts, OptsAcc)
end, Opts, Profiles),
State#state_t{current_profiles = deduplicate(CurrentProfiles ++ Profiles), opts=NewOpts}.
end, Defaults, AppliedProfiles),
State#state_t{current_profiles = AppliedProfiles, opts=NewOpts}.
deduplicate(Profiles) -> deduplicate(Profiles) ->
do_deduplicate(lists:reverse(Profiles), []). do_deduplicate(lists:reverse(Profiles), []).

+ 1
- 14
src/rebar_utils.erl Bestand weergeven

@ -257,20 +257,7 @@ tup_sort(List) ->
tup_umerge([], Olds) -> tup_umerge([], Olds) ->
Olds; Olds;
tup_umerge([New|News], Olds) -> tup_umerge([New|News], Olds) ->
reverse_deduplicate( umerge(News, Olds, [], New) ).
reverse_deduplicate(List) ->
lists:reverse( do_deduplicate(lists:reverse(List), []) ).
do_deduplicate([], Acc) ->
Acc;
do_deduplicate([Value | Rest], Acc) ->
case lists:member(Value, Acc) of
true ->
do_deduplicate(Rest, Acc);
false ->
do_deduplicate(Rest, [Value | Acc])
end.
lists:reverse( umerge(News, Olds, [], New) ).
%% This is equivalent to umerge2_2 in the stdlib, except we use the expanded %% This is equivalent to umerge2_2 in the stdlib, except we use the expanded
%% value/key only to compare %% value/key only to compare

+ 3
- 13
test/rebar_utils_SUITE.erl Bestand weergeven

@ -21,8 +21,7 @@
task_with_flag_with_trailing_comma/1, task_with_flag_with_trailing_comma/1,
task_with_flag_with_commas/1, task_with_flag_with_commas/1,
task_with_multiple_flags/1, task_with_multiple_flags/1,
special_task_do/1,
tup_umerge_deduplication/1]).
special_task_do/1]).
-include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
@ -30,8 +29,7 @@
all() -> all() ->
[{group, args_to_tasks},
tup_umerge_deduplication
[{group, args_to_tasks}
]. ].
groups() -> groups() ->
@ -120,12 +118,4 @@ special_task_do(_Config) ->
[{"foo", []}, {"do", ["bar,", "baz"]}] = rebar_utils:args_to_tasks(["foo,", [{"foo", []}, {"do", ["bar,", "baz"]}] = rebar_utils:args_to_tasks(["foo,",
"do", "do",
"bar,", "bar,",
"baz"]).
tup_umerge_deduplication(_Config) ->
Old = [{key,c},{key,b},{key,a}],
New = [{key, a}],
?assertEqual(
[{key, a}, {key, c}, {key, b}],
rebar_utils:tup_umerge(New, Old)
).
"baz"]).

Laden…
Annuleren
Opslaan