From b726aa64b8adf64579007242eafc71338481399d Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Mon, 17 Apr 2023 22:07:03 -0700 Subject: [PATCH] python: Fixed bootstrap template not being passed to py_binary from py_runtime on bazel latest This PR fixes a small bug where the bootstrap template runtime file was not being passed to Py Binary. This broke the bootstrap template feature on bazel latest authored in https://github.com/bazelbuild/bazel/pull/16806 Closes #18103. PiperOrigin-RevId: 525042380 Change-Id: I8b8a200634eb98e156b4d8ba6b2e5baef5d06c73 --- .../builtins_bzl/common/python/py_executable_bazel.bzl | 4 +++- .../build/lib/rules/python/PythonStarlarkApiTest.java | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/starlark/builtins_bzl/common/python/py_executable_bazel.bzl b/src/main/starlark/builtins_bzl/common/python/py_executable_bazel.bzl index 6969cbdb227d68..09b8916db13e32 100644 --- a/src/main/starlark/builtins_bzl/common/python/py_executable_bazel.bzl +++ b/src/main/starlark/builtins_bzl/common/python/py_executable_bazel.bzl @@ -290,11 +290,13 @@ def _expand_bootstrap_template( if runtime: shebang = runtime.stub_shebang + template = runtime.bootstrap_template else: shebang = DEFAULT_STUB_SHEBANG + template = ctx.file._bootstrap_template ctx.actions.expand_template( - template = ctx.file._bootstrap_template, + template = template, output = output, substitutions = { "%shebang%": shebang, diff --git a/src/test/java/com/google/devtools/build/lib/rules/python/PythonStarlarkApiTest.java b/src/test/java/com/google/devtools/build/lib/rules/python/PythonStarlarkApiTest.java index c6b4d68affb3ff..5231839f249850 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/python/PythonStarlarkApiTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/python/PythonStarlarkApiTest.java @@ -120,7 +120,8 @@ public void runtimeSandwich() throws Exception { " return [PyRuntimeInfo(", " interpreter = ctx.file.interpreter,", " files = depset(direct = ctx.files.files, transitive=[info.files]),", - " python_version = info.python_version)]", + " python_version = info.python_version,", + " bootstrap_template = ctx.file.bootstrap_template)]", "", "userruntime = rule(", " implementation = _userruntime_impl,", @@ -128,6 +129,7 @@ public void runtimeSandwich() throws Exception { " 'runtime': attr.label(),", " 'interpreter': attr.label(allow_single_file=True),", " 'files': attr.label_list(allow_files=True),", + " 'bootstrap_template': attr.label(allow_single_file=True),", " },", ")"); scratch.file( @@ -148,6 +150,7 @@ public void runtimeSandwich() throws Exception { " runtime = ':pyruntime',", " interpreter = ':userintr',", " files = ['userdata.txt'],", + " bootstrap_template = 'bootstrap.txt',", ")", "py_runtime_pair(", " name = 'userruntime_pair',",