summaryrefslogtreecommitdiff
path: root/eclass
diff options
context:
space:
mode:
authorV3n3RiX <venerix@koprulu.sector>2024-05-15 00:01:28 +0100
committerV3n3RiX <venerix@koprulu.sector>2024-05-15 00:01:28 +0100
commit514c44bb9cc421df9c323acbad430cbb6ee5b89a (patch)
tree22621125c9bc9177d5339f093f57cb928531f33f /eclass
parent59c2499e0c9720169c9d5a02168c51c807a21467 (diff)
gentoo auto-resync : 15:05:2024 - 00:01:27
Diffstat (limited to 'eclass')
-rw-r--r--eclass/Manifest.gzbin39416 -> 39578 bytes
-rw-r--r--eclass/edo.eclass67
-rwxr-xr-xeclass/tests/edo.sh113
-rw-r--r--eclass/texlive-common.eclass8
4 files changed, 175 insertions, 13 deletions
diff --git a/eclass/Manifest.gz b/eclass/Manifest.gz
index f6ed992a62be..9c620b74027c 100644
--- a/eclass/Manifest.gz
+++ b/eclass/Manifest.gz
Binary files differ
diff --git a/eclass/edo.eclass b/eclass/edo.eclass
index c2e7ed60083f..5fd77a676a8b 100644
--- a/eclass/edo.eclass
+++ b/eclass/edo.eclass
@@ -1,4 +1,4 @@
-# Copyright 2022 Gentoo Authors
+# Copyright 2022-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: edo.eclass
@@ -12,10 +12,16 @@
# This eclass provides the 'edo' command, and an 'edob' variant for ebegin/eend,
# which logs the command used verbosely and dies (exits) on failure.
#
-# This eclass should be used only where needed to give a more verbose log, e.g.
-# for invoking non-standard ./configure scripts, or building objects/binaries
-# directly within ebuilds via compiler invocations. It is NOT to be used
-# in place of generic 'command || die' where verbosity is unnecessary.
+# The 'edo' command should be used only where needed to give a more verbose log,
+# e.g. for invoking non-standard ./configure scripts, or building
+# objects/binaries directly within ebuilds via compiler invocations. It is NOT
+# to be used in place of generic 'command || die' where verbosity is
+# unnecessary.
+#
+# 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) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
@@ -35,14 +41,55 @@ edo() {
}
# @FUNCTION: edob
-# @USAGE: <command> [<args>...]
+# @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'.
+# 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() {
- ebegin "Running $@"
- "$@"
- eend $? || die -n "Failed to run command: $@"
+ 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
diff --git a/eclass/tests/edo.sh b/eclass/tests/edo.sh
new file mode 100755
index 000000000000..cac03e0401ba
--- /dev/null
+++ b/eclass/tests/edo.sh
@@ -0,0 +1,113 @@
+#!/bin/bash
+# Copyright 1999-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+source tests-common.sh || exit
+
+inherit edo
+
+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
diff --git a/eclass/texlive-common.eclass b/eclass/texlive-common.eclass
index 15d475799a88..072581dde78e 100644
--- a/eclass/texlive-common.eclass
+++ b/eclass/texlive-common.eclass
@@ -22,6 +22,8 @@ case ${EAPI} in
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac
+inherit edo
+
if [[ -z ${_TEXLIVE_COMMON_ECLASS} ]]; then
_TEXLIVE_COMMON_ECLASS=1
@@ -199,9 +201,9 @@ etexmf-update() {
efmtutil-sys() {
if has_version 'app-text/texlive-core' ; then
if [[ -z ${ROOT} && -x "${EPREFIX}"/usr/bin/fmtutil-sys ]] ; then
- einfo "Rebuilding formats"
- "${EPREFIX}"/usr/bin/fmtutil-sys --all &> /dev/null ||
- die -n "fmtutil-sys returned non-zero exit status ${?}"
+ edob -m "Rebuilding TexLive formats" \
+ -l fmtutils-sys-all \
+ "${EPREFIX}"/usr/bin/fmtutil-sys --all
else
ewarn "Cannot run fmtutil-sys for some reason."
ewarn "Your formats might be inconsistent with your installed ${PN} version"