-
Notifications
You must be signed in to change notification settings - Fork 4.4k
No way to run action with a modified version of default_shell_env #4912
Description
First of all, I started writing this issue as a bug since a recent commit broke my code but then I thought it could be also a feature request. If you think it is more of a FR than a bug, please tell me and I will edit it to match the correct format.
Description of the problem / feature request:
Since 0f5679e, ctx.configuration.default_shell_env would return an empty dictionary on Linux; Bazel no longer inherits environment variables from the compiling host in the analysis phase but only in execution time (according to @ulfjack 's comments on BazelConfiguration.java#135). However, that make it impossible to append environment variable to the default shell environment.
I can't think of a good way to solve this problem without a magic value that get changed on execution time (similar to cmake's generator expressions). Another way is to maybe transparently return a unique UncookedDefaultEnv from ctx.configuration.default_shell_env that will behave like a regular dictionary and would transparently forward null keys to the action, to be replaced in execution time.
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
example.bzl:
def _impl(ctx):
# Add 'TheAnswer' to the default shell environment.
environment_vars = ctx.configuration.default_shell_env
environment_vars['TheAnswer'] = '42'
ctx.actions.run_shell(
outputs = [ctx.outputs.dummy],
command='env && touch dummy',
env = environment_vars,
)
example = rule(
implementation=_impl,
outputs = {
'dummy':'dummy'
}
)BUILD:
load(':example.bzl', 'example')
example(name='example')Example output with bazel 0.11.1
...
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl
...
Example output for the current master:
PWD=/home/reflexe/.cache/bazel/_bazel_reflexe/95fc1ed1afdc0650f9a0db1c7a4b7c34/sandbox/9014715435859486979/execroot/__main__
TMPDIR=/tmp
TheAnswer=42
SHLVL=1
_=/usr/bin/env
Result: you should see that the output of env does not contain the default PATH.
What operating system are you running Bazel on?
Linux - ArchLinux
What's the output of bazel info release?
development version
If bazel info release returns "development version" or "(@Non-Git)", tell us how you built Bazel.
$ git clone github://bazelbuild/bazel
$ bazel build //src:bazelWhat's the output of git remote get-url origin ; git rev-parse master ; git rev-parse HEAD ?
https://github.com/bazelbuild/bazel
bffa2db380cb3ca2fd9262ac5a45d02518376e03
bffa2db380cb3ca2fd9262ac5a45d02518376e03
And I need to say that every time, thank you very much for this amazing thing called Bazel. It feels so right to use it; and the best and somehow the simplest build system I ever had to use. Just thanks :)