From 932bd6dd932e4ffd4bf7ce03abc622d7bd79f3b7 Mon Sep 17 00:00:00 2001 From: Pablo Costas Date: Thu, 25 Jun 2020 20:16:44 +0200 Subject: [PATCH 1/2] Make local commands remove libs before unpacking --- src/rebar_prv_local_install.erl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rebar_prv_local_install.erl b/src/rebar_prv_local_install.erl index 8b0ef48f..9a278dea 100644 --- a/src/rebar_prv_local_install.erl +++ b/src/rebar_prv_local_install.erl @@ -83,6 +83,9 @@ extract_escript(State, ScriptPath) -> throw(?PRV_ERROR({non_writeable, OutputDir})) end, + ?INFO("Removing existing rebar3 libs from ~ts...", [OutputDir]), + rebar_file_utils:rm_rf(filename:join(OutputDir, "*")), + ?INFO("Extracting rebar3 libs to ~ts...", [OutputDir]), zip:extract(Archive, [{cwd, OutputDir}]), From 385c94a4c5ccdcff342b744ccee7d636fdc056df Mon Sep 17 00:00:00 2001 From: Pablo Costas Date: Fri, 26 Jun 2020 15:38:18 +0200 Subject: [PATCH 2/2] 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. --- src/rebar_prv_local_install.erl | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/rebar_prv_local_install.erl b/src/rebar_prv_local_install.erl index 9a278dea..3c8737f1 100644 --- a/src/rebar_prv_local_install.erl +++ b/src/rebar_prv_local_install.erl @@ -61,11 +61,11 @@ format_error({non_writeable, Dir}) -> format_error(Reason) -> io_lib:format("~p", [Reason]). -bin_contents(OutputDir) -> - {ok, Vsn} = application:get_key(rebar, vsn), +bin_contents(OutputDir, Vsn) -> <<"#!/usr/bin/env sh ## Rebar3 ", (iolist_to_binary(Vsn))/binary, " -erl -pz ", (rebar_utils:to_binary(OutputDir))/binary,"/*/ebin +sbtu +A1 -noshell -boot start_clean -s rebar3 main $REBAR3_ERL_ARGS -extra \"$@\" +VSN=${VSN:-", (iolist_to_binary(Vsn))/binary, "} +erl -pz ", (rebar_utils:to_binary(OutputDir))/binary,"/${VSN}/lib/*/ebin +sbtu +A1 -noshell -boot start_clean -s rebar3 main $REBAR3_ERL_ARGS -extra \"$@\" ">>. extract_escript(State, ScriptPath) -> @@ -75,17 +75,16 @@ extract_escript(State, ScriptPath) -> %% Extract contents of Archive to ~/.cache/rebar3/lib %% And add a rebar3 bin script to ~/.cache/rebar3/bin Opts = rebar_state:opts(State), - OutputDir = filename:join(rebar_dir:global_cache_dir(Opts), "lib"), - case filelib:ensure_dir(filename:join(OutputDir, "empty")) of + {ok, Vsn} = application:get_key(rebar, vsn), + VersionsDir = filename:join(rebar_dir:global_cache_dir(Opts), "vsns"), + OutputDir = filename:join([VersionsDir, Vsn, "lib"]), + case filelib:ensure_dir(filename:join([OutputDir, "empty"])) of ok -> ok; {error, Posix} when Posix == eaccess; Posix == enoent -> throw(?PRV_ERROR({non_writeable, OutputDir})) end, - ?INFO("Removing existing rebar3 libs from ~ts...", [OutputDir]), - rebar_file_utils:rm_rf(filename:join(OutputDir, "*")), - ?INFO("Extracting rebar3 libs to ~ts...", [OutputDir]), zip:extract(Archive, [{cwd, OutputDir}]), @@ -94,7 +93,7 @@ extract_escript(State, ScriptPath) -> filelib:ensure_dir(BinFile), ?INFO("Writing rebar3 run script ~ts...", [BinFile]), - file:write_file(BinFile, bin_contents(OutputDir)), + file:write_file(BinFile, bin_contents(VersionsDir, Vsn)), ok = file:write_file_info(BinFile, #file_info{mode=33277}), ?INFO("Add to $PATH for use: export PATH=~ts:$PATH", [BinDir]),