diff --git a/CHANGELOG.md b/CHANGELOG.md index ac11e14cff..cc44a47be0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/python/private/stage1_bootstrap_template.sh b/python/private/stage1_bootstrap_template.sh index fb46cc696c..48711aa92f 100644 --- a/python/private/stage1_bootstrap_template.sh +++ b/python/private/stage1_bootstrap_template.sh @@ -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