• Re: [gentoo-dev] [PATCH v2] meson.eclass: allow disabling verbose compi

    From Matt Turner@21:1/5 to flow@gentoo.org on Thu Jul 20 17:10:01 2023
    On Wed, Jul 19, 2023 at 3:23 AM Florian Schmaus <flow@gentoo.org> wrote:

    On 18/07/2023 18.44, Matt Turner wrote:
    From: Jonas Rakebrandt <xarblu@protonmail.com>

    This works similar to cmake.eclass's ${CMAKE_VERBOSE}.

    Closes: https://github.com/gentoo/gentoo/pull/28942
    Signed-off-by: Jonas Rakebrandt <xarblu@protonmail.com>
    Signed-off-by: Matt Turner <mattst88@gentoo.org>
    ---
    eclass/meson.eclass | 15 +++++++++++++--
    1 file changed, 13 insertions(+), 2 deletions(-)

    diff --git a/eclass/meson.eclass b/eclass/meson.eclass
    index 2c274b213191..3b30f66bf30a 100644
    --- a/eclass/meson.eclass
    +++ b/eclass/meson.eclass
    @@ -55,6 +55,12 @@ BDEPEND=">=dev-util/meson-0.62.2
    # Build directory, location where all generated files should be placed.
    # If this isn't set, it defaults to ${WORKDIR}/${P}-build.

    +# @ECLASS_VARIABLE: MESON_VERBOSE
    +# @USER_VARIABLE
    +# @DESCRIPTION:
    +# Set to OFF to disable verbose messages during compilation
    +: "${MESON_VERBOSE:=ON}"
    +
    # @ECLASS_VARIABLE: EMESON_BUILDTYPE
    # @DESCRIPTION:
    # The buildtype value to pass to meson setup.
    @@ -385,10 +391,15 @@ meson_src_compile() {
    -C "${BUILD_DIR}"
    --jobs "$(makeopts_jobs "${MAKEOPTS}" 0)"
    --load-average "$(makeopts_loadavg "${MAKEOPTS}" 0)"
    - --verbose
    - "$@"
    )

    + case ${MESON_VERBOSE} in
    + OFF) ;;
    + *) mesoncompileargs+=( --verbose ) ;;
    + esac

    No strong opinion, just to educate myself, but is there an advantage of
    using case/easc over if/fi here?

    That is

    if [[ ${MESON_VERBOSE} != off ]]; then
    mesoncompileargs+=( --verbose )
    fi

    or even the shell-style short idiom using ||.

    No advantage as far as I'm aware. I was just copying the style used in cmake.eclass.

    I really wish bash just had boolean types :(

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Gilbert@21:1/5 to flow@gentoo.org on Thu Jul 20 17:50:01 2023
    On Thu, Jul 20, 2023 at 11:06 AM Florian Schmaus <flow@gentoo.org> wrote:

    On 20/07/2023 17.00, Matt Turner wrote:
    On Wed, Jul 19, 2023 at 3:23 AM Florian Schmaus <flow@gentoo.org> wrote:

    On 18/07/2023 18.44, Matt Turner wrote:
    From: Jonas Rakebrandt <xarblu@protonmail.com>

    This works similar to cmake.eclass's ${CMAKE_VERBOSE}.

    Closes: https://github.com/gentoo/gentoo/pull/28942
    Signed-off-by: Jonas Rakebrandt <xarblu@protonmail.com>
    Signed-off-by: Matt Turner <mattst88@gentoo.org>
    ---
    eclass/meson.eclass | 15 +++++++++++++--
    1 file changed, 13 insertions(+), 2 deletions(-)

    diff --git a/eclass/meson.eclass b/eclass/meson.eclass
    index 2c274b213191..3b30f66bf30a 100644
    --- a/eclass/meson.eclass
    +++ b/eclass/meson.eclass
    @@ -55,6 +55,12 @@ BDEPEND=">=dev-util/meson-0.62.2
    # Build directory, location where all generated files should be placed.
    # If this isn't set, it defaults to ${WORKDIR}/${P}-build.

    +# @ECLASS_VARIABLE: MESON_VERBOSE
    +# @USER_VARIABLE
    +# @DESCRIPTION:
    +# Set to OFF to disable verbose messages during compilation
    +: "${MESON_VERBOSE:=ON}"
    +
    # @ECLASS_VARIABLE: EMESON_BUILDTYPE
    # @DESCRIPTION:
    # The buildtype value to pass to meson setup.
    @@ -385,10 +391,15 @@ meson_src_compile() {
    -C "${BUILD_DIR}"
    --jobs "$(makeopts_jobs "${MAKEOPTS}" 0)"
    --load-average "$(makeopts_loadavg "${MAKEOPTS}" 0)"
    - --verbose
    - "$@"
    )

    + case ${MESON_VERBOSE} in
    + OFF) ;;
    + *) mesoncompileargs+=( --verbose ) ;;
    + esac

    No strong opinion, just to educate myself, but is there an advantage of
    using case/easc over if/fi here?

    That is

    if [[ ${MESON_VERBOSE} != off ]]; then
    mesoncompileargs+=( --verbose )
    fi

    or even the shell-style short idiom using ||.

    No advantage as far as I'm aware. I was just copying the style used in cmake.eclass.

    I really wish bash just had boolean types :(

    While the bash language has no boolean datatype, you can exploit the
    fact that 'true' and 'false' are usually shell builtins:

    : "${MESON_VERBOSE:=true}"

    and then later

    if $MESON_VERBOSE; then
    mesoncompileargs+=( --verbose )
    fi

    I think we generally try to avoid exploiting that behavior in ebuilds.
    It's usually much more obvious to check for a non-empty string, or for
    a specific value.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ulrich Mueller@21:1/5 to All on Thu Jul 20 19:00:01 2023
    On Thu, 20 Jul 2023, Mike Gilbert wrote:

    On Thu, Jul 20, 2023 at 11:06 AM Florian Schmaus <flow@gentoo.org> wrote:
    While the bash language has no boolean datatype, you can exploit the
    fact that 'true' and 'false' are usually shell builtins:

    : "${MESON_VERBOSE:=true}"

    and then later

    if $MESON_VERBOSE; then
    mesoncompileargs+=( --verbose )
    fi

    I think we generally try to avoid exploiting that behavior in ebuilds.
    It's usually much more obvious to check for a non-empty string, or for
    a specific value.

    Testing for a non-empty variable is also faster than executing "true"
    or "false" builtins from variable values. (Which doesn't play any role
    here, but readability of the code does.)

    --=-=-Content-Type: application/pgp-signature; name="signature.asc"

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

    iQFDBAEBCAAtFiEEtDnZ1O9xIP68rzDbUYgzUIhBXi4FAmS5Z50PHHVsbUBnZW50 b28ub3JnAAoJEFGIM1CIQV4uZBsH/17od8RhRXZAAfxJzWCrtYIngHRNSEHUhMHH FM1qF6pEsnZOhKlJV/deobCKulPgJUUA37enSz0i4aqaO+57/gALTHq6+TCd7nNH iYtWCXvjDKJoiIc0JCKhSA3VXdCe6vuuLyKCiWxhqos+nJb9OEl97wOAp4Pmyt4I KB8kn/Kl4DujBao+KTyBsI4hAO0GAtdasM9B2PGmnCa6NwtLweir8e9A2+sJRBq6 zSDuTHFoAf6VHKaNSwkRakA+LqmTG1vRSOVDcQ/Ia2EarD2ciXmDvD9pYYeYcWsF H1f0kd5yPe5PG4+E+DoC63sgvjNNWSY5eixjTxPlo5+2dvwijq0=2NwN
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ionen Wolkens@21:1/5 to Ulrich Mueller on Thu Jul 20 19:20:01 2023
    On Thu, Jul 20, 2023 at 06:58:04PM +0200, Ulrich Mueller wrote:
    On Thu, 20 Jul 2023, Mike Gilbert wrote:

    On Thu, Jul 20, 2023 at 11:06 AM Florian Schmaus <flow@gentoo.org> wrote:
    While the bash language has no boolean datatype, you can exploit the
    fact that 'true' and 'false' are usually shell builtins:

    : "${MESON_VERBOSE:=true}"

    and then later

    if $MESON_VERBOSE; then
    mesoncompileargs+=( --verbose )
    fi

    I think we generally try to avoid exploiting that behavior in ebuilds.
    It's usually much more obvious to check for a non-empty string, or for
    a specific value.

    Testing for a non-empty variable is also faster than executing "true"
    or "false" builtins from variable values. (Which doesn't play any role
    here, but readability of the code does.)

    Yes, this is what I'd recommend typically. Then documentation can say
    "if set to a non-empty value" to toggle.

    Unfortunately this doesn't work so great when the default is enabled.
    Telling people to empty it is probably weird.

    wrt true/false, given MESON_VERBOSE can be set "by users" to anything
    I think trying to execute that would be extra weird.

    On a side-note, another way to avoid case statements is extglob which
    is always enabled in [[ ]] (no need for shopt)

    aka: [[ ${var} == @(first|second|third) ]]
    --
    ionen

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

    iQEzBAABCAAdFiEEx3SLh1HBoPy/yLVYskQGsLCsQzQFAmS5aq4ACgkQskQGsLCs QzRRNwf8CAL7Zeqmwk96d/fCPvAZZckH0MND55copN2ZbIzSYc+X6wff5TqyYftO bllwtiUj6wbmZluQeOV8FwOhsJt5YxLaeWFNLqiezGs7hhrS8+xuzmG1OaYonXQM FY+QPH+RtQbPv9E2wpKxZ00gf4CJqR7shXs2LHpSt36gOVo5xpQp+lmZ+yVMOVwr lhkHfLqJe54cycGurLsAxqJPSdi6tBUG04s7Ijp71d57gwNqjfmb8vKIJp1eHZYV rvG96AexT2BKPflid3okTSFjrswRdQGV+eyuAlCmPjDAIEDeW+MuO2pTMzg9b9HQ KcF3cTyG09UKeYHSZcJg5xY3Cj4SkA==
    =cGmI
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ionen Wolkens@21:1/5 to Ionen Wolkens on Thu Jul 20 19:40:01 2023
    On Thu, Jul 20, 2023 at 01:11:10PM -0400, Ionen Wolkens wrote:
    On Thu, Jul 20, 2023 at 06:58:04PM +0200, Ulrich Mueller wrote:
    On Thu, 20 Jul 2023, Mike Gilbert wrote:

    On Thu, Jul 20, 2023 at 11:06 AM Florian Schmaus <flow@gentoo.org> wrote:
    While the bash language has no boolean datatype, you can exploit the
    fact that 'true' and 'false' are usually shell builtins:

    : "${MESON_VERBOSE:=true}"

    and then later

    if $MESON_VERBOSE; then
    mesoncompileargs+=( --verbose )
    fi

    I think we generally try to avoid exploiting that behavior in ebuilds. It's usually much more obvious to check for a non-empty string, or for
    a specific value.

    Testing for a non-empty variable is also faster than executing "true"
    or "false" builtins from variable values. (Which doesn't play any role here, but readability of the code does.)

    Yes, this is what I'd recommend typically. Then documentation can say
    "if set to a non-empty value" to toggle.

    ...ultimately I feel these should be e.g. MESON_NO_VERBOSE, and be
    default unset (same for the others build systems).

    Alternatively could also consider a unified SOMETHING_NO_VERBOSE
    variable that would be used by all eclasses / ebuild where possible
    or relevant.


    Unfortunately this doesn't work so great when the default is enabled.
    Telling people to empty it is probably weird.

    wrt true/false, given MESON_VERBOSE can be set "by users" to anything
    I think trying to execute that would be extra weird.

    On a side-note, another way to avoid case statements is extglob which
    is always enabled in [[ ]] (no need for shopt)

    s/another/a/, just meant this as a side-tidbit that doesn't use
    full on regex (unrelated)


    aka: [[ ${var} == @(first|second|third) ]]

    --
    ionen

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

    iQEzBAABCAAdFiEEx3SLh1HBoPy/yLVYskQGsLCsQzQFAmS5b/QACgkQskQGsLCs QzQbhQf/X6xlsLVim52R5J6fwWEYpf1RHe4LiaW5NP3SZcwvLU0yLclmnKsYDQMF hsN/50NEim+VupwQspq4EIFbOoqmEBdr2xtFCW8XCOUlsid1zW9dJvXXdJIuojGU 62bJqqR0/azc0hJtTT++VFmrB6eeP8lWJqLHWIyQ10zZUkyjOmTls/7MngQGg7dN PGyeGnqD5Uukvxz37gtAHiERZyBQ9MvJwpXw0cegKezzEAyF4v+2sr1CyGHBpfOU ndA/8mp8HkYJmdFEuTLE7s/G0FdBLuPA6oN/1KAzp+P6dvC8PVAQAUzNo1z36R4j MNgDI48YSRS8baogiRq03uJnFRnITg==
    =2hjA
    -----END PGP SIGNATURE-----

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