summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar_dir.erl11
-rw-r--r--test/rebar_dir_SUITE.erl31
2 files changed, 39 insertions, 3 deletions
diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl
index 17bc48e..aac6210 100644
--- a/src/rebar_dir.erl
+++ b/src/rebar_dir.erl
@@ -107,8 +107,15 @@ home_dir() ->
%% may be stored.
-spec global_config_dir(rebar_state:t()) -> file:filename_all().
global_config_dir(State) ->
- Home = home_dir(),
- rebar_state:get(State, global_rebar_dir, filename:join([Home, ".config", "rebar3"])).
+ filename:join([rebar_config_dir(State), ".config", "rebar3"]).
+
+rebar_config_dir(State) ->
+ case os:getenv("REBAR_GLOBAL_CONFIG_DIR") of
+ false ->
+ rebar_state:get(State, global_rebar_dir, home_dir());
+ ConfDir ->
+ ConfDir
+ end.
%% @doc returns the path of the global rebar.config file
-spec global_config(rebar_state:t()) -> file:filename_all().
diff --git a/test/rebar_dir_SUITE.erl b/test/rebar_dir_SUITE.erl
index 81051e6..2a5d0ca 100644
--- a/test/rebar_dir_SUITE.erl
+++ b/test/rebar_dir_SUITE.erl
@@ -10,6 +10,7 @@
-export([profile_src_dir_opts/1]).
-export([retarget_path/1, alt_base_dir_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]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -21,7 +22,8 @@ all() -> [default_src_dirs, default_extra_src_dirs, default_all_src_dirs,
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].
+ default_global_cache_dir, overwrite_default_global_cache_dir,
+ default_global_config, overwrite_default_global_config].
init_per_testcase(default_global_cache_dir, Config) ->
[{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, _State} | Config] = rebar_test_utils:init_rebar_state(Config),
@@ -34,6 +36,19 @@ init_per_testcase(overwrite_default_global_cache_dir, Config) ->
NewState = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])}
,{root_dir, AppsDir}]),
[{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, NewState} | Config];
+init_per_testcase(default_global_config, Config) ->
+ [{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, _State} | Config] = rebar_test_utils:init_rebar_state(Config),
+ NewState = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])}
+ ,{root_dir, AppsDir}]),
+ [{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, NewState} | Config];
+init_per_testcase(overwrite_default_global_config, Config) ->
+ ConfDir = filename:join([?config(priv_dir, Config), "custom"]),
+ ok = file:make_dir(ConfDir),
+ os:putenv("REBAR_GLOBAL_CONFIG_DIR", ConfDir),
+ [{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, _State} | Config] = rebar_test_utils:init_rebar_state(Config),
+ NewState = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])}
+ ,{root_dir, AppsDir}]),
+ [{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, NewState} | Config];
init_per_testcase(_, Config) ->
C = rebar_test_utils:init_rebar_state(Config),
AppDir = ?config(apps, C),
@@ -282,3 +297,17 @@ overwrite_default_global_cache_dir(Config) ->
{ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
Expected = ?config(priv_dir, Config),
?assertEqual(Expected, rebar_dir:global_cache_dir(rebar_state:opts(State))).
+
+default_global_config(Config) ->
+ RebarConfig = [{erl_opts, []}],
+ {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
+ ConfDir = ?config(priv_dir, Config),
+ Expected = filename:join([ConfDir, ".config", "rebar3", "rebar.config"]),
+ ?assertEqual(Expected, rebar_dir:global_config(State)).
+
+overwrite_default_global_config(Config) ->
+ RebarConfig = [{erl_opts, []}],
+ {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
+ Expected = filename:join([os:getenv("REBAR_GLOBAL_CONFIG_DIR"), ".config", "rebar3", "rebar.config"]),
+ rebar_dir:global_config(State),
+ ?assertEqual(Expected, rebar_dir:global_config(State)).