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(-) 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