From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 6F49F15838C for ; Mon, 22 Jan 2024 17:52:37 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id D8729E2A93; Mon, 22 Jan 2024 17:52:35 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B69EEE2A93 for ; Mon, 22 Jan 2024 17:52:35 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 8E00B343281 for ; Mon, 22 Jan 2024 17:52:34 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id ED3EF105D for ; Mon, 22 Jan 2024 17:52:32 +0000 (UTC) From: "Anna Vyalkova" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Anna Vyalkova" Message-ID: <1705944809.1271f372c1b9485b899a364e11e41514d15c9302.cybertailor@gentoo> Subject: [gentoo-commits] repo/proj/guru:dev commit in: eclass/ X-VCS-Repository: repo/proj/guru X-VCS-Files: eclass/databases.eclass X-VCS-Directories: eclass/ X-VCS-Committer: cybertailor X-VCS-Committer-Name: Anna Vyalkova X-VCS-Revision: 1271f372c1b9485b899a364e11e41514d15c9302 X-VCS-Branch: dev Date: Mon, 22 Jan 2024 17:52:32 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 5d1eacf1-1f6a-46ed-bd28-a96cb5a476eb X-Archives-Hash: f74eed85e5ce6693768f1a14972c4cd7 commit: 1271f372c1b9485b899a364e11e41514d15c9302 Author: Anna (cybertailor) Vyalkova sysrq in> AuthorDate: Sun Jan 21 20:27:36 2024 +0000 Commit: Anna Vyalkova sysrq in> CommitDate: Mon Jan 22 17:33:29 2024 +0000 URL: https://gitweb.gentoo.org/repo/proj/guru.git/commit/?id=1271f372 databases.eclass: replace "--get-depend" with variables It slows down metadata regeneration, so associative arrays are used instead. Suggested-by: sam_ Signed-off-by: Anna (cybertailor) Vyalkova sysrq.in> eclass/databases.eclass | 111 +++++++++++++++++++++++++++--------------------- 1 file changed, 63 insertions(+), 48 deletions(-) diff --git a/eclass/databases.eclass b/eclass/databases.eclass index d906f2a547..9c2457e93e 100644 --- a/eclass/databases.eclass +++ b/eclass/databases.eclass @@ -1,4 +1,4 @@ -# Copyright 2022 Gentoo Authors +# Copyright 2022-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 # @ECLASS: databases.eclass @@ -37,10 +37,6 @@ # # Returns the directory where the server stores database files. # -# --get-depend [use1,use2,...] -# -# Returns a dependency string (to be included in BDEPEND). -# # --get-logfile # # Returns the path to the server's log file. @@ -76,18 +72,21 @@ # # ... # +# DATABASES_REQ_USE=( +# [postgres]="xml" +# ) # inherit databases distutils-r1 # # ... # -# BDEPEND="$(eredis --get-depend)" +# BDEPEND="test? ( ${DATABASES_DEPEND[postgres]} )" # # distutils_enable_tests pytest # # src_test() { -# eredis --start 16739 +# epostgres --start 65432 # distutils-r1_src_test -# eredis --stop +# epostgres --stop # } # @CODE @@ -99,47 +98,66 @@ esac if [[ ! ${_DATABASES_ECLASS} ]]; then _DATABASES_ECLASS=1 -# ============================================================================== -# GENERIC FUNCTIONS -# ============================================================================== +# @ECLASS_VARIABLE: DATABASES_REQ_USE +# @PRE_INHERIT +# @DEFAULT_UNSET +# @DESCRIPTION: +# Bash associative array of USE flags required to be enabled on database +# servers, formed as a USE-dependency string. +# +# Keys are helper function names without the "e" prefix. -# @FUNCTION: _databases_gen_depend -# @USAGE: -# @INTERNAL +# @ECLASS_VARIABLE: DATABASES_DEPEND +# @OUTPUT_VARIABLE # @DESCRIPTION: -# Get a dependency string for the given helper function. -_databases_gen_depend() { - local srvname=${1:1} - local req_use=${2} - - local pkg_dep - case ${srvname} in - memcached) - pkg_dep="net-misc/memcached" - ;; - mongod) - pkg_dep="dev-db/mongodb" - ;; - mysql) - pkg_dep="virtual/mysql" - req_use="server,${req_use}" - ;; - postgres) - pkg_dep="dev-db/postgresql" - req_use="server,${req_use}" - ;; - redis) - pkg_dep="dev-db/redis" - ;; - *) - die "${ECLASS}: unknown database: ${srvname}" - esac +# This is an eclass-generated bash associative array of dependency strings for +# database servers. +# +# Keys are helper function names without the "e" prefix. +declare -Ag DATABASES_DEPEND=() - req_use=${req_use%,} # strip trailing comma - printf "%s" "${pkg_dep}" - [[ ${req_use} ]] && \ - printf "[%s]" "${req_use}" +# @FUNCTION: _databases_set_globals +# @INTERNAL +_databases_set_globals() { + local -A db_pkgs=( + [memcached]="net-misc/memcached" + [mongod]="dev-db/mongodb" + [mysql]="virtual/mysql" + [postgres]="dev-db/postgresql" + [redis]="dev-db/redis" + ) + + local -A db_useflags=( + [mysql]="server" + [postgres]="server" + ) + + if declare -p DATABASES_REQ_USE &>/dev/null; then + [[ $(declare -p DATABASES_REQ_USE) == "declare -A"* ]] || \ + die "DATABASES_REQ_USE must be declared as an associative array" + fi + + local name dep usestr + for name in "${!db_pkgs[@]}"; do + dep=${db_pkgs[${name}]?} + usestr=${db_useflags[${name}]} + usestr+=",${DATABASES_REQ_USE[${name}]}" + # strip leading/trailing commas + usestr=${usestr#,} + usestr=${usestr%,} + + [[ ${usestr} ]] && usestr="[${usestr}]" + DATABASES_DEPEND[${name?}]="${dep?}${usestr}" + done + + readonly DATABASES_DEPEND } +_databases_set_globals +unset -f _databases_set_globals + +# ============================================================================== +# GENERIC FUNCTIONS +# ============================================================================== # @FUNCTION: _databases_die # @USAGE: [msg] @@ -198,9 +216,6 @@ _databases_dispatch() { --die) _databases_die ${funcname} "${@}" ;; - --get-depend) - _databases_gen_depend ${funcname} "${@}" - ;; --get-dbpath) echo "${T}"/${funcname}/db/ ;;