Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use exec to invoke the stage-2 bootstrap for non-zip case #2047

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ A brief description of the categories of changes:
* Nothing yet

### Fixed
* (rules) Signals are properly received when using {obj}`--bootstrap_impl=script`
(for non-zip builds).
([#2043](https://github.com/bazelbuild/rules_python/issues/2043))
* (rules) Fixes python builds when the `--build_python_zip` is set to `false` on Windows. See [#1840](https://github.com/bazelbuild/rules_python/issues/1840).
* (pip) Fixed pypi parse_simpleapi_html function for feeds with package metadata
containing ">" sign
Expand Down
33 changes: 24 additions & 9 deletions python/private/stage1_bootstrap_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,28 @@ declare -a interpreter_args
interpreter_env+=("PYTHONSAFEPATH=1")

export RUNFILES_DIR
# NOTE: We use <(...) to pass the Python program as a file so that stdin can
# still be passed along as normal.
env \
"${interpreter_env[@]}" \
"$python_exe" \
"${interpreter_args[@]}" \
"$stage2_bootstrap" \
"$@"

exit $?
command=(
env
"${interpreter_env[@]}"
"$python_exe"
"${interpreter_args[@]}"
"$stage2_bootstrap"
"$@"
)

# We use `exec` instead of a child process so that signals sent directly (e.g.
# using `kill`) to this process (the PID seen by the calling process) are
# received by the Python process. Otherwise, this process receives the signal
# and would have to manually propagate it.
# See https://github.com/bazelbuild/rules_python/issues/2043#issuecomment-2215469971
# for more information.
#
# However, when running a zip file, we need to clean up the workspace after the
# process finishes so control must return here.
if [[ "$IS_ZIPFILE" == "1" ]]; then
"${command[@]}"
exit $?
else
exec "${command[@]}"
fi