diff options
author | Viacheslav V. Kovalev <kovyl2404@gmail.com> | 2015-04-21 01:22:28 +0300 |
---|---|---|
committer | Viacheslav V. Kovalev <kovyl2404@gmail.com> | 2015-04-21 09:27:12 +0300 |
commit | 381c6f4779a93b50308f2cc86de8a19b23ebcee5 (patch) | |
tree | acf47ce67548731d353b56646f970daad2245dfc | |
parent | cb14a33fdd9eb7e4bf0cacde52c3027910de34b3 (diff) |
Correctly deduplicate profiles when applying
Conflicts:
src/rebar_state.erl
-rw-r--r-- | src/rebar_dir.erl | 2 | ||||
-rw-r--r-- | 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), |