From bb8af6ddec20f44599f7cd0c3e626996a3206dad Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Fri, 5 Oct 2018 07:13:56 -0600 Subject: support tuples in overlay_vars so rebar3 can pass variables (#672) --- src/rlx_config.erl | 8 +++++--- src/rlx_prv_overlay.erl | 21 ++++++++------------- 2 files changed, 13 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/rlx_config.erl b/src/rlx_config.erl index ee58db5..b341ae7 100644 --- a/src/rlx_config.erl +++ b/src/rlx_config.erl @@ -303,8 +303,9 @@ list_of_overlay_vars_files(undefined) -> []; list_of_overlay_vars_files([]) -> []; -list_of_overlay_vars_files([H | _]=FileNames) when erlang:is_list(H) -> - FileNames; +list_of_overlay_vars_files([H | _]=Vars) when erlang:is_list(H) ; + is_tuple(H) -> + Vars; list_of_overlay_vars_files(FileName) when is_list(FileName) -> [FileName]. @@ -328,7 +329,8 @@ merge_configs([{Key, Value} | CliTerms], ConfigTerms) -> end; overlay_vars -> case lists:keyfind(overlay_vars, 1, ConfigTerms) of - {_, [H | _] = Vars} when is_list(H) -> + {_, [H | _] = Vars} when is_list(H) ; + is_tuple(H) -> MergedValue = Vars ++ Value, merge_configs(CliTerms, lists:keyreplace(overlay_vars, 1, ConfigTerms, {Key, MergedValue})); {_, Vars} when is_list(Vars) -> diff --git a/src/rlx_prv_overlay.erl b/src/rlx_prv_overlay.erl index 645f691..516d238 100644 --- a/src/rlx_prv_overlay.erl +++ b/src/rlx_prv_overlay.erl @@ -145,7 +145,8 @@ get_overlay_vars_from_file(State, OverlayVars) -> OverlayVars; [] -> OverlayVars; - [H | _]=FileNames when is_list(H) -> + [H | _]=FileNames when is_list(H) ; + is_tuple(H) -> read_overlay_vars(State, OverlayVars, FileNames); FileName when is_list(FileName) -> read_overlay_vars(State, OverlayVars, [FileName]) @@ -181,30 +182,24 @@ check_overlay_inclusion(_State, _RelativeRoot, [], Terms) -> proplists:proplist(). merge_overlay_vars(State, FileNames) -> RelativeRoot = get_relative_root(State), - lists:foldl(fun(FileName, Acc) -> - RelativePath = filename:join(RelativeRoot, erlang:iolist_to_binary(FileName)), + lists:foldl(fun(FileName, Acc) when is_list(FileName) -> + RelativePath = filename:join(RelativeRoot, iolist_to_binary(FileName)), case file:consult(RelativePath) of - %% {ok, [Terms]} -> - %% lists:ukeymerge(1, lists:ukeysort(1, Terms), Acc); - %% % the location of the included overlay files will be relative - %% %% to the current one being read - %% %% OverlayRelativeRoot = filename:dirname(FileName), - %% %% NewTerms = check_overlay_inclusion(State, OverlayRelativeRoot, Terms), - - %% %% lists:ukeymerge(1, lists:ukeysort(1, NewTerms), Acc); {ok, Terms} -> %% the location of the included overlay files will be relative %% to the current one being read OverlayRelativeRoot = filename:dirname(FileName), NewTerms = check_overlay_inclusion(State, OverlayRelativeRoot, Terms), lists:foldl(fun(NewTerm, A) -> - lists:keystore(element(1, NewTerm), 1, A, NewTerm) + lists:keystore(element(1, NewTerm), 1, A, NewTerm) end, Acc, NewTerms); {error, Reason} -> ec_cmd_log:warn(rlx_state:log(State), format_error({unable_to_read_varsfile, FileName, Reason})), Acc - end + end; + (Var, Acc) -> + lists:keystore(element(1, Var), 1, Acc, Var) end, [], FileNames). -spec render_overlay_vars(proplists:proplist(), proplists:proplist(), -- cgit v1.2.3