aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuis Rascao <[email protected]>2015-02-19 11:05:49 +0000
committerLuis Rascao <[email protected]>2015-02-19 11:48:54 +0000
commitd1f1c8dc134cb1d4c832cfb0171ca7b859a2a600 (patch)
tree3f47f9dd515980b5bf7cf4974fe1467107f09111
parenta2e8eaa4fb6307e0d71ba932de6eb9378ddae937 (diff)
downloadrelx-d1f1c8dc134cb1d4c832cfb0171ca7b859a2a600.tar.gz
relx-d1f1c8dc134cb1d4c832cfb0171ca7b859a2a600.tar.bz2
relx-d1f1c8dc134cb1d4c832cfb0171ca7b859a2a600.zip
support overlay file inclusion
allow overlay inclusion of other files, similarly to what OTP already does in sys.config files
-rw-r--r--src/rlx_prv_overlay.erl21
-rw-r--r--test/rlx_release_SUITE.erl10
-rw-r--r--test/rlx_test_utils.erl1
3 files changed, 30 insertions, 2 deletions
diff --git a/src/rlx_prv_overlay.erl b/src/rlx_prv_overlay.erl
index ab0f74e..cdce915 100644
--- a/src/rlx_prv_overlay.erl
+++ b/src/rlx_prv_overlay.erl
@@ -161,6 +161,21 @@ read_overlay_vars(State, OverlayVars, FileNames) ->
Error
end.
+-spec check_overlay_inclusion(rlx_state:t(), string(), proplists:proplist()) ->
+ proplists:proplist().
+check_overlay_inclusion(State, RelativeRoot, Terms) ->
+ check_overlay_inclusion(State, RelativeRoot, Terms, []).
+
+-spec check_overlay_inclusion(rlx_state:t(), string(), proplists:proplist(), proplists:proplist()) ->
+ proplists:proplist().
+check_overlay_inclusion(State, RelativeRoot, [File|T], Terms) when is_list(File) ->
+ IncludedTerms = merge_overlay_vars(State, [filename:join(RelativeRoot, File)]),
+ check_overlay_inclusion(State, RelativeRoot, T, Terms ++ IncludedTerms);
+check_overlay_inclusion(State, RelativeRoot, [Tuple|T], Terms) ->
+ check_overlay_inclusion(State, RelativeRoot, T, Terms ++ [Tuple]);
+check_overlay_inclusion(_State, _RelativeRoot, [], Terms) ->
+ Terms.
+
-spec merge_overlay_vars(rlx_state:t(), [file:name()]) ->
proplists:proplist().
merge_overlay_vars(State, FileNames) ->
@@ -169,7 +184,11 @@ merge_overlay_vars(State, FileNames) ->
RelativePath = filename:join(RelativeRoot, erlang: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);
{error, Reason} ->
ec_cmd_log:warn(rlx_state:log(State),
format_error({unable_to_read_varsfile, FileName, Reason})),
diff --git a/test/rlx_release_SUITE.erl b/test/rlx_release_SUITE.erl
index eeab491..766eb40 100644
--- a/test/rlx_release_SUITE.erl
+++ b/test/rlx_release_SUITE.erl
@@ -471,6 +471,7 @@ overlay_release(Config) ->
ConfigFile = filename:join([LibDir1, "relx.config"]),
OverlayVars1 = filename:join([LibDir1, "vars1.config"]),
OverlayVars2 = filename:join([LibDir1, "vars2.config"]),
+ OverlayVars3 = filename:join([LibDir1, "vars3.config"]),
Template = filename:join([LibDir1, "test_template"]),
TestDir = "first_test_dir",
TestFile = "test_file",
@@ -502,7 +503,12 @@ overlay_release(Config) ->
VarsFile2 = filename:join([LibDir1, "vars2.config"]),
rlx_test_utils:write_config(VarsFile2, [{google, "yahoo"},
- {yahoo2, [{foo, "foo"}]}]),
+ {yahoo2, [{foo, "foo"}]},
+ OverlayVars3]),
+
+ VarsFile3 = filename:join([LibDir1, "vars3.config"]),
+ rlx_test_utils:write_config(VarsFile3, [{google, "yahoo"},
+ {yahoo4, [{foo, "{{yahoo}}/{{yahoo2.foo}}4"}]}]),
ok = rlx_util:mkdir_p(TestDirFull),
ok = file:write_file(TestFileFull, rlx_test_utils:test_template_contents()),
@@ -604,6 +610,8 @@ overlay_release(Config) ->
proplists:get_value(foo_dir, TemplateData)),
?assertEqual("yahoo/foo",
proplists:get_value(yahoo3, TemplateData)),
+ ?assertEqual("yahoo/foo4",
+ proplists:get_value(yahoo4, TemplateData)),
?assertEqual("yahoo",
proplists:get_value(google, TemplateData)).
diff --git a/test/rlx_test_utils.erl b/test/rlx_test_utils.erl
index 0428966..644c49f 100644
--- a/test/rlx_test_utils.erl
+++ b/test/rlx_test_utils.erl
@@ -94,4 +94,5 @@ test_template_contents() ->
"{yahoo2_foo, \"{{yahoo2.foo}}\"}.\n"
"{foo_dir, \"{{foo_dir}}\"}.\n"
"{yahoo3, \"{{yahoo3.bar}}\"}.\n"
+ "{yahoo4, \"{{yahoo4.foo}}\"}.\n"
"{google, \"{{google}}\"}.\n".