aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJordan Wilberding <[email protected]>2014-12-16 17:01:40 -0800
committerJordan Wilberding <[email protected]>2014-12-16 17:01:40 -0800
commit8a64fd860e354cd3c32b5d6471052314bdd50674 (patch)
tree566c18f442f778cafd0320b91ab868c8a18eb10a
parent98c0290b8be73b31515b6da4c85a6c0f89a69b5a (diff)
parent63587bb0b40d5a396bd8b277f89a5afe901843e1 (diff)
downloadrelx-8a64fd860e354cd3c32b5d6471052314bdd50674.tar.gz
relx-8a64fd860e354cd3c32b5d6471052314bdd50674.tar.bz2
relx-8a64fd860e354cd3c32b5d6471052314bdd50674.zip
Merge pull request #281 from tsloughter/overlays_archive
render overlay filenames for tar archive
-rw-r--r--rebar.config2
-rw-r--r--src/rlx_prv_archive.erl16
-rw-r--r--src/rlx_prv_overlay.erl36
-rw-r--r--test/rlx_release_SUITE.erl4
4 files changed, 45 insertions, 13 deletions
diff --git a/rebar.config b/rebar.config
index 37f4550..e990194 100644
--- a/rebar.config
+++ b/rebar.config
@@ -10,7 +10,7 @@
{branch, "master"}}},
{providers, ".*",
{git, "https://github.com/tsloughter/providers.git",
- {branch, "format_error1"}}},
+ {tag, "v1.0.0"}}},
{erlydtl, ".*",
{git, "https://github.com/erlydtl/erlydtl.git",
{tag, "0.9.0"}}},
diff --git a/src/rlx_prv_archive.erl b/src/rlx_prv_archive.erl
index 8ec7973..0532dc5 100644
--- a/src/rlx_prv_archive.erl
+++ b/src/rlx_prv_archive.erl
@@ -104,10 +104,13 @@ make_tar(State, Release, OutputDir) ->
end.
update_tar(State, TempDir, OutputDir, Name, Vsn, ErtsVersion) ->
+ {RelName, RelVsn} = rlx_state:default_configured_release(State),
+ Release = rlx_state:get_realized_release(State, RelName, RelVsn),
TarFile = filename:join(OutputDir, Name++"-"++Vsn++".tar.gz"),
file:rename(filename:join(OutputDir, Name++".tar.gz"), TarFile),
erl_tar:extract(TarFile, [{cwd, TempDir}, compressed]),
- OverlayFiles = overlay_files(rlx_state:get(State, overlay, undefined), OutputDir),
+ OverlayVars = rlx_prv_overlay:generate_overlay_vars(State, Release),
+ OverlayFiles = overlay_files(OverlayVars, rlx_state:get(State, overlay, undefined), OutputDir),
ok =
erl_tar:create(TarFile,
[{"lib", filename:join(TempDir, "lib")},
@@ -130,10 +133,15 @@ update_tar(State, TempDir, OutputDir, Name, Vsn, ErtsVersion) ->
ec_file:remove(TempDir, [recursive]),
{ok, State}.
-overlay_files(undefined, _) ->
+overlay_files(_, undefined, _) ->
[];
-overlay_files(Overlay, OutputDir) ->
- [{to(O), filename:join(OutputDir, to(O))} || O <- Overlay, filter(O)].
+overlay_files(OverlayVars, Overlay, OutputDir) ->
+ [begin
+ To = to(O),
+ ToTemplateName = rlx_prv_overlay:make_template_name("rlx_template_to_template", To),
+ File = rlx_prv_overlay:render_string(OverlayVars, To, ToTemplateName),
+ {ec_cnv:to_list(File), ec_cnv:to_list(filename:join(OutputDir, File))}
+ end || O <- Overlay, filter(O)].
to({copy, _, To}) ->
To;
diff --git a/src/rlx_prv_overlay.erl b/src/rlx_prv_overlay.erl
index f7e2be8..f14963e 100644
--- a/src/rlx_prv_overlay.erl
+++ b/src/rlx_prv_overlay.erl
@@ -28,6 +28,10 @@
do/1,
format_error/1]).
+-export([generate_overlay_vars/2,
+ make_template_name/2,
+ render_string/3]).
+
-define(DIRECTORY_RE, ".*(\/|\\\\)$").
-define(ERLYDTL_COMPILE_OPTS, [report_warnings, return_errors, {auto_escape, false}, {out_dir, false}]).
@@ -61,7 +65,12 @@ do(State) ->
Release = rlx_state:get_realized_release(State, RelName, RelVsn),
case rlx_release:realized(Release) of
true ->
- generate_overlay_vars(State, Release);
+ case generate_overlay_vars(State, Release) of
+ {error, Reason} ->
+ {error, Reason};
+ OverlayVars ->
+ do_overlay(State, OverlayVars)
+ end;
false ->
?RLX_ERROR({unresolved_release, RelName, RelVsn})
end.
@@ -126,20 +135,20 @@ format_errors(_, []) -> [].
-spec generate_overlay_vars(rlx_state:t(), rlx_release:t()) ->
- {ok, rlx_state:t()} | relx:error().
+ proplists:proplist() | relx:error().
generate_overlay_vars(State, Release) ->
StateVars = generate_state_vars(State),
ReleaseVars = generate_release_vars(Release),
get_overlay_vars_from_file(State, StateVars ++ ReleaseVars).
-spec get_overlay_vars_from_file(rlx_state:t(), proplists:proplist()) ->
- {ok, rlx_state:t()} | relx:error().
+ proplists:proplist() | relx:error().
get_overlay_vars_from_file(State, OverlayVars) ->
case rlx_state:get(State, overlay_vars, undefined) of
undefined ->
- do_overlay(State, OverlayVars);
+ OverlayVars;
[] ->
- do_overlay(State, OverlayVars);
+ OverlayVars;
[H | _]=FileNames when is_list(H) ->
read_overlay_vars(State, OverlayVars, FileNames);
FileName when is_list(FileName) ->
@@ -147,12 +156,12 @@ get_overlay_vars_from_file(State, OverlayVars) ->
end.
-spec read_overlay_vars(rlx_state:t(), proplists:proplist(), [file:name()]) ->
- {ok, rlx_state:t()} | relx:error().
+ proplists:proplist() | relx:error().
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);
+ OverlayVars ++ NewTerms;
Error ->
Error
end.
@@ -431,6 +440,19 @@ write_template(OverlayVars, FromFile, ToFile) ->
Error
end.
+render_string(OverlayVars, Data, TemplateName) ->
+ case erlydtl:compile(erlang:iolist_to_binary(Data), TemplateName, ?ERLYDTL_COMPILE_OPTS) of
+ {ok, TemplateName} ->
+ case render(TemplateName, OverlayVars) of
+ {ok, IoList} ->
+ erlang:iolist_to_binary(IoList);
+ {error, Error} ->
+ ?RLX_ERROR({render_failed, Data, Error})
+ end;
+ {error, Reason, _Warnings} ->
+ ?RLX_ERROR({unable_to_compile_template, Data, Reason})
+ end.
+
-spec file_render_do(proplists:proplist(), iolist(), module(),
fun((term()) -> {ok, rlx_state:t()} | relx:error())) ->
{ok, rlx_state:t()} | relx:error().
diff --git a/test/rlx_release_SUITE.erl b/test/rlx_release_SUITE.erl
index 837e030..b850edc 100644
--- a/test/rlx_release_SUITE.erl
+++ b/test/rlx_release_SUITE.erl
@@ -524,7 +524,9 @@ overlay_release(Config) ->
{copy, TestDirFull,
"{{target_dir}}/"++SecondTestDir++"/"},
{template, Template,
- "{{target_dir}}/test_template_resolved"}]},
+ "{{target_dir}}/test_template_resolved"},
+ {template, Template,
+ "bin/{{default_release_name}}-{{default_release_version}}"}]},
{release, {foo, "0.0.1"},
[goal_app_1,
goal_app_2]}]),