Delete existing out-edges before adding new ones in modify_erlcinfo

When the source file changes it could happen that some of its
dependecies get removed.  In that case we should remove these
former dependencies from the graph, so that they don't influence
recompilation of the source file anymore.
This commit is contained in:
David Kubecka 2015-03-25 09:57:42 +01:00
parent 13fe77d3f5
commit 462962ebab
3 changed files with 27 additions and 3 deletions

View file

@ -40,7 +40,7 @@ files() ->
run(_Dir) ->
compile_all(ok, ""),
check_beams_ok(),
check_beams_untouched(),
check_beams_untouched(filelib:wildcard("ebin/*.beam")),
modify_and_recompile_ok("src/lisp.erl", "ebin/lisp.beam"),
clean_all_ok(),
@ -48,14 +48,27 @@ run(_Dir) ->
compile_all(ok, ""),
modify_and_recompile_ok("extra_include/extra.hrl", "ebin/java.beam"),
Java = "src/java.erl",
{ok, OrigContent} = file:read_file(Java),
%% Remove header file inclusion
{ok, _} = file:copy("src/java.erl.no_extra", Java),
%% Ensure recompilation
touch([Java]),
compile_all(ok, ""),
%% Modify that header file
touch(["extra_include/extra.hrl"]),
%% Ensure we don't have to recompile anything
check_beams_untouched(["ebin/java.beam"]),
%% Clean up
ok = file:write_file(Java, OrigContent),
ok.
check_beams_ok() ->
F = fun(BeamFile) -> ?assert(filelib:is_regular(BeamFile)) end,
with_erl_beams(F).
check_beams_untouched() ->
Beams = filelib:wildcard("ebin/*.beam"),
check_beams_untouched(Beams) ->
compile_all_and_assert_mtimes(Beams, fun erlang:'=:='/2).
modify_and_recompile_ok(TouchFile, CheckFile) ->

View file

@ -0,0 +1,10 @@
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ts=4 sw=4 ft=erlang et
-module(java).
-export([factory/0]).
-include("lambda.hrl").
factory() ->
?FUN.

View file

@ -448,6 +448,7 @@ modify_erlcinfo(G, Source, Dirs) ->
ok = file:close(Fd),
LastUpdated = {date(), time()},
digraph:add_vertex(G, Source, LastUpdated),
digraph:del_edges(G, digraph:out_edges(G, Source)),
lists:foreach(
fun(Incl) ->
update_erlcinfo(G, Dirs, Incl),