summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Sloughter <t@crashfast.com>2019-08-11 14:01:51 -0600
committerTristan Sloughter <t@crashfast.com>2019-08-11 14:01:51 -0600
commit9402857f5527e300bf28b7e3744bef3fc88f3379 (patch)
treebbea88d606a668871a94d7623b6f78b213c3ecce
parent6abe440ec550dc91354456417d03d5b77dd7adfe (diff)
support REBAR_BASE_DIR for setting the base_dir
-rw-r--r--src/rebar3.erl8
-rw-r--r--test/rebar_dir_SUITE.erl28
2 files changed, 31 insertions, 5 deletions
diff --git a/src/rebar3.erl b/src/rebar3.erl
index a490a15..9112346 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -151,8 +151,12 @@ run_aux(State, RawArgs) ->
%% bootstrap test profile
State3 = rebar_state:add_to_profile(State2_, test, test_state(State1)),
- %% Process each command, resetting any state between each one
- BaseDir = rebar_state:get(State, base_dir, ?DEFAULT_BASE_DIR),
+ BaseDir = case os:getenv("REBAR_BASE_DIR") of
+ D when D =:= false orelse D =:= "" ->
+ rebar_state:get(State, base_dir, ?DEFAULT_BASE_DIR);
+ Dir ->
+ Dir
+ end,
State4 = rebar_state:set(State3, base_dir,
filename:join(filename:absname(rebar_state:dir(State3)), BaseDir)),
diff --git a/test/rebar_dir_SUITE.erl b/test/rebar_dir_SUITE.erl
index 2a5d0ca..a1f2ef8 100644
--- a/test/rebar_dir_SUITE.erl
+++ b/test/rebar_dir_SUITE.erl
@@ -8,7 +8,7 @@
-export([top_src_dirs/1]).
-export([profile_src_dirs/1, profile_extra_src_dirs/1, profile_all_src_dirs/1]).
-export([profile_src_dir_opts/1]).
--export([retarget_path/1, alt_base_dir_abs/1, alt_base_dir_rel/1]).
+-export([retarget_path/1, alt_base_dir_abs/1, alt_base_dir_env_variable_abs/1, alt_base_dir_rel/1]).
-export([global_cache_dir/1, default_global_cache_dir/1, overwrite_default_global_cache_dir/1]).
-export([default_global_config/1, overwrite_default_global_config/1]).
@@ -21,8 +21,8 @@ all() -> [default_src_dirs, default_extra_src_dirs, default_all_src_dirs,
src_dirs, alt_src_dir_nested, extra_src_dirs, all_src_dirs, src_dir_opts, recursive,
profile_src_dirs, profile_extra_src_dirs, profile_all_src_dirs,
profile_src_dir_opts, top_src_dirs,
- retarget_path, alt_base_dir_abs, alt_base_dir_rel, global_cache_dir,
- default_global_cache_dir, overwrite_default_global_cache_dir,
+ retarget_path, alt_base_dir_abs, alt_base_dir_env_variable_abs, alt_base_dir_rel,
+ global_cache_dir, default_global_cache_dir, overwrite_default_global_cache_dir,
default_global_config, overwrite_default_global_config].
init_per_testcase(default_global_cache_dir, Config) ->
@@ -261,6 +261,28 @@ alt_base_dir_abs(Config) ->
?assert(filelib:is_file(filename:join([BaseDir, "lib", Name2, "ebin", Name2++".app"]))),
?assert(filelib:is_file(filename:join([BaseDir, "lib", Name2, "ebin", Name2++".beam"]))).
+alt_base_dir_env_variable_abs(Config) ->
+ AltName = lists:flatten(io_lib:format("~p", [os:timestamp()])),
+ AltBaseDir = filename:join(?config(priv_dir, Config), AltName),
+ RebarConfig = [],
+
+ true = os:putenv("REBAR_BASE_DIR", AltBaseDir),
+ {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
+ true = os:unsetenv("REBAR_BASE_DIR"),
+
+ BaseDir = rebar_dir:base_dir(State),
+ ?assertEqual(filename:join(AltBaseDir, "default"), BaseDir),
+
+ Name1 = ?config(app_one, Config),
+ Name2 = ?config(app_two, Config),
+
+ ?assert(filelib:is_dir(filename:join([BaseDir, "lib", Name1, "ebin"]))),
+ ?assert(filelib:is_file(filename:join([BaseDir, "lib", Name1, "ebin", Name1++".app"]))),
+ ?assert(filelib:is_file(filename:join([BaseDir, "lib", Name1, "ebin", Name1++".beam"]))),
+ ?assert(filelib:is_dir(filename:join([BaseDir, "lib", Name2, "ebin"]))),
+ ?assert(filelib:is_file(filename:join([BaseDir, "lib", Name2, "ebin", Name2++".app"]))),
+ ?assert(filelib:is_file(filename:join([BaseDir, "lib", Name2, "ebin", Name2++".beam"]))).
+
alt_base_dir_rel(Config) ->
AltName = lists:flatten(io_lib:format("~p", [os:timestamp()])),
AltBaseDir = filename:join("..", AltName),