mirror of
https://github.com/correl/rebar.git
synced 2024-11-23 19:19:54 +00:00
Avoid extra list traversal when checking for modified source files
This commit is contained in:
parent
22acf8db67
commit
13fe77d3f5
1 changed files with 18 additions and 14 deletions
|
@ -406,16 +406,23 @@ init_erlcinfo(InclDirs, Erls) ->
|
||||||
ok = file:delete(erlcinfo_file())
|
ok = file:delete(erlcinfo_file())
|
||||||
end,
|
end,
|
||||||
Dirs = source_and_include_dirs(InclDirs, Erls),
|
Dirs = source_and_include_dirs(InclDirs, Erls),
|
||||||
Updates = [update_erlcinfo(G, Erl, Dirs) || Erl <- Erls],
|
Modified = lists:foldl(update_erlcinfo_fun(G, Dirs), false, Erls),
|
||||||
Modified = lists:member(modified, Updates),
|
if Modified -> store_erlcinfo(G, InclDirs); not Modified -> ok end,
|
||||||
ok = store_erlcinfo(G, Modified, InclDirs),
|
|
||||||
G.
|
G.
|
||||||
|
|
||||||
source_and_include_dirs(InclDirs, Erls) ->
|
source_and_include_dirs(InclDirs, Erls) ->
|
||||||
SourceDirs = lists:map(fun filename:dirname/1, Erls),
|
SourceDirs = lists:map(fun filename:dirname/1, Erls),
|
||||||
lists:usort(["include" | InclDirs ++ SourceDirs]).
|
lists:usort(["include" | InclDirs ++ SourceDirs]).
|
||||||
|
|
||||||
update_erlcinfo(G, Source, Dirs) ->
|
update_erlcinfo_fun(G, Dirs) ->
|
||||||
|
fun(Erl, Modified) ->
|
||||||
|
case update_erlcinfo(G, Dirs, Erl) of
|
||||||
|
modified -> true;
|
||||||
|
unmodified -> Modified
|
||||||
|
end
|
||||||
|
end.
|
||||||
|
|
||||||
|
update_erlcinfo(G, Dirs, Source) ->
|
||||||
case digraph:vertex(G, Source) of
|
case digraph:vertex(G, Source) of
|
||||||
{_, LastUpdated} ->
|
{_, LastUpdated} ->
|
||||||
case filelib:last_modified(Source) of
|
case filelib:last_modified(Source) of
|
||||||
|
@ -426,14 +433,12 @@ update_erlcinfo(G, Source, Dirs) ->
|
||||||
digraph:del_vertex(G, Source),
|
digraph:del_vertex(G, Source),
|
||||||
modified;
|
modified;
|
||||||
LastModified when LastUpdated < LastModified ->
|
LastModified when LastUpdated < LastModified ->
|
||||||
modify_erlcinfo(G, Source, Dirs),
|
modify_erlcinfo(G, Source, Dirs);
|
||||||
modified;
|
|
||||||
_ ->
|
_ ->
|
||||||
unmodified
|
unmodified
|
||||||
end;
|
end;
|
||||||
false ->
|
false ->
|
||||||
modify_erlcinfo(G, Source, Dirs),
|
modify_erlcinfo(G, Source, Dirs)
|
||||||
modified
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
modify_erlcinfo(G, Source, Dirs) ->
|
modify_erlcinfo(G, Source, Dirs) ->
|
||||||
|
@ -445,9 +450,10 @@ modify_erlcinfo(G, Source, Dirs) ->
|
||||||
digraph:add_vertex(G, Source, LastUpdated),
|
digraph:add_vertex(G, Source, LastUpdated),
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun(Incl) ->
|
fun(Incl) ->
|
||||||
update_erlcinfo(G, Incl, Dirs),
|
update_erlcinfo(G, Dirs, Incl),
|
||||||
digraph:add_edge(G, Source, Incl)
|
digraph:add_edge(G, Source, Incl)
|
||||||
end, AbsIncls).
|
end, AbsIncls),
|
||||||
|
modified.
|
||||||
|
|
||||||
restore_erlcinfo(G, InclDirs) ->
|
restore_erlcinfo(G, InclDirs) ->
|
||||||
case file:read_file(erlcinfo_file()) of
|
case file:read_file(erlcinfo_file()) of
|
||||||
|
@ -468,9 +474,7 @@ restore_erlcinfo(G, InclDirs) ->
|
||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
store_erlcinfo(_G, _Modified = false, _InclDirs) ->
|
store_erlcinfo(G, InclDirs) ->
|
||||||
ok;
|
|
||||||
store_erlcinfo(G, _Modified, InclDirs) ->
|
|
||||||
Vs = lists:map(
|
Vs = lists:map(
|
||||||
fun(V) ->
|
fun(V) ->
|
||||||
digraph:vertex(G, V)
|
digraph:vertex(G, V)
|
||||||
|
@ -486,7 +490,7 @@ store_erlcinfo(G, _Modified, InclDirs) ->
|
||||||
File = erlcinfo_file(),
|
File = erlcinfo_file(),
|
||||||
ok = filelib:ensure_dir(File),
|
ok = filelib:ensure_dir(File),
|
||||||
Data = term_to_binary(#erlcinfo{info={Vs, Es, InclDirs}}, [{compressed, 9}]),
|
Data = term_to_binary(#erlcinfo{info={Vs, Es, InclDirs}}, [{compressed, 9}]),
|
||||||
file:write_file(File, Data).
|
ok = file:write_file(File, Data).
|
||||||
|
|
||||||
%% NOTE: If, for example, one of the entries in Files refers to
|
%% NOTE: If, for example, one of the entries in Files refers to
|
||||||
%% gen_server.erl, that entry will be dropped. It is dropped because
|
%% gen_server.erl, that entry will be dropped. It is dropped because
|
||||||
|
|
Loading…
Reference in a new issue