public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] eutils.eclass: further cleanup for EAPI 6
@ 2015-11-29 13:29 Ulrich Mueller
  2015-11-29 13:29 ` [gentoo-dev] [PATCH 1/2] eutils.eclass: Disable epatch_user in " Ulrich Müller
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Ulrich Mueller @ 2015-11-29 13:29 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 295 bytes --]

Two patches for eutils.eclass will follow. The first patch disables
epatch_user in EAPI 6. There it is mandatory to call eapply_user which
replaces epatch_user.

The second patch moves all deprecated functions to the end of the
eclass, and consolidates several of the EAPI conditionals.

Ulrich

[-- Attachment #2: Type: application/pgp-signature, Size: 490 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [gentoo-dev] [PATCH 1/2] eutils.eclass: Disable epatch_user in EAPI 6.
  2015-11-29 13:29 [gentoo-dev] eutils.eclass: further cleanup for EAPI 6 Ulrich Mueller
@ 2015-11-29 13:29 ` Ulrich Müller
  2015-11-29 13:31 ` [gentoo-dev] [PATCH 2/2] eutils.eclass: Move all deprecated functions to the end Ulrich Müller
  2015-11-29 16:48 ` [gentoo-dev] [PATCH] eutils.eclass: In EAPI conditionals, replace "has" by case statements Ulrich Mueller
  2 siblings, 0 replies; 9+ messages in thread
From: Ulrich Müller @ 2015-11-29 13:29 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 1380 bytes --]

Date: Sun, 29 Nov 2015 13:35:08 +0100

EAPI 6 has eapply_user which should be used instead.
---
 eclass/eutils.eclass | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/eclass/eutils.eclass b/eclass/eutils.eclass
index 6457501..5481b7f 100644
--- a/eclass/eutils.eclass
+++ b/eclass/eutils.eclass
@@ -350,12 +350,6 @@ EPATCH_FORCE="no"
 # List of patches not to apply.	 Note this is only file names,
 # and not the full path.  Globs accepted.
 
-# @VARIABLE: EPATCH_USER_SOURCE
-# @DESCRIPTION:
-# Location for user patches, see the epatch_user function.
-# Should be set by the user. Don't set this in ebuilds.
-: ${EPATCH_USER_SOURCE:=${PORTAGE_CONFIGROOT%/}/etc/portage/patches}
-
 # @FUNCTION: epatch
 # @USAGE: [options] [patches] [dirs of patches]
 # @DESCRIPTION:
@@ -669,6 +663,13 @@ epatch() {
 	: # everything worked
 }
 
+if has "${EAPI:-0}" 0 1 2 3 4 5; then
+# @VARIABLE: EPATCH_USER_SOURCE
+# @DESCRIPTION:
+# Location for user patches, see the epatch_user function.
+# Should be set by the user. Don't set this in ebuilds.
+: ${EPATCH_USER_SOURCE:=${PORTAGE_CONFIGROOT%/}/etc/portage/patches}
+
 # @FUNCTION: epatch_user
 # @USAGE:
 # @DESCRIPTION:
