From 15b5426cfac681e92b09c70ca1e1d011df03a7c6 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Tue, 10 Mar 2015 14:16:16 -0500 Subject: merge rebar config opts for parent like done for profiles --- src/rebar_state.erl | 49 +++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 20 deletions(-) (limited to 'src/rebar_state.erl') diff --git a/src/rebar_state.erl b/src/rebar_state.erl index e77a259..008f202 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -97,9 +97,8 @@ new(ParentState, Config, Dir) -> dict:from_list([{{deps, default}, D} | Config]) end, - NewOpts = dict:merge(fun(_Key, Value1, _Value2) -> - Value1 - end, LocalOpts, Opts), + NewOpts = merge_opts(LocalOpts, Opts), + ParentState#state_t{dir=Dir ,opts=NewOpts ,default=NewOpts}. @@ -213,23 +212,8 @@ apply_profiles(State=#state_t{opts=Opts, current_profiles=CurrentProfiles}, Prof State#state_t{current_profiles=CurrentProfiles++Profiles1, opts=NewOpts}. merge_opts(Profile, NewOpts, OldOpts) -> - Opts = dict:merge(fun(_Key, NewValue, OldValue) when is_list(NewValue) -> - case io_lib:printable_list(NewValue) of - true when NewValue =:= [] -> - case io_lib:printable_list(OldValue) of - true -> - NewValue; - false -> - OldValue - end; - true -> - NewValue; - false -> - OldValue ++ NewValue - end; - (_Key, NewValue, _OldValue) -> - NewValue - end, NewOpts, OldOpts), + Opts = merge_opts(NewOpts, OldOpts), + case dict:find(deps, NewOpts) of {ok, Value} -> dict:store({deps, Profile}, Value, Opts); @@ -237,6 +221,31 @@ merge_opts(Profile, NewOpts, OldOpts) -> Opts end. +merge_opts(NewOpts, OldOpts) -> + dict:merge(fun(deps, NewValue, _OldValue) -> + NewValue; + ({deps, _}, NewValue, _OldValue) -> + NewValue; + (profiles, NewValue, OldValue) -> + dict:to_list(merge_opts(dict:from_list(NewValue), dict:from_list(OldValue))); + (_Key, NewValue, OldValue) when is_list(NewValue) -> + case io_lib:printable_list(NewValue) of + true when NewValue =:= [] -> + case io_lib:printable_list(OldValue) of + true -> + NewValue; + false -> + OldValue + end; + true -> + NewValue; + false -> + lists:umerge(lists:sort(NewValue), lists:sort(OldValue)) + end; + (_Key, NewValue, _OldValue) -> + NewValue + end, NewOpts, OldOpts). + dir(#state_t{dir=Dir}) -> Dir. -- cgit v1.1