Skip to content

Add REBAR to environment before executing hooks #229

Merged
merged 1 commit into from Jun 14, 2014

5 participants

@tolbrino

REBAR will be set to the rebar binary which was executed and runs the
builds. Enables the use of the same binary for rebar invocations as
part of a pre or post hook like so:

${REBAR} escriptize
@tuncer tuncer commented on an outdated diff Feb 24, 2014
src/rebar_utils.erl
@@ -508,3 +508,17 @@ filter_defines([{platform_define, ArchRegex, Key, Value} | Rest], Acc) ->
end;
filter_defines([Opt | Rest], Acc) ->
filter_defines(Rest, [Opt | Acc]).
+
+patch_env([]) ->
+ [];
+patch_env([{env, Env0} | Rest]) ->
+ Env = try
+ Path = escript:script_name(),
+ [{"REBAR", Path} | Env0]
+ catch
+ _:_ -> % rebar was involed programmatically
@tuncer
tuncer added a note Feb 24, 2014

s/involed/invoked/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@uwiger
uwiger commented Feb 24, 2014

Note, it really needs to be filename:absname(escript:script_name()) in order to have a working path once rebar moves down into dependent apps.

BTW, this is already stored in xconf here:
https://github.com/rebar/rebar/blob/master/src/rebar.erl#L156

@tuncer
tuncer commented Feb 24, 2014

@uwiger good catch, that can and should be reused.

@tuncer tuncer commented on an outdated diff Feb 24, 2014
src/rebar_utils.erl
@@ -508,3 +508,17 @@ filter_defines([{platform_define, ArchRegex, Key, Value} | Rest], Acc) ->
end;
filter_defines([Opt | Rest], Acc) ->
filter_defines(Rest, [Opt | Acc]).
+
+patch_env([]) ->
+ [];
+patch_env([{env, Env0} | Rest]) ->
+ Env = try
+ Path = escript:script_name(),
@tuncer
tuncer added a note Feb 24, 2014

As @uwiger suggested, we should reuse the existing xconf variable here:

Path = rebar_config:get_xconf(Config, escript, ""),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@tolbrino

Thanks guys, I've updated the PR.

@tuncer tuncer commented on an outdated diff Feb 24, 2014
src/rebar_utils.erl
@@ -314,6 +315,21 @@ processing_base_dir(Config) ->
processing_base_dir(Config, Dir) ->
Dir =:= rebar_config:get_xconf(Config, base_dir).
+%% @doc Returns list of environment variables including 'REBAR' which points to the rebar executable used to execute the currently running command. The environment is not modified if rebar was invoked programmatically.
@tuncer
tuncer added a note Feb 24, 2014

Overlong line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Vagabond
Vagabond commented Mar 5, 2014

This looks fine, just needs a rebase.

@tuncer
tuncer commented May 29, 2014

What's the status?

@tolbrino tolbrino Add REBAR to environment before executing hooks
REBAR will be set to the rebar binary which was executed and runs the
builds. Enables the use of the same binary for rebar invocations as
part of a pre or post hook like so:

    ${REBAR} escriptize
9c23dfe
@tolbrino
tolbrino commented Jun 2, 2014

I've rebased the patch. It's been in use without issues.

@tsloughter tsloughter merged commit 9380583 into rebar:master Jun 14, 2014

1 check passed

Details continuous-integration/travis-ci The Travis CI build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.