@@ -731,6 +732,7 @@ epatch_user() {
 epatch_user_death_notice() {
 	ewarn "!!! User patches were applied to this build!"
 }
+fi
 
 # @FUNCTION: emktemp
 # @USAGE: [temp dir]
-- 
2.6.3

[-- Attachment #2: Type: application/pgp-signature, Size: 490 bytes --]

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [gentoo-dev] [PATCH 2/2] eutils.eclass: Move all deprecated functions to the end.
  2015-11-29 13:29 [gentoo-dev] eutils.eclass: further cleanup for EAPI 6 Ulrich Mueller
  2015-11-29 13:29 ` [gentoo-dev] [PATCH 1/2] eutils.eclass: Disable epatch_user in " Ulrich Müller
@ 2015-11-29 13:31 ` Ulrich Müller
  2015-11-29 16:48 ` [gentoo-dev] [PATCH] eutils.eclass: In EAPI conditionals, replace "has" by case statements Ulrich Mueller
  2 siblings, 0 replies; 9+ messages in thread
From: Ulrich Müller @ 2015-11-29 13:31 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 15576 bytes --]

---
 eclass/eutils.eclass | 423 ++++++++++++++++++++++++++-------------------------
 1 file changed, 213 insertions(+), 210 deletions(-)

diff --git a/eclass/eutils.eclass b/eclass/eutils.eclass
index 5481b7f..5c7d1aa 100644
--- a/eclass/eutils.eclass
+++ b/eclass/eutils.eclass
@@ -20,50 +20,6 @@ _EUTILS_ECLASS=1
 
 inherit multilib toolchain-funcs
 
-if has "${EAPI:-0}" 0 1 2; then
-
-# @FUNCTION: epause
-# @USAGE: [seconds]
-# @DESCRIPTION:
-# Sleep for the specified number of seconds (default of 5 seconds).  Useful when
-# printing a message the user should probably be reading and often used in
-# conjunction with the ebeep function.  If the EPAUSE_IGNORE env var is set,
-# don't wait at all. Defined in EAPIs 0 1 and 2.
-epause() {
-	[[ -z ${EPAUSE_IGNORE} ]] && sleep ${1:-5}
-}
-
-# @FUNCTION: ebeep
-# @USAGE: [number of beeps]
-# @DESCRIPTION:
-# Issue the specified number of beeps (default of 5 beeps).  Useful when
-# printing a message the user should probably be reading and often used in
-# conjunction with the epause function.  If the EBEEP_IGNORE env var is set,
-# don't beep at all. Defined in EAPIs 0 1 and 2.
-ebeep() {
-	local n
-	if [[ -z ${EBEEP_IGNORE} ]] ; then
-		for ((n=1 ; n <= ${1:-5} ; n++)) ; do
-			echo -ne "\a"
-			sleep 0.1 &>/dev/null ; sleep 0,1 &>/dev/null
-			echo -ne "\a"
-			sleep 1
-		done
-	fi
-}
-
-else
-
-ebeep() {
-	ewarn "QA Notice: ebeep is not defined in EAPI=${EAPI}, please file a bug at https://bugs.gentoo.org"
-}
-
-epause() {
-	ewarn "QA Notice: epause is not defined in EAPI=${EAPI}, please file a bug at https://bugs.gentoo.org"
-}
-
-fi
-
 # @FUNCTION: eqawarn
 # @USAGE: [message]
 # @DESCRIPTION:
@@ -663,77 +619,6 @@ epatch() {
 	: # everything worked
 }
 
-if has "${EAPI:-0}" 0 1 2 3 4 5; then
-# @VARIABLE: EPATCH_USER_SOURCE
-# @DESCRIPTION:
-# Location for user patches, see the epatch_user function.
-# Should be set by the user. Don't set this in ebuilds.
-: ${EPATCH_USER_SOURCE:=${PORTAGE_CONFIGROOT%/}/etc/portage/patches}
-
-# @FUNCTION: epatch_user
-# @USAGE:
-# @DESCRIPTION:
-# Applies user-provided patches to the source tree. The patches are
-# taken from /etc/portage/patches/<CATEGORY>/<P-PR|P|PN>[:SLOT]/, where the first
-# of these three directories to exist will be the one to use, ignoring
-# any more general directories which might exist as well. They must end
-# in ".patch" to be applied.
-#
-# User patches are intended for quick testing of patches without ebuild
-# modifications, as well as for permanent customizations a user might
-# desire. Obviously, there can be no official support for arbitrarily
-# patched ebuilds. So whenever a build log in a bug report mentions that
-# user patches were applied, the user should be asked to reproduce the
-# problem without these.
-#
-# Not all ebuilds do call this function, so placing patches in the
-# stated directory might or might not work, depending on the package and
-# the eclasses it inherits and uses. It is safe to call the function
-# repeatedly, so it is always possible to add a call at the ebuild
-# level. The first call is the time when the patches will be
-# applied.
-#
-# Ideally, this function should be called after gentoo-specific patches
-# have been applied, so that their code can be modified as well, but
-# before calls to e.g. eautoreconf, as the user patches might affect
-# autotool input files as well.
-epatch_user() {
-	[[ $# -ne 0 ]] && die "epatch_user takes no options"
-
-	# Allow multiple calls to this function; ignore all but the first
-	local applied="${T}/epatch_user.log"
-	[[ -e ${applied} ]] && return 2
-
-	# don't clobber any EPATCH vars that the parent might want
-	local EPATCH_SOURCE check
-	for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}{,:${SLOT}}; do
-		EPATCH_SOURCE=${EPATCH_USER_SOURCE}/${CTARGET}/${check}
-		[[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${EPATCH_USER_SOURCE}/${CHOST}/${check}
-		[[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${EPATCH_USER_SOURCE}/${check}
-		if [[ -d ${EPATCH_SOURCE} ]] ; then
-			EPATCH_SOURCE=${EPATCH_SOURCE} \
-			EPATCH_SUFFIX="patch" \
-			EPATCH_FORCE="yes" \
-			EPATCH_MULTI_MSG="Applying user patches from ${EPATCH_SOURCE} ..." \
-			epatch
-			echo "${EPATCH_SOURCE}" > "${applied}"
-			has epatch_user_death_notice ${EBUILD_DEATH_HOOKS} || EBUILD_DEATH_HOOKS+=" epatch_user_death_notice"
-			return 0
-		fi
-	done
-	echo "none" > "${applied}"
-	return 1
-}
-# @FUNCTION: epatch_user_death_notice
-# @INTERNAL
-# @DESCRIPTION:
-# Include an explicit notice in the die message itself that user patches were
-# applied to this build.
-epatch_user_death_notice() {
-	ewarn "!!! User patches were applied to this build!"
-}
-fi
-
 # @FUNCTION: emktemp
 # @USAGE: [temp dir]
 # @DESCRIPTION:
@@ -1521,25 +1406,6 @@ path_exists() {
 	esac
 }
 
-# @FUNCTION: in_iuse
-# @USAGE: <flag>
-# @DESCRIPTION:
-# Determines whether the given flag is in IUSE. Strips IUSE default prefixes
-# as necessary.
-#
-# Note that this function should not be used in the global scope.
-if has "${EAPI:-0}" 0 1 2 3 4 5; then
-	in_iuse() {
-		debug-print-function ${FUNCNAME} "${@}"
-		[[ ${#} -eq 1 ]] || die "Invalid args to ${FUNCNAME}()"
-
-		local flag=${1}
-		local liuse=( ${IUSE} )
-
-		has "${flag}" "${liuse[@]#[+-]}"
-	}
-fi
-
 # @FUNCTION: use_if_iuse
 # @USAGE: <flag>
 # @DESCRIPTION:
@@ -1551,17 +1417,6 @@ use_if_iuse() {
 	use $1
 }
 
-# @FUNCTION: usex
-# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix]
-# @DESCRIPTION:
-# Proxy to declare usex for package managers or EAPIs that do not provide it
-# and use the package manager implementation when available (i.e. EAPI >= 5).
-# If USE flag is set, echo [true output][true suffix] (defaults to "yes"),
-# otherwise echo [false output][false suffix] (defaults to "no").
-if has "${EAPI:-0}" 0 1 2 3 4; then
-	usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963
-fi
-
 # @FUNCTION: prune_libtool_files
 # @USAGE: [--all|--modules]
 # @DESCRIPTION:
@@ -1708,71 +1563,6 @@ prune_libtool_files() {
 	fi
 }
 
-# @FUNCTION: einstalldocs
-# @DESCRIPTION:
-# Install documentation using DOCS and HTML_DOCS.
-#
-# If DOCS is declared and non-empty, all files listed in it are
-# installed. The files must exist, otherwise the function will fail.
-# In EAPI 4 and subsequent EAPIs DOCS may specify directories as well,
-# in other EAPIs using directories is unsupported.
-#
-# If DOCS is not declared, the files matching patterns given
-# in the default EAPI implementation of src_install will be installed.
-# If this is undesired, DOCS can be set to empty value to prevent any
-# documentation from being installed.
-#
-# If HTML_DOCS is declared and non-empty, all files and/or directories
-# listed in it are installed as HTML docs (using dohtml).
-#
-# Both DOCS and HTML_DOCS can either be an array or a whitespace-
-# separated list. Whenever directories are allowed, '<directory>/.' may
-# be specified in order to install all files within the directory
-# without creating a sub-directory in docdir.
-#
-# Passing additional options to dodoc and dohtml is not supported.
-# If you needed such a thing, you need to call those helpers explicitly.
-if has "${EAPI:-0}" 0 1 2 3 4 5; then
-	einstalldocs() {
-		debug-print-function ${FUNCNAME} "${@}"
-
-		local dodoc_opts=-r
-		has ${EAPI} 0 1 2 3 && dodoc_opts=
-
-		if ! declare -p DOCS &>/dev/null ; then
-			local d
-			for d in README* ChangeLog AUTHORS NEWS TODO CHANGES \
-					THANKS BUGS FAQ CREDITS CHANGELOG ; do
-				if [[ -s ${d} ]] ; then
-					dodoc "${d}" || die
-				fi
-			done
-		elif [[ $(declare -p DOCS) == "declare -a"* ]] ; then
-			if [[ ${DOCS[@]} ]] ; then
-				dodoc ${dodoc_opts} "${DOCS[@]}" || die
-			fi
-		else
-			if [[ ${DOCS} ]] ; then
-				dodoc ${dodoc_opts} ${DOCS} || die
-			fi
-		fi
-
-		if [[ $(declare -p HTML_DOCS 2>/dev/null) == "declare -a"* ]] ; then
-			if [[ ${HTML_DOCS[@]} ]] ; then
-				dohtml -r "${HTML_DOCS[@]}" || die
-			fi
-		else
-			if [[ ${HTML_DOCS} ]] ; then
-				dohtml -r ${HTML_DOCS} || die
-			fi
-		fi
-
-		return 0
-	}
-fi
-
-check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; }
-
 # @FUNCTION: optfeature
 # @USAGE: <short description> <package atom to match> [other atoms]
 # @DESCRIPTION:
@@ -1819,3 +1609,216 @@ optfeature() {
 }
 
 fi
+
+check_license() {
+	die "you no longer need this as portage supports ACCEPT_LICENSE itself"
+}
+
+if has "${EAPI:-0}" 0 1 2; then
+
+# @FUNCTION: epause
+# @USAGE: [seconds]
+# @DESCRIPTION:
+# Sleep for the specified number of seconds (default of 5 seconds).  Useful when
+# printing a message the user should probably be reading and often used in
+# conjunction with the ebeep function.  If the EPAUSE_IGNORE env var is set,
+# don't wait at all. Defined in EAPIs 0 1 and 2.
+epause() {
+	[[ -z ${EPAUSE_IGNORE} ]] && sleep ${1:-5}
+}
+
+# @FUNCTION: ebeep
+# @USAGE: [number of beeps]
+# @DESCRIPTION:
+# Issue the specified number of beeps (default of 5 beeps).  Useful when
+# printing a message the user should probably be reading and often used in
+# conjunction with the epause function.  If the EBEEP_IGNORE env var is set,
+# don't beep at all. Defined in EAPIs 0 1 and 2.
+ebeep() {
+	local n
+	if [[ -z ${EBEEP_IGNORE} ]] ; then
+		for ((n=1 ; n <= ${1:-5} ; n++)) ; do
+			echo -ne "\a"
+			sleep 0.1 &>/dev/null ; sleep 0,1 &>/dev/null
+			echo -ne "\a"
+			sleep 1
+		done
+	fi
+}
+
+else
+
+ebeep() {
+	ewarn "QA Notice: ebeep is not defined in EAPI=${EAPI}, please file a bug at https://bugs.gentoo.org"
+}
+
+epause() {
+	ewarn "QA Notice: epause is not defined in EAPI=${EAPI}, please file a bug at https://bugs.gentoo.org"
+}
+
+fi
+
+if has "${EAPI:-0}" 0 1 2 3 4; then
+
+# @FUNCTION: usex
+# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix]
+# @DESCRIPTION:
+# Proxy to declare usex for package managers or EAPIs that do not provide it
+# and use the package manager implementation when available (i.e. EAPI >= 5).
+# If USE flag is set, echo [true output][true suffix] (defaults to "yes"),
+# otherwise echo [false output][false suffix] (defaults to "no").
+usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963
+
+fi
+
+if has "${EAPI:-0}" 0 1 2 3 4 5; then
+
+# @VARIABLE: EPATCH_USER_SOURCE
+# @DESCRIPTION:
+# Location for user patches, see the epatch_user function.
+# Should be set by the user. Don't set this in ebuilds.
+: ${EPATCH_USER_SOURCE:=${PORTAGE_CONFIGROOT%/}/etc/portage/patches}
+
+# @FUNCTION: epatch_user
+# @USAGE:
+# @DESCRIPTION:
+# Applies user-provided patches to the source tree. The patches are
+# taken from /etc/portage/patches/<CATEGORY>/<P-PR|P|PN>[:SLOT]/, where the first
+# of these three directories to exist will be the one to use, ignoring
+# any more general directories which might exist as well. They must end
+# in ".patch" to be applied.
+#
+# User patches are intended for quick testing of patches without ebuild
+# modifications, as well as for permanent customizations a user might
+# desire. Obviously, there can be no official support for arbitrarily
+# patched ebuilds. So whenever a build log in a bug report mentions that
+# user patches were applied, the user should be asked to reproduce the
+# problem without these.
+#
+# Not all ebuilds do call this function, so placing patches in the
+# stated directory might or might not work, depending on the package and
+# the eclasses it inherits and uses. It is safe to call the function
+# repeatedly, so it is always possible to add a call at the ebuild
+# level. The first call is the time when the patches will be
+# applied.
+#
+# Ideally, this function should be called after gentoo-specific patches
+# have been applied, so that their code can be modified as well, but
+# before calls to e.g. eautoreconf, as the user patches might affect
+# autotool input files as well.
+epatch_user() {
+	[[ $# -ne 0 ]] && die "epatch_user takes no options"
+
+	# Allow multiple calls to this function; ignore all but the first
+	local applied="${T}/epatch_user.log"
+	[[ -e ${applied} ]] && return 2
+
+	# don't clobber any EPATCH vars that the parent might want
+	local EPATCH_SOURCE check
+	for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}{,:${SLOT}}; do
+		EPATCH_SOURCE=${EPATCH_USER_SOURCE}/${CTARGET}/${check}
+		[[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${EPATCH_USER_SOURCE}/${CHOST}/${check}
+		[[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${EPATCH_USER_SOURCE}/${check}
+		if [[ -d ${EPATCH_SOURCE} ]] ; then
+			EPATCH_SOURCE=${EPATCH_SOURCE} \
+			EPATCH_SUFFIX="patch" \
+			EPATCH_FORCE="yes" \
+			EPATCH_MULTI_MSG="Applying user patches from ${EPATCH_SOURCE} ..." \
+			epatch
+			echo "${EPATCH_SOURCE}" > "${applied}"
+			has epatch_user_death_notice ${EBUILD_DEATH_HOOKS} || EBUILD_DEATH_HOOKS+=" epatch_user_death_notice"
+			return 0
+		fi
+	done
+	echo "none" > "${applied}"
+	return 1
+}
+
+# @FUNCTION: epatch_user_death_notice
+# @INTERNAL
+# @DESCRIPTION:
+# Include an explicit notice in the die message itself that user patches were
+# applied to this build.
+epatch_user_death_notice() {
+	ewarn "!!! User patches were applied to this build!"
+}
+
+# @FUNCTION: einstalldocs
+# @DESCRIPTION:
+# Install documentation using DOCS and HTML_DOCS.
+#
+# If DOCS is declared and non-empty, all files listed in it are
+# installed. The files must exist, otherwise the function will fail.
+# In EAPI 4 and subsequent EAPIs DOCS may specify directories as well,
+# in other EAPIs using directories is unsupported.
+#
+# If DOCS is not declared, the files matching patterns given
+# in the default EAPI implementation of src_install will be installed.
+# If this is undesired, DOCS can be set to empty value to prevent any
+# documentation from being installed.
+#
+# If HTML_DOCS is declared and non-empty, all files and/or directories
+# listed in it are installed as HTML docs (using dohtml).
+#
+# Both DOCS and HTML_DOCS can either be an array or a whitespace-
+# separated list. Whenever directories are allowed, '<directory>/.' may
+# be specified in order to install all files within the directory
+# without creating a sub-directory in docdir.
+#
+# Passing additional options to dodoc and dohtml is not supported.
+# If you needed such a thing, you need to call those helpers explicitly.
+einstalldocs() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	local dodoc_opts=-r
+	has ${EAPI} 0 1 2 3 && dodoc_opts=
+
+	if ! declare -p DOCS &>/dev/null ; then
+		local d
+		for d in README* ChangeLog AUTHORS NEWS TODO CHANGES \
+				THANKS BUGS FAQ CREDITS CHANGELOG ; do
+			if [[ -s ${d} ]] ; then
+				dodoc "${d}" || die
+			fi
+		done
+	elif [[ $(declare -p DOCS) == "declare -a"* ]] ; then
+		if [[ ${DOCS[@]} ]] ; then
+			dodoc ${dodoc_opts} "${DOCS[@]}" || die
+		fi
+	else
+		if [[ ${DOCS} ]] ; then
+			dodoc ${dodoc_opts} ${DOCS} || die
+		fi
+	fi
+
+	if [[ $(declare -p HTML_DOCS 2>/dev/null) == "declare -a"* ]] ; then
+		if [[ ${HTML_DOCS[@]} ]] ; then
+			dohtml -r "${HTML_DOCS[@]}" || die
+		fi
+	else
+		if [[ ${HTML_DOCS} ]] ; then
+			dohtml -r ${HTML_DOCS} || die
+		fi
+	fi
+
+	return 0
+}
+
+# @FUNCTION: in_iuse
+# @USAGE: <flag>
+# @DESCRIPTION:
+# Determines whether the given flag is in IUSE. Strips IUSE default prefixes
+# as necessary.
+#
+# Note that this function should not be used in the global scope.
+in_iuse() {
+	debug-print-function ${FUNCNAME} "${@}"
+	[[ ${#} -eq 1 ]] || die "Invalid args to ${FUNCNAME}()"
+
+	local flag=${1}
+	local liuse=( ${IUSE} )
+
+	has "${flag}" "${liuse[@]#[+-]}"
+}
+
+fi
-- 
2.6.3

[-- Attachment #2: Type: application/pgp-signature, Size: 490 bytes --]

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [gentoo-dev] [PATCH] eutils.eclass: In EAPI conditionals, replace "has" by case statements.
  2015-11-29 13:29 [gentoo-dev] eutils.eclass: further cleanup for EAPI 6 Ulrich Mueller
  2015-11-29 13:29 ` [gentoo-dev] [PATCH 1/2] eutils.eclass: Disable epatch_user in " Ulrich Müller
  2015-11-29 13:31 ` [gentoo-dev] [PATCH 2/2] eutils.eclass: Move all deprecated functions to the end Ulrich Müller
@ 2015-11-29 16:48 ` Ulrich Mueller
  2015-11-29 23:29   ` Davide Pesavento
  2 siblings, 1 reply; 9+ messages in thread
From: Ulrich Mueller @ 2015-11-29 16:48 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 1992 bytes --]

As suggested by mgorny, we could use bash internals instead of the
"has" function calls in global scope.

The patch below replaces them by case statements. (Unfortunately we
cannot use fall-through (&;) because it is a bash 4 feature.)

Ulrich


From 89e837f5179354aa3dfa454f51282ad9d1143402 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ulrich=20M=C3=BCller?= <ulm@gentoo.org>
Date: Sun, 29 Nov 2015 17:33:08 +0100
Subject: [PATCH] eutils.eclass: In EAPI conditionals, replace "has" by
 case statements.

---
 eclass/eutils.eclass | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/eclass/eutils.eclass b/eclass/eutils.eclass
index 5c7d1aa..1163051 100644
--- a/eclass/eutils.eclass
+++ b/eclass/eutils.eclass
@@ -1614,7 +1614,8 @@ check_license() {
 	die "you no longer need this as portage supports ACCEPT_LICENSE itself"
 }
 
-if has "${EAPI:-0}" 0 1 2; then
+case ${EAPI:-0} in
+0|1|2)
 
 # @FUNCTION: epause
 # @USAGE: [seconds]
@@ -1646,7 +1647,8 @@ ebeep() {
 	fi
 }
 
-else
+;;
+*)
 
 ebeep() {
 	ewarn "QA Notice: ebeep is not defined in EAPI=${EAPI}, please file a bug at https://bugs.gentoo.org"
@@ -1656,9 +1658,11 @@ epause() {
 	ewarn "QA Notice: epause is not defined in EAPI=${EAPI}, please file a bug at https://bugs.gentoo.org"
 }
 
-fi
+;;
+esac
 
-if has "${EAPI:-0}" 0 1 2 3 4; then
+case ${EAPI:-0} in
+0|1|2|3|4)
 
 # @FUNCTION: usex
 # @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix]
@@ -1669,9 +1673,11 @@ if has "${EAPI:-0}" 0 1 2 3 4; then
 # otherwise echo [false output][false suffix] (defaults to "no").
 usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963
 
-fi
+;;
+esac
 
-if has "${EAPI:-0}" 0 1 2 3 4 5; then
+case ${EAPI:-0} in
+0|1|2|3|4|5)
 
 # @VARIABLE: EPATCH_USER_SOURCE
 # @DESCRIPTION:
@@ -1821,4 +1827,5 @@ in_iuse() {
 	has "${flag}" "${liuse[@]#[+-]}"
 }
 
-fi
+;;
+esac
-- 
2.6.3

[-- Attachment #2: Type: application/pgp-signature, Size: 490 bytes --]

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [gentoo-dev] [PATCH] eutils.eclass: In EAPI conditionals, replace "has" by case statements.
  2015-11-29 16:48 ` [gentoo-dev] [PATCH] eutils.eclass: In EAPI conditionals, replace "has" by case statements Ulrich Mueller
@ 2015-11-29 23:29   ` Davide Pesavento
  2015-11-30  6:52     ` Ulrich Mueller
  0 siblings, 1 reply; 9+ messages in thread
From: Davide Pesavento @ 2015-11-29 23:29 UTC (permalink / raw
  To: gentoo-dev

On Sun, Nov 29, 2015 at 5:48 PM, Ulrich Mueller <ulm@gentoo.org> wrote:
> As suggested by mgorny, we could use bash internals instead of the
> "has" function calls in global scope.
>
> The patch below replaces them by case statements. (Unfortunately we
> cannot use fall-through (&;) because it is a bash 4 feature.)

Sounds reasonable, although I'd find an 'if' clause slightly more
readable, since there wouldn't be an 'else' branch in 2 out of 3
cases.

Thanks,
Davide


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-dev] [PATCH] eutils.eclass: In EAPI conditionals, replace "has" by case statements.
  2015-11-29 23:29   ` Davide Pesavento
@ 2015-11-30  6:52     ` Ulrich Mueller
  2015-11-30  9:47       ` Michał Górny
                         ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Ulrich Mueller @ 2015-11-30  6:52 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 715 bytes --]

>>>>> On Mon, 30 Nov 2015, Davide Pesavento wrote:

>> The patch below replaces them by case statements. (Unfortunately we
>> cannot use fall-through (&;) because it is a bash 4 feature.)

> Sounds reasonable, although I'd find an 'if' clause slightly more
> readable, since there wouldn't be an 'else' branch in 2 out of 3
> cases.

It is slightly more complicated to match multiple patterns with [[ ]]
because it requires multiple conditions, regexps, or extglob. We could
of course use a bracket expression like [[ ${EAPI:-0} = [012345] ]]
but I find it ugly in this context (and it won't be able to check for
EAPI 10 ;) ).

Besides, case seems to be the command most used for EAPI checking in
eclasses.

Ulrich

[-- Attachment #2: Type: application/pgp-signature, Size: 490 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-dev] [PATCH] eutils.eclass: In EAPI conditionals, replace "has" by case statements.
  2015-11-30  6:52     ` Ulrich Mueller
@ 2015-11-30  9:47       ` Michał Górny
  2015-11-30 17:33       ` Davide Pesavento
  2015-12-01 13:50       ` [gentoo-dev] " Duncan
  2 siblings, 0 replies; 9+ messages in thread
From: Michał Górny @ 2015-11-30  9:47 UTC (permalink / raw
  To: gentoo-dev, Ulrich Mueller

,

Dnia 30 listopada 2015 07:52:59 CET, Ulrich Mueller <ulm@gentoo.org> napisał(a):
>>>>>> On Mon, 30 Nov 2015, Davide Pesavento wrote:
>
>>> The patch below replaces them by case statements. (Unfortunately we
>>> cannot use fall-through (&;) because it is a bash 4 feature.)
>
>> Sounds reasonable, although I'd find an 'if' clause slightly more
>> readable, since there wouldn't be an 'else' branch in 2 out of 3
>> cases.
>
>It is slightly more complicated to match multiple patterns with [[ ]]
>because it requires multiple conditions, regexps, or extglob. We could
>of course use a bracket expression like [[ ${EAPI:-0} = [012345] ]]
>but I find it ugly in this context (and it won't be able to check for
>EAPI 10 ;) ).

Do you expect those functions to be restored in the eclass in EAPI 10? As I see it, it's moot argument.

>
>Besides, case seems to be the command most used for EAPI checking in
>eclasses.

Because usually it has three branches, not one or two.

>
>Ulrich

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-dev] [PATCH] eutils.eclass: In EAPI conditionals, replace "has" by case statements.
  2015-11-30  6:52     ` Ulrich Mueller
  2015-11-30  9:47       ` Michał Górny
@ 2015-11-30 17:33       ` Davide Pesavento
  2015-12-01 13:50       ` [gentoo-dev] " Duncan
  2 siblings, 0 replies; 9+ messages in thread
From: Davide Pesavento @ 2015-11-30 17:33 UTC (permalink / raw
  To: gentoo-dev

On Mon, Nov 30, 2015 at 7:52 AM, Ulrich Mueller <ulm@gentoo.org> wrote:
>>>>>> On Mon, 30 Nov 2015, Davide Pesavento wrote:
>
>>> The patch below replaces them by case statements. (Unfortunately we
>>> cannot use fall-through (&;) because it is a bash 4 feature.)
>
>> Sounds reasonable, although I'd find an 'if' clause slightly more
>> readable, since there wouldn't be an 'else' branch in 2 out of 3
>> cases.
>
> It is slightly more complicated to match multiple patterns with [[ ]]
> because it requires multiple conditions, regexps, or extglob. We could
> of course use a bracket expression like [[ ${EAPI:-0} = [012345] ]]
> but I find it ugly in this context (and it won't be able to check for
> EAPI 10 ;) ).

Yeah I had a bracket expression in mind... which I find less ugly than
a case/esac in this context. And I agree with mgorny that the EAPI=10
argument is kinda moot. Anyway, this is really not important, feel
free to ignore my comment.

Thanks,
Davide


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [gentoo-dev] Re: [PATCH] eutils.eclass: In EAPI conditionals, replace "has" by case statements.
  2015-11-30  6:52     ` Ulrich Mueller
  2015-11-30  9:47       ` Michał Górny
  2015-11-30 17:33       ` Davide Pesavento
@ 2015-12-01 13:50       ` Duncan
  2 siblings, 0 replies; 9+ messages in thread
From: Duncan @ 2015-12-01 13:50 UTC (permalink / raw
  To: gentoo-dev

Ulrich Mueller posted on Mon, 30 Nov 2015 07:52:59 +0100 as excerpted:

> It is slightly more complicated to match multiple patterns with [[ ]]
> because it requires multiple conditions, regexps, or extglob. We could 
of
> course use a bracket expression like [[ ${EAPI:-0} = [012345] ]] but I
> find it ugly in this context (and it won't be able to check for EAPI
> 10 ;)
> ).

Of course we could switch to abc... after ...789, instead of switching to 
double-digits.  And then to ABC... which should cover us for a few 
years...

If gentoo's still around and still using compatible EAPIs after Z... 
that's a problem we'll be lucky to have! =:^)

-- 
Duncan - List replies preferred.   No HTML msgs.
"Every nonfree program has a lord, a master --
and if you use the program, he is your master."  Richard Stallman



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-12-01 13:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-29 13:29 [gentoo-dev] eutils.eclass: further cleanup for EAPI 6 Ulrich Mueller
2015-11-29 13:29 ` [gentoo-dev] [PATCH 1/2] eutils.eclass: Disable epatch_user in " Ulrich Müller
2015-11-29 13:31 ` [gentoo-dev] [PATCH 2/2] eutils.eclass: Move all deprecated functions to the end Ulrich Müller
2015-11-29 16:48 ` [gentoo-dev] [PATCH] eutils.eclass: In EAPI conditionals, replace "has" by case statements Ulrich Mueller
2015-11-29 23:29   ` Davide Pesavento
2015-11-30  6:52     ` Ulrich Mueller
2015-11-30  9:47       ` Michał Górny
2015-11-30 17:33       ` Davide Pesavento
2015-12-01 13:50       ` [gentoo-dev] " Duncan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox