From fb26525a52935e98ef2521133d2b7bf5f34d5ab9 Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Sat, 11 Jun 2016 16:13:03 -0700 Subject: REBAR-1184 always recompile if `ERL_COMPILER_OPTIONS` env var is set partially addresses #1184 --- src/rebar_erlc_compiler.erl | 7 +++++++ test/rebar_compile_SUITE.erl | 47 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index 3480cf6..2a9f310 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -308,6 +308,7 @@ needed_files(G, ErlOpts, Dir, OutDir, SourceFiles) -> ,{i, Dir}] ++ ErlOpts, digraph:vertex(G, Source) > {Source, filelib:last_modified(Target)} orelse opts_changed(AllOpts, TargetBase) + orelse erl_compiler_opts_set() end, SourceFiles). maybe_rm_beam_and_edge(G, OutDir, Source) -> @@ -340,6 +341,12 @@ compile_info(Target) -> {error, Reason} end. +erl_compiler_opts_set() -> + case os:getenv("ERL_COMPILER_OPTIONS") of + false -> false; + _ -> true + end. + erlcinfo_file(Dir) -> filename:join(rebar_dir:local_cache_dir(Dir), ?ERLCINFO_FILE). diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index 76a3de5..d6d91b4 100644 --- a/test/rebar_compile_SUITE.erl +++ b/test/rebar_compile_SUITE.erl @@ -40,7 +40,8 @@ profile_override_deps/1, deps_build_in_prod/1, include_file_relative_to_working_directory/1, - include_file_in_src/1]). + include_file_in_src/1, + always_recompile_when_erl_compiler_options_set/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -62,7 +63,8 @@ all() -> parse_transform_test, erl_first_files_test, mib_test, umbrella_mib_first_test, only_default_transitive_deps, clean_all, override_deps, profile_override_deps, deps_build_in_prod, - include_file_relative_to_working_directory, include_file_in_src]. + include_file_relative_to_working_directory, include_file_in_src, + always_recompile_when_erl_compiler_options_set]. groups() -> [{basic_app, [], [build_basic_app, paths_basic_app, clean_basic_app]}, @@ -1265,3 +1267,44 @@ include_file_in_src(Config) -> rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}). + +always_recompile_when_erl_compiler_options_set(Config) -> + %% save existing env to restore after test + ExistingEnv = os:getenv("ERL_COMPILER_OPTIONS"), + + AppDir = ?config(apps, Config), + + Name = rebar_test_utils:create_random_name("erl_compiler_options_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + true = os:unsetenv("ERL_COMPILER_OPTIONS"), + + rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}), + + EbinDir = filename:join([AppDir, "_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), + + true = os:putenv("ERL_COMPILER_OPTIONS", "[{d, some_macro}]"), + + rebar_test_utils:run_and_check(Config, [], ["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"], + + ?assert(ModTime =/= NewModTime), + + %% restore existing env + case ExistingEnv of + false -> ok; + _ -> os:putenv("ERL_COMPILER_OPTIONS", ExistingEnv) + end. + + + -- cgit v1.1 From aba5a721e10f5577ae8e06b10d2b9cd8fe9e0804 Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Sat, 11 Jun 2016 16:28:32 -0700 Subject: REBAR-1184 exclude tests for `ERL_COMPILER_OPTIONS` on r15 --- test/rebar_compile_SUITE.erl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index d6d91b4..2f01dd4 100644 --- a/test/rebar_compile_SUITE.erl +++ b/test/rebar_compile_SUITE.erl @@ -63,8 +63,11 @@ all() -> parse_transform_test, erl_first_files_test, mib_test, umbrella_mib_first_test, only_default_transitive_deps, clean_all, override_deps, profile_override_deps, deps_build_in_prod, - include_file_relative_to_working_directory, include_file_in_src, - always_recompile_when_erl_compiler_options_set]. + include_file_relative_to_working_directory, include_file_in_src] ++ + case erlang:function_exported(os, unsetenv, 1) of + true -> [always_recompile_when_erl_compiler_options_set]; + false -> [] + end. groups() -> [{basic_app, [], [build_basic_app, paths_basic_app, clean_basic_app]}, -- cgit v1.1