sys-apps/gentoo-functions: Sync with Gentoo

It's from Gentoo commit 5fccbf281ae32847683b2e4a1fab5b6bf30ed6b7.
This commit is contained in:
Flatcar Buildbot 2024-08-12 07:19:18 +00:00 committed by Krzesimir Nowak
parent e211426965
commit 77cfef27ee
6 changed files with 298 additions and 16 deletions

View File

@ -1,3 +1,3 @@
DIST gentoo-functions-0.19.tar.bz2 12079 BLAKE2B be0a3a54d4dee1755866047b670a69cd6fec368239123c3f0c08180b79a33c20147bca0e35e568faef6877513551e731bdf0c181aeb0460f6574d2d708219373 SHA512 2674d3fe5724cc6d685ae58bf0ee33f4a1bdba2c5e5809cfb193fd0a710d4678c2d9392c2c62d2321cf455f524950266dc1629ab684fe46632d179e539d5a39e DIST gentoo-functions-0.19.tar.bz2 12079 BLAKE2B be0a3a54d4dee1755866047b670a69cd6fec368239123c3f0c08180b79a33c20147bca0e35e568faef6877513551e731bdf0c181aeb0460f6574d2d708219373 SHA512 2674d3fe5724cc6d685ae58bf0ee33f4a1bdba2c5e5809cfb193fd0a710d4678c2d9392c2c62d2321cf455f524950266dc1629ab684fe46632d179e539d5a39e
DIST gentoo-functions-1.5.tar.bz2 15808 BLAKE2B 99c330eb4c7f1d7af67b6f93dba565f9ea37c15e82d0b97157067279671dc3918668bf8120f7c410f018d67761cee41320efaec4df43639765d023b23a3a9a7f SHA512 f7add7770f40e110864f16978e968bfd937c1a5099e336cc04f6861483bae36ff7932f502994df1ddfa347beef8736bd39bd276bafbe04190c9915446457ce15
DIST gentoo-functions-1.6.tar.bz2 16795 BLAKE2B c901cdb8f2fcb507b5397e9ce674a12641f2129b9be05776bb272e09b9db3a6d205e6a00ef51f71b3203eac4e333b297cfe5ae5d61f9dd43074073a749ca171e SHA512 922b801c79f12d15bcabdb6cd52246cc60a4b512dfcc10bb3933f07d2ec03e01fe5be72502ae34c87374c8a7e880ce268e7dc8d1afcbd28b65efb51b9e467306 DIST gentoo-functions-1.6.tar.bz2 16795 BLAKE2B c901cdb8f2fcb507b5397e9ce674a12641f2129b9be05776bb272e09b9db3a6d205e6a00ef51f71b3203eac4e333b297cfe5ae5d61f9dd43074073a749ca171e SHA512 922b801c79f12d15bcabdb6cd52246cc60a4b512dfcc10bb3933f07d2ec03e01fe5be72502ae34c87374c8a7e880ce268e7dc8d1afcbd28b65efb51b9e467306
DIST gentoo-functions-1.7.2.tar.bz2 29059 BLAKE2B 2b3d13e6f5b553fd0fa7a0880677bd61c82c8815d3801a2d80e7632a97c36f81b41075109856f6248ad0eb2453b511066e63a110c97984e6427135ad19cdc234 SHA512 3839b04784576cc5c5824b24f967862ea421be051983d1ac587de7e21b0fbc4f403e0d4f707ee5cbcf466ec4a12d188da9413a81ca71993c957328ff225cb9af

View File

@ -0,0 +1,34 @@
From 755177bbfcf4c46ad1ac31ad9501a6c8725b1a68 Mon Sep 17 00:00:00 2001
From: Kerin Millar <kfm@plushkava.net>
Date: Sun, 2 Jun 2024 04:36:27 +0100
Subject: Add the warn() function
This will be used internally by a forthcoming commit.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
---
functions.sh | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/functions.sh b/functions.sh
index 9736747..a97dde7 100644
--- a/functions.sh
+++ b/functions.sh
@@ -473,6 +473,14 @@ vewend()
fi
}
+#
+# Prints a diagnostic message prefixed with the basename of the running script.
+#
+warn()
+{
+ printf '%s: %s\n' "${0##*/}" "$*" >&2
+}
+
#
# Determines whether the first parameter is truthy. The values taken to be true
# are "yes", "true", "on" and "1", whereas their opposites are taken to be
--
cgit v1.2.3-65-gdbad

