Browse Source

Read env var REBAR_CACHE_DIR on rebar3 only once

Instead of reading every time that rebar_dir:global_cache_dir/1 is
called
pull/1121/head
Francisco Rojas 9 years ago
parent
commit
243e94391a
3 changed files with 13 additions and 12 deletions
  1. +10
    -3
      src/rebar3.erl
  2. +2
    -8
      src/rebar_dir.erl
  3. +1
    -1
      test/rebar_dir_SUITE.erl

+ 10
- 3
src/rebar3.erl View File

@ -129,13 +129,20 @@ run_aux(State, RawArgs) ->
%% Initializing project_plugins which can override default providers
State6 = rebar_plugins:project_plugins_install(State5),
State7 = rebar_plugins:top_level_install(State6),
State8 = rebar_state:default(State7, rebar_state:opts(State7)),
State8 = case os:getenv("REBAR_CACHE_DIR") of
false ->
State7;
ConfigFile ->
rebar_state:set(State7, global_rebar_dir, ConfigFile)
end,
State9 = rebar_state:default(State8, rebar_state:opts(State8)),
{Task, Args} = parse_args(RawArgs),
State9 = rebar_state:code_paths(State8, default, code:get_path()),
State10 = rebar_state:code_paths(State9, default, code:get_path()),
rebar_core:init_command(rebar_state:command_args(State9, Args), Task).
rebar_core:init_command(rebar_state:command_args(State10, Args), Task).
init_config() ->
%% Initialize logging system

+ 2
- 8
src/rebar_dir.erl View File

@ -94,14 +94,8 @@ global_config() ->
-spec global_cache_dir(rebar_dict()) -> file:filename_all().
global_cache_dir(Opts) ->
RebarCacheDir = case os:getenv("REBAR_CACHE_DIR") of
false ->
Home = home_dir(),
filename:join([Home, ".cache", "rebar3"]);
ConfigFile ->
ConfigFile
end,
rebar_opts:get(Opts, global_rebar_dir, RebarCacheDir).
Home = home_dir(),
rebar_opts:get(Opts, global_rebar_dir, filename:join([Home, ".cache", "rebar3"])).
local_cache_dir(Dir) ->
filename:join(Dir, ".rebar3").

+ 1
- 1
test/rebar_dir_SUITE.erl View File

@ -25,6 +25,7 @@ init_per_testcase(default_global_cache_dir, Config) ->
,{root_dir, AppsDir}]),
[{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, NewState} | Config];
init_per_testcase(overwrite_default_global_cache_dir, Config) ->
os:putenv("REBAR_CACHE_DIR", ?config(priv_dir, 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}]),
@ -189,7 +190,6 @@ default_global_cache_dir(Config) ->
?assertEqual(Expected, rebar_dir:global_cache_dir(rebar_state:opts(State))).
overwrite_default_global_cache_dir(Config) ->
os:putenv("REBAR_CACHE_DIR", ?config(priv_dir, Config)),
RebarConfig = [{erl_opts, []}],
{ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
Expected = ?config(priv_dir, Config),

Loading…
Cancel
Save