@@ -61,11 +61,11 @@ format_error({non_writeable, Dir}) ->
61
61
format_error (Reason ) ->
62
62
io_lib :format (" ~p " , [Reason ]).
63
63
64
- bin_contents (OutputDir ) ->
65
- {ok , Vsn } = application :get_key (rebar , vsn ),
64
+ bin_contents (OutputDir , Vsn ) ->
66
65
<<" #!/usr/bin/env sh
67
66
## 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 \" $@\"
69
69
" >>.
70
70
71
71
extract_escript (State , ScriptPath ) ->
@@ -75,8 +75,10 @@ extract_escript(State, ScriptPath) ->
75
75
% % Extract contents of Archive to ~/.cache/rebar3/lib
76
76
% % And add a rebar3 bin script to ~/.cache/rebar3/bin
77
77
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
80
82
ok ->
81
83
ok ;
82
84
{error , Posix } when Posix == eaccess ; Posix == enoent ->
@@ -91,7 +93,7 @@ extract_escript(State, ScriptPath) ->
91
93
filelib :ensure_dir (BinFile ),
92
94
93
95
? INFO (" Writing rebar3 run script ~ts ..." , [BinFile ]),
94
- file :write_file (BinFile , bin_contents (OutputDir )),
96
+ file :write_file (BinFile , bin_contents (VersionsDir , Vsn )),
95
97
ok = file :write_file_info (BinFile , # file_info {mode = 33277 }),
96
98
97
99
? INFO (" Add to $PATH for use: export PATH=~ts :$PATH" , [BinDir ]),
0 commit comments