summaryrefslogtreecommitdiff
path: root/src/rebar_opts.erl
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2017-08-13 15:44:01 -0400
committerGitHub <noreply@github.com>2017-08-13 15:44:01 -0400
commit9c4e40d5b93c83f853be84685242d264b0892115 (patch)
treecdf2d2d1962d36deb1c5531b6575eca4dff64bf9 /src/rebar_opts.erl
parentd9064768e842d0d685287755bc2b31b223488923 (diff)
parentbed661aef80d113ae04e8e9da035f904b7c4aec4 (diff)
Merge pull request #1606 from ferd/recurive-profile-merge
Fix recursive profile merging, particularly for umbrella apps
Diffstat (limited to 'src/rebar_opts.erl')
-rw-r--r--src/rebar_opts.erl30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/rebar_opts.erl b/src/rebar_opts.erl
index 589dbb8..8863b4c 100644
--- a/src/rebar_opts.erl
+++ b/src/rebar_opts.erl
@@ -117,7 +117,12 @@ merge_opt(plugins, NewValue, _OldValue) ->
merge_opt({plugins, _}, NewValue, _OldValue) ->
NewValue;
merge_opt(profiles, NewValue, OldValue) ->
- dict:to_list(merge_opts(dict:from_list(NewValue), dict:from_list(OldValue)));
+ %% Merge up sparse pairs of {Profile, Opts} into a joined up
+ %% {Profile, OptsNew, OptsOld} list.
+ ToMerge = normalise_profile_pairs(lists:sort(NewValue),
+ lists:sort(OldValue)),
+ [{K,dict:to_list(merge_opts(dict:from_list(New), dict:from_list(Old)))}
+ || {K,New,Old} <- ToMerge];
merge_opt(erl_first_files, Value, Value) ->
Value;
merge_opt(erl_first_files, NewValue, OldValue) ->
@@ -190,3 +195,26 @@ filter_defines([{platform_define, ArchRegex, Key, Value} | Rest], Acc) ->
end;
filter_defines([Opt | Rest], Acc) ->
filter_defines(Rest, [Opt | Acc]).
+
+%% @private takes two lists of profile tuples and merges them
+%% into one list of 3-tuples containing the values of either
+%% profiles.
+%% Any missing profile in one of the keys is replaced by an
+%% empty one.
+-spec normalise_profile_pairs([Profile], [Profile]) -> [Pair] when
+ Profile :: {Name, Opts},
+ Pair :: {Name, Opts, Opts},
+ Name :: atom(),
+ Opts :: [term()].
+normalise_profile_pairs([], []) ->
+ [];
+normalise_profile_pairs([{P,V}|Ps], []) ->
+ [{P,V,[]} | normalise_profile_pairs(Ps, [])];
+normalise_profile_pairs([], [{P,V}|Ps]) ->
+ [{P,[],V} | normalise_profile_pairs([], Ps)];
+normalise_profile_pairs([{P,VA}|PAs], [{P,VB}|PBs]) ->
+ [{P,VA,VB} | normalise_profile_pairs(PAs, PBs)];
+normalise_profile_pairs([{PA,VA}|PAs], [{PB,VB}|PBs]) when PA < PB ->
+ [{PA,VA,[]} | normalise_profile_pairs(PAs, [{PB, VB}|PBs])];
+normalise_profile_pairs([{PA,VA}|PAs], [{PB,VB}|PBs]) when PA > PB ->
+ [{PB,[],VB} | normalise_profile_pairs([{PA,VA}|PAs], PBs)].