From 81369d99a9b6ee5caae6b5e6a5faffb8a65fb588 Mon Sep 17 00:00:00 2001 From: Luis Rascao Date: Sun, 20 Nov 2016 22:19:08 +0000 Subject: 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()]} ]} --- test/rlx_test_utils.erl | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'test/rlx_test_utils.erl') 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}]). -- cgit v1.2.3