aboutsummaryrefslogtreecommitdiffstats
path: root/test/rlx_test_utils.erl
diff options
context:
space:
mode:
authorLuis Rascao <[email protected]>2016-11-20 22:19:08 +0000
committerLuis Rascao <[email protected]>2016-11-21 00:24:37 +0000
commit81369d99a9b6ee5caae6b5e6a5faffb8a65fb588 (patch)
tree8b3e2acce5896f977bd264fb1cf66a9ffe6e6fd6 /test/rlx_test_utils.erl
parentc305c89713abf48570e2db152b367f00ac641893 (diff)
downloadrelx-81369d99a9b6ee5caae6b5e6a5faffb8a65fb588.tar.gz
relx-81369d99a9b6ee5caae6b5e6a5faffb8a65fb588.tar.bz2
relx-81369d99a9b6ee5caae6b5e6a5faffb8a65fb588.zip
Provide a new config directive that allows per-app module exclusion
By introducing a new entry in the config file allow excluding specific modules from a given app, they will not be copied onto the final release and their reference removed from the .app file. The new entry takes on the following form: {exclude_modules, [ {App :: atom(), [Module :: atom()]} ]}
Diffstat (limited to 'test/rlx_test_utils.erl')
-rw-r--r--test/rlx_test_utils.erl43
1 files changed, 28 insertions, 15 deletions
diff --git a/test/rlx_test_utils.erl b/test/rlx_test_utils.erl
index 3ddc134..d1b7fe4 100644
--- a/test/rlx_test_utils.erl
+++ b/test/rlx_test_utils.erl
@@ -6,27 +6,26 @@
create_app(Dir, Name, Vsn, Deps, LibDeps) ->
AppDir = filename:join([Dir, Name ++ "-" ++ Vsn]),
- write_app_file(AppDir, Name, Vsn, Deps, LibDeps),
+ write_app_file(AppDir, Name, Vsn, app_modules(Name), Deps, LibDeps),
write_src_file(AppDir, Name),
- write_beam_file(AppDir, Name),
+ compile_src_files(AppDir),
rlx_app_info:new(erlang:list_to_atom(Name), Vsn, AppDir,
Deps, []).
create_empty_app(Dir, Name, Vsn, Deps, LibDeps) ->
AppDir = filename:join([Dir, Name ++ "-" ++ Vsn]),
- write_app_file(AppDir, Name, Vsn, Deps, LibDeps),
+ write_app_file(AppDir, Name, Vsn, [], Deps, LibDeps),
rlx_app_info:new(erlang:list_to_atom(Name), Vsn, AppDir,
Deps, []).
-write_beam_file(Dir, Name) ->
- Beam = filename:join([Dir, "ebin", "not_a_real_beam" ++ Name ++ ".beam"]),
- ok = filelib:ensure_dir(Beam),
- ok = ec_file:write_term(Beam, testing_purposes_only).
+app_modules(Name) ->
+ [list_to_atom(M ++ Name) ||
+ M <- ["a_real_beam"]].
write_src_file(Dir, Name) ->
- Src = filename:join([Dir, "src", "not_a_real_beam" ++ Name ++ ".erl"]),
+ Src = filename:join([Dir, "src", "a_real_beam" ++ Name ++ ".erl"]),
ok = filelib:ensure_dir(Src),
- ok = ec_file:write_term(Src, testing_purposes_only).
+ ok = file:write_file(Src, beam_file_contents("a_real_beam"++Name)).
write_appup_file(AppInfo, DownVsn) ->
Dir = rlx_app_info:dir(AppInfo),
@@ -36,16 +35,27 @@ write_appup_file(AppInfo, DownVsn) ->
ok = filelib:ensure_dir(Filename),
ok = ec_file:write_term(Filename, {Vsn, [{DownVsn, []}], [{DownVsn, []}]}).
-write_app_file(Dir, Name, Version, Deps, LibDeps) ->
+write_app_file(Dir, Name, Version, Modules, Deps, LibDeps) ->
Filename = filename:join([Dir, "ebin", Name ++ ".app"]),
ok = filelib:ensure_dir(Filename),
- ok = ec_file:write_term(Filename, get_app_metadata(Name, Version, Deps, LibDeps)).
-
-get_app_metadata(Name, Vsn, Deps, LibDeps) ->
+ ok = ec_file:write_term(Filename, get_app_metadata(Name, Version, Modules,
+ Deps, LibDeps)).
+
+compile_src_files(Dir) ->
+ %% compile all *.erl files in src to ebin
+ SrcDir = filename:join([Dir, "src"]),
+ OutputDir = filename:join([Dir, "ebin"]),
+ lists:foreach(fun(SrcFile) ->
+ {ok, _} = compile:file(SrcFile, [{outdir, OutputDir},
+ return_errors])
+ end, ec_file:find(SrcDir, "\\.erl")),
+ ok.
+
+get_app_metadata(Name, Vsn, Modules, Deps, LibDeps) ->
{application, erlang:list_to_atom(Name),
[{description, ""},
{vsn, Vsn},
- {modules, []},
+ {modules, Modules},
{included_applications, LibDeps},
{registered, []},
{applications, Deps}]}.
@@ -63,6 +73,9 @@ write_config(Filename, Values) ->
ok = ec_file:write(Filename,
[io_lib:format("~p.\n", [Val]) || Val <- Values]).
+beam_file_contents(Name) ->
+ "-module("++Name++").".
+
test_template_contents() ->
"{erts_vsn, \"{{erts_vsn}}\"}.\n"
"{release_erts_version, \"{{release_erts_version}}\"}.\n"
@@ -113,4 +126,4 @@ list_to_term(String) ->
unescape_string(String) ->
re:replace(String, "\"", "",
- [global, {return, list}]). \ No newline at end of file
+ [global, {return, list}]).