commit:     50ac4e2e3401be2410a01f7d5d7923672b57798f
Author:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Mon Jul 11 19:48:48 2022 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Jul 11 23:01:04 2022 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=50ac4e2e

Allow nested ebegin calls using a count variable

At the start of each phase, the count is set to 0.

The count is incremented each time ebegin is called.

If the count is equal to 0 when eend is called, a warning is output.
Otherwise, the count is decremented by 1.

At the end of each phase, if the count is greater than 0, a warning is
output.

Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>
Closes: https://github.com/gentoo/portage/pull/854
Signed-off-by: Sam James <sam <AT> gentoo.org>

 bin/isolated-functions.sh | 12 ++++--------
 bin/phase-functions.sh    |  8 ++++----
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh
index dea0d7f49..55c38fbb0 100644
--- a/bin/isolated-functions.sh
+++ b/bin/isolated-functions.sh
@@ -339,10 +339,7 @@ ebegin() {
        [[ ${RC_ENDCOL} == "yes" ]] && echo >&2
        LAST_E_LEN=$(( 3 + ${#RC_INDENTATION} + ${#msg} ))
        LAST_E_CMD="ebegin"
-       if [[ -v EBEGIN_EEND ]] ; then
-               eqawarn "QA Notice: ebegin called, but missing call to eend 
(phase: ${EBUILD_PHASE})"
-       fi
-       EBEGIN_EEND=1
+       let ++__EBEGIN_EEND_COUNT
        return 0
 }
 
@@ -371,10 +368,9 @@ __eend() {
 
 eend() {
        [[ -n $1 ]] || eqawarn "QA Notice: eend called without first argument"
-       if [[ -v EBEGIN_EEND ]] ; then
-               unset EBEGIN_EEND
-       else
-               eqawarn "QA Notice: eend called without preceding ebegin 
(phase: ${EBUILD_PHASE})"
+       if (( --__EBEGIN_EEND_COUNT < 0 )); then
+               __EBEGIN_EEND_COUNT=0
+               eqawarn "QA Notice: eend called without preceding ebegin in 
${FUNCNAME[1]}"
        fi
        local retval=${1:-0}
        shift

diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh
index 25e25cc1e..84a5c1ec3 100644
--- a/bin/phase-functions.sh
+++ b/bin/phase-functions.sh
@@ -207,7 +207,11 @@ __preprocess_ebuild_env() {
 }
 
 __ebuild_phase() {
+       local __EBEGIN_EEND_COUNT=0
        declare -F "$1" >/dev/null && __qa_call $1
+       if (( __EBEGIN_EEND_COUNT > 0 )); then
+               eqawarn "QA Notice: ebegin called without eend in $1"
+       fi
 }
 
 __ebuild_phase_with_hooks() {
@@ -1088,10 +1092,6 @@ __ebuild_main() {
                ;;
        esac
 
-       if [[ -v EBEGIN_EEND ]] ; then
-               eqawarn "QA Notice: ebegin called, but missing call to eend 
(phase: ${1})"
-       fi
-
        # Save the env only for relevant phases.
        if ! has "${1}" clean help info nofetch ; then
                umask 002

Reply via email to