diff options
Diffstat (limited to 'src/rebar_otp_app.erl')
-rw-r--r-- | src/rebar_otp_app.erl | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/rebar_otp_app.erl b/src/rebar_otp_app.erl index 278d7e5..e850e58 100644 --- a/src/rebar_otp_app.erl +++ b/src/rebar_otp_app.erl @@ -100,7 +100,7 @@ preprocess(State, AppInfo, AppSrcFile) -> %% substitute. Note that we include the list of modules available in %% ebin/ and update the app data accordingly. OutDir = rebar_app_info:out_dir(AppInfo), - AppVars = load_app_vars(State) ++ [{modules, ebin_modules(OutDir)}], + AppVars = load_app_vars(State) ++ [{modules, ebin_modules(AppInfo, OutDir)}], A1 = apply_app_vars(AppVars, AppData), %% AppSrcFile may contain instructions for generating a vsn number @@ -157,9 +157,31 @@ validate_name(AppName, File) -> ?PRV_ERROR({invalid_name, File, AppName}) end. -ebin_modules(Dir) -> - lists:sort([rebar_utils:beam_to_mod(N) || - N <- rebar_utils:beams(filename:join(Dir, "ebin"))]). +ebin_modules(App, Dir) -> + Beams = lists:sort(rebar_utils:beams(filename:join(Dir, "ebin"))), + F = fun(Beam) -> not lists:prefix(filename:join([rebar_app_info:dir(App), "test"]), + beam_src(Beam)) + end, + Filtered = lists:filter(F, Beams), + [rebar_utils:beam_to_mod(N) || N <- Filtered]. + +beam_src(Beam) -> + try + Mod = list_to_atom(filename:basename(Beam, ".beam")), + _ = purge(Mod), + {module, Mod} = code:load_abs(filename:rootname(Beam, ".beam")), + Compile = Mod:module_info(compile), + proplists:get_value(source, Compile, []) + catch + error:undef -> []; + error:nofile -> [] + end. + +purge(Mod) -> + %% remove old code if necessary + _ = code:purge(Mod), + %% move current code to old + _ = code:delete(Mod). ensure_registered(AppData) -> case lists:keyfind(registered, 1, AppData) of |