public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Marty E. Plummer" <hanetzer@startmail.com>
To: gentoo-dev@lists.gentoo.org
Cc: "Marty E. Plummer" <hanetzer@startmail.com>
Subject: [gentoo-dev] [PATCH] eutils.eclass: split unique functions into eutils-r1
Date: Sun,  8 Apr 2018 07:29:29 -0500	[thread overview]
Message-ID: <20180408122929.20363-1-hanetzer@startmail.com> (raw)

Split all functions unique to eutils into eutils-r1, and inherit it
from eutils. Issue a QA warning on EAPI=6 ebuilds using eutils directly
and suggest migrating to direct use of the needed eclass, with a list of
functions unique to eutils-r1.

With this we can start moving ebuilds which inherit eutils because they
need a function unique to the old eutils to eutils-r1, while being able
to single out ebuilds which used eutils to inherit other ebuilds lazily
or just cargo cult coding of always inheriting eutils.

Package-Manager: Portage-2.3.28, Repoman-2.3.9
---
 eclass/eutils-r1.eclass | 265 ++++++++++++++++++++++++++++++++++++++++
 eclass/eutils.eclass    | 253 ++------------------------------------
 2 files changed, 278 insertions(+), 240 deletions(-)
 create mode 100644 eclass/eutils-r1.eclass

diff --git a/eclass/eutils-r1.eclass b/eclass/eutils-r1.eclass
new file mode 100644
index 00000000000..93fd0be7928
--- /dev/null
+++ b/eclass/eutils-r1.eclass
@@ -0,0 +1,265 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: eutils-r1.eclass
+# @MAINTAINER:
+# base-system@gentoo.org
+# @BLURB: many extra (but common) functions that are used in ebuilds
+# @DESCRIPTION:
+# The eutils eclass contains a suite of functions that complement
+# the ones that ebuild.sh already contain.  The idea is that the functions
+# are not required in all ebuilds but enough utilize them to have a common
+# home rather than having multiple ebuilds implementing the same thing.
+#
+# Due to the nature of this eclass, some functions may have maintainers
+# different from the overall eclass!
+
+if [[ -z ${_EUTILS_R1_ECLASS} ]]; then
+_EUTILS_R1_ECLASS=1
+
+case ${EAPI:-0} in
+	6) ;;
+	*) [[ ${_EUTILS_ECLASS} == 1 ]] || die "${ECLASS}.eclass is banned n EAPI=${EAPI}" ;;
+esac
+
+# @FUNCTION: eqawarn
+# @USAGE: [message]
+# @DESCRIPTION:
+# Proxy to ewarn for package managers that don't provide eqawarn and use the PM
+# implementation if available. Reuses PORTAGE_ELOG_CLASSES as set by the dev
+# profile.
+if ! declare -F eqawarn >/dev/null ; then
+	eqawarn() {
+		has qa ${PORTAGE_ELOG_CLASSES} && ewarn "$@"
+		:
+	}
+fi
+
+# @FUNCTION: emktemp
+# @USAGE: [temp dir]
+# @DESCRIPTION:
+# Cheap replacement for when debianutils (and thus mktemp)
+# does not exist on the users system.
+emktemp() {
+	local exe="touch"
+	[[ $1 == -d ]] && exe="mkdir" && shift
+	local topdir=$1
+
+	if [[ -z ${topdir} ]] ; then
+		[[ -z ${T} ]] \
+			&& topdir="/tmp" \
+			|| topdir=${T}
+	fi
+
+	if ! type -P mktemp > /dev/null ; then
+		# system lacks `mktemp` so we have to fake it
+		local tmp=/
+		while [[ -e ${tmp} ]] ; do
+			tmp=${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM}
+		done
+		${exe} "${tmp}" || ${exe} -p "${tmp}"
+		echo "${tmp}"
+	else
+		# the args here will give slightly wierd names on BSD,
+		# but should produce a usable file on all userlands
+		if [[ ${exe} == "touch" ]] ; then
+			TMPDIR="${topdir}" mktemp -t tmp.XXXXXXXXXX
+		else
+			TMPDIR="${topdir}" mktemp -dt tmp.XXXXXXXXXX
+		fi
+	fi
+}
+
+# @FUNCTION: edos2unix
+# @USAGE: <file> [more files ...]
+# @DESCRIPTION:
+# A handy replacement for dos2unix, recode, fixdos, etc...  This allows you
+# to remove all of these text utilities from DEPEND variables because this
+# is a script based solution.  Just give it a list of files to convert and
+# they will all be changed from the DOS CRLF format to the UNIX LF format.
+edos2unix() {
+	[[ $# -eq 0 ]] && return 0
+	sed -i 's/\r$//' -- "$@" || die
+}
+
+# @FUNCTION: strip-linguas
+# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>]
+# @DESCRIPTION:
+# Make sure that LINGUAS only contains languages that
+# a package can support.  The first form allows you to
+# specify a list of LINGUAS.  The -i builds a list of po
+# files found in all the directories and uses the
+# intersection of the lists.  The -u builds a list of po
+# files found in all the directories and uses the union
+# of the lists.
+strip-linguas() {
+	local ls newls nols
+	if [[ $1 == "-i" ]] || [[ $1 == "-u" ]] ; then
+		local op=$1; shift
+		ls=$(find "$1" -name '*.po' -exec basename {} .po ';'); shift
+		local d f
+		for d in "$@" ; do
+			if [[ ${op} == "-u" ]] ; then
+				newls=${ls}
+			else
+				newls=""
+			fi
+			for f in $(find "$d" -name '*.po' -exec basename {} .po ';') ; do
+				if [[ ${op} == "-i" ]] ; then
+					has ${f} ${ls} && newls="${newls} ${f}"
+				else
+					has ${f} ${ls} || newls="${newls} ${f}"
+				fi
+			done
+			ls=${newls}
+		done
+	else
+		ls="$@"
+	fi
+
+	nols=""
+	newls=""
+	for f in ${LINGUAS} ; do
+		if has ${f} ${ls} ; then
+			newls="${newls} ${f}"
+		else
+			nols="${nols} ${f}"
+		fi
+	done
+	[[ -n ${nols} ]] \
+		&& einfo "Sorry, but ${PN} does not support the LINGUAS:" ${nols}
+	export LINGUAS=${newls:1}
+}
+
+# @FUNCTION: make_wrapper
+# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath]
+# @DESCRIPTION:
+# Create a shell wrapper script named wrapper in installpath
+# (defaults to the bindir) to execute target (default of wrapper) by
+# first optionally setting LD_LIBRARY_PATH to the colon-delimited
+# libpaths followed by optionally changing directory to chdir.
+make_wrapper() {
+	local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5
+	local tmpwrapper=$(emktemp)
+	has "${EAPI:-0}" 0 1 2 && local EPREFIX=""
+
+	(
+	echo '#!/bin/sh'
+	[[ -n ${chdir} ]] && printf 'cd "%s"\n' "${EPREFIX}${chdir}"
+	if [[ -n ${libdir} ]] ; then
+		local var
+		if [[ ${CHOST} == *-darwin* ]] ; then
+			var=DYLD_LIBRARY_PATH
+		else
+			var=LD_LIBRARY_PATH
+		fi
+		cat <<-EOF
+			if [ "\${${var}+set}" = "set" ] ; then
+				export ${var}="\${${var}}:${EPREFIX}${libdir}"
+			else
+				export ${var}="${EPREFIX}${libdir}"
+			fi
+		EOF
+	fi
+	# We don't want to quote ${bin} so that people can pass complex
+	# things as ${bin} ... "./someprog --args"
+	printf 'exec %s "$@"\n' "${bin/#\//${EPREFIX}/}"
+	) > "${tmpwrapper}"
+	chmod go+rx "${tmpwrapper}"
+
+	if [[ -n ${path} ]] ; then
+		(
+		exeinto "${path}"
+		newexe "${tmpwrapper}" "${wrapper}"
+		) || die
+	else
+		newbin "${tmpwrapper}" "${wrapper}" || die
+	fi
+}
+
+# @FUNCTION: path_exists
+# @USAGE: [-a|-o] <paths>
+# @DESCRIPTION:
+# Check if the specified paths exist.  Works for all types of paths
+# (files/dirs/etc...).  The -a and -o flags control the requirements
+# of the paths.  They correspond to "and" and "or" logic.  So the -a
+# flag means all the paths must exist while the -o flag means at least
+# one of the paths must exist.  The default behavior is "and".  If no
+# paths are specified, then the return value is "false".
+path_exists() {
+	local opt=$1
+	[[ ${opt} == -[ao] ]] && shift || opt="-a"
+
+	# no paths -> return false
+	# same behavior as: [[ -e "" ]]
+	[[ $# -eq 0 ]] && return 1
+
+	local p r=0
+	for p in "$@" ; do
+		[[ -e ${p} ]]
+		: $(( r += $? ))
+	done
+
+	case ${opt} in
+		-a) return $(( r != 0 )) ;;
+		-o) return $(( r == $# )) ;;
+	esac
+}
+
+# @FUNCTION: use_if_iuse
+# @USAGE: <flag>
+# @DESCRIPTION:
+# Return true if the given flag is in USE and IUSE.
+#
+# Note that this function should not be used in the global scope.
+use_if_iuse() {
+	in_iuse $1 || return 1
+	use $1
+}
+
+# @FUNCTION: optfeature
+# @USAGE: <short description> <package atom to match> [other atoms]
+# @DESCRIPTION:
+# Print out a message suggesting an optional package (or packages)
+# not currently installed which provides the described functionality.
+#
+# The following snippet would suggest app-misc/foo for optional foo support,
+# app-misc/bar or app-misc/baz[bar] for optional bar support
+# and either both app-misc/a and app-misc/b or app-misc/c for alphabet support.
+# @CODE
+#	optfeature "foo support" app-misc/foo
+#	optfeature "bar support" app-misc/bar app-misc/baz[bar]
+#	optfeature "alphabet support" "app-misc/a app-misc/b" app-misc/c
+# @CODE
+optfeature() {
+	debug-print-function ${FUNCNAME} "$@"
+	local i j msg
+	local desc=$1
+	local flag=0
+	shift
+	for i; do
+		for j in ${i}; do
+			if has_version "${j}"; then
+				flag=1
+			else
+				flag=0
+				break
+			fi
+		done
+		if [[ ${flag} -eq 1 ]]; then
+			break
+		fi
+	done
+	if [[ ${flag} -eq 0 ]]; then
+		for i; do
+			msg=" "
+			for j in ${i}; do
+				msg+=" ${j} and"
+			done
+			msg="${msg:0: -4} for ${desc}"
+			elog "${msg}"
+		done
+	fi
+}
+
+fi
diff --git a/eclass/eutils.eclass b/eclass/eutils.eclass
index 7840afbb77b..9b3c20db3b9 100644
--- a/eclass/eutils.eclass
+++ b/eclass/eutils.eclass
@@ -20,250 +20,23 @@ _EUTILS_ECLASS=1
 # implicitly inherited (now split) eclasses
 case ${EAPI:-0} in
 0|1|2|3|4|5|6)
-	inherit desktop epatch estack ltprune multilib preserve-libs \
+	inherit desktop epatch estack eutils-r1 ltprune multilib preserve-libs \
 		toolchain-funcs vcs-clean
 	;;
 esac
 
-# @FUNCTION: eqawarn
-# @USAGE: [message]
-# @DESCRIPTION:
-# Proxy to ewarn for package managers that don't provide eqawarn and use the PM
-# implementation if available. Reuses PORTAGE_ELOG_CLASSES as set by the dev
-# profile.
-if ! declare -F eqawarn >/dev/null ; then
-	eqawarn() {
-		has qa ${PORTAGE_ELOG_CLASSES} && ewarn "$@"
-		:
-	}
-fi
-
-# @FUNCTION: emktemp
-# @USAGE: [temp dir]
-# @DESCRIPTION:
-# Cheap replacement for when debianutils (and thus mktemp)
-# does not exist on the users system.
-emktemp() {
-	local exe="touch"
-	[[ $1 == -d ]] && exe="mkdir" && shift
-	local topdir=$1
-
-	if [[ -z ${topdir} ]] ; then
-		[[ -z ${T} ]] \
-			&& topdir="/tmp" \
-			|| topdir=${T}
-	fi
-
-	if ! type -P mktemp > /dev/null ; then
-		# system lacks `mktemp` so we have to fake it
-		local tmp=/
-		while [[ -e ${tmp} ]] ; do
-			tmp=${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM}
-		done
-		${exe} "${tmp}" || ${exe} -p "${tmp}"
-		echo "${tmp}"
-	else
-		# the args here will give slightly wierd names on BSD,
-		# but should produce a usable file on all userlands
-		if [[ ${exe} == "touch" ]] ; then
-			TMPDIR="${topdir}" mktemp -t tmp.XXXXXXXXXX
-		else
-			TMPDIR="${topdir}" mktemp -dt tmp.XXXXXXXXXX
-		fi
-	fi
-}
-
-# @FUNCTION: edos2unix
-# @USAGE: <file> [more files ...]
-# @DESCRIPTION:
-# A handy replacement for dos2unix, recode, fixdos, etc...  This allows you
-# to remove all of these text utilities from DEPEND variables because this
-# is a script based solution.  Just give it a list of files to convert and
-# they will all be changed from the DOS CRLF format to the UNIX LF format.
-edos2unix() {
-	[[ $# -eq 0 ]] && return 0
-	sed -i 's/\r$//' -- "$@" || die
-}
-
-# @FUNCTION: strip-linguas
-# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>]
-# @DESCRIPTION:
-# Make sure that LINGUAS only contains languages that
-# a package can support.  The first form allows you to
-# specify a list of LINGUAS.  The -i builds a list of po
-# files found in all the directories and uses the
-# intersection of the lists.  The -u builds a list of po
-# files found in all the directories and uses the union
-# of the lists.
-strip-linguas() {
-	local ls newls nols
-	if [[ $1 == "-i" ]] || [[ $1 == "-u" ]] ; then
-		local op=$1; shift
-		ls=$(find "$1" -name '*.po' -exec basename {} .po ';'); shift
-		local d f
-		for d in "$@" ; do
-			if [[ ${op} == "-u" ]] ; then
-				newls=${ls}
-			else
-				newls=""
-			fi
-			for f in $(find "$d" -name '*.po' -exec basename {} .po ';') ; do
-				if [[ ${op} == "-i" ]] ; then
-					has ${f} ${ls} && newls="${newls} ${f}"
-				else
-					has ${f} ${ls} || newls="${newls} ${f}"
-				fi
-			done
-			ls=${newls}
-		done
-	else
-		ls="$@"
-	fi
-
-	nols=""
-	newls=""
-	for f in ${LINGUAS} ; do
-		if has ${f} ${ls} ; then
-			newls="${newls} ${f}"
-		else
-			nols="${nols} ${f}"
-		fi
-	done
-	[[ -n ${nols} ]] \
-		&& einfo "Sorry, but ${PN} does not support the LINGUAS:" ${nols}
-	export LINGUAS=${newls:1}
-}
-
-# @FUNCTION: make_wrapper
-# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath]
-# @DESCRIPTION:
-# Create a shell wrapper script named wrapper in installpath
-# (defaults to the bindir) to execute target (default of wrapper) by
-# first optionally setting LD_LIBRARY_PATH to the colon-delimited
-# libpaths followed by optionally changing directory to chdir.
-make_wrapper() {
-	local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5
-	local tmpwrapper=$(emktemp)
-	has "${EAPI:-0}" 0 1 2 && local EPREFIX=""
-
-	(
-	echo '#!/bin/sh'
-	[[ -n ${chdir} ]] && printf 'cd "%s"\n' "${EPREFIX}${chdir}"
-	if [[ -n ${libdir} ]] ; then
-		local var
-		if [[ ${CHOST} == *-darwin* ]] ; then
-			var=DYLD_LIBRARY_PATH
-		else
-			var=LD_LIBRARY_PATH
-		fi
-		cat <<-EOF
-			if [ "\${${var}+set}" = "set" ] ; then
-				export ${var}="\${${var}}:${EPREFIX}${libdir}"
-			else
-				export ${var}="${EPREFIX}${libdir}"
-			fi
-		EOF
-	fi
-	# We don't want to quote ${bin} so that people can pass complex
-	# things as ${bin} ... "./someprog --args"
-	printf 'exec %s "$@"\n' "${bin/#\//${EPREFIX}/}"
-	) > "${tmpwrapper}"
-	chmod go+rx "${tmpwrapper}"
-
-	if [[ -n ${path} ]] ; then
-		(
-		exeinto "${path}"
-		newexe "${tmpwrapper}" "${wrapper}"
-		) || die
-	else
-		newbin "${tmpwrapper}" "${wrapper}" || die
-	fi
-}
-
-# @FUNCTION: path_exists
-# @USAGE: [-a|-o] <paths>
-# @DESCRIPTION:
-# Check if the specified paths exist.  Works for all types of paths
-# (files/dirs/etc...).  The -a and -o flags control the requirements
-# of the paths.  They correspond to "and" and "or" logic.  So the -a
-# flag means all the paths must exist while the -o flag means at least
-# one of the paths must exist.  The default behavior is "and".  If no
-# paths are specified, then the return value is "false".
-path_exists() {
-	local opt=$1
-	[[ ${opt} == -[ao] ]] && shift || opt="-a"
-
-	# no paths -> return false
-	# same behavior as: [[ -e "" ]]
-	[[ $# -eq 0 ]] && return 1
-
-	local p r=0
-	for p in "$@" ; do
-		[[ -e ${p} ]]
-		: $(( r += $? ))
-	done
-
-	case ${opt} in
-		-a) return $(( r != 0 )) ;;
-		-o) return $(( r == $# )) ;;
-	esac
-}
-
-# @FUNCTION: use_if_iuse
-# @USAGE: <flag>
-# @DESCRIPTION:
-# Return true if the given flag is in USE and IUSE.
-#
-# Note that this function should not be used in the global scope.
-use_if_iuse() {
-	in_iuse $1 || return 1
-	use $1
-}
-
-# @FUNCTION: optfeature
-# @USAGE: <short description> <package atom to match> [other atoms]
-# @DESCRIPTION:
-# Print out a message suggesting an optional package (or packages)
-# not currently installed which provides the described functionality.
-#
-# The following snippet would suggest app-misc/foo for optional foo support,
-# app-misc/bar or app-misc/baz[bar] for optional bar support
-# and either both app-misc/a and app-misc/b or app-misc/c for alphabet support.
-# @CODE
-#	optfeature "foo support" app-misc/foo
-#	optfeature "bar support" app-misc/bar app-misc/baz[bar]
-#	optfeature "alphabet support" "app-misc/a app-misc/b" app-misc/c
-# @CODE
-optfeature() {
-	debug-print-function ${FUNCNAME} "$@"
-	local i j msg
-	local desc=$1
-	local flag=0
-	shift
-	for i; do
-		for j in ${i}; do
-			if has_version "${j}"; then
-				flag=1
-			else
-				flag=0
-				break
-			fi
-		done
-		if [[ ${flag} -eq 1 ]]; then
-			break
-		fi
-	done
-	if [[ ${flag} -eq 0 ]]; then
-		for i; do
-			msg=" "
-			for j in ${i}; do
-				msg+=" ${j} and"
-			done
-			msg="${msg:0: -4} for ${desc}"
-			elog "${msg}"
-		done
-	fi
-}
+# warn users to migrate away from eutils to direct use of inherited eclasses
+# in EAPI 6
+case ${EAPI:-0} in
+6)
+	eqawarn "QA warning: eutils should not be used in EAPI=6. Instead, directly"
+	eqawarn "inherit the eclasses you need."
+	eqawarn "Should you require the functions emktemp, edos2unix, strip-linguas,"
+	eqawarn "make_wrapper, path_exists, use_if_iuse, or optfeature please use"
+	eqawarn "eutils-r1."
+	;;
+0|1|2|3|4|5) ;;
+esac
 
 case ${EAPI:-0} in
 0|1|2)
-- 
2.17.0



             reply	other threads:[~2018-04-08 13:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-08 12:29 Marty E. Plummer [this message]
2018-04-08 13:26 ` [gentoo-dev] [PATCH] eutils.eclass: split unique functions into eutils-r1 Ulrich Mueller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180408122929.20363-1-hanetzer@startmail.com \
    --to=hanetzer@startmail.com \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox