summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Zamarin <arthurzam@gentoo.org>2024-03-14 16:04:04 +0200
committerArthur Zamarin <arthurzam@gentoo.org>2024-03-23 10:27:42 +0200
commit949b5c8afe07fd5f54942d7190d963b4ccf1e38a (patch)
tree2ef3e1938d9bd08571ab58f0959a31933c5eea9c /eclass/tree-sitter-grammar.eclass
parenttree-sitter-grammar.eclass: support for new upstream makefile (diff)
downloadgentoo-949b5c8afe07fd5f54942d7190d963b4ccf1e38a.tar.gz
gentoo-949b5c8afe07fd5f54942d7190d963b4ccf1e38a.tar.bz2
gentoo-949b5c8afe07fd5f54942d7190d963b4ccf1e38a.zip
tree-sitter-grammar.eclass: support opt in python bindings
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 <arthurzam@gentoo.org>
Diffstat (limited to 'eclass/tree-sitter-grammar.eclass')
-rw-r--r--eclass/tree-sitter-grammar.eclass86
1 files changed, 85 insertions, 1 deletions
diff --git a/eclass/tree-sitter-grammar.eclass b/eclass/tree-sitter-grammar.eclass
index 13539daf7e61..74443e213b89 100644
--- a/eclass/tree-sitter-grammar.eclass
+++ b/eclass/tree-sitter-grammar.eclass
@@ -36,6 +36,44 @@ 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? (
+ ${PYTHON_DEPS}
+ ${DISTUTILS_DEPS}
+ dev-python/wheel[${PYTHON_USEDEP}]
+ )"
+ ;;
+ *)
+ die "Unknown binding: ${_BINDING}"
+ ;;
+ esac
+done
+unset _BINDING
+
# @FUNCTION: _get_tsg_abi_ver
# @INTERNAL
# @DESCRIPTION:
@@ -49,6 +87,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 +168,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 +206,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