From 488b167ec4bd3c6a700640044ea62cc1a10a7b69 Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Thu, 23 Apr 2020 14:22:01 +0000 Subject: [PATCH] Annotate generated escript with last release End result should allow to look like this: $ head -n 3 rebar3 #!/usr/bin/env escript %% Rebar3 3.14.0-rc1 %%! +sbtu +A1 This will allow tools like mix to read the top of the file to know the version being used in the current path (when using features that aren't forwards-compatible) without having to invoke the tool itself. The version (full dynamic one) is also added to the local install: $ head -n 2 /home/ferd/.cache/rebar3/bin/rebar3 #!/usr/bin/env sh ## Rebar3 3.14.0-rc1+build.4599.ref6b0f90d The `##` comments are used to keep a fixed width over the other form. To be backported to 3.13.2 as well. --- rebar.config | 1 + src/rebar_prv_local_install.erl | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/rebar.config b/rebar.config index dc1eceb1..ee192d9f 100644 --- a/rebar.config +++ b/rebar.config @@ -24,6 +24,7 @@ ]}. {escript_name, rebar3}. +{escript_comment, "%%Rebar3 3.14.0-rc1\n"}. {escript_emu_args, "%%! +sbtu +A1\n"}. %% escript_incl_extra is for internal rebar-private use only. %% Do not use outside rebar. Config interface is not stable. diff --git a/src/rebar_prv_local_install.erl b/src/rebar_prv_local_install.erl index cd6a2047..8b0ef48f 100644 --- a/src/rebar_prv_local_install.erl +++ b/src/rebar_prv_local_install.erl @@ -62,8 +62,9 @@ format_error(Reason) -> io_lib:format("~p", [Reason]). bin_contents(OutputDir) -> + {ok, Vsn} = application:get_key(rebar, 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 \"$@\" ">>.