summaryrefslogtreecommitdiff
path: root/src/rebar_opts.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_opts.erl')
-rw-r--r--src/rebar_opts.erl36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/rebar_opts.erl b/src/rebar_opts.erl
index 589dbb8..b7156b2 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) ->
@@ -127,7 +132,11 @@ merge_opt(mib_first_files, Value, Value) ->
merge_opt(mib_first_files, NewValue, OldValue) ->
OldValue ++ NewValue;
merge_opt(relx, NewValue, OldValue) ->
- rebar_utils:tup_umerge(OldValue, NewValue);
+ Partition = fun(C) -> is_tuple(C) andalso element(1, C) =:= overlay end,
+ {NewOverlays, NewOther} = lists:partition(Partition, NewValue),
+ {OldOverlays, OldOther} = lists:partition(Partition, OldValue),
+ rebar_utils:tup_umerge(NewOverlays, OldOverlays)
+ ++ rebar_utils:tup_umerge(OldOther, NewOther);
merge_opt(Key, NewValue, OldValue)
when Key == erl_opts; Key == eunit_compile_opts; Key == ct_compile_opts ->
merge_erl_opts(lists:reverse(OldValue), NewValue);
@@ -190,3 +199,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)].