Skip to content

Commit

Permalink
Modify provider and modify py_executable
Browse files Browse the repository at this point in the history
  • Loading branch information
mishazharov committed Dec 31, 2023
1 parent c60b21f commit 7cf394f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions python/private/common/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def _PyRuntimeInfo_init(
interpreter_path = None,
interpreter = None,
files = None,
runfiles = None,
coverage_tool = None,
coverage_files = None,
python_version,
Expand Down Expand Up @@ -73,8 +74,11 @@ def _PyRuntimeInfo_init(
if interpreter:
if files == None:
files = depset()

# Not really sure if we can default initialize `runfiles` here
else:
files = None
runfiles = None

if coverage_files == None:
coverage_files = depset()
Expand All @@ -90,6 +94,7 @@ def _PyRuntimeInfo_init(
"interpreter": interpreter,
"interpreter_path": interpreter_path,
"python_version": python_version,
"runfiles": runfiles,
"stub_shebang": stub_shebang,
}

Expand Down Expand Up @@ -141,6 +146,10 @@ the same conventions as the standard CPython interpreter.
"Valid values are (only) `\"PY2\"` and " +
"`\"PY3\"`."
),
"runfiles": (
"If this is an in-build runtime, this field can be used to specify a" +
"`runfiles` object which will be used during execution of the interpreter"
),
"stub_shebang": (
"\"Shebang\" expression prepended to the bootstrapping Python stub " +
"script used when executing `py_binary` targets. Does not " +
Expand Down
3 changes: 3 additions & 0 deletions python/private/common/py_executable.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""Common functionality between test/binary executables."""

load("@bazel_skylib//lib:dicts.bzl", "dicts")
load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER")
load(
":attributes.bzl",
"AGNOSTIC_EXECUTABLE_ATTRS",
Expand Down Expand Up @@ -264,6 +265,8 @@ def _get_runtime_details(ctx, semantics):
direct.append(effective_runtime.coverage_tool)
if effective_runtime.coverage_files:
transitive.append(effective_runtime.coverage_files)
if IS_BAZEL_7_OR_HIGHER and effective_runtime.runfiles:
transitive.append(effective_runtime.runfiles)
runtime_files = depset(direct = direct, transitive = transitive)
else:
runtime_files = depset()
Expand Down
5 changes: 5 additions & 0 deletions python/private/common/py_runtime_rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def _py_runtime_impl(ctx):
interpreter_path = interpreter_path or None,
interpreter = interpreter,
files = runtime_files if hermetic else None,
runfiles = runfiles,
coverage_tool = coverage_tool,
coverage_files = coverage_files,
python_version = python_version,
Expand All @@ -97,6 +98,10 @@ def _py_runtime_impl(ctx):
builtin_py_runtime_info_kwargs = dict(py_runtime_info_kwargs)
if not IS_BAZEL_7_OR_HIGHER:
builtin_py_runtime_info_kwargs.pop("bootstrap_template")

# Unsupported by the old provider
builtin_py_runtime_info_kwargs.pop("runfiles")

return [
PyRuntimeInfo(**py_runtime_info_kwargs),
# Return the builtin provider for better compatibility.
Expand Down

0 comments on commit 7cf394f

Please sign in to comment.