diff options
| author | 2022-04-21 10:41:14 +0200 | |
|---|---|---|
| committer | 2022-04-28 16:50:16 +0100 | |
| commit | 605ad0d675a64eb39144122cf284100192cdfea0 (patch) | |
| tree | c448335abed1f987c87ca962131f31938167e045 | |
| parent | install-qa-check.d/10ignored-flags: sync check with other examples (cosmetic) (diff) | |
| download | portage-605ad0d675a64eb39144122cf284100192cdfea0.tar.gz portage-605ad0d675a64eb39144122cf284100192cdfea0.tar.bz2 portage-605ad0d675a64eb39144122cf284100192cdfea0.zip | |
ebegin/eend: accept properly nested calls in different functions
Turn the EBEGIN_EEND variable into a stack that tracks which function
called ebegin. Calls to ebegin may be stacked and do not generate a QA
warning if the callers are different functions. Calls to eend then check
that the function name at the top of the stack matches the caller's
function name.
Bug: https://bugs.gentoo.org/839585
Bug: https://bugs.gentoo.org/839588
Signed-off-by: Thomas Bracht Laumann Jespersen <t@laumann.xyz>
Closes: https://github.com/gentoo/portage/pull/824
Signed-off-by: Sam James <sam@gentoo.org>
| -rw-r--r-- | bin/isolated-functions.sh | 22 | ||||
| -rw-r--r-- | bin/phase-functions.sh | 4 |
2 files changed, 21 insertions, 5 deletions
diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh index 03983a9fa..912782914 100644 --- a/bin/isolated-functions.sh +++ b/bin/isolated-functions.sh @@ -340,9 +340,15 @@ ebegin() { 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})" + # Already a call to ebegin + local prev="${EBEGIN_EEND[-1]}" + if [[ "${prev}" == "${FUNCNAME[1]}" ]] ; then + eqawarn "QA Notice: ebegin called in ${prev}, but missing call to eend (${FUNCNAME[1]})" + fi + EBEGIN_EEND+=( "${FUNCNAME[1]}" ) + else + EBEGIN_EEND=( "${FUNCNAME[1]}" ) fi - EBEGIN_EEND=1 return 0 } @@ -372,9 +378,17 @@ __eend() { eend() { [[ -n $1 ]] || eqawarn "QA Notice: eend called without first argument" if [[ -v EBEGIN_EEND ]] ; then - unset EBEGIN_EEND + local caller="${FUNCNAME[1]}" + local tos="${EBEGIN_EEND[-1]}" + if [[ "${caller}" != "${tos}" ]] ; then + eqawarn "QA Notice: eend (in ${caller}) improperly matched with ebegin (called in ${tos})" + fi + unset EBEGIN_EEND[-1] + if [[ ${#EBEGIN_EEND[@]} -eq 0 ]] ; then + unset EBEGIN_EEND + fi else - eqawarn "QA Notice: eend called without preceding ebegin (phase: ${EBUILD_PHASE})" + eqawarn "QA Notice: eend called without preceding ebegin (phase: ${FUNCNAME[1]})" fi local retval=${1:-0} shift diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh index bccf88226..6b48c2351 100644 --- a/bin/phase-functions.sh +++ b/bin/phase-functions.sh @@ -1089,7 +1089,9 @@ __ebuild_main() { esac if [[ -v EBEGIN_EEND ]] ; then - eqawarn "QA Notice: ebegin called, but missing call to eend (phase: ${1})" + for func in "${EBEGIN_EEND[@]}" ; do + eqawarn "QA Notice: ebegin called in ${func} but missing call to eend" + done fi # Save the env only for relevant phases. |
