Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 2.35 KB | None | 0 0
  1. lm() -> [c:l(M) || M <- mm()].
  2.  
  3. mm() -> modified_modules().
  4.  
  5. modified_modules() ->                                                            
  6.     [M                                                                          
  7.      || {M, _} <- code:all_loaded(),                                            
  8.         module_modified(M) == true].                                            
  9.                                                                                  
  10. module_modified(Module) ->                                                      
  11.     case code:is_loaded(Module) of                                              
  12.       {file, preloaded} -> false;                                                
  13.       {file, Path} ->                                                            
  14.           CompileOpts = proplists:get_value(compile,                            
  15.                                             Module:module_info()),              
  16.           CompileTime = proplists:get_value(time, CompileOpts),                  
  17.           Src = proplists:get_value(source, CompileOpts),                        
  18.           module_modified(Path, CompileTime, Src);                              
  19.       _ -> false                                                                
  20.     end.                                                                        
  21.                                                                                  
  22. module_modified(Path, PrevCompileTime, PrevSrc) ->                              
  23.     case find_module_file(Path) of                                              
  24.       false -> false;
  25.       ModPath ->
  26.           case beam_lib:chunks(ModPath, ["CInf"]) of
  27.             {ok, {_, [{_, CB}]}} ->
  28.                 CompileOpts = binary_to_term(CB),
  29.                 CompileTime = proplists:get_value(time, CompileOpts),
  30.                 Src = proplists:get_value(source, CompileOpts),
  31.                 not (CompileTime == PrevCompileTime) and
  32.                   (Src == PrevSrc);
  33.             _ -> false
  34.           end
  35.     end.
  36.  
  37. find_module_file(Path) ->
  38.     case file:read_file_info(Path) of
  39.       {ok, _} -> Path;
  40.       _ ->
  41.           %% may be the path was changed
  42.           case code:where_is_file(filename:basename(Path)) of
  43.             non_existing -> false;
  44.             NewPath -> NewPath
  45.           end
  46.     end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement