From 90bead231032af39dcdf54dde47d85259cd1030a Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Tue, 12 May 2020 12:35:21 +0000 Subject: [PATCH] Extract artifact tracking to DAG module Cleans up some annoying broken abstraction. Also fix erl_first_file artifact tracking, which will avoid seeking to disk by finding the opts in the DAG --- src/rebar_compiler.erl | 10 +++++----- src/rebar_compiler_dag.erl | 6 +++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/rebar_compiler.erl b/src/rebar_compiler.erl index 8b83ec5a..5ff934bd 100644 --- a/src/rebar_compiler.erl +++ b/src/rebar_compiler.erl @@ -129,7 +129,7 @@ sort_apps(Names, Apps) -> {_, App} <- [lists:keyfind(Name, 1, NamedApps)]]. -spec compile_analyzed({module(), digraph:graph()}, rebar_app_info:t(), map()) -> ok. -compile_analyzed({Compiler, G}, AppInfo, Contexts) -> % > 3.13.0 +compile_analyzed({Compiler, G}, AppInfo, Contexts) -> % > 3.13.2 run(G, Compiler, AppInfo, Contexts), %% Extras are tricky and get their own mini-analysis ExtraApps = annotate_extras(AppInfo), @@ -183,8 +183,9 @@ run(G, CompilerMod, AppInfo, Contexts) -> {{FirstFiles, FirstFileOpts}, {RestFiles, Opts}} = CompilerMod:needed_files(G, FoundFiles, Mappings, AppInfo), - compile_each(FirstFiles, FirstFileOpts, BaseOpts, Mappings, CompilerMod), - Tracked = case RestFiles of + Tracked = + compile_each(FirstFiles, FirstFileOpts, BaseOpts, Mappings, CompilerMod) + ++ case RestFiles of {Sequential, Parallel} -> % parallelizable form compile_each(Sequential, Opts, BaseOpts, Mappings, CompilerMod) ++ compile_parallel(Parallel, Opts, BaseOpts, Mappings, CompilerMod); @@ -246,8 +247,7 @@ 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, {artifact, Meta}), - digraph:add_edge(G, Target, Source, artifact), + rebar_compiler_dag:store_artifact(G, Source, Target, Meta), 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 710cde89..6eb21fb8 100644 --- a/src/rebar_compiler_dag.erl +++ b/src/rebar_compiler_dag.erl @@ -3,7 +3,7 @@ -module(rebar_compiler_dag). -export([init/4, maybe_store/5, terminate/1]). -export([prune/5, populate_sources/5, populate_deps/3, propagate_stamps/1, - compile_order/2]). + compile_order/2, store_artifact/4]). -include("rebar.hrl"). @@ -192,6 +192,10 @@ maybe_store(G, Dir, Compiler, Label, CritMeta) -> terminate(G) -> true = digraph:delete(G). +store_artifact(G, Source, Target, Meta) -> + digraph:add_vertex(G, Target, {artifact, Meta}), + digraph:add_edge(G, Target, Source, artifact). + %%%%%%%%%%%%%%% %%% PRIVATE %%% %%%%%%%%%%%%%%%