aboutsummaryrefslogtreecommitdiffstats
path: root/src/rlx_prv_overlay.erl
diff options
context:
space:
mode:
authorJordan Wilberding <[email protected]>2013-10-12 09:35:26 -0700
committerJordan Wilberding <[email protected]>2013-10-12 09:35:26 -0700
commit7bcf3516d0c8aef9fd7cb0191dd9d36929d2a88d (patch)
tree8df6408f594c32fed2947bdadaef19ce77c3ece5 /src/rlx_prv_overlay.erl
parent55e82cd5ae42eac42244b55611450dc25c36a648 (diff)
parent51d787c7e3da7cbfa092b8455706911749f26d45 (diff)
downloadrelx-7bcf3516d0c8aef9fd7cb0191dd9d36929d2a88d.tar.gz
relx-7bcf3516d0c8aef9fd7cb0191dd9d36929d2a88d.tar.bz2
relx-7bcf3516d0c8aef9fd7cb0191dd9d36929d2a88d.zip
Merge pull request #66 from tsloughter/master
support list of overlay_vars files
Diffstat (limited to 'src/rlx_prv_overlay.erl')
-rw-r--r--src/rlx_prv_overlay.erl44
1 files changed, 28 insertions, 16 deletions
diff --git a/src/rlx_prv_overlay.erl b/src/rlx_prv_overlay.erl
index a16e7d3..cd1fe33 100644
--- a/src/rlx_prv_overlay.erl
+++ b/src/rlx_prv_overlay.erl
@@ -105,27 +105,39 @@ get_overlay_vars_from_file(State, OverlayVars) ->
case rlx_state:get(State, overlay_vars, undefined) of
undefined ->
do_overlay(State, OverlayVars);
- FileName ->
- read_overlay_vars(State, OverlayVars, FileName)
+ [H | _]=FileNames when is_list(H) ->
+ read_overlay_vars(State, OverlayVars, FileNames);
+ FileName when is_list(FileName) ->
+ read_overlay_vars(State, OverlayVars, [FileName])
end.
--spec read_overlay_vars(rlx_state:t(), proplists:proplist(), file:name()) ->
+-spec read_overlay_vars(rlx_state:t(), proplists:proplist(), [file:name()]) ->
{ok, rlx_state:t()} | relx:error().
-read_overlay_vars(State, OverlayVars, FileName) ->
- RelativeRoot = get_relative_root(State),
- RelativePath = filename:join(RelativeRoot, erlang:iolist_to_binary(FileName)),
- case file:consult(RelativePath) of
- {ok, Terms} ->
- case render_overlay_vars(OverlayVars, Terms, []) of
- {ok, NewTerms} ->
- do_overlay(State, NewTerms ++ OverlayVars);
- Error ->
- Error
- end;
- {error, Reason} ->
- ?RLX_ERROR({unable_to_read_varsfile, FileName, Reason})
+read_overlay_vars(State, OverlayVars, FileNames) ->
+ Terms = merge_overlay_vars(State, FileNames),
+ case render_overlay_vars(OverlayVars, Terms, []) of
+ {ok, NewTerms} ->
+ do_overlay(State, OverlayVars ++ NewTerms);
+ Error ->
+ Error
end.
+-spec merge_overlay_vars(rlx_state:t(), [file:name()]) ->
+ 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)),
+ case file:consult(RelativePath) of
+ {ok, Terms} ->
+ lists:ukeymerge(1, lists:ukeysort(1, Terms), Acc);
+ {error, Reason} ->
+ rlx_log:warn(rlx_state:log(State),
+ format_error({unable_to_read_varsfile, FileName, Reason})),
+ Acc
+ end
+ end, [], FileNames).
+
-spec render_overlay_vars(proplists:proplist(), proplists:proplist(),
proplists:proplist()) ->
{ok, proplists:proplist()} | relx:error().