public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH 0/2] edo.eclass: enhace edob for usage with nosiy commands
@ 2024-05-08 17:15 Florian Schmaus
  2024-05-08 17:15 ` [gentoo-dev] [PATCH 1/2] " Florian Schmaus
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Florian Schmaus @ 2024-05-08 17:15 UTC (permalink / raw)
  To: gentoo-dev; +Cc: qa, Florian Schmaus

The motivation for this change is to allow edob to be used with noisy
commands, i.e., commands that produce a lot of output, in cases where
the output is in general not of interest. However, if the command
fails, the output should be shown and appear in build.log.

We do this by simply redirecting the output to a file in $T, and show
this file if the command returned a non-zero exit status.

We already have a few cases in ::gentoo where such output is simply
redirected to /dev/null, hindering post-mortem analysis. Those could
be converted to edob with its new behavior.

PR at https://github.com/gentoo/gentoo/pull/36117

Florian Schmaus (2):
  edo.eclass: enhace edob for usage with nosiy commands
  eftmutil-sys: use edob

 eclass/edo.eclass            | 54 ++++++++++++++++++++++++++++++++----
 eclass/texlive-common.eclass |  8 ++++--
 2 files changed, 53 insertions(+), 9 deletions(-)

-- 
2.43.2



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [gentoo-dev] [PATCH 1/2] edo.eclass: enhace edob for usage with nosiy commands
  2024-05-08 17:15 [gentoo-dev] [PATCH 0/2] edo.eclass: enhace edob for usage with nosiy commands Florian Schmaus
@ 2024-05-08 17:15 ` Florian Schmaus
  2024-05-19  9:06   ` gentoo
  2024-05-08 17:15 ` [gentoo-dev] [PATCH 2/2] eftmutil-sys: use edob Florian Schmaus
  2024-05-13 15:05 ` [gentoo-dev] [PATCH 0/2] edo.eclass: enhace edob for usage with nosiy commands Sam James
  2 siblings, 1 reply; 5+ messages in thread
From: Florian Schmaus @ 2024-05-08 17:15 UTC (permalink / raw)
  To: gentoo-dev; +Cc: qa, Florian Schmaus

Normally, edob can, or rather should, not be used with noisy commands,
i.e., commands that produce an output. This is because the output
destroys the concept of ebegin and eend, where the eend marker is shown
on the same line that is produced by ebegin.

However, it sometimes would be nice to use edob with noisy commands, but
this means to redirect stdout and stderr of those commands. Instead of
redirecting the output to /dev/null, we save the output in a log file
under T. This allows us to present the output to the user in case the
command fails, making it futhermore part of the build.log, which we
expect users to attach to bug reports.

Signed-off-by: Florian Schmaus <flow@gentoo.org>
---
 eclass/edo.eclass | 66 ++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 56 insertions(+), 10 deletions(-)

diff --git a/eclass/edo.eclass b/eclass/edo.eclass
index c2e7ed60083f..0d410719675c 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,14 @@
 # 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 should be used if its output is not of general interest,
+# as it will be only shown if the command returns a non-zero exit status.
 case ${EAPI} in
 	7|8) ;;
 	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
@@ -35,14 +39,56 @@ edo() {
 }
 
 # @FUNCTION: edob
-# @USAGE: <command> [<args>...]
+# @USAGE: [-m <message>] [-l <log-name>] <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
+			-m|-n)
+				[[ $# -lt 2 ]] && die "Must provide an argument to ${1}"
+				case "${1}" in
+					-m)
+						message="${2}"
+						;;
+					-n)
+						log="${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"
+	[[ -f ${log_file} ]] && die "Log file ${log_file} exists. Consider using \"edob -l\""
+
+	ebegin "${message}"
+
+	"$@" &> "${log_file}"
+	local ret=$?
+
+	if ! eend $ret; then
+		cat "${log_file}"
+		die -n "Command \"$@\" failed with exit status $ret"
+	fi
 }
 
 fi
-- 
2.43.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-dev] [PATCH 2/2] eftmutil-sys: use edob
  2024-05-08 17:15 [gentoo-dev] [PATCH 0/2] edo.eclass: enhace edob for usage with nosiy commands Florian Schmaus
  2024-05-08 17:15 ` [gentoo-dev] [PATCH 1/2] " Florian Schmaus
