mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-14 16:37:01 +02:00
eclass/edo: Sync with Gentoo
It's from Gentoo commit b5d7d615c01a4b76bccde0a06de3a9ac3c7a850c.
This commit is contained in:
parent
b5d5b7e331
commit
49225d9e3c
@ -1,4 +1,4 @@
|
|||||||
# Copyright 2022 Gentoo Authors
|
# Copyright 2022-2024 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: edo.eclass
|
# @ECLASS: edo.eclass
|
||||||
@ -12,10 +12,16 @@
|
|||||||
# This eclass provides the 'edo' command, and an 'edob' variant for ebegin/eend,
|
# This eclass provides the 'edo' command, and an 'edob' variant for ebegin/eend,
|
||||||
# which logs the command used verbosely and dies (exits) on failure.
|
# 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.
|
# The 'edo' command should be used only where needed to give a more verbose log,
|
||||||
# for invoking non-standard ./configure scripts, or building objects/binaries
|
# e.g. for invoking non-standard ./configure scripts, or building
|
||||||
# directly within ebuilds via compiler invocations. It is NOT to be used
|
# objects/binaries directly within ebuilds via compiler invocations. It is NOT
|
||||||
# in place of generic 'command || die' where verbosity is unnecessary.
|
# 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
|
case ${EAPI} in
|
||||||
7|8) ;;
|
7|8) ;;
|
||||||
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
|
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
|
||||||
@ -35,14 +41,55 @@ edo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# @FUNCTION: edob
|
# @FUNCTION: edob
|
||||||
# @USAGE: <command> [<args>...]
|
# @USAGE: [-l <log-name>] [-m <message>] <command> [<args>...]
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# Executes 'command' with ebegin & eend with any given arguments and exits
|
# 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() {
|
edob() {
|
||||||
ebegin "Running $@"
|
local message
|
||||||
"$@"
|
local log_name
|
||||||
eend $? || die -n "Failed to run command: $@"
|
|
||||||
|
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
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user