• Re: [gentoo-dev] [PATCH v2 1/1] edo.eclass: add new eclass

    From =?UTF-8?Q?Micha=C5=82_G=C3=B3rny?=@21:1/5 to Sam James on Sat Apr 16 20:30:01 2022
    On Sat, 2022-04-16 at 19:14 +0100, Sam James wrote:
    Bug: https://bugs.gentoo.org/744880
    Signed-off-by: Sam James <sam@gentoo.org>
    ---
    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 000000000000..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 <qa@gentoo.org>
    +# @AUTHOR:
    +# Sam James <sam@gentoo.org>
    +# @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: <command> [<args>...]
    +# @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: <command> [<args>...]
    +# @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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Sam James@21:1/5 to All on Sat Apr 16 20:20:02 2022
    Bug: https://bugs.gentoo.org/744880
    Signed-off-by: Sam James <sam@gentoo.org>
    ---
    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 000000000000..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 <qa@gentoo.org>
    +# @AUTHOR:
    +# Sam James <sam@gentoo.org>
    +# @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: <command> [<args>...]
  • From Ionen Wolkens@21:1/5 to All on Sun Apr 17 03:00:01 2022
    On Sat, Apr 16, 2022 at 08:21:34PM +0200, Michał Górny wrote:
    +# @USAGE: <command> [<args>...]
    +# @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

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

    iQEzBAABCAAdFiEEx3SLh1HBoPy/yLVYskQGsLCsQzQFAmJbZGUACgkQskQGsLCs QzTGDggAuL+/t8GxwzOo74N32FZKAizy02cEIr4IKj9M2VrugOyHGm3Pa9CdX/Be 3xgIFPl2ZTCVrliDf19ZIMcS7EPM6cUB9AnpVoOIT2EZmN6/6sXU9gXGTKkLs4P9 BzaoBvimVBWQMhaSI4uNaHP4JiQNcXwXvmodVd3t9hB0fTJu07UGpzUvvp/Unqvi s6kb+lAhUh/LDsG9gKMq0Fc3EMmXm9JBqcB0vMnLaUX8sHyB86rQrPsR0mhq8gxC y0h7PE35LCqSO21xDYLDHAnVBDLq7nlWl3dWNOxoUwExSZGuDwYGNP/7kz6nSe2V jm+OyzilAYmWlTSFf48ILJMDq7+3kQ==
    =sc3q
    -----END PGP SIGNATURE-----

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

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

    iQEzBAABCAAdFiEEx3SLh1HBoPy/yLVYskQGsLCsQzQFAmJbapkACgkQskQGsLCs QzQ91Qf/Q7MfCr79we1opKHiIvpmSn3iCehDfHkORVym4RRW13WLVCN5ZwiAPJ2Q uqQ8L26grCpbjxbpUq0zI22qOeHFPGqO4WS5vnTEi0xj8XuNwN9MCvzYQb/SUcEz 583TFY3eXiC6IdEAFv+PfaquCuzsbLfCdVWzYlFVnOgUaH4x2aEThmvLWHTmKBRR QltMDr3PIqf6IHdlHONa1DAZE3l+ruAHQ4X3hfp2gKRyvxl4S8uj7e3gQqkSnF+S 7DbMNwpRmTYAGyYfG54vsCg6udKONtw+FAvQHJjbvHajwdlt7N/be2+Y9X9UMpcg 7PgmwFPB7IQj8KKZk7sJnt/LybfLkg==
    =tKb8
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Florian Schmaus@21:1/5 to Sam James on Sun Apr 17 14:20:01 2022
    On 16/04/2022 20.14, Sam James wrote:
    Bug: https://bugs.gentoo.org/744880
    Signed-off-by: Sam James <sam@gentoo.org>
    ---
    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 000000000000..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 <qa@gentoo.org>
    +# @AUTHOR:
    +# Sam James <sam@gentoo.org>
    +# @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

    typo: s/_CLASS/_ECLASS/


    +
    +# @FUNCTION: edo
    +# @USAGE: <command> [<args>...]
    +# @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: <command> [<args>...]
    +# @DESCRIPTION:
    +# Executes 'command' with ebegin & eend with any given arguments and exits +# on failure unless called under 'nonfatal'.

    Maybe mention that 'command' should be "short". I do not know if we want
    or can provide a concrete value that determines shortness.


    +# Intended for single commands, otherwise regular ebegin/eend should be used.

    I think it is obvious that it can be only used for single commands. If I
    am not mistaken, using multiple commands within ebegin/eend also means
    that those commands, or, at least all commands after the first, can not
    (or at least "should not") be printed/logged, as I assume that it would
    break eend()'s positioning.

    With multiple commands (e.g., cmd1, cmd2, cmd3), I'd probably suggest to

    edo cmd1
    edo cmd2
    edo cmd3

    since I personally like to avoid the inflationary usage of ebegin/eend
    and instead recommend to use ebegin/eend only for a few long-running
    milestone commands in the ebuild (if any).

    Hence I don't like that the description line above redirects the user to ebegin/eend. It can probably simply be dropped.


    +edob() {
    + ebegin "Running $@"
    + "$@"
    + eend $? || die -n "$@ failed"
    +}
    +
    +fi

    Like ionen, I also wondered if this could be an argument to edo, but I
    believe this would clutter edo's implementation with argument parsing
    and additional logic. Hence I believe having two separate functions, as
    in this patch, is the way to go.

    Thanks Sam!

    - Flow

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