Skip to content

Commit

Permalink
Fix global cache config overriding
Browse files Browse the repository at this point in the history
There was some confusion in the code:

- `rebar_dir:global_config()` returns the default path
- `rebar_dir:global_config(State)` returns the configured path based on
  the ENV overrides, and defaults to `global_config()` if nothing is
  given

Since no State term existed at this point in time, we just called out
directly to the argument-free version of the call, but this ignored all
overrides. Instead, we call it with an initialized `rebar_state:new()` to
properly handle configuration from users, and then use the actual
configured state (if any).
  • Loading branch information
ferd committed Feb 15, 2022
1 parent b5535b3 commit ffae612
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/rebar3.erl
Original file line number Diff line number Diff line change
Expand Up @@ -207,20 +207,21 @@ init_config() ->

Config = rebar_config:consult_root(),
Config1 = rebar_config:merge_locks(Config, rebar_config:consult_lock_file(?LOCK_FILE)),
InitState = rebar_state:new(Config1),

%% If $HOME/.config/rebar3/rebar.config exists load and use as global config
GlobalConfigFile = rebar_dir:global_config(),
GlobalConfigFile = rebar_dir:global_config(InitState),
State = case filelib:is_regular(GlobalConfigFile) of
true ->
?DEBUG("Load global config file ~ts", [GlobalConfigFile]),
try state_from_global_config(Config1, GlobalConfigFile)
catch
_:_ ->
?WARN("Global config ~ts exists but can not be read. Ignoring global config values.", [GlobalConfigFile]),
rebar_state:new(Config1)
InitState
end;
false ->
rebar_state:new(Config1)
InitState
end,

%% Determine the location of the rebar executable; important for pulling
Expand Down
1 change: 1 addition & 0 deletions test/rebar_plugins_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ compile_global_plugins(Config) ->

meck:new(rebar_dir, [passthrough]),
meck:expect(rebar_dir, global_config, fun() -> GlobalConfig end),
meck:expect(rebar_dir, global_config, fun(_) -> GlobalConfig end),
meck:expect(rebar_dir, global_cache_dir, fun(_) -> GlobalDir end),

Name = rebar_test_utils:create_random_name("app1_"),
Expand Down

0 comments on commit ffae612

Please sign in to comment.