From 1d106e43d1f67363f79f1692f7e5eb6b631e464c Mon Sep 17 00:00:00 2001 From: chowder <16789070+chowder@users.noreply.github.com> Date: Mon, 8 Jul 2024 18:02:38 +0100 Subject: [PATCH 1/3] use exec to invoke the stage-2 bootstrap in the common case --- python/private/stage1_bootstrap_template.sh | 22 +++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/python/private/stage1_bootstrap_template.sh b/python/private/stage1_bootstrap_template.sh index fb46cc696c..bfe960a1c7 100644 --- a/python/private/stage1_bootstrap_template.sh +++ b/python/private/stage1_bootstrap_template.sh @@ -108,11 +108,21 @@ 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" \ +command=( + env + "${interpreter_env[@]}" + "$python_exe" + "${interpreter_args[@]}" + "$stage2_bootstrap" "$@" +) -exit $? +# We want to use `exec` instead of a child process, which causes problems +# with signal passing. 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 From 9676b697257f82ce182904892ff8209066c47b0a Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Tue, 9 Jul 2024 19:15:20 -0700 Subject: [PATCH 2/3] Expand the comment a bit Also remove a defunct comment since we're here --- python/private/stage1_bootstrap_template.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/python/private/stage1_bootstrap_template.sh b/python/private/stage1_bootstrap_template.sh index bfe960a1c7..48711aa92f 100644 --- a/python/private/stage1_bootstrap_template.sh +++ b/python/private/stage1_bootstrap_template.sh @@ -106,8 +106,7 @@ 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. + command=( env "${interpreter_env[@]}" @@ -117,9 +116,15 @@ command=( "$@" ) -# We want to use `exec` instead of a child process, which causes problems -# with signal passing. However, when running a zip file, we need to clean -# up the workspace after the process finishes so control must return here. +# 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 $? From 28fa708f0f9ff0b5bdbcb2665328d82ffa003e29 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Tue, 9 Jul 2024 19:32:30 -0700 Subject: [PATCH 3/3] update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) 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