diff options
author | Tristan Sloughter <tristan.sloughter@gmail.com> | 2015-02-23 07:42:51 -0600 |
---|---|---|
committer | Tristan Sloughter <tristan.sloughter@gmail.com> | 2015-02-23 07:42:51 -0600 |
commit | 4153b3c7e599f553f6aaff5b4eddf5857814f1a8 (patch) | |
tree | 4c782c40e8a5c4b5a2182bd79c315268aafa9564 | |
parent | 4b9adefcb844111607891c9d7071794764126fc7 (diff) | |
parent | 521a49dd262da0264718d6e5765b23d37c6f6240 (diff) |
Merge pull request #176 from talentdeficit/no_unescessary_yrl_xrl_recompile
don't unescessarily recompile yrl/xrl files
-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 |