Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 23 additions & 45 deletions python/private/py_executable.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ load(":py_cc_link_params_info.bzl", "PyCcLinkParamsInfo")
load(":py_executable_info.bzl", "PyExecutableInfo")
load(":py_info.bzl", "PyInfo", "VenvSymlinkKind")
load(":py_internal.bzl", "py_internal")
load(":py_runtime_info.bzl", "DEFAULT_STUB_SHEBANG", "PyRuntimeInfo")
load(":py_runtime_info.bzl", "DEFAULT_STUB_SHEBANG")
load(":reexports.bzl", "BuiltinPyInfo", "BuiltinPyRuntimeInfo")
load(":rule_builders.bzl", "ruleb")
load(":toolchain_types.bzl", "EXEC_TOOLS_TOOLCHAIN_TYPE", "TARGET_TOOLCHAIN_TYPE", TOOLCHAIN_TYPE = "TARGET_TOOLCHAIN_TYPE")
Expand Down Expand Up @@ -203,15 +203,6 @@ accepting arbitrary Python versions.
# empty target for other platforms.
default = "//tools/launcher:launcher",
),
"_py_interpreter": lambda: attrb.Label(
# The configuration_field args are validated when called;
# we use the precense of py_internal to indicate this Bazel
# build has that fragment and name.
default = configuration_field(
fragment = "bazel_py",
name = "python_top",
) if py_internal else None,
),
# TODO: This appears to be vestigial. It's only added because
# GraphlessQueryTest.testLabelsOperator relies on it to test for
# query behavior of implicit dependencies.
Expand Down Expand Up @@ -1202,41 +1193,28 @@ def _maybe_get_runtime_from_ctx(ctx):
Returns:
2-tuple of toolchain_runtime, effective_runtime
"""
if ctx.fragments.py.use_toolchains:
toolchain = ctx.toolchains[TOOLCHAIN_TYPE]

if not hasattr(toolchain, "py3_runtime"):
fail("Python toolchain field 'py3_runtime' is missing")
if not toolchain.py3_runtime:
fail("Python toolchain missing py3_runtime")
py3_runtime = toolchain.py3_runtime

# Hack around the fact that the autodetecting Python toolchain, which is
# automatically registered, does not yet support Windows. In this case,
# we want to return null so that _get_interpreter_path falls back on
# --python_path. See tools/python/toolchain.bzl.
# TODO(#7844): Remove this hack when the autodetecting toolchain has a
# Windows implementation.
if py3_runtime.interpreter_path == "/_magic_pyruntime_sentinel_do_not_use":
return None, None

if py3_runtime.python_version != "PY3":
fail("Python toolchain py3_runtime must be python_version=PY3, got {}".format(
py3_runtime.python_version,
))
toolchain_runtime = toolchain.py3_runtime
effective_runtime = toolchain_runtime
else:
toolchain_runtime = None
attr_target = ctx.attr._py_interpreter

# In Bazel, --python_top is null by default.
if attr_target and PyRuntimeInfo in attr_target:
effective_runtime = attr_target[PyRuntimeInfo]
else:
return None, None

return toolchain_runtime, effective_runtime
toolchain = ctx.toolchains[TOOLCHAIN_TYPE]

if not hasattr(toolchain, "py3_runtime"):
fail("Python toolchain field 'py3_runtime' is missing")
if not toolchain.py3_runtime:
fail("Python toolchain missing py3_runtime")
py3_runtime = toolchain.py3_runtime

# Hack around the fact that the autodetecting Python toolchain, which is
# automatically registered, does not yet support Windows. In this case,
# we want to return null so that _get_interpreter_path falls back on
# --python_path. See tools/python/toolchain.bzl.
# TODO(#7844): Remove this hack when the autodetecting toolchain has a
# Windows implementation.
if py3_runtime.interpreter_path == "/_magic_pyruntime_sentinel_do_not_use":
return None, None

if py3_runtime.python_version != "PY3":
fail("Python toolchain py3_runtime must be python_version=PY3, got {}".format(
py3_runtime.python_version,
))
return py3_runtime, py3_runtime

def _get_base_runfiles_for_binary(
ctx,
Expand Down