bazelbuild / rules_python

Bazel Python Rules
https://rules-python.readthedocs.io
Apache License 2.0
523 stars 539 forks source link

Python zip built with bootstrap_impl=script not runnable on macOS #2030

Closed linzhp closed 2 months ago

linzhp commented 3 months ago

🐞 bug report

Affected Rule

The issue is caused by the rule: python/private/stage1_bootstrap_template.sh

Is this a regression?

Yes, the Python zip built with bootstrap_impl=system_python works on macOS

Description

The stage 1 bootstrapper for Python zip file cannot run on macOS

🔬 Minimal Reproduction

  1. Build a zip file with bazel build --build_python_zip --@rules_python//python/config_settings:bootstrap_impl=script
  2. Run the zip file on macOS

🔥 Exception or Error


mktemp: unrecognized option `--suffix'
usage: mktemp [-d] [-p tmpdir] [-q] [-t prefix] [-u] template ...
       mktemp [-d] [-p tmpdir] [-q] [-u] -t prefix

🌍 Your Environment

Operating System:

macOS Sonoma 14.5

Output of bazel version:

7.2.0

Rules_python version:

0.33.2

Anything else relevant? This line is triggered when running a Python zip file. However, the mktemp command on macOS doesn't have the option --suffix.

dws commented 3 months ago

One approach might be to change the line

 zip_dir=$(mktemp -d --suffix Bazel.runfiles_)

to

zip_dir=$(mktemp -d --suffix Bazel.runfiles_ 2>/dev/null || mktemp -d)

That would preserve existing behavior where --suffix Bazel.runfiles_ is available, and just drop it when it's not available.

linzhp commented 3 months ago

Or we can use prefix instead

rickeylev commented 2 months ago

I was poking this a bit yesterday. I can't find anything that indicates why the Bazel.runfiles_ substring is meaningful. There's some code in the stage2 bootstrap, that looks for a similar pattern, but the "Bazel." prefix and the "_" suffix would cause that logic to not match. So yeah, best guess, it was just added as a human-friendly informative marker.

I'll just change the code to simply mktemp -d.