From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1417500-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id 15BCF158094
	for <garchives@archives.gentoo.org>; Mon, 11 Jul 2022 23:02:09 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 55EFFE1039;
	Mon, 11 Jul 2022 23:02:08 +0000 (UTC)
Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 3443DE1036
	for <gentoo-commits@lists.gentoo.org>; Mon, 11 Jul 2022 23:02:08 +0000 (UTC)
Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 5275B3410B2
	for <gentoo-commits@lists.gentoo.org>; Mon, 11 Jul 2022 23:02:07 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id D9E5052D
	for <gentoo-commits@lists.gentoo.org>; Mon, 11 Jul 2022 23:02:05 +0000 (UTC)
From: "Sam James" <sam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" <sam@gentoo.org>
Message-ID: <1657580464.50ac4e2e3401be2410a01f7d5d7923672b57798f.sam@gentoo>
Subject: [gentoo-commits] proj/portage:master commit in: bin/
X-VCS-Repository: proj/portage
X-VCS-Files: bin/isolated-functions.sh bin/phase-functions.sh
X-VCS-Directories: bin/
X-VCS-Committer: sam
X-VCS-Committer-Name: Sam James
X-VCS-Revision: 50ac4e2e3401be2410a01f7d5d7923672b57798f
X-VCS-Branch: master
Date: Mon, 11 Jul 2022 23:02:05 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
X-Archives-Salt: 147b46ef-64b7-4def-a27f-0a0d5b978550
X-Archives-Hash: 0e276f22c4305e3acb809a1ddb85e2fc

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