-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No way to run action with a modified version of default_shell_env #4912
Comments
@ulfjack I see you did the original change referenced in this bug and this is assigned to you. Any thoughts on what the right behavior should be here? |
The problem is that we need to merge the environment set on the command-line with My personal preference is that the |
Note also that default_shell_env is a misnomer. We probably need to enforce that |
This is the exact problem I'm running into as well. The |
This workaround doesn't properly inherit values, but it allows for setting defaults that can be copied from the host environment. # .env.bazelrc: this file is like a .env file but in bazel CLI style.
build --action_env FOO=bar --action_env BAR=foo # .bazelrc: the configuration simply imports the environment if available.
try-import %workspace%/.env.bazelrc # example.bzl: example implementation showing that environment variables are available.
def _impl(ctx):
print(ctx.configuration.default_shell_env)
example = rule(
implementation=_impl,
) # BUILD: example invocation.
load("//:example.bzl", "example")
example(name="example") bazel build //:example
# DEBUG: /path/to/BUILD: {"FOO": "bar", "BAR": "foo"} This is of course not as nice as being able to use the host environment directly, but copying the relevant environment variables to |
Got hit by this too. I'm using Can someone confirm if this is actually a bug or an expected behavior? |
Is this fixed by #19317? |
Only partially. You can now choose to inherit the |
Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale. |
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
fromctx.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
:BUILD
:Example output with bazel 0.11.1
Example output for the current master:
Result: you should see that the output of
env
does not contain the defaultPATH
.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.What's the output of
git remote get-url origin ; git rev-parse master ; git rev-parse HEAD
?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 :)
The text was updated successfully, but these errors were encountered: