From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 0BE231382C5 for ; Sun, 8 Apr 2018 13:04:28 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id BCBB0E09DA; Sun, 8 Apr 2018 13:04:20 +0000 (UTC) Received: from mx-out1.startmail.com (mx-out1.startmail.com [145.131.90.139]) (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 2B62DE08E0 for ; Sun, 8 Apr 2018 13:04:20 +0000 (UTC) From: "Marty E. Plummer" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=startmail.com; s=2017-11; t=1523192657; bh=lTKFxGt0x+8URfu1bIQf2Iqb7z0XqyduBi8sus9W5Iw=; h=From:To:Cc:Subject:Date:From; b=HSuLGcNoZ841FZREqex3YbJBj9GRAwGBZwlhKSN3JYjJVQppXoBnMcgpOCpFRrjvT ZoidRsTIRqR4PVGY7i2sD5PBb3jmKhEHOeKd5tA2MUPKO1K5lhoAdwimWPyu2yxwEu 8wYpM3DZrI7w+hJ1mRo6u0dXml8SUsCrBRTEirFZ8o0vkjWcqWraTrHD3C2PWNaQK/ TtVACMUHIp9ROlS0IISLMt6RZmb6r6gSzjJHlUw+3NYnzamXE9bAfokJntOtWkTZsX YhSCuiHlo6NxDXNDSz0EYivphvv8QsSQZNKNI6r0umHISFZXVvLO/Y3YTFNV6KDnqC TcITe/kIGgMvg== To: gentoo-dev@lists.gentoo.org Cc: "Marty E. Plummer" Subject: [gentoo-dev] [PATCH] eutils.eclass: split unique functions into eutils-r1 Date: Sun, 8 Apr 2018 07:29:29 -0500 Message-Id: <20180408122929.20363-1-hanetzer@startmail.com> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Archives-Salt: 3bc97751-e3cd-4aec-8095-7f625399c526 X-Archives-Hash: 0c0ac8706ebc23683e17b9f4f8d60d65 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: [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: [|<-i|-u> ] +# @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: [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] +# @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: +# @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: [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: [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: [|<-i|-u> ] -# @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: [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] -# @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: -# @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: [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