mirror of
https://github.com/gentoo-mirror/gentoo.git
synced 2026-11-24 11:37:20 -08:00
edo.eclass: factor edob out in edob.eclass, support EAPI 9
We previously tried to add EAPI 9 support to edo eclass via conditional functions in039d53fd14("edo.eclass: Support EAPI 9"). Unfortunatley, this turned out to produce spurious pkgcheck warnings in EAPI 8 and was reverted with11f1705e0f("Revert "edo.eclass: Support EAPI 9""). Therefore, we instead now factor out edob in its own eclass, to make it available for EAPI 9 ebuilds and eclasses. Signed-off-by: Florian Schmaus <flow@gentoo.org>
This commit is contained in:
+8
-53
@@ -1,4 +1,4 @@
|
||||
# Copyright 2022-2025 Gentoo Authors
|
||||
# Copyright 2022-2026 Gentoo Authors
|
||||
# Distributed under the terms of the GNU General Public License v2
|
||||
|
||||
# @ECLASS: edo.eclass
|
||||
@@ -7,6 +7,7 @@
|
||||
# @AUTHOR:
|
||||
# Sam James <sam@gentoo.org>
|
||||
# @SUPPORTED_EAPIS: 7 8
|
||||
# @PROVIDES: edob
|
||||
# @BLURB: Convenience function to run commands verbosely and die on failure
|
||||
# @DESCRIPTION:
|
||||
# This eclass provides the 'edo' command, and an 'edob' variant for ebegin/eend,
|
||||
@@ -22,6 +23,10 @@
|
||||
# those commands produce output. The 'edob' command will suppress the
|
||||
# command's output and only present it if the command returned with a
|
||||
# non-zero exit status.
|
||||
#
|
||||
# Note that starting with EAPI 9, the edo command is provided by the
|
||||
# package manager. If you need the edob command in EAPI 9 ebuilds or
|
||||
# eclasses, then inherit edob.eclass directly.
|
||||
case ${EAPI} in
|
||||
7|8) ;;
|
||||
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
|
||||
@@ -30,6 +35,8 @@ esac
|
||||
if [[ -z ${_EDO_ECLASS} ]] ; then
|
||||
_EDO_ECLASS=1
|
||||
|
||||
inherit edob
|
||||
|
||||
# @FUNCTION: edo
|
||||
# @USAGE: <command> [<args>...]
|
||||
# @DESCRIPTION:
|
||||
@@ -58,56 +65,4 @@ edo() {
|
||||
"$@" || die -n "Failed to run command: ${1}"
|
||||
}
|
||||
|
||||
# @FUNCTION: edob
|
||||
# @USAGE: [-l <log-name>] [-m <message>] <command> [<args>...]
|
||||
# @DESCRIPTION:
|
||||
# Executes 'command' with ebegin & eend with any given arguments and exits
|
||||
# on failure unless called under 'nonfatal'. This function redirects
|
||||
# stdout and stderr to a log file. The content of the log file is shown
|
||||
# if the command returns with a non-zero exit status.
|
||||
#
|
||||
# If -m <message> is provided, then invokes ebegin with <message>, otherwise
|
||||
# a default message is used. If -l <log-name> is provided, then <log-name> is
|
||||
# used to construct the name of the log file where stdout and stderr of the
|
||||
# command is redirected to.
|
||||
edob() {
|
||||
local message
|
||||
local log_name
|
||||
|
||||
while true; do
|
||||
case "${1}" in
|
||||
-l|-m)
|
||||
[[ $# -lt 2 ]] && die "Must provide an argument to ${1}"
|
||||
case "${1}" in
|
||||
-l)
|
||||
log_name="${2}"
|
||||
;;
|
||||
-m)
|
||||
message="${2}"
|
||||
;;
|
||||
esac
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
[[ -z ${message} ]] && message="Running $@"
|
||||
[[ -z ${log_name} ]] && log_name="$(basename ${1})"
|
||||
|
||||
local log_file="${T}/${log_name}.log"
|
||||
|
||||
ebegin "${message}"
|
||||
|
||||
"$@" &> "${log_file}"
|
||||
local ret=$?
|
||||
|
||||
if ! eend $ret; then
|
||||
cat "${log_file}"
|
||||
die -n "Command \"$@\" failed with exit status $ret"
|
||||
fi
|
||||
}
|
||||
|
||||
fi
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
# Copyright 2022-2026 Gentoo Authors
|
||||
# Distributed under the terms of the GNU General Public License v2
|
||||
|
||||
# @ECLASS: edob.eclass
|
||||
# @MAINTAINER:
|
||||
# QA Team <qa@gentoo.org>
|
||||
# @AUTHOR:
|
||||
# Sam James <sam@gentoo.org>
|
||||
# Florian Schmaus <flow@gentoo.org>
|
||||
# @SUPPORTED_EAPIS: 7 8 9
|
||||
# @BLURB: Wrap output-producing commands in ebegin/eend
|
||||
# @DESCRIPTION:
|
||||
# This eclass provides the edob command for ebegin/eend,
|
||||
# which logs the command used verbosely and dies (exits) on failure.
|
||||
#
|
||||
# The edob command can be used for long running commands, even if
|
||||
# those commands produce output. The edob command will suppress the
|
||||
# command's output and only present it if the command returned with a
|
||||
# non-zero exit status.
|
||||
case ${EAPI} in
|
||||
7|8|9) ;;
|
||||
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
|
||||
esac
|
||||
|
||||
if [[ -z ${_EDOB_ECLASS} ]] ; then
|
||||
_EDOB_ECLASS=1
|
||||
|
||||
# @FUNCTION: edob
|
||||
# @USAGE: [-l <log-name>] [-m <message>] <command> [<args>...]
|
||||
# @DESCRIPTION:
|
||||
# Executes 'command' with any given arguments wrapped in ebegin and
|
||||
# eend. Aborts on failure unless called under 'nonfatal'.
|
||||
# Furthermore, redirects stdout and stderr to a log file. The content
|
||||
# of the log file is shown if the command returns with a non-zero exit
|
||||
# status.
|
||||
#
|
||||
# If -m <message> is provided, then invokes ebegin with <message>, otherwise
|
||||
# a default message is used. If -l <log-name> is provided, then <log-name> is
|
||||
# used to construct the name of the log file to which stdout and stderr of the
|
||||
# command is redirected to.
|
||||
edob() {
|
||||
local message
|
||||
local log_name
|
||||
|
||||
while true; do
|
||||
case "${1}" in
|
||||
-l|-m)
|
||||
[[ $# -lt 2 ]] && die "Must provide an argument to ${1}"
|
||||
case "${1}" in
|
||||
-l)
|
||||
log_name="${2}"
|
||||
;;
|
||||
-m)
|
||||
message="${2}"
|
||||
;;
|
||||
esac
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
[[ -z ${message} ]] && message="Running $@"
|
||||
[[ -z ${log_name} ]] && log_name="$(basename ${1})"
|
||||
|
||||
local log_file="${T}/${log_name}.log"
|
||||
|
||||
ebegin "${message}"
|
||||
|
||||
"$@" &> "${log_file}"
|
||||
local ret=$?
|
||||
|
||||
if ! eend $ret; then
|
||||
cat "${log_file}"
|
||||
die -n "Command \"$@\" failed with exit status $ret"
|
||||
fi
|
||||
}
|
||||
|
||||
fi
|
||||
+1
-98
@@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
# Copyright 1999-2025 Gentoo Authors
|
||||
# Copyright 1999-2026 Gentoo Authors
|
||||
# Distributed under the terms of the GNU General Public License v2
|
||||
|
||||
EAPI=8
|
||||
@@ -25,98 +25,6 @@ test_edo() {
|
||||
tend $? "returned: ${have_ret}, output: ${have_out}"
|
||||
}
|
||||
|
||||
test_edob_simple() {
|
||||
tbegin "edob with output test"
|
||||
(
|
||||
edob make_some_noise foo
|
||||
eend $?
|
||||
) &> "${T}/edob.out"
|
||||
local res=$?
|
||||
if [[ $res -ne 0 ]]; then
|
||||
tend $res
|
||||
return 0
|
||||
fi
|
||||
|
||||
local log_file="${T}/make_some_noise.log"
|
||||
local second_line="$(sed -n '2p' "${log_file}")"
|
||||
[[ "${second_line}" == "foo" ]];
|
||||
tend $? "Unexpected output, found \"${second_line}\", expected \"foo\""
|
||||
|
||||
rm "${log_file}" || die
|
||||
}
|
||||
|
||||
test_edob_explicit_log_name() {
|
||||
tbegin "edob with explicit logfile name"
|
||||
(
|
||||
edob -l mylog make_some_noise bar
|
||||
eend $?
|
||||
) &> "${T}/edob.out"
|
||||
local res=$?
|
||||
if [[ $res -ne 0 ]]; then
|
||||
cat "${T}/edob.out"
|
||||
tend $res
|
||||
return 0
|
||||
fi
|
||||
|
||||
local log_file="${T}/mylog.log"
|
||||
local second_line="$(sed -n '2p' "${log_file}")"
|
||||
[[ "${second_line}" == "bar" ]];
|
||||
tend $? "Unexpected output, found \"${second_line}\", expected \"foo\""
|
||||
|
||||
rm "${log_file}" || die
|
||||
}
|
||||
|
||||
test_edob_explicit_message() {
|
||||
tbegin "edob with explicit message"
|
||||
(
|
||||
edob -m "Making some noise" make_some_noise baz
|
||||
eend $?
|
||||
) &> "${T}/edob.out"
|
||||
local res=$?
|
||||
if [[ $res -ne 0 ]]; then
|
||||
cat "${T}/edob.out"
|
||||
tend $res
|
||||
return 0
|
||||
fi
|
||||
|
||||
local log_file="${T}/make_some_noise.log"
|
||||
local second_line="$(sed -n '2p' "${log_file}")"
|
||||
[[ "${second_line}" == "baz" ]];
|
||||
tend $? "Unexpected output, found \"${second_line}\", expected \"baz\""
|
||||
|
||||
rm "${log_file}" || die
|
||||
}
|
||||
|
||||
test_edob_failure() {
|
||||
make_some_noise_and_fail() {
|
||||
make_some_noise "$@"
|
||||
return 1
|
||||
}
|
||||
|
||||
tbegin "edob with failing command"
|
||||
(
|
||||
edob -m "Making some noise" make_some_noise_and_fail quz
|
||||
eend $?
|
||||
) &> "${T}/edob.out"
|
||||
local res=$?
|
||||
# Now, this time we expect res to be exactly '1'.
|
||||
if [[ $res -ne 1 ]]; then
|
||||
tend 1
|
||||
return 1
|
||||
fi
|
||||
|
||||
local log_file="${T}/make_some_noise_and_fail.log"
|
||||
local second_line="$(sed -n '2p' "${log_file}")"
|
||||
[[ "${second_line}" == "quz" ]];
|
||||
tend $? "Unexpected output, found \"${second_line}\", expected \"quz\""
|
||||
|
||||
rm "${log_file}" || die
|
||||
|
||||
local fourth_line_of_edob_out="$(sed -n '4p' "${T}/edob.out")"
|
||||
[[ "${fourth_line_of_edob_out}" == "quz" ]];
|
||||
tend $? "Unexpected output, found \"${fourth_line_of_edob_out}\", expected \"quz\""
|
||||
}
|
||||
|
||||
test_edo 0 "/bin/true foo" /bin/true foo
|
||||
test_edo 1 "/bin/false bar" /bin/false bar
|
||||
test_edo 0 "make_some_noise baz" make_some_noise baz
|
||||
@@ -128,9 +36,4 @@ test_edo 0 ": '\"' \\' 'foo'\\''bar'" : '"' "'" "foo'bar"
|
||||
test_edo 0 ": '' ' ' \$'\\t' \$'\\001'" : '' ' ' $'\t' $'\x01'
|
||||
test_edo 0 ": äöü" : 'äöü'
|
||||
|
||||
test_edob_simple
|
||||
test_edob_explicit_log_name
|
||||
test_edob_explicit_message
|
||||
test_edob_failure
|
||||
|
||||
texit
|
||||
|
||||
Executable
+113
@@ -0,0 +1,113 @@
|
||||
#!/bin/bash
|
||||
# Copyright 1999-2026 Gentoo Authors
|
||||
# Distributed under the terms of the GNU General Public License v2
|
||||
|
||||
EAPI=8
|
||||
source tests-common.sh || exit
|
||||
|
||||
inherit edob
|
||||
|
||||
make_some_noise() {
|
||||
echo "Here is some noise:"
|
||||
echo "${1:?Must provide some noise}"
|
||||
echo "EoN"
|
||||
}
|
||||
|
||||
test_edob_simple() {
|
||||
tbegin "edob with output test"
|
||||
(
|
||||
edob make_some_noise foo
|
||||
eend $?
|
||||
) &> "${T}/edob.out"
|
||||
local res=$?
|
||||
if [[ $res -ne 0 ]]; then
|
||||
tend $res
|
||||
return 0
|
||||
fi
|
||||
|
||||
local log_file="${T}/make_some_noise.log"
|
||||
local second_line="$(sed -n '2p' "${log_file}")"
|
||||
[[ "${second_line}" == "foo" ]];
|
||||
tend $? "Unexpected output, found \"${second_line}\", expected \"foo\""
|
||||
|
||||
rm "${log_file}" || die
|
||||
}
|
||||
|
||||
test_edob_explicit_log_name() {
|
||||
tbegin "edob with explicit logfile name"
|
||||
(
|
||||
edob -l mylog make_some_noise bar
|
||||
eend $?
|
||||
) &> "${T}/edob.out"
|
||||
local res=$?
|
||||
if [[ $res -ne 0 ]]; then
|
||||
cat "${T}/edob.out"
|
||||
tend $res
|
||||
return 0
|
||||
fi
|
||||
|
||||
local log_file="${T}/mylog.log"
|
||||
local second_line="$(sed -n '2p' "${log_file}")"
|
||||
[[ "${second_line}" == "bar" ]];
|
||||
tend $? "Unexpected output, found \"${second_line}\", expected \"foo\""
|
||||
|
||||
rm "${log_file}" || die
|
||||
}
|
||||
|
||||
test_edob_explicit_message() {
|
||||
tbegin "edob with explicit message"
|
||||
(
|
||||
edob -m "Making some noise" make_some_noise baz
|
||||
eend $?
|
||||
) &> "${T}/edob.out"
|
||||
local res=$?
|
||||
if [[ $res -ne 0 ]]; then
|
||||
cat "${T}/edob.out"
|
||||
tend $res
|
||||
return 0
|
||||
fi
|
||||
|
||||
local log_file="${T}/make_some_noise.log"
|
||||
local second_line="$(sed -n '2p' "${log_file}")"
|
||||
[[ "${second_line}" == "baz" ]];
|
||||
tend $? "Unexpected output, found \"${second_line}\", expected \"baz\""
|
||||
|
||||
rm "${log_file}" || die
|
||||
}
|
||||
|
||||
test_edob_failure() {
|
||||
make_some_noise_and_fail() {
|
||||
make_some_noise "$@"
|
||||
return 1
|
||||
}
|
||||
|
||||
tbegin "edob with failing command"
|
||||
(
|
||||
edob -m "Making some noise" make_some_noise_and_fail quz
|
||||
eend $?
|
||||
) &> "${T}/edob.out"
|
||||
local res=$?
|
||||
# Now, this time we expect res to be exactly '1'.
|
||||
if [[ $res -ne 1 ]]; then
|
||||
tend 1
|
||||
return 1
|
||||
fi
|
||||
|
||||
local log_file="${T}/make_some_noise_and_fail.log"
|
||||
local second_line="$(sed -n '2p' "${log_file}")"
|
||||
[[ "${second_line}" == "quz" ]];
|
||||
tend $? "Unexpected output, found \"${second_line}\", expected \"quz\""
|
||||
|
||||
rm "${log_file}" || die
|
||||
|
||||
local fourth_line_of_edob_out="$(sed -n '4p' "${T}/edob.out")"
|
||||
[[ "${fourth_line_of_edob_out}" == "quz" ]];
|
||||
tend $? "Unexpected output, found \"${fourth_line_of_edob_out}\", expected \"quz\""
|
||||
}
|
||||
|
||||
test_edob_simple
|
||||
test_edob_explicit_log_name
|
||||
test_edob_explicit_message
|
||||
test_edob_failure
|
||||
|
||||
texit
|
||||
Reference in New Issue
Block a user