@ 2024-05-08 17:15 ` Florian Schmaus
  2024-05-13 15:05 ` [gentoo-dev] [PATCH 0/2] edo.eclass: enhace edob for usage with nosiy commands Sam James
  2 siblings, 0 replies; 5+ messages in thread
From: Florian Schmaus @ 2024-05-08 17:15 UTC (permalink / raw)
  To: gentoo-dev; +Cc: qa, Florian Schmaus

Signed-off-by: Florian Schmaus <flow@gentoo.org>
---
 eclass/texlive-common.eclass | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

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"
-- 
2.43.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [gentoo-dev] [PATCH 0/2] edo.eclass: enhace edob for usage with nosiy commands
  2024-05-08 17:15 [gentoo-dev] [PATCH 0/2] edo.eclass: enhace edob for usage with nosiy commands Florian Schmaus
  2024-05-08 17:15 ` [gentoo-dev] [PATCH 1/2] " Florian Schmaus
  2024-05-08 17:15 ` [gentoo-dev] [PATCH 2/2] eftmutil-sys: use edob Florian Schmaus
@ 2024-05-13 15:05 ` Sam James
  2 siblings, 0 replies; 5+ messages in thread
From: Sam James @ 2024-05-13 15:05 UTC (permalink / raw)
  To: Florian Schmaus; +Cc: gentoo-dev, qa

Florian Schmaus <flow@gentoo.org> writes:

> The motivation for this change is to allow edob to be used with noisy
> commands, i.e., commands that produce a lot of output, in cases where
> the output is in general not of interest. However, if the command
> fails, the output should be shown and appear in build.log.
>
> We do this by simply redirecting the output to a file in $T, and show
> this file if the command returned a non-zero exit status.
>
> We already have a few cases in ::gentoo where such output is simply
> redirected to /dev/null, hindering post-mortem analysis. Those could
> be converted to edob with its new behavior.
>
> PR at https://github.com/gentoo/gentoo/pull/36117
>

LGTM. I agree there's value in it.

> Florian Schmaus (2):
>   edo.eclass: enhace edob for usage with nosiy commands

s/nosiy/noisy/

>   eftmutil-sys: use edob
>
>  eclass/edo.eclass            | 54 ++++++++++++++++++++++++++++++++----
>  eclass/texlive-common.eclass |  8 ++++--
>  2 files changed, 53 insertions(+), 9 deletions(-)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [gentoo-dev] [PATCH 1/2] edo.eclass: enhace edob for usage with nosiy commands
  2024-05-08 17:15 ` [gentoo-dev] [PATCH 1/2] " Florian Schmaus
@ 2024-05-19  9:06   ` gentoo
  0 siblings, 0 replies; 5+ messages in thread
From: gentoo @ 2024-05-19  9:06 UTC (permalink / raw)
  To: gentoo-dev

Hello,

08.05.2024 19:15:52 Florian Schmaus <flow@gentoo.org>:
[..]
> # @FUNCTION: edob
> -# @USAGE: <command> [<args>...]
> +# @USAGE: [-m <message>] [-l <log-name>] <command> [<args>...]
                             ^^!
[..]
> -l <log-name> is provided, then <log-name> is
[..]
> edob() {
[..]
> +   while true; do
> +       case "${1}" in
> +           -m|-n)
                 ^^! ITYM '-l' here

> +               [[ $# -lt 2 ]] && die "Must provide an argument to ${1}"
> +               case "${1}" in
> +                   -m)
> +                       message="${2}"
> +                       ;;
> +                   -n)
                      ^^! ITYM '-l' here

> +                       log="${2}"
>
[..]

Fix yer option character ;)

-dnh


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-05-19  9:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-08 17:15 [gentoo-dev] [PATCH 0/2] edo.eclass: enhace edob for usage with nosiy commands Florian Schmaus
2024-05-08 17:15 ` [gentoo-dev] [PATCH 1/2] " Florian Schmaus
2024-05-19  9:06   ` gentoo
2024-05-08 17:15 ` [gentoo-dev] [PATCH 2/2] eftmutil-sys: use edob Florian Schmaus
2024-05-13 15:05 ` [gentoo-dev] [PATCH 0/2] edo.eclass: enhace edob for usage with nosiy commands Sam James

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox