mirror of
https://github.com/flatcar/scripts.git
synced 2025-10-01 02:22:11 +02:00
eclass/eutils: Sync with gentoo
It's from gentoo commit 48651ecc0d4444536ed15b06736e331238b6f92b.
This commit is contained in:
parent
734cccb114
commit
cf383e6edf
@ -1,9 +1,10 @@
|
|||||||
# Copyright 1999-2018 Gentoo Foundation
|
# Copyright 1999-2021 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
|
||||||
# @BLURB: many extra (but common) functions that are used in ebuilds
|
# @BLURB: many extra (but common) functions that are used in ebuilds
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# The eutils eclass contains a suite of functions that complement
|
# The eutils eclass contains a suite of functions that complement
|
||||||
@ -13,24 +14,32 @@
|
|||||||
#
|
#
|
||||||
# Due to the nature of this eclass, some functions may have maintainers
|
# Due to the nature of this eclass, some functions may have maintainers
|
||||||
# different from the overall eclass!
|
# 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:-0} in
|
case ${EAPI} in
|
||||||
0|1|2|3|4|5|6)
|
5|6)
|
||||||
inherit desktop epatch estack ltprune multilib preserve-libs \
|
inherit desktop edos2unix epatch estack ltprune multilib \
|
||||||
toolchain-funcs vcs-clean
|
preserve-libs strip-linguas toolchain-funcs vcs-clean wrapper
|
||||||
;;
|
;;
|
||||||
|
7) inherit edos2unix strip-linguas wrapper ;;
|
||||||
|
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# @FUNCTION: emktemp
|
# @FUNCTION: emktemp
|
||||||
# @USAGE: [temp dir]
|
# @USAGE: [temp dir]
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# Cheap replacement for when debianutils (and thus mktemp)
|
# Cheap replacement for when coreutils (and thus mktemp) does not exist
|
||||||
# does not exist on the users system.
|
# on the user's system.
|
||||||
emktemp() {
|
emktemp() {
|
||||||
|
eqawarn "emktemp is deprecated. Create a temporary file in \${T} instead."
|
||||||
|
|
||||||
local exe="touch"
|
local exe="touch"
|
||||||
[[ $1 == -d ]] && exe="mkdir" && shift
|
[[ $1 == -d ]] && exe="mkdir" && shift
|
||||||
local topdir=$1
|
local topdir=$1
|
||||||
@ -60,114 +69,6 @@ emktemp() {
|
|||||||
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'
|
|
||||||
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
|
|
||||||
[[ -n ${chdir} ]] && printf 'cd "%s" &&\n' "${EPREFIX}${chdir}"
|
|
||||||
# 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
|
|
||||||
(
|
|
||||||
exeopts -m 0755
|
|
||||||
exeinto "${path}"
|
|
||||||
newexe "${tmpwrapper}" "${wrapper}"
|
|
||||||
) || die
|
|
||||||
else
|
|
||||||
newbin "${tmpwrapper}" "${wrapper}" || die
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
path_exists() {
|
path_exists() {
|
||||||
eerror "path_exists has been removed. Please see the following post"
|
eerror "path_exists has been removed. Please see the following post"
|
||||||
eerror "for a replacement snippet:"
|
eerror "for a replacement snippet:"
|
||||||
@ -182,119 +83,14 @@ path_exists() {
|
|||||||
#
|
#
|
||||||
# Note that this function should not be used in the global scope.
|
# Note that this function should not be used in the global scope.
|
||||||
use_if_iuse() {
|
use_if_iuse() {
|
||||||
|
eqawarn "use_if_iuse is deprecated."
|
||||||
|
eqawarn "Define it as a local function, or inline it:"
|
||||||
|
eqawarn " in_iuse foo && use foo"
|
||||||
in_iuse $1 || return 1
|
in_iuse $1 || return 1
|
||||||
use $1
|
use $1
|
||||||
}
|
}
|
||||||
|
|
||||||
# @FUNCTION: optfeature
|
if [[ ${EAPI} == 5 ]] ; then
|
||||||
# @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
|
|
||||||
}
|
|
||||||
|
|
||||||
case ${EAPI:-0} in
|
|
||||||
0|1|2)
|
|
||||||
|
|
||||||
# @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
|
|
||||||
}
|
|
||||||
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
case ${EAPI:-0} in
|
|
||||||
0|1|2|3|4)
|
|
||||||
|
|
||||||
# @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
|
|
||||||
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
case ${EAPI:-0} in
|
|
||||||
0|1|2|3|4|5)
|
|
||||||
|
|
||||||
# @FUNCTION: einstalldocs
|
# @FUNCTION: einstalldocs
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
@ -326,7 +122,6 @@ einstalldocs() {
|
|||||||
debug-print-function ${FUNCNAME} "${@}"
|
debug-print-function ${FUNCNAME} "${@}"
|
||||||
|
|
||||||
local dodoc_opts=-r
|
local dodoc_opts=-r
|
||||||
has ${EAPI} 0 1 2 3 && dodoc_opts=
|
|
||||||
|
|
||||||
if ! declare -p DOCS &>/dev/null ; then
|
if ! declare -p DOCS &>/dev/null ; then
|
||||||
local d
|
local d
|
||||||
@ -377,11 +172,9 @@ in_iuse() {
|
|||||||
has "${flag}" "${liuse[@]#[+-]}"
|
has "${flag}" "${liuse[@]#[+-]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
;;
|
fi # EAPI 5
|
||||||
esac
|
|
||||||
|
|
||||||
case ${EAPI:-0} in
|
if [[ ${EAPI} == [56] ]] ; then
|
||||||
0|1|2|3|4|5|6)
|
|
||||||
|
|
||||||
# @FUNCTION: eqawarn
|
# @FUNCTION: eqawarn
|
||||||
# @USAGE: [message]
|
# @USAGE: [message]
|
||||||
@ -396,7 +189,6 @@ if ! declare -F eqawarn >/dev/null ; then
|
|||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
;;
|
fi # EAPI [56]
|
||||||
esac
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user