summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2017-08-13 15:30:03 -0400
committerFred Hebert <mononcqc@ferd.ca>2017-08-13 15:30:03 -0400
commitbed661aef80d113ae04e8e9da035f904b7c4aec4 (patch)
treecdf2d2d1962d36deb1c5531b6575eca4dff64bf9
parent13bdb75b2961e1ae43e43e7c8d06bf463571d541 (diff)
Clarify function to normalise profile pairs
-rw-r--r--src/rebar_opts.erl38
1 files changed, 25 insertions, 13 deletions
diff --git a/src/rebar_opts.erl b/src/rebar_opts.erl
index e327e31..8863b4c 100644
--- a/src/rebar_opts.erl
+++ b/src/rebar_opts.erl
@@ -117,8 +117,10 @@ merge_opt(plugins, NewValue, _OldValue) ->
merge_opt({plugins, _}, NewValue, _OldValue) ->
NewValue;
merge_opt(profiles, NewValue, OldValue) ->
- ToMerge = fill_profile_gaps(lists:sort(NewValue),
- lists:sort(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) ->
@@ -194,15 +196,25 @@ filter_defines([{platform_define, ArchRegex, Key, Value} | Rest], Acc) ->
filter_defines([Opt | Rest], Acc) ->
filter_defines(Rest, [Opt | Acc]).
-fill_profile_gaps([], []) ->
+%% @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([], []) ->
[];
-fill_profile_gaps([{P,V}|Ps], []) ->
- [{P,V,[]} | fill_profile_gaps(Ps, [])];
-fill_profile_gaps([], [{P,V}|Ps]) ->
- [{P,[],V} | fill_profile_gaps([], Ps)];
-fill_profile_gaps([{P,VA}|PAs], [{P,VB}|PBs]) ->
- [{P,VA,VB} | fill_profile_gaps(PAs, PBs)];
-fill_profile_gaps([{PA,VA}|PAs], [{PB,VB}|PBs]) when PA < PB ->
- [{PA,VA,[]} | fill_profile_gaps(PAs, [{PB, VB}|PBs])];
-fill_profile_gaps([{PA,VA}|PAs], [{PB,VB}|PBs]) when PA > PB ->
- [{PB,[],VB} | fill_profile_gaps([{PA,VA}|PAs], PBs)]. \ No newline at end of file
+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)].