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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 7038D1382C5 for ; Sat, 3 Apr 2021 21:51:41 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id BD861E083B; Sat, 3 Apr 2021 21:51:38 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 69BA0E0821 for ; Sat, 3 Apr 2021 21:51:38 +0000 (UTC) From: Andreas Sturmlechner To: gentoo-dev@lists.gentoo.org Subject: [gentoo-dev] [PATCH v2] optfeature.eclass: Introduce optfeature header Date: Sat, 03 Apr 2021 23:51:29 +0200 Message-ID: <2128582.vFx2qVVIhK@tuxbrain> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart2530429.lGaqSPkdTl"; micalg="pgp-sha512"; protocol="application/pgp-signature" X-Archives-Salt: e12805ea-12fe-49c7-9808-c557eeb651f4 X-Archives-Hash: 30f784dd3a75757a606bb9ef752abbd7 --nextPart2530429.lGaqSPkdTl Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii"; protected-headers="v1" From: Andreas Sturmlechner To: gentoo-dev@lists.gentoo.org Subject: [PATCH v2] optfeature.eclass: Introduce optfeature header Date: Sat, 03 Apr 2021 23:51:29 +0200 Message-ID: <2128582.vFx2qVVIhK@tuxbrain> Before this change, optfeature() would print a list of optional dependencies, or nothing if deps are installed. Ebuilds commonly print their own elog ahead of optfeature, which then may not be followed up by any list at all. This change adds a default header text, which may be changed by the ebuild, that is only printed if optfeature is about to list at least one dependency. v2: Introduce optfeature_header() function Set a custom header for follow-up optfeature calls, or reset to default header by calling it without argument. This can not only be used to customize the header but also to distinguish optfeature "groups", e.g. to list a number of different possible database backends, and then a number of optional regular runtime features. Signed-off-by: Andreas Sturmlechner --- a/eclass/optfeature.eclass +++ b/eclass/optfeature.eclass @@ -1,4 +1,4 @@ -# Copyright 1999-2020 Gentoo Authors +# Copyright 1999-2021 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 # @ECLASS: optfeature.eclass @@ -14,6 +14,56 @@ esac if [[ -z ${_OPTFEATURE_ECLASS} ]]; then _OPTFEATURE_ECLASS=1 +# @ECLASS-VARIABLE: _OPTFEATURE_DEFAULT_HEADER +# @INTERNAL +# @DESCRIPTION: +# Default header printed ahead of optfeature output. Can be overridden +# by calling optfeature_header function. Will not be displayed if all optional +# dependencies are present. +_OPTFEATURE_DEFAULT_HEADER="Install additional packages for optional runtime features:" + +readonly _OPTFEATURE_DEFAULT_HEADER + +# @ECLASS-VARIABLE: _OPTFEATURE_HEADER +# @INTERNAL +# @DESCRIPTION: +# Default empty. Custom header printed ahead of optfeature output. +# Set by calling optfeature_header function with the desired output, or reset +# by optfeature_header without argument. Will not be displayed if all optional +# dependencies are present. +_OPTFEATURE_HEADER= + +# @ECLASS-VARIABLE: _OPTFEATURE_DOHEADER +# @INTERNAL +# @DESCRIPTION: +# If true, print header ahead of the first optfeature output. +_OPTFEATURE_DOHEADER=true + +# @FUNCTION: optfeature_header +# @USAGE: [custom header for follow-up optfeature calls] +# @DESCRIPTION: +# Set a custom header for follow-up optfeature calls, or reset to default +# header by calling it without argument. This can not only be used to customize +# the header but also to distinguish optfeature "groups", e.g. to list a number +# of different possible database backends, and then a number of optional +# regular runtime features. +# +# The following snippet will leave the default header untouched for the first +# two optfeature calls. Then a custom header is set that is going to be +# displayed in case dev-db/a or dev-db/b are not installed. +# @CODE +# optfeature "foo support" app-misc/foo +# optfeature "bar support" app-misc/bar +# optfeature_header "Install optional database backends:" +# optfeature "a DB backend" dev-db/a +# optfeature "b DB backend" dev-db/b +# @CODE +optfeature_header() { + debug-print-function ${FUNCNAME} "$@" + _OPTFEATURE_HEADER="${1}" + _OPTFEATURE_DOHEADER=true +} + # @FUNCTION: optfeature # @USAGE: [other atoms] # @DESCRIPTION: @@ -51,6 +101,10 @@ optfeature() { fi done if [[ ${flag} -eq 0 ]]; then + if [[ ${_OPTFEATURE_DOHEADER} == true ]]; then + elog ${_OPTFEATURE_HEADER:-${_OPTFEATURE_DEFAULT_HEADER}} + _OPTFEATURE_DOHEADER=false + fi for i; do read -r -d '' -a arr <<<"${i}" msg=" " --nextPart2530429.lGaqSPkdTl Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQGTBAABCgB9FiEE/x0UfMgLbk/MiQ+AUIqgAODug+AFAmBo42FfFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldEZG MUQxNDdDQzgwQjZFNEZDQzg5MEY4MDUwOEFBMDAwRTBFRTgzRTAACgkQUIqgAODu g+DlRggAvEGYYaML4r2rYcQdzAXZK/tYaCl5TqCzTsu4zuUPkCCwfP07+QSMTvT7 36mlBGhsVi8wo/brOLM9sNsLLGIB6HTPMVVyrj3ApVyvC3sa1sMAZ2s+5gYulNs8 FOxWUPublkU9TKPkanhn7SYWe8vhmF8w27QtcjVV0uxILUUeTM6c/3G/bhjOayy/ VqUth1Nal8Xdgq9g2Hg6KWKqC1burUfakL5SUgzo+MFtpnRix48LABoaha/RPI9e 8oSfaVqGtZ9527OPlVmWXTrouDCHKGYTrnVP66R9zkXW2btTWBxDkUU2cmHJt518 ZOxmXwrwFcaXHr8GjdjEEjxfallBJA== =wPio -----END PGP SIGNATURE----- --nextPart2530429.lGaqSPkdTl--