summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2017-08-30 08:03:11 -0400
committerGitHub <noreply@github.com>2017-08-30 08:03:11 -0400
commitaf3d3b73c0676f061c7c26a628059f48213f135d (patch)
tree153c72f1a6a04f66d3fc0dd4408ef3786d45dbb3
parent92d3fa9272582eea6ce77faab19fb74be0d4c6ce (diff)
parent7095382e2c769f43214c32c4cb7f357b15ee095c (diff)
Merge pull request #1619 from suexcxine/master
Recompile when include files change in non-default directories
-rw-r--r--src/rebar_erlc_compiler.erl5
-rw-r--r--test/rebar_compile_SUITE.erl49
2 files changed, 52 insertions, 2 deletions
diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl
index 94cbe13..c588a25 100644
--- a/src/rebar_erlc_compiler.erl
+++ b/src/rebar_erlc_compiler.erl
@@ -787,8 +787,9 @@ outdir(RebarOpts) ->
proplists:get_value(outdir, ErlOpts, ?DEFAULT_OUTDIR).
include_abs_dirs(ErlOpts, BaseDir) ->
- InclDirs = ["include"|proplists:get_all_values(i, ErlOpts)],
- lists:map(fun(Incl) -> filename:join([BaseDir, Incl]) end, InclDirs).
+ ErlOptIncludes = proplists:get_all_values(i, ErlOpts),
+ InclDirs = lists:map(fun(Incl) -> filename:absname(Incl) end, ErlOptIncludes),
+ [filename:join([BaseDir, "include"])|InclDirs].
dir_recursive(Opts, Dir, CompileOpts) when is_list(CompileOpts) ->
case proplists:get_value(recursive,CompileOpts) of
diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl
index 5a18745..6579617 100644
--- a/test/rebar_compile_SUITE.erl
+++ b/test/rebar_compile_SUITE.erl
@@ -24,6 +24,7 @@
clean_extra_dirs_in_project_root/1,
recompile_when_hrl_changes/1,
recompile_when_included_hrl_changes/1,
+ recompile_when_opts_included_hrl_changes/1,
recompile_when_opts_change/1,
dont_recompile_when_opts_dont_change/1,
dont_recompile_yrl_or_xrl/1,
@@ -66,6 +67,7 @@ all() ->
{group, basic_extras}, {group, release_extras}, {group, unbalanced_extras},
{group, root_extras},
recompile_when_hrl_changes, recompile_when_included_hrl_changes,
+ recompile_when_opts_included_hrl_changes,
recompile_when_opts_change,
dont_recompile_when_opts_dont_change, dont_recompile_yrl_or_xrl,
delete_beam_if_source_deleted,
@@ -752,6 +754,53 @@ recompile_when_included_hrl_changes(Config) ->
?assert(ModTime =/= NewModTime).
+recompile_when_opts_included_hrl_changes(Config) ->
+ AppsDir = ?config(apps, Config),
+
+ Name = rebar_test_utils:create_random_name("app1_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ AppDir = filename:join([AppsDir, "apps", Name]),
+
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ ExtraSrc = <<"-module(test_header_include).\n"
+ "-export([main/0]).\n"
+ "-include(\"test_header_include.hrl\").\n"
+ "main() -> ?SOME_DEFINE.\n">>,
+
+ ExtraHeader = <<"-define(SOME_DEFINE, true).\n">>,
+ ok = filelib:ensure_dir(filename:join([AppsDir, "include", "dummy"])),
+ HeaderFile = filename:join([AppsDir, "include", "test_header_include.hrl"]),
+ ok = file:write_file(filename:join([AppDir, "src", "test_header_include.erl"]), ExtraSrc),
+ ok = file:write_file(HeaderFile, ExtraHeader),
+
+ %% Using relative path from the project root
+ RebarConfig = [{erl_opts, [{i, "include/"}]}],
+ {ok,Cwd} = file:get_cwd(),
+ ok = file:set_cwd(AppsDir),
+
+ rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
+
+ EbinDir = filename:join([AppsDir, "_build", "default", "lib", Name, "ebin"]),
+ {ok, Files} = rebar_utils:list_dir(EbinDir),
+ ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
+ || F <- Files, filename:extension(F) == ".beam"],
+
+ timer:sleep(1000),
+
+ NewExtraHeader = <<"-define(SOME_DEFINE, false).\n">>,
+ ok = file:write_file(HeaderFile, NewExtraHeader),
+
+ rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
+
+ {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
+ NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
+ || F <- NewFiles, filename:extension(F) == ".beam"],
+
+ ok = file:set_cwd(Cwd),
+
+ ?assert(ModTime =/= NewModTime).
+
recompile_when_opts_change(Config) ->
AppDir = ?config(apps, Config),