From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-dev+bounces-95017-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id B26D413933E
	for <garchives@archives.gentoo.org>; Fri, 23 Jul 2021 06:58:06 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id F244AE0BF0;
	Fri, 23 Jul 2021 06:58:02 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 7EDF8E0A49
	for <gentoo-dev@lists.gentoo.org>; Fri, 23 Jul 2021 06:58:02 +0000 (UTC)
From: Andreas Sturmlechner <asturm@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Subject: [gentoo-dev] [PATCH v2 4/5] check-reqs.eclass: Prefix internal functions w/ underscore
Date: Fri, 23 Jul 2021 08:57:56 +0200
Message-ID: <4153190.UPlyArG6xL@tuxbook>
In-Reply-To: <9194842.eNJFYEL58v@tuxbook>
References: <2544843.lGaqSPkdTl@tuxbook> <5285163.rdbgypaU67@tuxbook> <9194842.eNJFYEL58v@tuxbook>
Precedence: bulk
List-Post: <mailto:gentoo-dev@lists.gentoo.org>
List-Help: <mailto:gentoo-dev+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-dev+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-dev+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-dev.gentoo.org>
X-BeenThere: gentoo-dev@lists.gentoo.org
Reply-to: gentoo-dev@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
MIME-Version: 1.0
Content-Type: multipart/signed; boundary="nextPart5337123.ZASKD2KPVS"; micalg="pgp-sha512"; protocol="application/pgp-signature"
X-Archives-Salt: 79af38bb-37c4-42b0-8fb2-91e55c910fad
X-Archives-Hash: b65ab9f04da558dd462b8a37dd7e9e9b

--nextPart5337123.ZASKD2KPVS
Content-Transfer-Encoding: 7Bit
Content-Type: text/plain; charset="us-ascii"; protected-headers="v1"
From: Andreas Sturmlechner <asturm@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Subject: [PATCH v2 4/5] check-reqs.eclass: Prefix internal functions w/ underscore
Date: Fri, 23 Jul 2021 08:57:56 +0200
Message-ID: <4153190.UPlyArG6xL@tuxbook>
In-Reply-To: <9194842.eNJFYEL58v@tuxbook>
References: <2544843.lGaqSPkdTl@tuxbook> <5285163.rdbgypaU67@tuxbook> <9194842.eNJFYEL58v@tuxbook>

Signed-off-by: Andreas Sturmlechner <asturm@gentoo.org>
---
 eclass/check-reqs.eclass | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 123 insertions(+), 17 deletions(-)

diff --git a/eclass/check-reqs.eclass b/eclass/check-reqs.eclass
index 6b11794fbb2..39e4bad1363 100644
--- a/eclass/check-reqs.eclass
+++ b/eclass/check-reqs.eclass
@@ -76,9 +76,9 @@ _CHECK_REQS_ECLASS=1
 check-reqs_pkg_setup() {
 	debug-print-function ${FUNCNAME} "$@"
 
-	check-reqs_prepare
-	check-reqs_run
-	check-reqs_output
+	_check-reqs_prepare
+	_check-reqs_run
+	_check-reqs_output
 }
 
 # @FUNCTION: check-reqs_pkg_pretend
