From cb14a33fdd9eb7e4bf0cacde52c3027910de34b3 Mon Sep 17 00:00:00 2001 From: "Viacheslav V. Kovalev" Date: Sun, 19 Apr 2015 16:24:43 +0300 Subject: Do not duplicate profile when applying. --- src/rebar_state.erl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/rebar_state.erl b/src/rebar_state.erl index f922977..7d872ee 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -213,8 +213,12 @@ apply_profiles(State=#state_t{opts=Opts, current_profiles=CurrentProfiles}, Prof lists:foldl(fun(default, {ProfilesAcc, OptsAcc}) -> {ProfilesAcc, OptsAcc}; (Profile, {ProfilesAcc, OptsAcc}) -> + NewProfilesAcc = case lists:member(Profile, CurrentProfiles) of + false -> [Profile]++ProfilesAcc; + true -> ProfilesAcc + end, ProfileOpts = dict:from_list(proplists:get_value(Profile, ConfigProfiles, [])), - {[Profile]++ProfilesAcc, merge_opts(Profile, ProfileOpts, OptsAcc)} + {NewProfilesAcc, merge_opts(Profile, ProfileOpts, OptsAcc)} end, {[], Opts}, Profiles), State#state_t{current_profiles=CurrentProfiles++Profiles1, opts=NewOpts}. -- cgit v1.1 From 381c6f4779a93b50308f2cc86de8a19b23ebcee5 Mon Sep 17 00:00:00 2001 From: "Viacheslav V. Kovalev" Date: Tue, 21 Apr 2015 01:22:28 +0300 Subject: Correctly deduplicate profiles when applying Conflicts: src/rebar_state.erl --- src/rebar_dir.erl | 2 +- src/rebar_state.erl | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl index 7903ed5..1885e9a 100644 --- a/src/rebar_dir.erl +++ b/src/rebar_dir.erl @@ -29,7 +29,7 @@ base_dir(State) -> ["default"] -> ["default"]; %% drop `default` from the profile dir if it's implicit and reverse order %% of profiles to match order passed to `as` - ["default"|Rest] -> lists:reverse(Rest) + ["default"|Rest] -> Rest end, ProfilesDir = string:join(ProfilesStrings, "+"), filename:join(rebar_state:get(State, base_dir, ?DEFAULT_BASE_DIR), ProfilesDir). diff --git a/src/rebar_state.erl b/src/rebar_state.erl index 7d872ee..22e5497 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -209,18 +209,25 @@ apply_profiles(State, [default]) -> State; apply_profiles(State=#state_t{opts=Opts, current_profiles=CurrentProfiles}, Profiles) -> ConfigProfiles = rebar_state:get(State, profiles, []), - {Profiles1, NewOpts} = - lists:foldl(fun(default, {ProfilesAcc, OptsAcc}) -> - {ProfilesAcc, OptsAcc}; - (Profile, {ProfilesAcc, OptsAcc}) -> - NewProfilesAcc = case lists:member(Profile, CurrentProfiles) of - false -> [Profile]++ProfilesAcc; - true -> ProfilesAcc - end, + NewOpts = + lists:foldl(fun(default, OptsAcc) -> + OptsAcc; + (Profile, OptsAcc) -> ProfileOpts = dict:from_list(proplists:get_value(Profile, ConfigProfiles, [])), - {NewProfilesAcc, merge_opts(Profile, ProfileOpts, OptsAcc)} - end, {[], Opts}, Profiles), - State#state_t{current_profiles=CurrentProfiles++Profiles1, opts=NewOpts}. + merge_opts(Profile, ProfileOpts, OptsAcc) + end, Opts, Profiles), + State#state_t{current_profiles = deduplicate(CurrentProfiles ++ Profiles), opts=NewOpts}. + +deduplicate(Profiles) -> + do_deduplicate(lists:reverse(Profiles), []). + +do_deduplicate([], Acc) -> + Acc; +do_deduplicate([Head | Rest], Acc) -> + case lists:member(Head, Acc) of + true -> do_deduplicate(Rest, Acc); + false -> do_deduplicate(Rest, [Head | Acc]) + end. merge_opts(Profile, NewOpts, OldOpts) -> Opts = merge_opts(NewOpts, OldOpts), -- cgit v1.1 From 82b0d4b7b29fe5d33148022be28eab55320f47a9 Mon Sep 17 00:00:00 2001 From: Viacheslav Kovalev Date: Wed, 22 Apr 2015 14:41:39 +0300 Subject: Implement opts umerge deduplication --- src/rebar_state.erl | 1 - src/rebar_utils.erl | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/rebar_state.erl b/src/rebar_state.erl index 22e5497..f73370b 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -231,7 +231,6 @@ do_deduplicate([Head | Rest], Acc) -> merge_opts(Profile, NewOpts, OldOpts) -> Opts = merge_opts(NewOpts, OldOpts), - case dict:find(deps, NewOpts) of {ok, Value} -> dict:store({deps, Profile}, Value, Opts); diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index bc2e4ac..76be9a8 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -257,7 +257,20 @@ tup_sort(List) -> tup_umerge([], Olds) -> Olds; tup_umerge([New|News], Olds) -> - lists:reverse(umerge(News, Olds, [], New)). + 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. %% This is equivalent to umerge2_2 in the stdlib, except we use the expanded %% value/key only to compare -- cgit v1.1 From e255529da5c2366f1a9c4eb823d3c3d02c237eae Mon Sep 17 00:00:00 2001 From: Viacheslav Kovalev Date: Wed, 22 Apr 2015 18:56:09 +0300 Subject: Get rid of rebar_utils:tup_umerge/2 patching --- src/rebar_state.erl | 7 ++++--- src/rebar_utils.erl | 15 +-------------- 2 files changed, 5 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/rebar_state.erl b/src/rebar_state.erl index f73370b..c2e479d 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -207,7 +207,8 @@ apply_profiles(State, Profile) when not is_list(Profile) -> apply_profiles(State, [Profile]); apply_profiles(State, [default]) -> 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, []), NewOpts = lists:foldl(fun(default, OptsAcc) -> @@ -215,8 +216,8 @@ apply_profiles(State=#state_t{opts=Opts, current_profiles=CurrentProfiles}, Prof (Profile, OptsAcc) -> ProfileOpts = dict:from_list(proplists:get_value(Profile, ConfigProfiles, [])), 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) -> do_deduplicate(lists:reverse(Profiles), []). diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index 76be9a8..004ed35 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -257,20 +257,7 @@ tup_sort(List) -> tup_umerge([], Olds) -> 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 %% value/key only to compare -- cgit v1.1 From 29a855d31c7fe7fd7504f5d0ec95c9a55e27276f Mon Sep 17 00:00:00 2001 From: "Viacheslav V. Kovalev" Date: Wed, 22 Apr 2015 21:44:23 +0300 Subject: Revert accidentially changed formatting --- src/rebar_state.erl | 1 + src/rebar_utils.erl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/rebar_state.erl b/src/rebar_state.erl index c2e479d..9b8d261 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -232,6 +232,7 @@ do_deduplicate([Head | Rest], Acc) -> merge_opts(Profile, NewOpts, OldOpts) -> Opts = merge_opts(NewOpts, OldOpts), + case dict:find(deps, NewOpts) of {ok, Value} -> dict:store({deps, Profile}, Value, Opts); diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index 004ed35..bc2e4ac 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -257,7 +257,7 @@ tup_sort(List) -> tup_umerge([], Olds) -> Olds; tup_umerge([New|News], Olds) -> - lists:reverse( umerge(News, Olds, [], New) ). + lists:reverse(umerge(News, Olds, [], New)). %% This is equivalent to umerge2_2 in the stdlib, except we use the expanded %% value/key only to compare -- cgit v1.1