summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Sloughter <t@crashfast.com>2018-11-09 12:22:12 -0700
committerTristan Sloughter <t@crashfast.com>2018-11-09 12:51:20 -0700
commit8d31d559c18b12d3d06655de2ca9c7f76c67c948 (patch)
treeb4115c9aff9fdec6c4bcb752c9a28d2980f443c1
parent60dc0504bf46e9ece179da9b20c54e0e2a3e11c6 (diff)
check last modified time on erl files for xrl and yrl files before compiling
-rw-r--r--src/rebar_compiler.erl13
-rw-r--r--src/rebar_compiler_erl.erl4
-rw-r--r--src/rebar_compiler_mib.erl4
-rw-r--r--src/rebar_compiler_xrl.erl8
-rw-r--r--src/rebar_compiler_yrl.erl8
-rw-r--r--test/rebar_compile_SUITE.erl25
6 files changed, 44 insertions, 18 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), []),
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}}.
diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl
index 6b1d791..4d51f2a 100644
--- a/test/rebar_compile_SUITE.erl
+++ b/test/rebar_compile_SUITE.erl
@@ -845,20 +845,33 @@ dont_recompile_yrl_or_xrl(Config) ->
"F -> number : '$1'.\n"],
ok = ec_file:write(Yrl, YrlBody),
- XrlBeam = filename:join([AppDir, "ebin", filename:basename(Xrl, ".xrl") ++ ".beam"]),
- YrlBeam = filename:join([AppDir, "ebin", filename:basename(Yrl, ".yrl") ++ ".beam"]),
+ XrlErl = filename:join([AppDir, "src", filename:basename(Xrl, ".xrl") ++ ".erl"]),
+ YrlErl = filename:join([AppDir, "src", filename:basename(Yrl, ".yrl") ++ ".erl"]),
+
+ EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
+ XrlBeam = filename:join([EbinDir, filename:basename(Xrl, ".xrl") ++ ".beam"]),
+ YrlBeam = filename:join([EbinDir, filename:basename(Yrl, ".yrl") ++ ".beam"]),
rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
- XrlModTime = filelib:last_modified(XrlBeam),
- YrlModTime = filelib:last_modified(YrlBeam),
+ XrlModTime = filelib:last_modified(XrlErl),
+ YrlModTime = filelib:last_modified(YrlErl),
+
+ XrlBeamModTime = filelib:last_modified(XrlBeam),
+ YrlBeamModTime = filelib:last_modified(YrlBeam),
timer:sleep(1000),
rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
- NewXrlModTime = filelib:last_modified(XrlBeam),
- NewYrlModTime = filelib:last_modified(YrlBeam),
+ NewXrlModTime = filelib:last_modified(XrlErl),
+ NewYrlModTime = filelib:last_modified(YrlErl),
+
+ NewXrlBeamModTime = filelib:last_modified(XrlBeam),
+ NewYrlBeamModTime = filelib:last_modified(YrlBeam),
+
+ ?assert(XrlBeamModTime == NewXrlBeamModTime),
+ ?assert(YrlBeamModTime == NewYrlBeamModTime),
?assert(XrlModTime == NewXrlModTime),
?assert(YrlModTime == NewYrlModTime).