Просмотр исходного кода

Support rebar config dir env var

pull/2060/head
Bryan Paxton 6 лет назад
Родитель
Сommit
4fdf2fe089
2 измененных файлов: 39 добавлений и 3 удалений
  1. +9
    -2
      src/rebar_dir.erl
  2. +30
    -1
      test/rebar_dir_SUITE.erl

+ 9
- 2
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().

+ 30
- 1
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)).

Загрузка…
Отмена
Сохранить