Skip to content

Commit 385c94a

Browse files
committed
Extract rebar3 libs in a version dependent directory
This commit changes the location where rebar3 will extract its libs upon calling a `local` command from `~/.cache/rebar3/lib` to `~/.cache/rebar3/vsns/VERSION/lib`, with `VERSION` being rebar3 current version. It also updates the bin script to reflect these changes.
1 parent 932bd6d commit 385c94a

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/rebar_prv_local_install.erl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ format_error({non_writeable, Dir}) ->
6161
format_error(Reason) ->
6262
io_lib:format("~p", [Reason]).
6363

64-
bin_contents(OutputDir) ->
65-
{ok, Vsn} = application:get_key(rebar, vsn),
64+
bin_contents(OutputDir, Vsn) ->
6665
<<"#!/usr/bin/env sh
6766
## Rebar3 ", (iolist_to_binary(Vsn))/binary, "
68-
erl -pz ", (rebar_utils:to_binary(OutputDir))/binary,"/*/ebin +sbtu +A1 -noshell -boot start_clean -s rebar3 main $REBAR3_ERL_ARGS -extra \"$@\"
67+
VSN=${VSN:-", (iolist_to_binary(Vsn))/binary, "}
68+
erl -pz ", (rebar_utils:to_binary(OutputDir))/binary,"/${VSN}/lib/*/ebin +sbtu +A1 -noshell -boot start_clean -s rebar3 main $REBAR3_ERL_ARGS -extra \"$@\"
6969
">>.
7070

7171
extract_escript(State, ScriptPath) ->
@@ -75,17 +75,16 @@ extract_escript(State, ScriptPath) ->
7575
%% Extract contents of Archive to ~/.cache/rebar3/lib
7676
%% And add a rebar3 bin script to ~/.cache/rebar3/bin
7777
Opts = rebar_state:opts(State),
78-
OutputDir = filename:join(rebar_dir:global_cache_dir(Opts), "lib"),
79-
case filelib:ensure_dir(filename:join(OutputDir, "empty")) of
78+
{ok, Vsn} = application:get_key(rebar, vsn),
79+
VersionsDir = filename:join(rebar_dir:global_cache_dir(Opts), "vsns"),
80+
OutputDir = filename:join([VersionsDir, Vsn, "lib"]),
81+
case filelib:ensure_dir(filename:join([OutputDir, "empty"])) of
8082
ok ->
8183
ok;
8284
{error, Posix} when Posix == eaccess; Posix == enoent ->
8385
throw(?PRV_ERROR({non_writeable, OutputDir}))
8486
end,
8587

86-
?INFO("Removing existing rebar3 libs from ~ts...", [OutputDir]),
87-
rebar_file_utils:rm_rf(filename:join(OutputDir, "*")),
88-
8988
?INFO("Extracting rebar3 libs to ~ts...", [OutputDir]),
9089
zip:extract(Archive, [{cwd, OutputDir}]),
9190

@@ -94,7 +93,7 @@ extract_escript(State, ScriptPath) ->
9493
filelib:ensure_dir(BinFile),
9594

9695
?INFO("Writing rebar3 run script ~ts...", [BinFile]),
97-
file:write_file(BinFile, bin_contents(OutputDir)),
96+
file:write_file(BinFile, bin_contents(VersionsDir, Vsn)),
9897
ok = file:write_file_info(BinFile, #file_info{mode=33277}),
9998

10099
?INFO("Add to $PATH for use: export PATH=~ts:$PATH", [BinDir]),

0 commit comments

Comments
 (0)