diff options
author | Tristan Sloughter <tristan.sloughter@gmail.com> | 2015-03-05 13:40:47 -0600 |
---|---|---|
committer | Tristan Sloughter <tristan.sloughter@gmail.com> | 2015-03-05 13:40:47 -0600 |
commit | 7e608a4c9ad50c54df69b859da9ba2e507f39cc4 (patch) | |
tree | dd35e4eed77379d444cf8478c05d03c272df9ede /src | |
parent | 3355e848b5b05b38120d5e6cbca7f415447aad5a (diff) | |
parent | ccfebdd1552128ef74841f12b3bf0ff3616ee40e (diff) |
Merge pull request #222 from talentdeficit/no_superfluous_loads
switch from loading modules to read compile info to using `beam_lib`
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_erlc_compiler.erl | 29 | ||||
-rw-r--r-- | src/rebar_otp_app.erl | 22 |
2 files changed, 20 insertions, 31 deletions
diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index c757511..a113fc4 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -256,24 +256,21 @@ needs_compile(Source, Target, Opts, Parents) -> source_changed(TargetLastMod, I) -> TargetLastMod < filelib:last_modified(I). -opts_changed(Opts, Target) -> - Basename = filename:basename(Target, ".beam"), - Dirname = filename:dirname(Target), - ObjectFile = filename:join([Dirname, Basename]), - _ = purge(list_to_atom(Basename)), - case code:load_abs(ObjectFile) of - {module, Mod} -> - Compile = Mod:module_info(compile), - lists:sort(Opts) =/= lists:sort(proplists:get_value(options, - Compile)); - {error, nofile} -> false +opts_changed(NewOpts, Target) -> + case compile_info(Target) of + {ok, Opts} -> lists:sort(Opts) =/= lists:sort(NewOpts); + _ -> true end. -purge(Mod) -> - %% remove old code if necessary - _ = code:purge(Mod), - %% move current code to old - _ = code:delete(Mod). +compile_info(Target) -> + case beam_lib:chunks(Target, [compile_info]) of + {ok, {_mod, Chunks}} -> + CompileInfo = proplists:get_value(compile_info, Chunks, []), + {ok, proplists:get_value(options, CompileInfo, [])}; + {error, beam_lib, Reason} -> + ?WARN("Couldn't read debug info from ~p for reason: ~p", [Target, Reason]), + {error, Reason} + end. check_erlcinfo(_Config, #erlcinfo{vsn=?ERLCINFO_VSN}) -> ok; diff --git a/src/rebar_otp_app.erl b/src/rebar_otp_app.erl index e850e58..2b5f682 100644 --- a/src/rebar_otp_app.erl +++ b/src/rebar_otp_app.erl @@ -166,23 +166,15 @@ ebin_modules(App, Dir) -> [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 -> [] + case beam_lib:chunks(Beam, [compile_info]) of + {ok, {_mod, Chunks}} -> + CompileInfo = proplists:get_value(compile_info, Chunks, []), + proplists:get_value(source, CompileInfo, []); + {error, beam_lib, Reason} -> + ?WARN("Couldn't read debug info from ~p for reason: ~p", [Beam, Reason]), + [] 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 false -> |