View File

@ -0,0 +1,233 @@
From 3f2519288f1074a7ef5e8378f4bdf37809b262e5 Mon Sep 17 00:00:00 2001
From: Kerin Millar <kfm@plushkava.net>
Date: Sun, 2 Jun 2024 04:36:37 +0100
Subject: Relax parameter validation for various functions
Following some deliberation over the matter, I have concluded that
calling die() for the handling of invalid parameters ought not to be
considered as a matter of course. As such, this commit retains the
existing diagnostics for the functions listed below, while modifying
them so as to no longer attempt to exit the shell.
- eend
- eqatag
- esyslog
- ewend
- is_older than
- veend
- vewend
- yesno
Signed-off-by: Kerin Millar <kfm@plushkava.net>
---
functions.sh | 69 ++++++++++++++++++++++++++++++++++------------------------
test-functions | 13 ++---------
2 files changed, 42 insertions(+), 40 deletions(-)
diff --git a/functions.sh b/functions.sh
index 48b4c5a..ec1f339 100644
--- a/functions.sh
+++ b/functions.sh
@@ -63,7 +63,7 @@ if ! command -v die >/dev/null; then
*)
genfun_status=$?
esac
- printf '%s: %s\n' "${0##*/}" "$*" >&2
+ warn "$@"
exit "${genfun_status}"
}
fi
@@ -209,7 +209,8 @@ eqatag()
shift
fi
if [ "$#" -eq 0 ]; then
- die "eqatag: no tag specified"
+ warn "eqatag: no tag specified"
+ return 1
fi
positional=0
tag=$1
@@ -222,7 +223,8 @@ eqatag()
case ${arg} in
[!=/]*=?*)
if [ "${positional}" -eq 1 ]; then
- _throw_invalid_args eqatag "${arg}"
+ _warn_for_args eqatag "${arg}"
+ return 1
fi
set -- "$@" --arg "${arg%%=*}" "${arg#*=}"
;;
@@ -234,7 +236,8 @@ eqatag()
set -- "$@" "${arg}"
;;
*)
- _throw_invalid_args eqatag "${arg}"
+ _warn_for_args eqatag "${arg}"
+ return 1
esac
done
json=$(
@@ -269,7 +272,8 @@ esyslog()
local pri tag msg
if [ "$#" -lt 2 ]; then
- die "esyslog: too few arguments (got $#, expected at least 2)"
+ warn "esyslog: too few arguments (got $#, expected at least 2)"
+ return 1
elif yesno "${EINFO_LOG}" && hash logger 2>/dev/null; then
pri=$1
tag=$2
@@ -380,8 +384,9 @@ is_older_than()
{
local ref has_gfind
- if [ "$#" -lt 2 ]; then
- die "is_older_than: too few arguments (got $#, expected at least 2)"
+ if [ "$#" -eq 0 ]; then
+ warn "is_older_than: too few arguments (got $#, expected at least 1)"
+ return 1
elif [ -e "$1" ]; then
ref=$1
else
@@ -431,7 +436,8 @@ veend()
if yesno "${EINFO_VERBOSE}"; then
GENFUN_CALLER=veend eend "$@"
elif [ "$#" -gt 0 ] && { ! is_int "$1" || [ "$1" -lt 0 ]; }; then
- _throw_invalid_args veend "$1"
+ _warn_for_args veend "$1"
+ false
else
return "$1"
fi
@@ -442,7 +448,8 @@ vewend()
if yesno "${EINFO_VERBOSE}"; then
GENFUN_CALLER=vewend ewend "$@"
elif [ "$#" -gt 0 ] && { ! is_int "$1" || [ "$1" -lt 0 ]; }; then
- _throw_invalid_args vewend "$1"
+ _warn_for_args vewend "$1"
+ false
else
return "$1"
fi
@@ -459,7 +466,8 @@ yesno()
local arg
if [ "$#" -eq 0 ]; then
- die "yesno: too few arguments (got $#, expected 1)"
+ warn "yesno: too few arguments (got $#, expected 1)"
+ return 1
fi
arg=$1
for _ in 1 2; do
@@ -471,14 +479,15 @@ yesno()
return 0
esac
if [ "$_" -ne 1 ] || ! is_identifier "$1"; then
- ! break
+ break
else
# The value appears to be a legal variable name. Treat
# it as a name reference and try again, once only.
eval "arg=\$$1"
fi
- done || _throw_invalid_args yesno "$1"
- return 1
+ done
+ _warn_for_args yesno "$@"
+ false
}
#
@@ -494,7 +503,9 @@ _eend()
if [ "$#" -eq 0 ]; then
retval=0
elif ! is_int "$1" || [ "$1" -lt 0 ]; then
- _throw_invalid_args "${GENFUN_CALLER}" "$1"
+ _warn_for_args "${GENFUN_CALLER}" "$1"
+ retval=1
+ msg=
else
retval=$1
shift
@@ -662,21 +673,6 @@ _print_args()
EOF
}
-#
-# Prints a diganostic message concerning invalid function arguments then exits.
-# The first argument shall be taken as a function identifier. The remaining
-# arguments shall be safely rendered as a part of the diagnostic.
-#
-_throw_invalid_args()
-{
- local ident plural
-
- ident=$1
- shift
- [ "$#" -gt 1 ] && plural=s || plural=
- die "${ident}: invalid argument${plural}: $(_print_args "$@")"
-}
-
#
# Determines whether the terminal on STDIN is able to report its dimensions.
# Upon success, the number of columns shall be stored in genfun_cols.
@@ -718,6 +714,21 @@ _update_tty_level()
fi
}
+#
+# Prints a diganostic message concerning invalid function arguments. The first
+# argument shall be taken as a function identifier. The remaining arguments
+# shall be safely rendered as a part of the diagnostic.
+#
+_warn_for_args()
+{
+ local ident plural
+
+ ident=$1
+ shift
+ [ "$#" -gt 1 ] && plural=s || plural=
+ warn "${ident}: invalid argument${plural}: $(_print_args "$@")"
+}
+
# All function declarations end here! Initialisation code only from hereon.
# shellcheck disable=2034
RC_GOT_FUNCTIONS=yes
diff --git a/test-functions b/test-functions
index d65a3a2..4a6e7dd 100755
--- a/test-functions
+++ b/test-functions
@@ -196,11 +196,7 @@ test_is_older_than() {
callback() {
shift
test_description="is_older_than $(_print_args "$@")"
- if [ "$#" -lt 2 ]; then
- ( is_older_than "$@" )
- else
- is_older_than "$@"
- fi
+ is_older_than "$@"
}
iterate_tests 4 "$@"
@@ -392,16 +388,11 @@ test_yesno() {
# shellcheck disable=2034
truthful_nameref=yes
- row=0
callback() {
shift
test_description="yesno $(_print_args "$@")"
- if [ "$(( row += 1 ))" -ge 22 ]; then
- ( yesno "$@" )
- else
- yesno "$@"
- fi
+ yesno "$@"
}
iterate_tests 3 "$@"
--
cgit v1.2.3-65-gdbad

View File

@ -16,7 +16,7 @@ inherit meson
DESCRIPTION="Base functions required by all Gentoo systems" DESCRIPTION="Base functions required by all Gentoo systems"
HOMEPAGE="https://gitweb.gentoo.org/proj/gentoo-functions.git" HOMEPAGE="https://gitweb.gentoo.org/proj/gentoo-functions.git"
LICENSE="GPL-2 public-domain" LICENSE="GPL-2"
SLOT="0" SLOT="0"
IUSE="test" IUSE="test"
RESTRICT="!test? ( test )" RESTRICT="!test? ( test )"
@ -24,6 +24,11 @@ RESTRICT="!test? ( test )"
# Specifically needs GNU find, as well. # Specifically needs GNU find, as well.
RDEPEND=">=sys-apps/findutils-4.9" RDEPEND=">=sys-apps/findutils-4.9"
PATCHES=(
"${FILESDIR}/${P}-relax-parameter-validation.patch"
"${FILESDIR}/${P}-add-warn-function.patch"
)
src_configure() { src_configure() {
local emesonargs=( local emesonargs=(
# Deliberately avoid /usr as consumers assume we're at /lib/gentoo. # Deliberately avoid /usr as consumers assume we're at /lib/gentoo.

View File

@ -3,6 +3,11 @@
EAPI=8 EAPI=8
inherit meson
DESCRIPTION="Base functions required by all Gentoo systems"
HOMEPAGE="https://gitweb.gentoo.org/proj/gentoo-functions.git"
if [[ ${PV} == 9999* ]]; then if [[ ${PV} == 9999* ]]; then
inherit git-r3 inherit git-r3
EGIT_REPO_URI="https://anongit.gentoo.org/git/proj/gentoo-functions.git" EGIT_REPO_URI="https://anongit.gentoo.org/git/proj/gentoo-functions.git"
@ -11,19 +16,11 @@ else
KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux ~arm64-macos ~ppc-macos ~x64-macos ~x64-solaris" KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux ~arm64-macos ~ppc-macos ~x64-macos ~x64-solaris"
fi fi
inherit meson LICENSE="GPL-2"
DESCRIPTION="Base functions required by all Gentoo systems"
HOMEPAGE="https://gitweb.gentoo.org/proj/gentoo-functions.git"
LICENSE="GPL-2 public-domain"
SLOT="0" SLOT="0"
IUSE="test" IUSE="test"
RESTRICT="!test? ( test )" RESTRICT="!test? ( test )"
# Specifically needs GNU find, as well.
RDEPEND=">=sys-apps/findutils-4.9"
src_configure() { src_configure() {
local emesonargs=( local emesonargs=(
# Deliberately avoid /usr as consumers assume we're at /lib/gentoo. # Deliberately avoid /usr as consumers assume we're at /lib/gentoo.
@ -34,3 +31,19 @@ src_configure() {
meson_src_configure meson_src_configure
} }
src_install() {
meson_src_install
if [[ ${EPREFIX} ]]; then
while read -r; do
if [[ ${REPLY} == $'\t'genfun_prefix= ]]; then
printf '\tgenfun_prefix=%q\n' "${EPREFIX}"
else
printf '%s\n' "${REPLY}"
fi || ! break
done < "${ED}/lib/gentoo/functions.sh" > "${T}/functions.sh" \
&& mv -- "${T}/functions.sh" "${ED}/lib/gentoo/functions.sh" \
|| die
fi
}

View File

@ -16,14 +16,11 @@ else
KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux ~arm64-macos ~ppc-macos ~x64-macos ~x64-solaris" KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux ~arm64-macos ~ppc-macos ~x64-macos ~x64-solaris"
fi fi
LICENSE="GPL-2 public-domain" LICENSE="GPL-2"
SLOT="0" SLOT="0"
IUSE="test" IUSE="test"
RESTRICT="!test? ( test )" RESTRICT="!test? ( test )"
# Specifically needs GNU find, as well.
RDEPEND=">=sys-apps/findutils-4.9"
src_configure() { src_configure() {
local emesonargs=( local emesonargs=(
# Deliberately avoid /usr as consumers assume we're at /lib/gentoo. # Deliberately avoid /usr as consumers assume we're at /lib/gentoo.
@ -41,7 +38,7 @@ src_install() {
if [[ ${EPREFIX} ]]; then if [[ ${EPREFIX} ]]; then
while read -r; do while read -r; do
if [[ ${REPLY} == $'\t'genfun_prefix= ]]; then if [[ ${REPLY} == $'\t'genfun_prefix= ]]; then
printf 'genfun_prefix=%q\n' "${EPREFIX}" printf '\tgenfun_prefix=%q\n' "${EPREFIX}"
else else
printf '%s\n' "${REPLY}" printf '%s\n' "${REPLY}"
fi || ! break fi || ! break