Yet another tip of the day
Bjorn Gustavsson
bjorn@REDACTED
Fri Nov 12 06:32:08 CET 2004
Excellent idea! Very useful.
To my user_default.erl, I also added:
lm() ->
[c:l(M) || M <- mm()].
/Bjorn
Vladimir Sekissov <svg@REDACTED> writes:
> Good day,
>
> I've added this code to my _user_default.erl_ when slightly tired to
> load every recompiled module manually.
>
> Now I can do after _make_ finished:
>
> 48> mm().
> [user_default, tacacs_tests]
>
> 49> [l(M) || M <- mm()].
> [{module,user_default},{module,tacacs_tests}]
>
> 50> mm().
> []
>
> ---------------------------- code ----------------------------
> mm() ->
> modified_modules().
>
> modified_modules() ->
> [M || {M, _} <- code:all_loaded(), module_modified(M) == true].
>
> module_modified(Module) ->
> case code:is_loaded(Module) of
> {file, preloaded} ->
> false;
> {file, Path} ->
> CompileOpts = proplists:get_value(compile, Module:module_info()),
> CompileTime = proplists:get_value(time, CompileOpts),
> Src = proplists:get_value(source, CompileOpts),
> module_modified(Path, CompileTime, Src);
> _ ->
> false
> end.
>
> module_modified(Path, PrevCompileTime, PrevSrc) ->
> case find_module_file(Path) of
> false ->
> false;
> ModPath ->
> {ok, {_, [{_, CB}]}} = beam_lib:chunks(ModPath, ["CInf"]),
> CompileOpts = binary_to_term(CB),
> CompileTime = proplists:get_value(time, CompileOpts),
> Src = proplists:get_value(source, CompileOpts),
> not (CompileTime == PrevCompileTime) and (Src == PrevSrc)
> end.
>
> find_module_file(Path) ->
> case file:read_file_info(Path) of
> {ok, _} ->
> Path;
> _ ->
> %% may be the path was changed?
> case code:where_is_file(filename:basename(Path)) of
> non_existing ->
> false;
> NewPath ->
> NewPath
> end
> end.
>
> ---
> Best Regards,
> Vladimir Sekissov
>
--
Björn Gustavsson, Erlang/OTP, Ericsson AB
More information about the erlang-questions
mailing list