Skip to content

Commit 1d99f70

Browse files
dzbarskyrickeylev
andauthored
fix: run executable zip action with execution Python to better support windows building (#3890)
The legacy self-executable zip action invokes `cat` through `run_shell`. The action does not declare `cat`, and a Windows-hosted Bazel invocation cannot use that action reliably when the selected execution platform is Linux. Run the existing `exe_zip_maker` through `actions_run` instead. This selects the helper and Python runtime from the execution configuration, preserves the prelude-plus-zip output format, and removes the ambient shell utility dependency. A news entry documents the fix. The Bazel integration that motivated this fix is [bazelbuild/bazel#30121](bazelbuild/bazel#30121). --------- Co-authored-by: Richard Levasseur <richardlev@gmail.com>
1 parent d77d5a4 commit 1d99f70

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

news/3890.fixed.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(binaries) Fixed building of legacy zipapps on Windows execution platforms by
2+
using a hermetic tool instead of host `cat`.

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)