• [gentoo-dev] [PATCH 0/1] Add edo.eclass

    From Sam James@21:1/5 to All on Sat Apr 16 08:20:01 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Sam James@21:1/5 to All on Sat Apr 16 08:30:01 2022
    Bug: https://bugs.gentoo.org/744880
    Signed-off-by: Sam James <sam@gentoo.org>
    ---
    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 000000000000..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 <qa@gentoo.org>
    +# @AUTHOR:
    +# Sam James <sam@gentoo.org>
    +# @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 g
  • From Ulrich Mueller@21:1/5 to All on Sat Apr 16 11:10:01 2022
    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 ...]]

    <command> should be in angle brackets, if we follow the usual
    convention. Maybe even "<command> [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

    -----BEGIN PGP SIGNATURE-----

    iQFDBAEBCAAtFiEEtDnZ1O9xIP68rzDbUYgzUIhBXi4FAmJagHYPHHVsbUBnZW50 b28ub3JnAAoJEFGIM1CIQV4uCHwIANoy3dd/4giRM8ppMOeTBUweGli0LGURfZq2 FJioFAtcrRUjVSOaCjLY1O6qmDCEOsSt5jJQy8J4Ej+Vrq/E3lDrHwIwzdeWOAwY lcZyMM6EhG3SNWGfapWGcYnf0+5fdUqeI0ymNHYfuSAEO5Ee4WC9BfZPxyd/w7wP hUEhX8Y+61+6Bab85GaZmBqsyQkiTI1Cv80g+Aj190aiitzTRCGWr1pywarJSPRT B5ccEwFW5xUgO5oYMyTrrSTSfIF11hqBC9bDL0KMqQn1uAVzwNRfx4wlPVlGd9KE Aqej6ZvdwbOGhn9SDcEfsJXEu75H1V7spiDgH6IR41H8mSBfhWs=
    =zwv2
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ionen Wolkens@21:1/5 to Florian Schmaus on Sat Apr 16 12:50:01 2022
    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

    -----BEGIN PGP SIGNATURE-----

    iQEzBAABCAAdFiEEx3SLh1HBoPy/yLVYskQGsLCsQzQFAmJanxgACgkQskQGsLCs QzT3uggAwOA/QmHckvghwMvoiBXcPk4ISsLD2YWhXIpHANNoUCCEOe0K7JzrPOzF rFZHoIVSo2rtSvTktbf0/rYgVu0ZDGxjZrH9L+CRKv+OAZvv9n66usa+UKHga8l1 3lLGLdvMx7CjFVi+RkZ5WToUa9UXEZBdIL8tVR4ZGmKe9iaEPmaBAx+Gi8RKjNj6 Ky/WX7semGC0kGyj26bqx+CJU+4CpeWIm3xgufR+gU/Sb4fpUycEkHvhfh5BvL5g RxIGz0NPtNWKcPBpg8Z9Koy68D/pW7LtuT6vM0oVSGnUZ2/o90j05swON6BINthc mL2QocU7iQ0GWICqlaNLhyTSLsxT2g==
    =2JNM
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ionen Wolkens@21:1/5 to Ionen Wolkens on Sat Apr 16 13:00:01 2022
    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

    -----BEGIN PGP SIGNATURE-----

    iQEzBAABCAAdFiEEx3SLh1HBoPy/yLVYskQGsLCsQzQFAmJan/UACgkQskQGsLCs QzSr5QgAyJNi+KMDDdLCH10gYhSjlXlzS7RIMspE1VveFkkg2NoStzr7UuMnEat1 OTNvRU+QNMqXvhK9RaaC5lu4n/IrXYPGKI47wkgiLReQ1CDzYxE1oihTrJde81ts bCdTKB/70vPPi5hsYL6joVX9SrhCs0LnzI9IhqKLfCbRe985VJNl8ehIjmEMX3QM Yd3Jt8Sf7J+6WgCZwwx0lk7uVNaqIcLsTVaE0FPHWFay44CM/9WPgdJ2DW012qYi pUjABYNMwalQiMB6yzFSLEADcXAg4Nq4yHDLZhAg1qWyXuZ6aBNmAyku1MEqy993 5AvgNpbikjSfFS2jk9CYU7ZwOgMuIg==
    =vgKD
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Florian Schmaus@21:1/5 to Ulrich Mueller on Sat Apr 16 12:30:01 2022
    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 ...]]

    <command> should be in angle brackets, if we follow the usual
    convention. Maybe even "<command> [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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ulrich Mueller@21:1/5 to All on Sat Apr 16 14:00:01 2022
    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

    -----BEGIN PGP SIGNATURE-----

    iQFDBAEBCAAtFiEEtDnZ1O9xIP68rzDbUYgzUIhBXi4FAmJarq8PHHVsbUBnZW50 b28ub3JnAAoJEFGIM1CIQV4uBPEH/3OFg99fD1Oh5ZqrlMGfnhcd7RN2TPU5KgFH 4ghrXYZsCfl7s5yN4QvmOjDz1bIOL8wLPFKg33I0E1qSn8T5s5iRSmciub8uzzx8 WXm8Z6inRBFZpUXLa73CykriQWJuZ/RNAFmADAhuVlinxLjeqACjfAdG5+1JF6cU MOtKgz9wzXzitOvn0SqjkcCZGLjOuWwoH42okW4mGvqLr1h6rFe42CupOQ3rDvuT Iy6vw38e9eiIWpMhgcsBv5NGJfnSGDNudaR9wU61UV+bJdRoWV47b/ef2XyWApMY HUqIuVhkcWyQvov5bFER5yhFOvofsSQuBMWviy/lNK82d/KieLs=
    =SvGc
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)