summaryrefslogtreecommitdiff
path: root/src/rebar_opts.erl
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2017-08-11 13:58:13 -0400
committerFred Hebert <mononcqc@ferd.ca>2017-08-11 13:58:13 -0400
commit13bdb75b2961e1ae43e43e7c8d06bf463571d541 (patch)
tree5037a533f3f1461b40e27398411a1ee680abc70d /src/rebar_opts.erl
parentd9064768e842d0d685287755bc2b31b223488923 (diff)
Fix recursive profile merging in umbrella apps
When a config file exists at the root of a project, defines a given configuration value for a given profile, and that a sub-application (umbrella app) also has the same profile defined with the same key (but different values), the configuration values of the sub-application's profile would get silently dropped. The problem being that when the function to merge profiles is applied recursively, it is applied to each profile (so it will merge on the keys test, prod, etc.) rather than to each of the values of each profile. This patch reworks the profile merging so that the current behaviour is respected overall (a profile cannot be cancelled by a subdep's non-existant profile since its value should have been ignored), but ensures that sub-deps' profiles are otherwise applied recursively with the proper rules: - dependencies favor prior values - plugins favor new values - erl_first_files combine the lists - relx uses the tuple merge algorithm - erl_opts has its own custom merge as well - otherwise the new value takes precedence A test has also been added. There is a risk of breakage in some applications that may have relied on the buggy behaviour to work, though at this time we are aware of none of them.
Diffstat (limited to 'src/rebar_opts.erl')
-rw-r--r--src/rebar_opts.erl18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/rebar_opts.erl b/src/rebar_opts.erl
index 589dbb8..e327e31 100644
--- a/src/rebar_opts.erl
+++ b/src/rebar_opts.erl
@@ -117,7 +117,10 @@ 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)));
+ ToMerge = fill_profile_gaps(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 +193,16 @@ filter_defines([{platform_define, ArchRegex, Key, Value} | Rest], Acc) ->
end;
filter_defines([Opt | Rest], Acc) ->
filter_defines(Rest, [Opt | Acc]).
+
+fill_profile_gaps([], []) ->
+ [];
+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