aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--src/rlx_prv_overlay.erl44
-rw-r--r--test/rlx_release_SUITE.erl40
2 files changed, 52 insertions, 32 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().
diff --git a/test/rlx_release_SUITE.erl b/test/rlx_release_SUITE.erl
index 7ac95bc..821a4d1 100644
--- a/test/rlx_release_SUITE.erl
+++ b/test/rlx_release_SUITE.erl
@@ -457,7 +457,8 @@ overlay_release(Config) ->
create_app(LibDir1, "non_goal_2", "0.0.1", [stdlib,kernel], []),
ConfigFile = filename:join([LibDir1, "relx.config"]),
- OverlayVars = filename:join([LibDir1, "vars.config"]),
+ OverlayVars1 = filename:join([LibDir1, "vars1.config"]),
+ OverlayVars2 = filename:join([LibDir1, "vars2.config"]),
Template = filename:join([LibDir1, "test_template"]),
TestDir = "first_test_dir",
TestFile = "test_file",
@@ -465,11 +466,11 @@ overlay_release(Config) ->
TestFileFull = filename:join(TestDirFull, TestFile),
SecondTestDir = "second_test_dir",
write_config(ConfigFile,
- [{overlay_vars, OverlayVars},
+ [{overlay_vars, [OverlayVars1, OverlayVars2]},
{overlay, [{mkdir, "{{target_dir}}/fooo"},
- {copy, OverlayVars,
- "{{target_dir}}/{{foo_dir}}/vars.config"},
- {copy, OverlayVars,
+ {copy, OverlayVars1,
+ "{{target_dir}}/{{foo_dir}}/vars1.config"},
+ {copy, OverlayVars1,
"{{target_dir}}/{{yahoo}}/"},
{copy, TestDirFull,
"{{target_dir}}/"++SecondTestDir++"/"},
@@ -479,11 +480,15 @@ overlay_release(Config) ->
[goal_app_1,
goal_app_2]}]),
- VarsFile = filename:join([LibDir1, "vars.config"]),
- write_config(VarsFile, [{yahoo, "yahoo"},
- {yahoo2, [{foo, "bar"}]},
- {yahoo3, [{bar, "{{yahoo}}/{{yahoo2.foo}}"}]},
- {foo_dir, "foodir"}]),
+ VarsFile1 = filename:join([LibDir1, "vars1.config"]),
+ write_config(VarsFile1, [{yahoo, "yahoo"},
+ {yahoo2, [{foo, "bar"}]},
+ {yahoo3, [{bar, "{{yahoo}}/{{yahoo2.foo}}"}]},
+ {foo_dir, "foodir"}]),
+
+ VarsFile2 = filename:join([LibDir1, "vars2.config"]),
+ write_config(VarsFile2, [{google, "yahoo"},
+ {yahoo2, [{foo, "foo"}]}]),
ok = rlx_util:mkdir_p(TestDirFull),
ok = file:write_file(TestFileFull, test_template_contents()),
@@ -510,8 +515,8 @@ overlay_release(Config) ->
?assert(lists:member({lib_dep_1, "0.0.1", load}, AppSpecs)),
?assert(ec_file:exists(filename:join(OutputDir, "fooo"))),
- ?assert(ec_file:exists(filename:join([OutputDir, "foodir", "vars.config"]))),
- ?assert(ec_file:exists(filename:join([OutputDir, "yahoo", "vars.config"]))),
+ ?assert(ec_file:exists(filename:join([OutputDir, "foodir", "vars1.config"]))),
+ ?assert(ec_file:exists(filename:join([OutputDir, "yahoo", "vars1.config"]))),
io:format("DirFile ~p~n", [filename:join([OutputDir, SecondTestDir, TestDir, TestFile])]),
?assert(ec_file:exists(filename:join([OutputDir, SecondTestDir, TestDir, TestFile]))),
@@ -579,12 +584,14 @@ overlay_release(Config) ->
proplists:get_value(default_release, TemplateData)),
?assertEqual("yahoo",
proplists:get_value(yahoo, TemplateData)),
- ?assertEqual("bar",
+ ?assertEqual("foo",
proplists:get_value(yahoo2_foo, TemplateData)),
?assertEqual("foodir",
proplists:get_value(foo_dir, TemplateData)),
- ?assertEqual("yahoo/bar",
- proplists:get_value(yahoo3, TemplateData)).
+ ?assertEqual("yahoo/foo",
+ proplists:get_value(yahoo3, TemplateData)),
+ ?assertEqual("yahoo",
+ proplists:get_value(google, TemplateData)).
make_goalless_release(Config) ->
LibDir1 = proplists:get_value(lib1, Config),
@@ -918,4 +925,5 @@ test_template_contents() ->
"{yahoo, \"{{yahoo}}\"}.\n"
"{yahoo2_foo, \"{{yahoo2.foo}}\"}.\n"
"{foo_dir, \"{{foo_dir}}\"}.\n"
- "{yahoo3, \"{{yahoo3.bar}}\"}.\n".
+ "{yahoo3, \"{{yahoo3.bar}}\"}.\n"
+ "{google, \"{{google}}\"}.\n".