@@ -95,6 +95,16 @@ check-reqs_pkg_pretend() {
 # @DESCRIPTION:
 # Internal function that checks the variables that should be defined.
 check-reqs_prepare() {
+	[[ ${EAPI} == [67] ]] ||
+		die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."
+	_check-reqs_prepare "$@"
+}
+
+# @FUNCTION: _check-reqs_prepare
+# @INTERNAL
+# @DESCRIPTION:
+# Internal function that checks the variables that should be defined.
+_check-reqs_prepare() {
 	debug-print-function ${FUNCNAME} "$@"
 
 	if [[ -z ${CHECKREQS_MEMORY} &&
@@ -112,6 +122,16 @@ check-reqs_prepare() {
 # @DESCRIPTION:
 # Internal function that runs the check based on variable settings.
 check-reqs_run() {
+	[[ ${EAPI} == [67] ]] ||
+		die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."
+	_check-reqs_run "$@"
+}
+
+# @FUNCTION: _check-reqs_run
+# @INTERNAL
+# @DESCRIPTION:
+# Internal function that runs the check based on variable settings.
+_check-reqs_run() {
 	debug-print-function ${FUNCNAME} "$@"
 
 	# some people are *censored*
@@ -119,23 +139,23 @@ check-reqs_run() {
 
 	if [[ ${MERGE_TYPE} != binary ]]; then
 		[[ -n ${CHECKREQS_MEMORY} ]] && \
-			check-reqs_memory \
+			_check-reqs_memory \
 				${CHECKREQS_MEMORY}
 
 		[[ -n ${CHECKREQS_DISK_BUILD} ]] && \
-			check-reqs_disk \
+			_check-reqs_disk \
 				"${T}" \
 				"${CHECKREQS_DISK_BUILD}"
 	fi
 
 	if [[ ${MERGE_TYPE} != buildonly ]]; then
 		[[ -n ${CHECKREQS_DISK_USR} ]] && \
-			check-reqs_disk \
+			_check-reqs_disk \
 				"${EROOT%/}/usr" \
 				"${CHECKREQS_DISK_USR}"
 
 		[[ -n ${CHECKREQS_DISK_VAR} ]] && \
-			check-reqs_disk \
+			_check-reqs_disk \
 				"${EROOT%/}/var" \
 				"${CHECKREQS_DISK_VAR}"
 	fi
@@ -147,6 +167,17 @@ check-reqs_run() {
 # Internal function that returns number in KiB.
 # Returns 1024**2 for 1G or 1024**3 for 1T.
 check-reqs_get_kibibytes() {
+	[[ ${EAPI} == [67] ]] ||
+		die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."
+	_check-reqs_get_kibibytes "$@"
+}
+
+# @FUNCTION: _check-reqs_get_kibibytes
+# @INTERNAL
+# @DESCRIPTION:
+# Internal function that returns number in KiB.
+# Returns 1024**2 for 1G or 1024**3 for 1T.
+_check-reqs_get_kibibytes() {
 	debug-print-function ${FUNCNAME} "$@"
 
 	[[ -z ${1} ]] && die "Usage: ${FUNCNAME} [size]"
@@ -170,6 +201,17 @@ check-reqs_get_kibibytes() {
 # Internal function that returns the numerical value without the unit.
 # Returns "1" for "1G" or "150" for "150T".
 check-reqs_get_number() {
+	[[ ${EAPI} == [67] ]] ||
+		die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."
+	_check-reqs_get_number "$@"
+}
+
+# @FUNCTION: _check-reqs_get_number
+# @INTERNAL
+# @DESCRIPTION:
+# Internal function that returns the numerical value without the unit.
+# Returns "1" for "1G" or "150" for "150T".
+_check-reqs_get_number() {
 	debug-print-function ${FUNCNAME} "$@"
 
 	[[ -z ${1} ]] && die "Usage: ${FUNCNAME} [size]"
@@ -186,6 +228,17 @@ check-reqs_get_number() {
 # Internal function that returns the unit without the numerical value.
 # Returns "GiB" for "1G" or "TiB" for "150T".
 check-reqs_get_unit() {
+	[[ ${EAPI} == [67] ]] ||
+		die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."
+	_check-reqs_get_unit "$@"
+}
+
+# @FUNCTION: _check-reqs_get_unit
+# @INTERNAL
+# @DESCRIPTION:
+# Internal function that returns the unit without the numerical value.
+# Returns "GiB" for "1G" or "TiB" for "150T".
+_check-reqs_get_unit() {
 	debug-print-function ${FUNCNAME} "$@"
 
 	[[ -z ${1} ]] && die "Usage: ${FUNCNAME} [size]"
@@ -208,6 +261,17 @@ check-reqs_get_unit() {
 # Internal function that prints the warning and dies if required based on
 # the test results.
 check-reqs_output() {
+	[[ ${EAPI} == [67] ]] ||
+		die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."
+	_check-reqs_get_unit "$@"
+}
+
+# @FUNCTION: _check-reqs_output
+# @INTERNAL
+# @DESCRIPTION:
+# Internal function that prints the warning and dies if required based on
+# the test results.
+_check-reqs_output() {
 	debug-print-function ${FUNCNAME} "$@"
 
 	local msg="ewarn"
@@ -230,6 +294,16 @@ check-reqs_output() {
 # @DESCRIPTION:
 # Internal function that checks size of RAM.
 check-reqs_memory() {
+	[[ ${EAPI} == [67] ]] ||
+		die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."
+	_check-reqs_memory "$@"
+}
+
+# @FUNCTION: _check-reqs_memory
+# @INTERNAL
+# @DESCRIPTION:
+# Internal function that checks size of RAM.
+_check-reqs_memory() {
 	debug-print-function ${FUNCNAME} "$@"
 
 	[[ -z ${1} ]] && die "Usage: ${FUNCNAME} [size]"
@@ -238,7 +312,7 @@ check-reqs_memory() {
 	local actual_memory
 	local actual_swap
 
-	check-reqs_start_phase \
+	_check-reqs_start_phase \
 		${size} \
 		"RAM"
 
@@ -254,17 +328,17 @@ check-reqs_memory() {
 			| sed -e 's/^[^:=]*[:=][[:space:]]*//')
 	fi
 	if [[ -n ${actual_memory} ]] ; then
-		if [[ ${actual_memory} -ge $(check-reqs_get_kibibytes ${size}) ]] ; then
+		if [[ ${actual_memory} -ge $(_check-reqs_get_kibibytes ${size}) ]] ; then
 			eend 0
 		elif [[ -n ${actual_swap} && $((${actual_memory} + ${actual_swap})) \
-				-ge $(check-reqs_get_kibibytes ${size}) ]] ; then
+				-ge $(_check-reqs_get_kibibytes ${size}) ]] ; then
 			ewarn "Amount of main memory is insufficient, but amount"
 			ewarn "of main memory combined with swap is sufficient."
 			ewarn "Build process may make computer very slow!"
 			eend 0
 		else
 			eend 1
-			check-reqs_unsatisfied \
+			_check-reqs_unsatisfied \
 				${size} \
 				"RAM"
 		fi
@@ -279,6 +353,16 @@ check-reqs_memory() {
 # @DESCRIPTION:
 # Internal function that checks space on the harddrive.
 check-reqs_disk() {
+	[[ ${EAPI} == [67] ]] ||
+		die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."
+	_check-reqs_disk "$@"
+}
+
+# @FUNCTION: _check-reqs_disk
+# @INTERNAL
+# @DESCRIPTION:
+# Internal function that checks space on the harddrive.
+_check-reqs_disk() {
 	debug-print-function ${FUNCNAME} "$@"
 
 	[[ -z ${2} ]] && die "Usage: ${FUNCNAME} [path] [size]"
@@ -287,16 +371,16 @@ check-reqs_disk() {
 	local size=${2}
 	local space_kbi
 
-	check-reqs_start_phase \
+	_check-reqs_start_phase \
 		${size} \
 		"disk space at \"${path}\""
 
 	space_kbi=$(df -Pk "${1}" 2>/dev/null | awk 'FNR == 2 {print $4}')
 
 	if [[ $? == 0 && -n ${space_kbi} ]] ; then
-		if [[ ${space_kbi} -lt $(check-reqs_get_kibibytes ${size}) ]] ; then
+		if [[ ${space_kbi} -lt $(_check-reqs_get_kibibytes ${size}) ]] ; then
 			eend 1
-			check-reqs_unsatisfied \
+			_check-reqs_unsatisfied \
 				${size} \
 				"disk space at \"${path}\""
 		else
@@ -313,13 +397,23 @@ check-reqs_disk() {
 # @DESCRIPTION:
 # Internal function that inform about started check
 check-reqs_start_phase() {
+	[[ ${EAPI} == [67] ]] ||
+		die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."
+	_check-reqs_start_phase "$@"
+}
+
+# @FUNCTION: _check-reqs_start_phase
+# @INTERNAL
+# @DESCRIPTION:
+# Internal function that inform about started check
+_check-reqs_start_phase() {
 	debug-print-function ${FUNCNAME} "$@"
 
 	[[ -z ${2} ]] && die "Usage: ${FUNCNAME} [size] [location]"
 
 	local size=${1}
 	local location=${2}
-	local sizeunit="$(check-reqs_get_number ${size}) $(check-reqs_get_unit ${size})"
+	local sizeunit="$(_check-reqs_get_number ${size}) $(_check-reqs_get_unit ${size})"
 
 	ebegin "Checking for at least ${sizeunit} ${location}"
 }
@@ -327,10 +421,22 @@ check-reqs_start_phase() {
 # @FUNCTION: check-reqs_unsatisfied
 # @INTERNAL
 # @DESCRIPTION:
-# Internal function that inform about check result.
+# Internal function that informs about check result.
 # It has different output between pretend and setup phase,
 # where in pretend phase it is fatal.
 check-reqs_unsatisfied() {
+	[[ ${EAPI} == [67] ]] ||
+		die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."
+	_check-reqs_unsatisfied "$@"
+}
+
+# @FUNCTION: _check-reqs_unsatisfied
+# @INTERNAL
+# @DESCRIPTION:
+# Internal function that informs about check result.
+# It has different output between pretend and setup phase,
+# where in pretend phase it is fatal.
+_check-reqs_unsatisfied() {
 	debug-print-function ${FUNCNAME} "$@"
 
 	[[ -z ${2} ]] && die "Usage: ${FUNCNAME} [size] [location]"
@@ -338,7 +444,7 @@ check-reqs_unsatisfied() {
 	local msg="ewarn"
 	local size=${1}
 	local location=${2}
-	local sizeunit="$(check-reqs_get_number ${size}) $(check-reqs_get_unit ${size})"
+	local sizeunit="$(_check-reqs_get_number ${size}) $(_check-reqs_get_unit ${size})"
 
 	[[ ${EBUILD_PHASE} == "pretend" && -z ${I_KNOW_WHAT_I_AM_DOING} ]] && msg="eerror"
 	${msg} "There is NOT at least ${sizeunit} ${location}"

--nextPart5337123.ZASKD2KPVS
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part.
Content-Transfer-Encoding: 7Bit

-----BEGIN PGP SIGNATURE-----

iQGTBAABCgB9FiEEexlipVqzuLtTjHMOREsPlv/SLMsFAmD6aHRfFIAAAAAALgAo
aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDdC
MTk2MkE1NUFCM0I4QkI1MzhDNzMwRTQ0NEIwRjk2RkZEMjJDQ0IACgkQREsPlv/S
LMsBiAf7BNZtruxWOdWdbNmjROWEo3B0mzH3wgerpVDKltzknF/Ax00VE+HYsu3q
ygK9IMWpdkERy9JBiQJL9+qa0+RbhWC1c+POMs4tUSNd4GBvngbnwE3RiXeiJMlo
OryLMF3BAFWOdOyyJrWoz/Ksl+RpGV7653xqNO6ZC52PCfzNyr3r0Qb+uDNPH37e
Ylb1NmIK+MBBtu/PquK0qPgwIGuPmwTQfrNuT19n6WbHckhqf899OoqOxdVD5JXk
w6GTJ8CKL1M/SKSIvUOQDA+tAVjY7fY1Wcx7RMY+quA4oGfXpXZWUJAc/gUzYzzi
CvA0ZBgyHm02dErJVvidvj+Mht/T1Q==
=XvRL
-----END PGP SIGNATURE-----

--nextPart5337123.ZASKD2KPVS--