diff options
-rw-r--r-- | src/rebar_config.erl | 2 | ||||
-rw-r--r-- | src/rebar_erlc_compiler.erl | 14 | ||||
-rw-r--r-- | src/rebar_hooks.erl | 2 | ||||
-rw-r--r-- | src/rebar_utils.erl | 3 | ||||
-rw-r--r-- | test/rebar_compile_SUITE.erl | 45 |
5 files changed, 57 insertions, 9 deletions
diff --git a/src/rebar_config.erl b/src/rebar_config.erl index 36d6b18..63b7af7 100644 --- a/src/rebar_config.erl +++ b/src/rebar_config.erl @@ -60,7 +60,7 @@ consult_file(File) -> end end. -merge_locks(Config, []) -> +merge_locks(Config, [[]]) -> Config; merge_locks(Config, [Locks]) -> {deps, ConfigDeps} = lists:keyfind(deps, 1, Config), diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index afdd6bd..ce15ab0 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -265,14 +265,20 @@ opts_changed(Opts, Target) -> case code:load_abs(ObjectFile) of {module, Mod} -> Compile = Mod:module_info(compile), - %% dialyzer and eunit have trouble without the next two lines - code:delete(Mod), - code:purge(Mod), + _ = purge(Mod), lists:sort(Opts) =/= lists:sort(proplists:get_value(options, Compile)); - {error, _} -> true + {error, nofile} -> false end. +purge(Mod) -> + %% remove old code if necessary + _ = code:purge(Mod), + %% move current code to old + true = code:delete(Mod), + %% remove new old code + _ = code:purge(Mod). + check_erlcinfo(_Config, #erlcinfo{vsn=?ERLCINFO_VSN}) -> ok; check_erlcinfo(Config, #erlcinfo{vsn=Vsn}) -> diff --git a/src/rebar_hooks.erl b/src/rebar_hooks.erl index a1a363e..706d6b9 100644 --- a/src/rebar_hooks.erl +++ b/src/rebar_hooks.erl @@ -22,4 +22,4 @@ apply_hook(Dir, Env, {Arch, Command, Hook}) -> end; apply_hook(Dir, Env, {Command, Hook}) -> Msg = lists:flatten(io_lib:format("Hook for ~p failed!~n", [Command])), - rebar_utils:sh(Hook, [{cd, Dir}, {env, Env}, {abort_on_error, Msg}]). + rebar_utils:sh(Hook, [use_stdout, {cd, Dir}, {env, Env}, {abort_on_error, Msg}]). diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index b3ae9ff..ab5167f 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -314,7 +314,8 @@ expand_sh_flag(debug_and_abort_on_error) -> expand_sh_flag(use_stdout) -> {output_handler, fun(Line, Acc) -> - ?CONSOLE("~s", [Line]), + %% Line already has a newline so don't use ?CONSOLE which adds one + io:format("~s", [Line]), [Line | Acc] end}; expand_sh_flag({use_stdout, false}) -> diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index fd1899f..9a21986 100644 --- a/test/rebar_compile_SUITE.erl +++ b/test/rebar_compile_SUITE.erl @@ -10,7 +10,8 @@ build_checkout_apps/1, build_checkout_deps/1, recompile_when_opts_change/1, - dont_recompile_when_opts_dont_change/1]). + dont_recompile_when_opts_dont_change/1, + dont_recompile_yrl_or_xrl/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -31,7 +32,8 @@ init_per_testcase(_, Config) -> all() -> [build_basic_app, build_release_apps, build_checkout_apps, build_checkout_deps, - recompile_when_opts_change, dont_recompile_when_opts_dont_change]. + recompile_when_opts_change, dont_recompile_when_opts_dont_change, + dont_recompile_yrl_or_xrl]. build_basic_app(Config) -> AppDir = ?config(apps, Config), @@ -141,4 +143,43 @@ dont_recompile_when_opts_dont_change(Config) -> NewModTime = [filelib:last_modified(filename:join([EbinDir, F])) || F <- NewFiles, filename:extension(F) == ".beam"], + ?assert(ModTime == NewModTime). + +dont_recompile_yrl_or_xrl(Config) -> + AppDir = ?config(apps, Config), + + Name = rebar_test_utils:create_random_name("app1_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + Xrl = filename:join([AppDir, "src", "not_a_real_xrl_" ++ Name ++ ".xrl"]), + ok = filelib:ensure_dir(Xrl), + XrlBody = + "Definitions." + "\n\n" + "D = [0-9]" + "\n\n" + "Rules." + "\n\n" + "{D}+ :" + " {token,{integer,TokenLine,list_to_integer(TokenChars)}}." + "\n\n" + "{D}+\\.{D}+((E|e)(\\+|\\-)?{D}+)? :" + " {token,{float,TokenLine,list_to_float(TokenChars)}}." + "\n\n" + "Erlang code.", + ok = ec_file:write(Xrl, XrlBody), + + XrlBeam = filename:join([AppDir, "ebin", filename:basename(Xrl, ".xrl") ++ ".beam"]), + + rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}), + + ModTime = filelib:last_modified(XrlBeam), + + timer:sleep(1000), + + rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}), + + NewModTime = filelib:last_modified(XrlBeam), + ?assert(ModTime == NewModTime).
\ No newline at end of file |