summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2015-05-04 00:24:21 +0000
committerFred Hebert <mononcqc@ferd.ca>2015-05-04 00:24:21 +0000
commit5920ee29bef1462434e419ceee1342a614e6f063 (patch)
tree2b13d7544d7f76ad93bad21cd3fb4fb76120f764 /src
parent9b770b896718aee800e43ac045582cd8abb266da (diff)
parent33736f32a9a8bfd30711270e8f1376280915d697 (diff)
Merge branch 'app-discover-profile-duplication' of https://github.com/kovyl2404/rebar3 into kovyl2404-app-discover-profile-duplication
Diffstat (limited to 'src')
-rw-r--r--src/rebar_dir.erl2
-rw-r--r--src/rebar_state.erl28
2 files changed, 21 insertions, 9 deletions
diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl
index c0c6bb2..a94c72d 100644
--- a/src/rebar_dir.erl
+++ b/src/rebar_dir.erl
@@ -34,7 +34,7 @@ profile_dir(State, Profiles) ->
["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 ddac9d2..46c870e 100644
--- a/src/rebar_state.erl
+++ b/src/rebar_state.erl
@@ -229,16 +229,28 @@ 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, []),
- {Profiles1, NewOpts} =
- lists:foldl(fun(default, {ProfilesAcc, OptsAcc}) ->
- {ProfilesAcc, OptsAcc};
- (Profile, {ProfilesAcc, OptsAcc}) ->
+ NewOpts =
+ lists:foldl(fun(default, OptsAcc) ->
+ OptsAcc;
+ (Profile, OptsAcc) ->
ProfileOpts = dict:from_list(proplists:get_value(Profile, ConfigProfiles, [])),
- {[Profile]++ProfilesAcc, merge_opts(Profile, ProfileOpts, OptsAcc)}
- end, {[], Opts}, Profiles),
- State#state_t{current_profiles=CurrentProfiles++Profiles1, opts=NewOpts}.
+ merge_opts(Profile, ProfileOpts, OptsAcc)
+ end, Defaults, AppliedProfiles),
+ State#state_t{current_profiles = AppliedProfiles, 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),