Re: [gentoo-dev] [PATCH v2 1/1] edo.eclass: add new eclass
On Sat, Apr 16, 2022 at 08:50:46PM -0400, Ionen Wolkens wrote: > e.g. if using edo to replace stuff like > # ./configure is not real autoconf! > local cmd=( > ./configure > --args > ${EXTRA_ECONF} > ) > echo ${cmd[*]}" > "${cmd[@]}" || die "cmd failed: ${cmd[*]}" Albeit on that note, when already using arrays like that edo is probably not super useful :) Just saved one line and a || die. -- ionen signature.asc Description: PGP signature
Re: [gentoo-dev] [PATCH v2 1/1] edo.eclass: add new eclass
On Sat, Apr 16, 2022 at 08:21:34PM +0200, Michał Górny wrote: > > +# @USAGE: [...] > > +# @DESCRIPTION: > > +# Executes 'command' with any given arguments and exits on failure unless > > +# called under 'nonfatal'. > > +edo() { > > + elog "$@" > > einfo? Way I see it, this could've even been just "echo", aka econf doesn't use einfo to show the ./configure command either but just simple echo. e.g. if using edo to replace stuff like # ./configure is not real autoconf! local cmd=( ./configure --args ${EXTRA_ECONF} ) echo ${cmd[*]}" "${cmd[@]}" || die "cmd failed: ${cmd[*]}" But einfo worksforme either way. Alternatively I guess it could also take switches for display behavior if don't want to have many functions using up the namespace. Not like a command would normally start with a dash (e.g. `edo -b command` is fine). -- ionen signature.asc Description: PGP signature
Re: [gentoo-dev] [PATCH] gnuconfig.eclass: fix eend w/o ebegin
On Sat, Apr 16, 2022 at 2:28 AM Sam James wrote: > > eend should be preceded by an begin call. Looks ok.
Re: [gentoo-dev] [PATCH v2 1/1] edo.eclass: add new eclass
On Sat, 2022-04-16 at 19:14 +0100, Sam James wrote: > Bug: https://bugs.gentoo.org/744880 > Signed-off-by: Sam James > --- > eclass/edo.eclass | 46 ++ > 1 file changed, 46 insertions(+) > create mode 100644 eclass/edo.eclass > > diff --git a/eclass/edo.eclass b/eclass/edo.eclass > new file mode 100644 > index ..7b4ae04c43ab > --- /dev/null > +++ b/eclass/edo.eclass > @@ -0,0 +1,46 @@ > +# Copyright 2022 Gentoo Authors > +# Distributed under the terms of the GNU General Public License v2 > + > +# @ECLASS: edo.class > +# @MAINTAINER: > +# QA Team > +# @AUTHOR: > +# Sam James > +# @SUPPORTED_EAPIS: 7 8 > +# @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, > +# which dies (exits) on failure and logs the command used verbosely. > +# > + > +case ${EAPI:-0} in > + 7|8) ;; > + *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; > +esac > + > +if [[ -z ${_EDO_ECLASS} ]] ; then > + _EDO_CLASS=1 > + > +# @FUNCTION: edo How about calling it 'tokyo'? > +# @USAGE: [...] > +# @DESCRIPTION: > +# Executes 'command' with any given arguments and exits on failure unless > +# called under 'nonfatal'. > +edo() { > + elog "$@" einfo? > + "$@" || die -n "Failed to run command: $@ failed" > +} > + > +# @FUNCTION: edob > +# @USAGE: [...] > +# @DESCRIPTION: > +# Executes 'command' with ebegin & eend with any given arguments and exits > +# on failure unless called under 'nonfatal'. > +# Intended for single commands, otherwise regular ebegin/eend should be used. > +edob() { > + ebegin "Running $@" > + "$@" > + eend $? || die -n "$@ failed" > +} > + > +fi -- Best regards, Michał Górny
[gentoo-dev] [PATCH v2 0/1] Add edo.eclass
Changes since v1: - Add EAPI 7 support (useful for e.g. base-system@ ebuilds) - Add 'edob' (edo with ebegin/eend for better logs log-running commands, UX) Sam James (1): edo.eclass: add new eclass eclass/edo.eclass | 46 ++ 1 file changed, 46 insertions(+) create mode 100644 eclass/edo.eclass -- 2.35.1
[gentoo-dev] [PATCH v2 1/1] edo.eclass: add new eclass
Bug: https://bugs.gentoo.org/744880 Signed-off-by: Sam James --- eclass/edo.eclass | 46 ++ 1 file changed, 46 insertions(+) create mode 100644 eclass/edo.eclass diff --git a/eclass/edo.eclass b/eclass/edo.eclass new file mode 100644 index ..7b4ae04c43ab --- /dev/null +++ b/eclass/edo.eclass @@ -0,0 +1,46 @@ +# Copyright 2022 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: edo.class +# @MAINTAINER: +# QA Team +# @AUTHOR: +# Sam James +# @SUPPORTED_EAPIS: 7 8 +# @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, +# which dies (exits) on failure and logs the command used verbosely. +# + +case ${EAPI:-0} in + 7|8) ;; + *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; +esac + +if [[ -z ${_EDO_ECLASS} ]] ; then + _EDO_CLASS=1 + +# @FUNCTION: edo +# @USAGE: [...] +# @DESCRIPTION: +# Executes 'command' with any given arguments and exits on failure unless +# called under 'nonfatal'. +edo() { + elog "$@" + "$@" || die -n "Failed to run command: $@ failed" +} + +# @FUNCTION: edob +# @USAGE: [...] +# @DESCRIPTION: +# Executes 'command' with ebegin & eend with any given arguments and exits +# on failure unless called under 'nonfatal'. +# Intended for single commands, otherwise regular ebegin/eend should be used. +edob() { + ebegin "Running $@" + "$@" + eend $? || die -n "$@ failed" +} + +fi -- 2.35.1
Re: [gentoo-dev] Re: [PATCH 1/1] edo.eclass: add new eclass
> On Sat, 16 Apr 2022, Florian Schmaus wrote: >> edobe() { > nit: I'd personally would use 'edob', as shorter is sometimes better > plus every begin needs an end, so no need to explicitly state that > there is an end. It's even more obscure as a name however. :) >> ebegin "Running $@" >> "$@" >> eend $? || die -n "$@ failed" >> return $? > I think this return statement can be omitted since it will always be > invoked with 0 as argument, and this is the default behavior of > implicit function return (IIRC). You're right, the return statement is redundant. >> } Ulrich signature.asc Description: PGP signature
Re: [gentoo-dev] Re: [PATCH 1/1] edo.eclass: add new eclass
On Sat, Apr 16, 2022 at 06:48:56AM -0400, Ionen Wolkens wrote: > On Sat, Apr 16, 2022 at 12:23:18PM +0200, Florian Schmaus wrote: > > > ebegin "Running $@" > > > "$@" > > > eend $? || die -n "$@ failed" > return $? > > > > I think this return statement can be omitted since it will always be > > invoked with 0 as argument, and this is the default behavior of implicit > > function return (IIRC). > > Not with nonfatal (die is using -n to allow it) > > nonfatal edo false || echo "different error handling: $?" > > Without return $?, the above will echo 0 or 1 if die was triggered > but (with current implementation) won't be the actual return code. Err wait, return $? won't help with that, need a temporary variable to preserve. return $? indeed does nothing here :) -- ionen signature.asc Description: PGP signature
Re: [gentoo-dev] Re: [PATCH 1/1] edo.eclass: add new eclass
On Sat, Apr 16, 2022 at 12:23:18PM +0200, Florian Schmaus wrote: > > ebegin "Running $@" > > "$@" > > eend $? || die -n "$@ failed" > return $? > > I think this return statement can be omitted since it will always be > invoked with 0 as argument, and this is the default behavior of implicit > function return (IIRC). Not with nonfatal (die is using -n to allow it) nonfatal edo false || echo "different error handling: $?" Without return $?, the above will echo 0 or 1 if die was triggered but (with current implementation) won't be the actual return code. That still mostly work but maybe, e.g. the code need to check if grep returned 2 (aka error) while 1 isn't an error but just didn't match anything. -- ionen signature.asc Description: PGP signature
Re: [gentoo-dev] Re: [PATCH 1/1] edo.eclass: add new eclass
On 16/04/2022 10.38, Ulrich Mueller wrote: On Sat, 16 Apr 2022, Sam James wrote: +# @FUNCTION: edo Just a remark: A similar command existed a long time ago under the name "try". [1] It was executed under "env" [2], should we also do that? +# @USAGE: command [arg1 [arg2 ...]] should be in angle brackets, if we follow the usual convention. Maybe even " [arg]..." +# @DESCRIPTION: +# Executes 'command' with any given arguments and exits on failure unless +# called under 'nonfatal'. +edo() { + elog "$@" + "$@" || die -n "Failed to run command: $@ failed" +} Maybe add an ebegin/eend variant? +1 edobe() { nit: I'd personally would use 'edob', as shorter is sometimes better plus every begin needs an end, so no need to explicitly state that there is an end. ebegin "Running $@" "$@" eend $? || die -n "$@ failed" > return $? I think this return statement can be omitted since it will always be invoked with 0 as argument, and this is the default behavior of implicit function return (IIRC). - Flow
[gentoo-dev] Re: [PATCH 1/1] edo.eclass: add new eclass
> On Sat, 16 Apr 2022, Sam James wrote: > +# @FUNCTION: edo Just a remark: A similar command existed a long time ago under the name "try". [1] It was executed under "env" [2], should we also do that? > +# @USAGE: command [arg1 [arg2 ...]] should be in angle brackets, if we follow the usual convention. Maybe even " [arg]..." > +# @DESCRIPTION: > +# Executes 'command' with any given arguments and exits on failure unless > +# called under 'nonfatal'. > +edo() { > + elog "$@" > + "$@" || die -n "Failed to run command: $@ failed" > +} Maybe add an ebegin/eend variant? edobe() { ebegin "Running $@" "$@" eend $? || die -n "$@ failed" return $? } Ulrich [1] https://gitweb.gentoo.org/archive/proj/portage-cvs.git/tree/bin/ebuild.sh?id=b7c9c02ee04ae62068f8db775c1189fd796cd797#n85 [2] https://gitweb.gentoo.org/archive/repo/gentoo-2.git/commit/?id=e5168d05cad140ecd7e966bce3f771003e6d392b signature.asc Description: PGP signature
[gentoo-dev] [PATCH] gnuconfig.eclass: fix eend w/o ebegin
eend should be preceded by an begin call. Signed-off-by: Sam James --- eclass/gnuconfig.eclass | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eclass/gnuconfig.eclass b/eclass/gnuconfig.eclass index 58bdcfd660a6b..0791798632cdb 100644 --- a/eclass/gnuconfig.eclass +++ b/eclass/gnuconfig.eclass @@ -1,4 +1,4 @@ -# Copyright 1999-2021 Gentoo Authors +# Copyright 1999-2022 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 # @ECLASS: gnuconfig.eclass @@ -84,9 +84,9 @@ gnuconfig_do_update() { if [[ -n ${targetlist} ]] ; then for target in ${targetlist} ; do [[ -L ${target} ]] && rm -f "${target}" - einfo " Updating ${target/$startdir\//}" + ebegin " Updating ${target/$startdir\//}" cp -f "${configsubs_dir}/${file}" "${target}" - eend $? + eend $? || die done else ewarn " No ${file} found in ${startdir}, skipping ..." -- 2.35.1
[gentoo-dev] [PATCH 1/1] edo.eclass: add new eclass
Bug: https://bugs.gentoo.org/744880 Signed-off-by: Sam James --- eclass/edo.eclass | 34 ++ 1 file changed, 34 insertions(+) create mode 100644 eclass/edo.eclass diff --git a/eclass/edo.eclass b/eclass/edo.eclass new file mode 100644 index ..fc025ddf4503 --- /dev/null +++ b/eclass/edo.eclass @@ -0,0 +1,34 @@ +# Copyright 2022 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: edo.class +# @MAINTAINER: +# QA Team +# @AUTHOR: +# Sam James +# @SUPPORTED_EAPIS: 8 +# @BLURB: Convenience function to run commands verbosely and die on failure +# @DESCRIPTION: +# This eclass provides the 'edo' command which dies (exits) on failure +# and logs the command used verbosely. +# + +case ${EAPI:-0} in + 8) ;; + *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; +esac + +if [[ -z ${_EDO_ECLASS} ]] ; then + _EDO_CLASS=1 + +# @FUNCTION: edo +# @USAGE: command [arg1 [arg2 ...]] +# @DESCRIPTION: +# Executes 'command' with any given arguments and exits on failure unless +# called under 'nonfatal'. +edo() { + elog "$@" + "$@" || die -n "Failed to run command: $@ failed" +} + +fi -- 2.35.1
[gentoo-dev] [PATCH 0/1] Add edo.eclass
Intended as a discussion starter after recent discussions in #gentoo-dev. I don't necc. expect this to be the final implementation at all, but it's often helpful to have something concrete to discuss & iterate on. I think the need for this is pretty strong in sci-*/* ebuilds which tend to need custom homebrew commands executed and such an edo helper allows us to: - have a more verbose log (which is one of our general principles and policies) - make the ebuild cleaner, as we only need one line to both echo-and-run Sam James (1): edo.eclass: add new eclass eclass/edo.eclass | 34 ++ 1 file changed, 34 insertions(+) create mode 100644 eclass/edo.eclass -- 2.35.1