Skip to content

Commit 1716b1b

Browse files
committed
fix: run executable zip action with execution Python
The legacy self-executable zip action used run_shell and an undeclared cat binary, so a Windows-hosted Bazel invocation could not run the action remotely on Linux. Run the existing exe_zip_maker through actions_run so the helper and Python runtime come from the execution configuration.
1 parent f3fa8da commit 1716b1b

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Use the execution platform's Python runtime when building self-executable Python
2+
zip files, allowing a Windows-hosted Bazel invocation to run the action remotely
3+
on Linux.

python/private/py_executable.bzl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ load(":cc_helper.bzl", "cc_helper")
3838
load(
3939
":common.bzl",
4040
"ExplicitSymlink",
41+
"actions_run",
4142
"collect_cc_info",
4243
"collect_deps",
4344
"collect_imports",
@@ -219,6 +220,10 @@ accepting arbitrary Python versions.
219220
default = "//python/private:debugger_if_target_config",
220221
providers = [PyInfo],
221222
),
223+
"_exe_zip_maker": lambda: attrb.Label(
224+
cfg = "exec",
225+
default = "//tools/private/zipapp:exe_zip_maker",
226+
),
222227
"_launcher": lambda: attrb.Label(
223228
cfg = "target",
224229
# NOTE: This is an executable, but is only used for Windows. It
@@ -1095,15 +1100,16 @@ def _create_executable_zip_file(
10951100
else:
10961101
ctx.actions.write(prelude, "#!/usr/bin/env python3\n")
10971102

1098-
ctx.actions.run_shell(
1099-
command = "cat {prelude} {zip} > {output}".format(
1100-
prelude = prelude.path,
1101-
zip = zip_file.path,
1102-
output = output.path,
1103-
),
1104-
inputs = [prelude, zip_file],
1103+
args = ctx.actions.args()
1104+
args.add(prelude)
1105+
args.add(zip_file)
1106+
args.add(output)
1107+
actions_run(
1108+
ctx,
1109+
executable = ctx.attr._exe_zip_maker,
1110+
arguments = [args],
1111+
inputs = depset([prelude, zip_file]),
11051112
outputs = [output],
1106-
use_default_shell_env = True,
11071113
mnemonic = "PyBuildExecutableZip",
11081114
progress_message = "Build Python zip executable: %{label}",
11091115
)

0 commit comments

Comments
 (0)