diff options
-rw-r--r-- | src/rebar3.erl | 23 | ||||
-rw-r--r-- | src/rebar_dir.erl | 6 | ||||
-rw-r--r-- | src/rebar_prv_eunit.erl | 21 | ||||
-rw-r--r-- | src/rebar_utils.erl | 8 | ||||
-rw-r--r-- | test/rebar_dir_SUITE.erl | 12 | ||||
-rw-r--r-- | test/rebar_src_dirs_SUITE.erl | 12 |
6 files changed, 45 insertions, 37 deletions
diff --git a/src/rebar3.erl b/src/rebar3.erl index e55db71..2b73844 100644 --- a/src/rebar3.erl +++ b/src/rebar3.erl @@ -96,7 +96,7 @@ run(RawArgs) -> run_aux(BaseState2, RawArgs). run_aux(State, RawArgs) -> - State2 = case os:getenv("REBAR_PROFILE") of + State1 = case os:getenv("REBAR_PROFILE") of false -> State; "" -> @@ -105,6 +105,9 @@ run_aux(State, RawArgs) -> rebar_state:apply_profiles(State, [list_to_atom(Profile)]) end, + %% bootstrap test profile + State2 = rebar_state:add_to_profile(State1, test, test_state(State1)), + %% Process each command, resetting any state between each one BaseDir = rebar_state:get(State, base_dir, ?DEFAULT_BASE_DIR), State3 = rebar_state:set(State2, base_dir, @@ -319,3 +322,21 @@ state_from_global_config(Config, GlobalConfigFile) -> GlobalConfig2 = rebar_state:set(GlobalConfig, plugins, []), GlobalConfig3 = rebar_state:set(GlobalConfig2, {plugins, global}, rebar_state:get(GlobalConfigThrowAway, plugins, [])), rebar_state:providers(rebar_state:new(GlobalConfig3, Config), GlobalPlugins). + +test_state(State) -> + ErlOpts = rebar_state:get(State, erl_opts, []), + TestOpts = safe_define_test_macro(ErlOpts), + [{extra_src_dirs, ["test"]}, {erl_opts, TestOpts}]. + +safe_define_test_macro(Opts) -> + %% defining a compile macro twice results in an exception so + %% make sure 'TEST' is only defined once + case test_defined(Opts) of + true -> []; + false -> [{d, 'TEST'}] + end. + +test_defined([{d, 'TEST'}|_]) -> true; +test_defined([{d, 'TEST', true}|_]) -> true; +test_defined([_|Rest]) -> test_defined(Rest); +test_defined([]) -> false.
\ No newline at end of file diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl index 364e197..09e3114 100644 --- a/src/rebar_dir.erl +++ b/src/rebar_dir.erl @@ -139,7 +139,7 @@ src_dirs(Opts, Default) -> Vs = proplists:get_all_values(src_dirs, ErlOpts), case lists:append([rebar_opts:get(Opts, src_dirs, []) | Vs]) of [] -> Default; - Dirs -> Dirs + Dirs -> lists:usort(Dirs) end. -spec extra_src_dirs(rebar_dict()) -> list(file:filename_all()). @@ -151,7 +151,7 @@ extra_src_dirs(Opts, Default) -> Vs = proplists:get_all_values(extra_src_dirs, ErlOpts), case lists:append([rebar_opts:get(Opts, extra_src_dirs, []) | Vs]) of [] -> Default; - Dirs -> Dirs + Dirs -> lists:usort(Dirs) end. -spec all_src_dirs(rebar_dict()) -> list(file:filename_all()). @@ -160,7 +160,7 @@ all_src_dirs(Opts) -> all_src_dirs(Opts, [], []). -spec all_src_dirs(rebar_dict(), list(file:filename_all()), list(file:filename_all())) -> list(file:filename_all()). all_src_dirs(Opts, SrcDefault, ExtraDefault) -> - src_dirs(Opts, SrcDefault) ++ extra_src_dirs(Opts, ExtraDefault). + lists:usort(src_dirs(Opts, SrcDefault) ++ extra_src_dirs(Opts, ExtraDefault)). %% given a path if that path is an ancestor of an app dir return the path relative to that %% apps outdir. if the path is not an ancestor to any app dirs but is an ancestor of the diff --git a/src/rebar_prv_eunit.erl b/src/rebar_prv_eunit.erl index 357b92f..0cdc20b 100644 --- a/src/rebar_prv_eunit.erl +++ b/src/rebar_prv_eunit.erl @@ -34,8 +34,7 @@ init(State) -> {opts, eunit_opts(State)}, {profiles, [test]}]), State1 = rebar_state:add_provider(State, Provider), - State2 = rebar_state:add_to_profile(State1, test, test_state(State1)), - {ok, State2}. + {ok, State1}. -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> @@ -103,19 +102,6 @@ format_error({error, Error}) -> %% Internal functions %% =================================================================== -test_state(State) -> - ErlOpts = rebar_state:get(State, erl_opts, []), - TestOpts = safe_define_test_macro(ErlOpts), - [{extra_src_dirs, ["test"]}, {erl_opts, TestOpts}]. - -safe_define_test_macro(Opts) -> - %% defining a compile macro twice results in an exception so - %% make sure 'TEST' is only defined once - case test_defined(Opts) of - true -> Opts; - false -> [{d, 'TEST'}] ++ Opts - end. - compile(State, {ok, Tests}) -> %% inject `eunit_first_files`, `eunit_compile_opts` and any %% directories required by tests into the applications @@ -191,11 +177,6 @@ inject_test_dir(Opts, Dir) -> ExtraSrcDirs = rebar_opts:get(Opts, extra_src_dirs, []), rebar_opts:set(Opts, extra_src_dirs, ExtraSrcDirs ++ [Dir]). -test_defined([{d, 'TEST'}|_]) -> true; -test_defined([{d, 'TEST', true}|_]) -> true; -test_defined([_|Rest]) -> test_defined(Rest); -test_defined([]) -> false. - prepare_tests(State) -> %% parse and translate command line tests CmdTests = resolve_tests(State), diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index 4fd4bd1..d00a46f 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -654,13 +654,19 @@ update_code(Paths) -> code:add_patha(Path), ok; {ok, Modules} -> + %% stick rebar ebin dir before purging to prevent + %% inadvertent termination + RebarBin = code:lib_dir(rebar, ebin), + ok = code:stick_dir(RebarBin), %% replace_path causes problems when running %% tests in projects like erlware_commons that rebar3 %% also includes %code:replace_path(App, Path), code:del_path(App), code:add_patha(Path), - [begin code:purge(M), code:delete(M) end || M <- Modules] + [begin code:purge(M), code:delete(M) end || M <- Modules], + %% unstick rebar dir + ok = code:unstick_dir(RebarBin) end end, Paths). diff --git a/test/rebar_dir_SUITE.erl b/test/rebar_dir_SUITE.erl index a9e44db..526f827 100644 --- a/test/rebar_dir_SUITE.erl +++ b/test/rebar_dir_SUITE.erl @@ -55,19 +55,19 @@ src_dirs(Config) -> RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar", "baz"]}]}], {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), - ["foo", "bar", "baz"] = rebar_dir:src_dirs(rebar_state:opts(State)). + ["bar", "baz", "foo"] = rebar_dir:src_dirs(rebar_state:opts(State)). extra_src_dirs(Config) -> RebarConfig = [{erl_opts, [{extra_src_dirs, ["foo", "bar", "baz"]}]}], {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), - ["foo", "bar", "baz"] = rebar_dir:extra_src_dirs(rebar_state:opts(State)). + ["bar", "baz", "foo"] = rebar_dir:extra_src_dirs(rebar_state:opts(State)). all_src_dirs(Config) -> RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar"]}, {extra_src_dirs, ["baz", "qux"]}]}], {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), - ["foo", "bar", "baz", "qux"] = rebar_dir:all_src_dirs(rebar_state:opts(State)). + ["bar", "baz", "foo", "qux"] = rebar_dir:all_src_dirs(rebar_state:opts(State)). profile_src_dirs(Config) -> RebarConfig = [ @@ -79,7 +79,7 @@ profile_src_dirs(Config) -> {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "more", "compile"], return), R = lists:sort(["foo", "bar", "baz", "qux"]), - R = lists:sort(rebar_dir:src_dirs(rebar_state:opts(State))). + R = rebar_dir:src_dirs(rebar_state:opts(State)). profile_extra_src_dirs(Config) -> RebarConfig = [ @@ -91,7 +91,7 @@ profile_extra_src_dirs(Config) -> {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "more", "compile"], return), R = lists:sort(["foo", "bar", "baz", "qux"]), - R = lists:sort(rebar_dir:extra_src_dirs(rebar_state:opts(State))). + R = rebar_dir:extra_src_dirs(rebar_state:opts(State)). profile_all_src_dirs(Config) -> RebarConfig = [ @@ -103,7 +103,7 @@ profile_all_src_dirs(Config) -> {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "more", "compile"], return), R = lists:sort(["foo", "bar", "baz", "qux"]), - R = lists:sort(rebar_dir:all_src_dirs(rebar_state:opts(State))). + R = rebar_dir:all_src_dirs(rebar_state:opts(State)). retarget_path(Config) -> {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return), diff --git a/test/rebar_src_dirs_SUITE.erl b/test/rebar_src_dirs_SUITE.erl index 5a00515..f854a94 100644 --- a/test/rebar_src_dirs_SUITE.erl +++ b/test/rebar_src_dirs_SUITE.erl @@ -49,7 +49,7 @@ src_dirs_at_root(Config) -> {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), - ["foo", "bar", "baz"] = rebar_dir:src_dirs(rebar_state:opts(State), []). + ["bar", "baz", "foo"] = rebar_dir:src_dirs(rebar_state:opts(State), []). extra_src_dirs_at_root(Config) -> AppDir = ?config(apps, Config), @@ -62,7 +62,7 @@ extra_src_dirs_at_root(Config) -> {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), - ["foo", "bar", "baz"] = rebar_dir:extra_src_dirs(rebar_state:opts(State), []). + ["bar", "baz", "foo"] = rebar_dir:extra_src_dirs(rebar_state:opts(State), []). src_dirs_in_erl_opts(Config) -> AppDir = ?config(apps, Config), @@ -75,7 +75,7 @@ src_dirs_in_erl_opts(Config) -> {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), - ["foo", "bar", "baz"] = rebar_dir:src_dirs(rebar_state:opts(State), []). + ["bar", "baz", "foo"] = rebar_dir:src_dirs(rebar_state:opts(State), []). extra_src_dirs_in_erl_opts(Config) -> AppDir = ?config(apps, Config), @@ -88,7 +88,7 @@ extra_src_dirs_in_erl_opts(Config) -> {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), - ["foo", "bar", "baz"] = rebar_dir:extra_src_dirs(rebar_state:opts(State), []). + ["bar", "baz", "foo"] = rebar_dir:extra_src_dirs(rebar_state:opts(State), []). src_dirs_at_root_and_in_erl_opts(Config) -> AppDir = ?config(apps, Config), @@ -101,7 +101,7 @@ src_dirs_at_root_and_in_erl_opts(Config) -> {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), - ["baz", "qux", "foo", "bar"] = rebar_dir:src_dirs(rebar_state:opts(State), []). + ["bar", "baz", "foo", "qux"] = rebar_dir:src_dirs(rebar_state:opts(State), []). extra_src_dirs_at_root_and_in_erl_opts(Config) -> AppDir = ?config(apps, Config), @@ -114,7 +114,7 @@ extra_src_dirs_at_root_and_in_erl_opts(Config) -> {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), - ["baz", "qux", "foo", "bar"] = rebar_dir:extra_src_dirs(rebar_state:opts(State), []). + ["bar", "baz", "foo", "qux"] = rebar_dir:extra_src_dirs(rebar_state:opts(State), []). build_basic_app(Config) -> AppDir = ?config(apps, Config), |