From d95d565813cd0b0e38ec9430a15e3cfb6572685a Mon Sep 17 00:00:00 2001 From: Eric Joldasov Date: Thu, 14 May 2026 23:36:29 +0500 Subject: [PATCH] zig-utils.eclass: improve `ZIG_SLOT` checks Move global variables' validations and modifications to a new internal function, executed at inherit-time. Also check that `ZIG_SLOT` is a string, not an array. Avoids confusing errors like these: ```console # ZIG_SLOT=( "0.16", "9999" ) invalid: BDEPEND: Invalid atom (dev-lang/zig:0.16,9999), token 4 ``` Closes: https://bugs.gentoo.org/963399 Signed-off-by: Eric Joldasov Part-of: https://github.com/gentoo/gentoo/pull/46260 Closes: https://github.com/gentoo/gentoo/pull/46260 Signed-off-by: Sam James --- eclass/zig-utils.eclass | 56 +++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/eclass/zig-utils.eclass b/eclass/zig-utils.eclass index 95f979b98c786..8ed9cc55ab9b0 100644 --- a/eclass/zig-utils.eclass +++ b/eclass/zig-utils.eclass @@ -76,20 +76,6 @@ inherit edo flag-o-matic linux-info # # For zig.eclass users: see documentation in zig.eclass # instead. -if [[ ! ${ZIG_OPTIONAL} ]]; then - _ZIG_USEDEP="" - if [[ ${ZIG_NEEDS_LLVM} ]]; then - _ZIG_USEDEP="[llvm(+)]" - fi - - # NOTE: zig-bin is always built with LLVM support, so no USE needed. - BDEPEND=" - || ( - dev-lang/zig:${ZIG_SLOT}${_ZIG_USEDEP} - dev-lang/zig-bin:${ZIG_SLOT} - ) - " -fi # @ECLASS_VARIABLE: ZIG_TARGET # @DEFAULT_UNSET @@ -202,6 +188,43 @@ fi # 0.13.0 # @CODE +# @FUNCTION: _zig_utils_set_globals +# @INTERNAL +# @DESCRIPTION: +# Check correctness of ZIG_SLOT variable value. +# Update BDEPEND if ZIG_OPTIONAL is not set. +_zig_utils_set_globals() { + debug-print-function ${FUNCNAME} "$@" + + [[ -n "${ZIG_SLOT}" ]] || die "ZIG_SLOT must be set" + + if [[ ${ZIG_SLOT@a} =~ [aA] ]]; then + die "ZIG_SLOT must be a string, not an array" + fi + + if ver_test "${ZIG_SLOT}" -lt "0.13"; then + die "ZIG_SLOT must be >= 0.13, found ${ZIG_SLOT}" + fi + + if [[ ! ${ZIG_OPTIONAL} ]]; then + _ZIG_USEDEP="" + if [[ ${ZIG_NEEDS_LLVM} ]]; then + _ZIG_USEDEP="[llvm(+)]" + fi + + # NOTE: zig-bin is always built with LLVM support, so no USE needed. + BDEPEND=" + || ( + dev-lang/zig:${ZIG_SLOT}${_ZIG_USEDEP} + dev-lang/zig-bin:${ZIG_SLOT} + ) + " + fi +} + +_zig_utils_set_globals +unset -f _zig_utils_set_globals + # @FUNCTION: _get-c-option # @INTERNAL # @USAGE: @@ -484,11 +507,6 @@ zig-utils_find_installation() { # Adapted from https://github.com/gentoo/gentoo/pull/28986 # Many thanks to Florian Schmaus (Flowdalic)! - [[ -n "${ZIG_SLOT}" ]] || die "${FUNCNAME[0]}: ZIG_SLOT must be set" - if ver_test "${ZIG_SLOT}" -lt "0.13"; then - die "${ECLASS}: ZIG_SLOT must be >= 0.13, found ${ZIG_SLOT}" - fi - einfo "Searching Zig ${ZIG_SLOT}..." # Upstream skipped releasing 0.15.0