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 ||.
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
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.
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.)
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) ]]
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 407 |
Nodes: | 16 (2 / 14) |
Uptime: | 15:32:54 |
Calls: | 8,555 |
Calls today: | 7 |
Files: | 13,219 |
Messages: | 5,925,665 |