summaryrefslogtreecommitdiff
path: root/src/rebar_compiler.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_compiler.erl')
-rw-r--r--src/rebar_compiler.erl13
1 files changed, 11 insertions, 2 deletions
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), []),