From 8d31d559c18b12d3d06655de2ca9c7f76c67c948 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Fri, 9 Nov 2018 12:22:12 -0700 Subject: check last modified time on erl files for xrl and yrl files before compiling --- src/rebar_compiler.erl | 13 +++++++++++-- src/rebar_compiler_erl.erl | 4 ++-- src/rebar_compiler_mib.erl | 4 ++-- src/rebar_compiler_xrl.erl | 8 +++++--- src/rebar_compiler_yrl.erl | 8 +++++--- 5 files changed, 25 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/rebar_compiler.erl b/src/rebar_compiler.erl index 6e94cb2..256794a 100644 --- a/src/rebar_compiler.erl +++ b/src/rebar_compiler.erl @@ -3,6 +3,7 @@ -export([compile_all/2, clean/2, + needs_compile/3, ok_tuple/2, error_tuple/4, maybe_report/1, @@ -18,7 +19,7 @@ include_dirs => [file:dirname()], src_ext => extension(), out_mappings => out_mappings()}. --callback needed_files(digraph:graph(), [file:filename()], rebar_app_info:t()) -> [file:filename()]. +-callback needed_files(digraph:graph(), [file:filename()], list(), rebar_app_info:t()) -> [file:filename()]. -callback dependencies(file:filename(), file:dirname(), [file:dirname()]) -> [file:filename()]. -callback compile(file:filename(), out_mappings(), rebar_dict(), list()) -> ok | {ok, [string()]} | {ok, [string()], [string()]}. @@ -66,7 +67,8 @@ run(CompilerMod, AppInfo) -> OutDir = rebar_app_info:out_dir(AppInfo), AbsSrcDirs = [filename:join(BaseDir, SrcDir) || SrcDir <- SrcDirs], G = init_dag(CompilerMod, AbsInclDirs, AbsSrcDirs, FoundFiles, OutDir, EbinDir), - {{FirstFiles, FirstFileOpts}, {RestFiles, Opts}} = CompilerMod:needed_files(G, FoundFiles, AppInfo), + {{FirstFiles, FirstFileOpts}, {RestFiles, Opts}} = CompilerMod:needed_files(G, FoundFiles, + Mappings, AppInfo), true = digraph:delete(G), compile_each(FirstFiles, FirstFileOpts, BaseOpts, Mappings, CompilerMod), @@ -111,6 +113,13 @@ clean_(CompilerMod, AppInfo) -> CompilerMod:clean(FoundFiles, AppInfo), rebar_file_utils:rm_rf(dag_file(CompilerMod, EbinDir)). +-spec needs_compile(filename:all(), extension(), [{extension(), file:dirname()}]) -> boolean(). +needs_compile(Source, OutExt, Mappings) -> + Ext = filename:extension(Source), + BaseName = filename:basename(Source, Ext), + {_, OutDir} = lists:keyfind(OutExt, 1, Mappings), + Target = filename:join(OutDir, BaseName++OutExt), + filelib:last_modified(Source) > filelib:last_modified(Target). run_on_extra_src_dirs(CompilerMod, AppInfo, Fun) -> ExtraDirs = rebar_dir:extra_src_dirs(rebar_app_info:opts(AppInfo), []), diff --git a/src/rebar_compiler_erl.erl b/src/rebar_compiler_erl.erl index d9bc69b..f0ae6f4 100644 --- a/src/rebar_compiler_erl.erl +++ b/src/rebar_compiler_erl.erl @@ -3,7 +3,7 @@ -behaviour(rebar_compiler). -export([context/1, - needed_files/3, + needed_files/4, dependencies/3, compile/4, clean/2]). @@ -31,7 +31,7 @@ context(AppInfo) -> out_mappings => Mappings}. -needed_files(Graph, FoundFiles, AppInfo) -> +needed_files(Graph, FoundFiles, _, AppInfo) -> OutDir = rebar_app_info:out_dir(AppInfo), Dir = rebar_app_info:dir(AppInfo), EbinDir = rebar_app_info:ebin_dir(AppInfo), diff --git a/src/rebar_compiler_mib.erl b/src/rebar_compiler_mib.erl index 32516bf..c731c27 100644 --- a/src/rebar_compiler_mib.erl +++ b/src/rebar_compiler_mib.erl @@ -3,7 +3,7 @@ -behaviour(rebar_compiler). -export([context/1, - needed_files/3, + needed_files/4, dependencies/3, compile/4, clean/2]). @@ -21,7 +21,7 @@ context(AppInfo) -> src_ext => ".mib", out_mappings => Mappings}. -needed_files(_, FoundFiles, AppInfo) -> +needed_files(_, FoundFiles, _, AppInfo) -> FirstFiles = [], %% Remove first files from found files diff --git a/src/rebar_compiler_xrl.erl b/src/rebar_compiler_xrl.erl index 5c023f0..23ed1eb 100644 --- a/src/rebar_compiler_xrl.erl +++ b/src/rebar_compiler_xrl.erl @@ -3,7 +3,7 @@ -behaviour(rebar_compiler). -export([context/1, - needed_files/3, + needed_files/4, dependencies/3, compile/4, clean/2]). @@ -16,11 +16,13 @@ context(AppInfo) -> src_ext => ".xrl", out_mappings => Mappings}. -needed_files(_, FoundFiles, AppInfo) -> +needed_files(_, FoundFiles, Mappings, AppInfo) -> FirstFiles = [], %% Remove first files from found files - RestFiles = [Source || Source <- FoundFiles, not lists:member(Source, FirstFiles)], + RestFiles = [Source || Source <- FoundFiles, + not lists:member(Source, FirstFiles), + rebar_compiler:needs_compile(Source, ".erl", Mappings)], Opts = rebar_opts:get(rebar_app_info:opts(AppInfo), xrl_opts, []), diff --git a/src/rebar_compiler_yrl.erl b/src/rebar_compiler_yrl.erl index 41d93b1..9c1767e 100644 --- a/src/rebar_compiler_yrl.erl +++ b/src/rebar_compiler_yrl.erl @@ -3,7 +3,7 @@ -behaviour(rebar_compiler). -export([context/1, - needed_files/3, + needed_files/4, dependencies/3, compile/4, clean/2]). @@ -16,11 +16,13 @@ context(AppInfo) -> src_ext => ".yrl", out_mappings => Mappings}. -needed_files(_, FoundFiles, AppInfo) -> +needed_files(_, FoundFiles, Mappings, AppInfo) -> FirstFiles = [], %% Remove first files from found files - RestFiles = [Source || Source <- FoundFiles, not lists:member(Source, FirstFiles)], + RestFiles = [Source || Source <- FoundFiles, + not lists:member(Source, FirstFiles), + rebar_compiler:needs_compile(Source, ".erl", Mappings)], Opts = rebar_opts:get(rebar_app_info:opts(AppInfo), yrl_opts, []), {{FirstFiles, Opts}, {RestFiles, Opts}}. -- cgit v1.1