From 4e1c23abec65a62fbd8e1ff16fffb619d5608881 Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Sat, 14 Mar 2020 19:48:44 +0000 Subject: [PATCH] Fix Artifact tagging in DAG The propagation was confusing source files and artifacts; the artifact ordering was flipped, and the tagging non-mandatory (aside from as edges), which made things hard to identify when plugins for compilers are used. --- src/rebar_compiler.erl | 4 ++-- src/rebar_compiler_dag.erl | 18 ++++++++++++------ src/rebar_compiler_erl.erl | 2 +- test/rebar_compile_SUITE.erl | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/rebar_compiler.erl b/src/rebar_compiler.erl index ccc0e160..8b83ec5a 100644 --- a/src/rebar_compiler.erl +++ b/src/rebar_compiler.erl @@ -246,8 +246,8 @@ store_artifacts(_G, []) -> ok; store_artifacts(G, [{Source, Target, Meta}|Rest]) -> %% Assume the source exists since it was tracked to be compiled - digraph:add_vertex(G, Target, Meta), - digraph:add_edge(G, Source, Target, artifact), + digraph:add_vertex(G, Target, {artifact, Meta}), + digraph:add_edge(G, Target, Source, artifact), store_artifacts(G, Rest). compile_worker(QueuePid, Opts, Config, Outs, CompilerMod) -> diff --git a/src/rebar_compiler_dag.erl b/src/rebar_compiler_dag.erl index 884bc847..a80ce5c5 100644 --- a/src/rebar_compiler_dag.erl +++ b/src/rebar_compiler_dag.erl @@ -233,7 +233,7 @@ maybe_rm_artifact_and_edge(G, OutDir, SrcExt, Ext, Source) -> %% Actually exists, don't delete false; false -> - Edges = digraph:out_edges(G, Source), + Edges = digraph:in_edges(G, Source), Targets = [V2 || Edge <- Edges, {_E, _V1, V2, artifact} <- [digraph:edge(G, Edge)]], case Targets of @@ -281,8 +281,7 @@ prepopulate_deps(G, Compiler, InDirs, Source, DepOpts, Status) -> %% drop edges from deps that aren't included! [digraph:del_edge(G, Edge) || Status == old, Edge <- digraph:out_edges(G, Source), - {_, _Src, Path, Label} <- [digraph:edge(G, Edge)], - Label =/= artifact, + {_, _Src, Path, _Label} <- [digraph:edge(G, Edge)], not lists:member(Path, AbsIncls)], %% Add the rest [digraph:add_edge(G, Source, Incl) || Incl <- AbsIncls], @@ -296,11 +295,14 @@ refresh_dep(G, File) -> %% Gone! Erase from the graph digraph:del_vertex(G, File), mark_dirty(G); + {artifact, _} -> + %% ignore artifacts + ok; LastModified when LastUpdated < LastModified -> digraph:add_vertex(G, File, LastModified), mark_dirty(G); _ -> - % unchanged + %% unchanged ok end. @@ -310,14 +312,18 @@ refresh_dep(G, File) -> propagate_stamps(_G, []) -> ok; propagate_stamps(G, [File|Files]) -> - Stamps = [element(2, digraph:vertex(G, F)) - || F <- digraph:out_neighbours(G, File)], + Stamps = [Stamp + || F <- digraph:out_neighbours(G, File), + {_, Stamp} <- [digraph:vertex(G, F)], + is_tuple(Stamp) andalso element(1, Stamp) =/= artifact], case Stamps of [] -> ok; _ -> Max = lists:max(Stamps), case digraph:vertex(G, File) of + {_, {artifact, _}} -> + ok; {_, Smaller} when Smaller < Max -> digraph:add_vertex(G, File, Max); _ -> diff --git a/src/rebar_compiler_erl.erl b/src/rebar_compiler_erl.erl index bc80e275..86d6b4fb 100644 --- a/src/rebar_compiler_erl.erl +++ b/src/rebar_compiler_erl.erl @@ -235,7 +235,7 @@ opts_changed(Graph, NewOpts, Target, TargetBase) -> false -> NewOpts end, TargetOpts = case digraph:vertex(Graph, Target) of - {_Target, Opts} -> % tracked dep is found + {_Target, {artifact, Opts}} -> % tracked dep is found Opts; false -> % not found; might be a non-tracked DAG case compile_info(TargetBase) of diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index c121bd7e..55e0cda5 100644 --- a/test/rebar_compile_SUITE.erl +++ b/test/rebar_compile_SUITE.erl @@ -939,7 +939,7 @@ recompile_when_dag_opts_change(Config) -> DepsDir = filename:join([AppDir, "_build", "default", "lib"]), G = rebar_compiler_dag:init(DepsDir, rebar_compiler_erl, "project_apps", []), %% change the config in the DAG... - [digraph:add_vertex(G, Beam, [{d, some_define}]) || Beam <- Beams], + [digraph:add_vertex(G, Beam, {artifact, [{d, some_define}]}) || Beam <- Beams], digraph:add_vertex(G, '$r3_dirty_bit', true), % trigger a save rebar_compiler_dag:maybe_store(G, DepsDir, rebar_compiler_erl, "project_apps", []), rebar_compiler_dag:terminate(G),