• [gentoo-dev] [PATCH] edo.eclass: Fix two issues with edo() output

    From =?UTF-8?q?Ulrich=20M=C3=BCller?=@21:1/5 to All on Mon May 12 17:50:02 2025
    This updates the edo function to behave similar to its possible
    implementation in the package manager for EAPI 9:

    - Backslash-escaping (as einfo does via "echo -e") is not wanted.

    - Arguments should be printed in a quoted format that could be reused
    as shell input. We quote arguments using the "@Q" operator of Bash
    parameter expansion, but avoid excessive quoting by testing each
    argument for shell metacharacters. The resulting output should be
    very similar to that of the trace obtained with "set -x".

    Note that the @Q operator did not exist in Bash 4.2, therefore
    arguments are printed literally in EAPI 7.

    Bug: https://bugs.gentoo.org/744880#c13
    Suggested-by: Eli Schwartz <eschwartz@gentoo.org>
    Reviewed-by: Eli Schwartz <eschwartz@gentoo.org>
    Signed-off-by: Ulrich Müller <ulm@gentoo.org>
    ---
    eclass/edo.eclass | 20 +++++++++++++++++---
    1 file changed, 17 insertions(+), 3 deletions(-)

    diff --git a/eclass/edo.eclass b/eclass/edo.eclass
    index 5fd77a676a8b..0612617a276c 100644
    --- a/eclass/edo.eclass
    +++ b/eclass/edo.eclass
    @@ -1,4 +1,4 @@
    -# Copyright 2022-2024 Gentoo Authors
    +# Copyright 2022-2025 Gentoo Authors
    # Distributed under the terms of the GNU General Public License v2

    # @ECLASS: edo.eclass
    @@ -36,8 +36,22 @@ _EDO_ECLASS=1
    # Executes a short 'command' with any given arguments and exits on failure
    # unless called under 'nonfatal'.
    edo() {
    - einfo "$@"
    - "$@" || die -n "Failed to run command: $@"
    + # list of special characters taken from sh_contains_shell_metas
    + # in shquote.c (bash-5.2)
    + local a out regex='[] '\''"\|&;()<>!{}*[?^$`]|^[#~]|[=:]~'
    + if [[ ${EAPI} = 7 ]]; then
    + # no @Q in bash-4.2
    + out=" $*"
    + else
    + for a; do
    + # quote if (and only if) necessary
    + [[ ${a} =~ ${regex} || ! ${a} =~ ^[[:print:]]+$ ]] && a=${a@Q}
    + out+=" ${a
  • From =?UTF-8?q?Ulrich=20M=C3=BCller?=@21:1/5 to All on Tue May 13 06:30:01 2025
    This updates the edo function to behave similar to its possible
    implementation in the package manager for EAPI 9:

    - Backslash-escaping (as einfo does via "echo -e") is not wanted.

    - Arguments should be printed in a quoted format that could be reused
    as shell input. We quote arguments using the "@Q" operator of Bash
    parameter expansion, but avoid excessive quoting by testing each
    argument for shell metacharacters. The resulting output should be
    very similar to that of the trace obtained with "set -x".

    Note that the @Q operator did not exist in Bash 4.2, therefore
    arguments are printed literally in EAPI 7.

    Bug: https://bugs.gentoo.org/744880#c13
    Suggested-by: Eli Schwartz <eschwartz@gentoo.org>
    Reviewed-by: Eli Schwartz <eschwartz@gentoo.org>
    Signed-off-by: Ulrich Müller <ulm@gentoo.org>
    ---
    Changes in v2:
    - Test number of arguments
    - Add some test cases

    eclass/edo.eclass | 24 +++++++++++++++++++++---
    eclass/tests/edo.sh | 25 ++++++++++++++++++++++++-
    2 files changed, 45 insertions(+), 4 deletions(-)

    diff --git a/eclass/edo.eclass b/eclass/edo.eclass
    index 5fd77a676a8b..a308851aca7f 100644
    --- a/eclass/edo.eclass
    +++ b/eclass/edo.eclass
    @@ -1,4 +1,4 @@
    -# Copyright 2022-2024 Gentoo Authors
    +# Copyright 2022-2025 Gentoo Authors
    # Distributed under the terms of the GNU General Public License v2

    # @ECLASS: edo.eclass
    @@ -36,8 +36,26 @@ _EDO_ECLASS=1
    # Executes a short 'command' with any given arguments and exits on failure
    # unless called under 'nonfatal'.
    edo() {
    - einfo "$@"
    - "$@" || die -n "Failed to run command: $@"
    + # list of special characters taken from sh_contains_shell_metas
    + # in shquote.c (bash-5.2)
    + local a out regex='[] '\''"\|&;()<>!{}*[?^$`]|^[#~]|[=:]~'
    +
    + [[ $# -ge 1 ]] || die "edo: at least one argument needed"
    +
    + if [[ ${EAPI}