diff options
-rw-r--r-- | src/rebar_erlc_compiler.erl | 14 | ||||
-rw-r--r-- | test/rebar_compile_SUITE.erl | 45 |
2 files changed, 53 insertions, 6 deletions
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/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 |