rebar3
rebar3 copied to clipboard
REBAR_CACHE_DIR and global config clash
When setting REBAR_CACHE_DIR
the internal config of global_rebar_dir
get's set with that prefix (see apps/rebar/src/rebar3.erl:427).
Some things that are looking for global configuration will actually end up in REBAR_CACHE_DIR/.config/rebar3/...
which is wrong (in my opinion).
One example where this becomes a problem would be the templating system, which uses rebar_dir:template_dir(State)
. That function in turn eventually gets the value for global_rebar_dir
, as set above. E.g. if REBAR_CACHE_DIR
is set to ~/.cache/rebar3
templates are looked for in ~/.cache/rebar3/.config/rebar3/templates
which is incorrect.
There is a workaround, which is setting REBAR_GLOBAL_CONFIG_DIR
too. That variable has it's own issues, in that it needs to be set to $HOME
(and not $HOME/.config/rebar3
which one would think, so that's probably another bug).
There is also an internal config called global_cache_dir
but if rebar3.erl
is changed to set that instead, it also doesn't work correctly.
It seems settingglobar_rebar_dir
if REBAR_CACHE_DIR
is set is too heavy-handed, but a better implementation is not obvious to me. What would be the correct fix for these issues?
Some things that are looking for global configuration will actually end up in REBAR_CACHE_DIR/.config/rebar3/... which is wrong (in my opinion).
I faced this issue today when I tried to use rebar3 with kerl, where kerl defines the REBAR_CACHE_DIR environment variable specific for each OTP installation. The rebar3 new
command didn't look up ~/.config/rebar3/templates, and it took a few hours for me to find out why by thoroughly reviewing the source code.
I looked at this, and reading @eproxus' comment, I'm as confused regarding what should be set. I do agree that it seems odd we're setting global_rebar_dir
for REBAR_CACHE_DIR
(this appears to be done twice), but I didn't dig much further.
Yeah I think I recall digging in slack, and the unfortunate state is that this stuff is all very inconsistent and will be hard to fix without breaking anyone's setup. This would need a full re-mapping and clean-up to re-define where the values are set, what they mean, and how they're used.
It's very possible right now that it was intended one way in a code area, and was used another one in another area, and that there's no way to fix this without willingly breaking either pattern in a specific context.
One thing I'd like to suggest is that this behavior of ${REBAR_CACHE_DIR/.config/rebar3/templates
and the other affected settings should be documented. I couldn't find the document.
I just came across this issue as well (with an automated template install that wasn't being recognized), and my solution was to make a little plugin for outputting directories.
https://github.com/choptastic/rebar3_dirs and https://hex.pm/packages/rebar3_dirs
At least this way, I can use something that, should this functionality ever change, will hopefully remain backwards compatible, rather than having to know and then code around the internal logic for where the config directory ends up.
$ rebar3 dirs template_dir
/home/gumm/kerl/26.2.4/.cache/rebar3/.config/rebar3/templates
$ rebar3 dirs
base_dir: /home/gumm/code/myapp/_build/default
deps_dir: /home/gumm/code/myapp/_build/default/lib
root_dir: /home/gumm/code/myapp/.
checkouts_dir: /home/gumm/code/myapp/_checkouts
checkouts_out_dir: /home/gumm/code/myapp/_build/default/checkouts
plugins_dir: /home/gumm/code/myapp/_build/default/plugins
lib_dirs: apps/*lib/*.
project_plugin_dirs: plugins/*
global_config_dir: /home/gumm/kerl/26.2.4/.cache/rebar3/.config/rebar3
global_config: /home/gumm/kerl/26.2.4/.cache/rebar3/.config/rebar3/rebar.config
template_dir: /home/gumm/kerl/26.2.4/.cache/rebar3/.config/rebar3/templates
@choptastic That should be built into Rebar itself! ❤️
@choptastic That should be built into Rebar itself! ❤️
I certainly appreciate the appreciation.
I'll gladly submit a PR to rebar3 if the team wants.
I wouldn't be opposed to having this sort of stuff built in, though there's some potential confusion around what we do for subtasks and hooks' env vars: https://github.com/erlang/rebar3/blob/main/apps/rebar/src/rebar_env.erl