-
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
Windows, launcher: support python/bash toolchain #8440
Conversation
dc91ade
to
4e2762f
Compare
src/tools/launcher/bash_launcher.cc
Outdated
@@ -30,6 +30,10 @@ static constexpr const char* BASH_BIN_PATH = "bash_bin_path"; | |||
|
|||
ExitCode BashBinaryLauncher::Launch() { | |||
wstring bash_binary = this->GetLaunchInfoByKey(BASH_BIN_PATH); | |||
|
|||
// Rlocation returns the original path if bash_binary is an absolute path. | |||
bash_binary = this->Rlocation(bash_binary, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the input bash_binary
ever be just bash.exe
for example, which would mean "whatever is on the PATH"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are two ways to tell which shell binary to use, BAZEL_SH
or --shell_executable
. Both way requires user to set an absolute path. The only case bash_binary
is a relative path (runfile path) is that when using shell toolchain (similar to python toolchain), but I'm not sure it's implemented.
@@ -30,6 +30,10 @@ static constexpr const char* WINDOWS_STYLE_ESCAPE_JVM_FLAGS = "escape_args"; | |||
|
|||
ExitCode PythonBinaryLauncher::Launch() { | |||
wstring python_binary = this->GetLaunchInfoByKey(PYTHON_BIN_PATH); | |||
|
|||
// Rlocation returns the original path if python_binary is an absolute path. | |||
python_binary = this->Rlocation(python_binary, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But here, python_binary
will just be python
if nothing is specified.. I need to fix this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, let me know when the PR is ready for another review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching the problem! Please take a look again. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, just realized I had a typo. It should be GetBinaryPathWithoutExtension(bash_binary) != L"bash")
, GetBinaryPathWithoutExtension
just strips out the ending .exe
if there is any. I wanted to check if bash_binary is already bash
or bash.exe
. Similar for the python case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add comment for this!
@@ -30,6 +30,12 @@ static constexpr const char* WINDOWS_STYLE_ESCAPE_JVM_FLAGS = "escape_args"; | |||
|
|||
ExitCode PythonBinaryLauncher::Launch() { | |||
wstring python_binary = this->GetLaunchInfoByKey(PYTHON_BIN_PATH); | |||
|
|||
if (GetBinaryPathWithoutExtension(python_binary) == L"python") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What other values could python_binary
have, and in what situations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to shell, we have
--python_path
, gives an absolute path--python_top
, gives an runfile path- python toolchain (
py_runtime
), gives a runfile path - Default if nothing specified:
python
@brandjon Can confirm this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Waiting for @brandjon to confirm before LGTM. Please add a comment in the code summarizing Jon's answer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both --python_top
and Python toolchains select a py_runtime
to use. py_runtime
provides a runfiles path if its interpreter
attribute is set, and an absolute path if its interpreter_path
attribute is set (these attributes are exclusive).
--python_path
is validated to be an absolute path. If nothing is specified, the python
default is passed along the same code path that --python_path
uses but skips this validation check as a special case. It is intended that both of these approaches are deprecated and replaced by toolchains, with the python
PATH lookup behavior provided by an autodetecting toolchain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the confirmation, I'll add those to comment
I don't understand how this change is supposed to work. How do you rlocation a binary in runfiles if the runfiles are packed in a zip that has yet to be extracted (by the zip file's I'm not sure how much test coverage for Python we have on windows. Some of the tests I wrote I've disabled because we haven't had both Python 2 and 3 on the test machines until recently. See #8411. |
We don't rlocation in runfiles, the rlocation function reads the MANIFEST file and maps a runfile path (relative path) to its absolute path. This way doesn't care if there is a runfiles tree or not, so it will also work when people using
Yes, we definitely need to enable those test. |
And I presume the code works with |
Yes, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, please wait for Jon's LGTM too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but please wait for my fix to #8411 so we have some test coverage.
@@ -30,6 +30,17 @@ static constexpr const char* WINDOWS_STYLE_ESCAPE_JVM_FLAGS = "escape_args"; | |||
|
|||
ExitCode PythonBinaryLauncher::Launch() { | |||
wstring python_binary = this->GetLaunchInfoByKey(PYTHON_BIN_PATH); | |||
|
|||
// The value of python_binary could be the following cases: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrite comment as follows:
There are three kinds of values for
python_binary
:
- An absolute path to a system interpreter. This is the case if
--python_path
is set by the user, or if apy_runtime
is used that hasinterpreter_path
set.- A runfile path to an in-workspace interpreter. This is the case if a
py_runtime
is used that hasinterpreter
set.- The special constant, "python". This is the default case if neither of the above apply.
Rlocation resolves runfiles paths to absolute paths, and if given an absolute path it leaves it alone, so it's suitable for cases 1 and 2.
There's a slight detail that the default toolchain's py_runtime on windows contains a sentinel value hack that tells bazel to use legacy --python_path, but I don't think we need to mention that in this comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for help with the comment!
Previously, we assume the python/bash binary path passed to the launcher is an absolute path specified by `--python_path` or `--shell_executable`, but this is not true when using python/shell toolchain. When using the python toolchain, the given python binary path will be a runfile path, we can use `Rlocation` to find the absolute path. Fixes bazelbuild#7947 Closes bazelbuild#8440. PiperOrigin-RevId: 250569171
Previously, we assume the python/bash binary path passed to the launcher is an absolute path specified by `--python_path` or `--shell_executable`, but this is not true when using python/shell toolchain. When using the python toolchain, the given python binary path will be a runfile path, we can use `Rlocation` to find the absolute path. Fixes bazelbuild#7947 Closes bazelbuild#8440. PiperOrigin-RevId: 250569171
Previously, we assume the python/bash binary path passed to the launcher is an absolute path specified by
--python_path
or--shell_executable
, but this is not true when using python/shell toolchain. When using the python toolchain, the given python binary path will be a runfile path, we can useRlocation
to find the absolute path.Fixes #7947