aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric <[email protected]>2012-12-27 11:54:38 -0500
committerEric <[email protected]>2012-12-27 11:54:38 -0500
commit901f020a4e0e5635b2d242f75ead571830395a06 (patch)
tree3c75699e234f1023cb7a31f665a9dc9e3656593a
parentb87e030af2e3120ea4a6950c9808285897ce7be9 (diff)
downloadrelx-901f020a4e0e5635b2d242f75ead571830395a06.tar.gz
relx-901f020a4e0e5635b2d242f75ead571830395a06.tar.bz2
relx-901f020a4e0e5635b2d242f75ead571830395a06.zip
suport variables in vars files of overlays
-rw-r--r--src/rcl_prv_overlay.erl48
-rw-r--r--test/rclt_release_SUITE.erl8
2 files changed, 52 insertions, 4 deletions
diff --git a/src/rcl_prv_overlay.erl b/src/rcl_prv_overlay.erl
index 7e8b369..d7fcc1b 100644
--- a/src/rcl_prv_overlay.erl
+++ b/src/rcl_prv_overlay.erl
@@ -112,11 +112,55 @@ get_overlay_vars_from_file(State, OverlayVars) ->
read_overlay_vars(State, OverlayVars, FileName) ->
case file:consult(FileName) of
{ok, Terms} ->
- do_overlay(State, OverlayVars ++ Terms);
+ case render_overlay_vars(OverlayVars, Terms, []) of
+ {ok, NewTerms} ->
+ do_overlay(State, NewTerms ++ OverlayVars);
+ Error ->
+ Error
+ end;
{error, Reason} ->
?RCL_ERROR({unable_to_read_varsfile, FileName, Reason})
end.
+-spec render_overlay_vars(proplists:proplist(), proplists:proplist(),
+ proplists:proplist()) ->
+ {ok, proplists:proplist()} | relcool:error().
+render_overlay_vars(OverlayVars, [{Key, Value} | Rest], Acc)
+ when erlang:is_list(Value) ->
+ case io_lib:printable_list(Value) of
+ true ->
+ case render_template(Acc ++ OverlayVars, erlang:iolist_to_binary(Value)) of
+ {ok, Data} ->
+ %% Adding to the end sucks, but ordering needs to be retained
+ render_overlay_vars(OverlayVars, Rest, Acc ++ [{Key, Data}]);
+ Error ->
+ Error
+ end;
+ false ->
+ case render_overlay_vars(Acc ++ OverlayVars, Value, []) of
+ {ok, NewValue} ->
+ render_overlay_vars(OverlayVars, Rest, Acc ++ [{Key, NewValue}]);
+ Error ->
+ Error
+ end
+ end;
+render_overlay_vars(OverlayVars, [{Key, Value} | Rest], Acc)
+ when erlang:is_binary(Value) ->
+ case render_template(Acc ++ OverlayVars, erlang:iolist_to_binary(Value)) of
+ {ok, Data} ->
+ render_overlay_vars(OverlayVars, Rest, Acc ++ [{Key, erlang:iolist_to_binary(Data)}]);
+ Error ->
+ Error
+ end;
+render_overlay_vars(OverlayVars, [KeyValue | Rest], Acc) ->
+ render_overlay_vars(OverlayVars, Rest, Acc ++ KeyValue);
+render_overlay_vars(_OverlayVars, [], Acc) ->
+ {ok, Acc}.
+
+
+
+
+
-spec generate_release_vars(rcl_release:t()) -> proplists:proplist().
generate_release_vars(Release) ->
[{erts_vsn, rcl_release:erts(Release)},
@@ -258,7 +302,7 @@ do_individual_overlay(State, OverlayVars, {template, From, To}) ->
render_template(OverlayVars, Data) ->
TemplateName = make_template_name("rcl_template_renderer", Data),
case erlydtl:compile(Data, TemplateName) of
- Good when Good =:= ok; ok =:= {ok, TemplateName} ->
+ Good when Good =:= ok; Good =:= {ok, TemplateName} ->
case render(TemplateName, OverlayVars) of
{ok, IoData} ->
{ok, IoData};
diff --git a/test/rclt_release_SUITE.erl b/test/rclt_release_SUITE.erl
index f4f0ecc..890a24b 100644
--- a/test/rclt_release_SUITE.erl
+++ b/test/rclt_release_SUITE.erl
@@ -269,6 +269,7 @@ overlay_release(Config) ->
VarsFile = filename:join([LibDir1, "vars.config"]),
write_config(VarsFile, [{yahoo, "yahoo"},
{yahoo2, [{foo, "bar"}]},
+ {yahoo3, [{bar, "{{yahoo}}/{{yahoo2.foo}}"}]},
{foo_dir, "foodir"}]),
TemplateFile = filename:join([LibDir1, "test_template"]),
@@ -358,7 +359,9 @@ overlay_release(Config) ->
?assertEqual("bar",
proplists:get_value(yahoo2_foo, TemplateData)),
?assertEqual("foodir",
- proplists:get_value(foo_dir, TemplateData)).
+ proplists:get_value(foo_dir, TemplateData)),
+ ?assertEqual("yahoo/bar",
+ proplists:get_value(yahoo3, TemplateData)).
%%%===================================================================
%%% Helper Functions
@@ -436,4 +439,5 @@ test_template_contents() ->
"{default_release, \"{{default_release}}\"}.\n"
"{yahoo, \"{{yahoo}}\"}.\n"
"{yahoo2_foo, \"{{yahoo2.foo}}\"}.\n"
- "{foo_dir, \"{{foo_dir}}\"}.\n".
+ "{foo_dir, \"{{foo_dir}}\"}.\n"
+ "{yahoo3, \"{{yahoo3.bar}}\"}.\n".