summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rebar_dir.erl2
-rw-r--r--src/rebar_state.erl29
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),