-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
bazel run
of py_binary
target uses client PATH
#8425
Comments
#7026 might be relevant to this. Not sure.
The stub script should be able to run on any reasonable modern system Python interpreter. If it can't we'd probably consider that a bug. Alternatively, we could add a feature to customize the shebang, but I'd like to avoid that for now if possible. The problems with how the environment is setup for an in-workspace Edit: For example, it might be that we're adding a bunch of artifacts instead of using something like Edit edit: And sure enough, here's my previous writeup of what I was thinking of, which may or may not be the cause of this issue. |
bazel run
of py_binary
target uses client PATH
After doing more experimentation for #8536, it appears that the action environment, whether set by So I think the question is whether action environments should override the client environment for executable artifacts that are not being used as tools for other build steps. I can make an argument that they shouldn't: For instance, you wouldn't be able to write a command line tool that inspects the current environment and launch that tool with In any case, to the extent that this interferes with a |
I can confirm that this same environment behavior is present for the java rules: So the real issue here is how Python artifacts depend on the |
@brandjon any advice on how to go about fixing this? We had our first case of this actually causing issues today where because of this |
Turns out this issue affects more than just py #12049 |
OK, then let's close this as a duplicate of #12049. |
Description of the problem:
Currently when setting up a
py_runtime
, any script you have called for theinterpreter
isn't called with anyPATH
, and ends up defaulting to the shell's defaultPATH
, which can lead to using the wrong binaries depending on your system's configuration.This was discovered while debugging #8414
In our case we exec bazel with
env -i PATH=/usr/bin:/bin
and pass--action_env=PATH=/usr/bin:/bin
because we don't want user configuration to leak into the build. Because of this issue, you can see the error message in the linked issue is:Where this default path (on macOS) appears to be coming from bash's default path (where
/bin/sh
on macOS is actually just bash), which is defined as:Not being called with a
PATH
is what causes #8414 (although because of this default PATH you canexport PATH
to fix the specific issues there).This issue cascades to this script as well https://github.com/bazelbuild/bazel/blob/b7a961517f928e6539b62f73bcb5b1c311396559/src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt that asks for
/usr/bin/env python
, which has to be pulled from the default PATH, which could result in a homebrew installed python (on macOS) instead of the system one.It also attempts to read the
PATH
environment variable directlybazel/src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt
Line 46 in b7a9615
I believe the
interpreter
set forpy_runtime
should inherit the--action_env=PATH
value set, if it is, and otherwise bazel should be calling these with a default PATH, and not falling back on the shell to do this itself.Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Make the auto detection wrapper script
echo $PATH
andexit 1
https://github.com/bazelbuild/bazel/blob/1193e696b08f0932e1430c87dcfb51fe6c18d7e9/tools/python/pywrapper_template.txt and try to build a python targetWhat operating system are you running Bazel on?
macOS
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.bazel build src:bazel
What's the output of
git remote get-url origin ; git rev-parse master ; git rev-parse HEAD
?https://github.com/bazelbuild/bazel
1193e69
1193e69
Have you found anything relevant by searching the web?
Related to #8414
The text was updated successfully, but these errors were encountered: