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 918F1158041 for ; Wed, 20 Mar 2024 20:58:26 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 1268AE29C3; Wed, 20 Mar 2024 20:57:39 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 6DC24E29BE for ; Wed, 20 Mar 2024 20:57:38 +0000 (UTC) From: Arthur Zamarin To: gentoo-dev@lists.gentoo.org Cc: Matthew Smith , Nick Sarnie , Arthur Zamarin Subject: [gentoo-dev] [PATCH 2/2] tree-sitter-grammar.eclass: support opt in python bindings Date: Wed, 20 Mar 2024 22:52:39 +0200 Message-ID: <20240320205659.204635-3-arthurzam@gentoo.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240320205659.204635-1-arthurzam@gentoo.org> References: <20240320205659.204635-1-arthurzam@gentoo.org> 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-Transfer-Encoding: 8bit X-Archives-Salt: 9187040f-0b25-44b7-9f42-70345a1e6a87 X-Archives-Hash: fd5d5839a39c9375cc3352ccea83c079 New tree-sitter cli generated bindings and code around grammars and parsers now support bulding a python wheel which supply much better API and library for consumers in python bindings. Currently I've added only python as a binding languages, even though rust, swift, and go are also available. We should add them when we see a request for them. Python will be needed for pkgcheck. When we opt in into python bindings, we call the matching distutils phase functions when `use python` is true. Signed-off-by: Arthur Zamarin --- eclass/tree-sitter-grammar.eclass | 85 ++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/eclass/tree-sitter-grammar.eclass b/eclass/tree-sitter-grammar.eclass index 13539daf7e6..b04d5ee1103 100644 --- a/eclass/tree-sitter-grammar.eclass +++ b/eclass/tree-sitter-grammar.eclass @@ -36,6 +36,43 @@ RESTRICT+=" !test? ( test )" # Used to override upstream tag name if tagged differently, e.g. most releases # are v${PV} but some are tagged as rust-${PV}. +# @ECLASS_VARIABLE: TS_BINDINGS +# @PRE_INHERIT +# @DEFAULT_UNSET +# @DESCRIPTION: +# Array of bindings language to build. Currently only "python" is supported. + +for _BINDING in "${TS_BINDINGS[@]}"; do + case ${_BINDING} in + python) + DISTUTILS_EXT=1 + DISTUTILS_OPTIONAL=1 + DISTUTILS_USE_PEP517=setuptools + PYTHON_COMPAT=( python3_{10..12} ) + inherit distutils-r1 + + IUSE+=" python" + REQUIRED_USE+=" python? ( ${PYTHON_REQUIRED_USE} )" + + DEPEND+=" python? ( + ${PYTHON_DEPS} + )" + RDEPEND+=" python? ( + ${PYTHON_DEPS} + >=dev-python/tree-sitter-0.21.0[${PYTHON_USEDEP}] + )" + BDEPEND+=" python? ( + ${DISTUTILS_DEPS} + dev-python/wheel[${PYTHON_USEDEP}] + )" + ;; + *) + die "Unknown binding: ${_BINDING}" + ;; + esac +done +unset _BINDING + # @FUNCTION: _get_tsg_abi_ver # @INTERNAL # @DESCRIPTION: @@ -49,6 +86,34 @@ _get_tsg_abi_ver() { die "Unable to extract ABI version for this grammar" } +tree-sitter-grammar_src_prepare() { + debug-print-function ${FUNCNAME} "${@}" + + default + + local binding + for binding in "${TS_BINDINGS[@]}"; do + case ${binding} in + python) + use python && distutils-r1_src_prepare + ;; + esac + done +} + +tree-sitter-grammar_src_configure() { + debug-print-function ${FUNCNAME} "${@}" + + local binding + for binding in "${TS_BINDINGS[@]}"; do + case ${binding} in + python) + use python && distutils-r1_src_configure + ;; + esac + done +} + # @FUNCTION: _tree-sitter-grammar_legacy_compile # @INTERNAL # @DESCRIPTION: @@ -102,6 +167,15 @@ tree-sitter-grammar_src_compile() { else _tree-sitter-grammar_legacy_compile fi + + local binding + for binding in "${TS_BINDINGS[@]}"; do + case ${binding} in + python) + use python && distutils-r1_src_compile + ;; + esac + done } # @FUNCTION: tree-sitter-grammar_src_test @@ -131,8 +205,17 @@ tree-sitter-grammar_src_install() { dolib.so "${WORKDIR}/${soname}" dosym "${soname}" /usr/$(get_libdir)/lib${PN}$(get_libname) fi + + local binding + for binding in "${TS_BINDINGS[@]}"; do + case ${binding} in + python) + use python && distutils-r1_src_install + ;; + esac + done } fi -EXPORT_FUNCTIONS src_compile src_test src_install +EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install -- 2.44.0