mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-15 08:56:58 +02:00
eclass/eutils: Sync with Gentoo
It's from Gentoo commit 77b4d89d0fa056317e53d8a80e216531ee192f8e.
This commit is contained in:
parent
dfb818cb2d
commit
4935a404f3
@ -1,72 +1,28 @@
|
|||||||
# Copyright 1999-2021 Gentoo Authors
|
# Copyright 1999-2022 Gentoo Authors
|
||||||
# Distributed under the terms of the GNU General Public License v2
|
# Distributed under the terms of the GNU General Public License v2
|
||||||
|
|
||||||
# @ECLASS: eutils.eclass
|
# @ECLASS: eutils.eclass
|
||||||
# @MAINTAINER:
|
# @MAINTAINER:
|
||||||
# base-system@gentoo.org
|
# base-system@gentoo.org
|
||||||
# @SUPPORTED_EAPIS: 5 6 7
|
# @SUPPORTED_EAPIS: 6 7
|
||||||
# @BLURB: many extra (but common) functions that are used in ebuilds
|
# @BLURB: many extra (but common) functions that are used in ebuilds
|
||||||
# @DESCRIPTION:
|
# @DEPRECATED: native package manager functions, more specific eclasses
|
||||||
# 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!
|
|
||||||
#
|
|
||||||
# This eclass is DEPRECATED and must not be inherited by any new ebuilds
|
|
||||||
# or eclasses. Use the more specific split eclasses instead, or native
|
|
||||||
# package manager functions when available.
|
|
||||||
|
|
||||||
if [[ -z ${_EUTILS_ECLASS} ]]; then
|
if [[ -z ${_EUTILS_ECLASS} ]]; then
|
||||||
_EUTILS_ECLASS=1
|
_EUTILS_ECLASS=1
|
||||||
|
|
||||||
# implicitly inherited (now split) eclasses
|
# implicitly inherited (now split) eclasses
|
||||||
case ${EAPI} in
|
case ${EAPI} in
|
||||||
5|6)
|
6) inherit desktop edos2unix epatch eqawarn estack ltprune multilib \
|
||||||
inherit desktop edos2unix epatch estack ltprune multilib \
|
preserve-libs strip-linguas toolchain-funcs vcs-clean wrapper ;;
|
||||||
preserve-libs strip-linguas toolchain-funcs vcs-clean wrapper
|
|
||||||
;;
|
|
||||||
7) inherit edos2unix strip-linguas wrapper ;;
|
7) inherit edos2unix strip-linguas wrapper ;;
|
||||||
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
|
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# @FUNCTION: emktemp
|
|
||||||
# @USAGE: [temp dir]
|
|
||||||
# @DESCRIPTION:
|
|
||||||
# Cheap replacement for when coreutils (and thus mktemp) does not exist
|
|
||||||
# on the user's system.
|
|
||||||
emktemp() {
|
emktemp() {
|
||||||
eqawarn "emktemp is deprecated. Create a temporary file in \${T} instead."
|
eerror "emktemp has been removed."
|
||||||
|
eerror "Create a temporary file in \${T} instead."
|
||||||
local exe="touch"
|
die "emktemp is banned"
|
||||||
[[ $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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
path_exists() {
|
path_exists() {
|
||||||
@ -76,119 +32,11 @@ path_exists() {
|
|||||||
die "path_exists is banned"
|
die "path_exists is banned"
|
||||||
}
|
}
|
||||||
|
|
||||||
# @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() {
|
use_if_iuse() {
|
||||||
eqawarn "use_if_iuse is deprecated."
|
eerror "use_if_iuse has been removed."
|
||||||
eqawarn "Define it as a local function, or inline it:"
|
eerror "Define it as a local function, or inline it:"
|
||||||
eqawarn " in_iuse foo && use foo"
|
eerror " in_iuse foo && use foo"
|
||||||
in_iuse $1 || return 1
|
die "use_if_iuse is banned"
|
||||||
use $1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ ${EAPI} == 5 ]] ; then
|
|
||||||
|
|
||||||
# @FUNCTION: einstalldocs
|
|
||||||
# @DESCRIPTION:
|
|
||||||
# Install documentation using DOCS and HTML_DOCS, in EAPIs that do not
|
|
||||||
# provide this function. When available (i.e., in EAPI 6 or later),
|
|
||||||
# the package manager implementation should be used instead.
|
|
||||||
#
|
|
||||||
# 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 5, DOCS may specify directories as well; in earlier
|
|
||||||
# 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
|
|
||||||
|
|
||||||
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. In EAPIs where it is available (i.e., EAPI 6
|
|
||||||
# or later), the package manager implementation should be used instead.
|
|
||||||
#
|
|
||||||
# Note that this function must 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 # EAPI 5
|
|
||||||
|
|
||||||
if [[ ${EAPI} == [56] ]] ; then
|
|
||||||
|
|
||||||
# @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
|
|
||||||
|
|
||||||
fi # EAPI [56]
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user