summaryrefslogtreecommitdiff
path: root/eclass
diff options
context:
space:
mode:
authorV3n3RiX <venerix@koprulu.sector>2024-03-23 13:01:09 +0000
committerV3n3RiX <venerix@koprulu.sector>2024-03-23 13:01:09 +0000
commitacc2dacf2ee9a5b03df96da670153f2e3a24d80c (patch)
tree852bc5b5f64c3dc59ac09c6a2314c63b9a901ac0 /eclass
parent2c9b8fbe41c04a94054b0540b54fcf2de0b79166 (diff)
gentoo auto-resync : 23:03:2024 - 13:01:09
Diffstat (limited to 'eclass')
-rw-r--r--eclass/Manifest.gzbin39628 -> 39624 bytes
-rw-r--r--eclass/llvm.org.eclass6
-rw-r--r--eclass/tree-sitter-grammar.eclass148
3 files changed, 127 insertions, 27 deletions
diff --git a/eclass/Manifest.gz b/eclass/Manifest.gz
index 2bc4dd2b9cb6..b2fe7df20efb 100644
--- a/eclass/Manifest.gz
+++ b/eclass/Manifest.gz
Binary files differ
diff --git a/eclass/llvm.org.eclass b/eclass/llvm.org.eclass
index 2086d44e7576..bd1b726a9a4e 100644
--- a/eclass/llvm.org.eclass
+++ b/eclass/llvm.org.eclass
@@ -75,12 +75,6 @@ if [[ -z ${_LLVM_SOURCE_TYPE+1} ]]; then
19.0.0_pre20240316)
EGIT_COMMIT=6d3cec01a6c29fa4e51ba129fa13dbf55d2b928e
;;
- 19.0.0_pre20240309)
- EGIT_COMMIT=1c7607e8ee6ec4ca3abce1561dd39a98d4efac96
- ;;
- 19.0.0_pre20240302)
- EGIT_COMMIT=597f9761c3a5ba278fa930d2fac13f156287d505
- ;;
*)
die "Unknown snapshot: ${PV}"
;;
diff --git a/eclass/tree-sitter-grammar.eclass b/eclass/tree-sitter-grammar.eclass
index b2563220cfc2..74443e213b89 100644
--- a/eclass/tree-sitter-grammar.eclass
+++ b/eclass/tree-sitter-grammar.eclass
@@ -1,10 +1,11 @@
-# Copyright 1999-2023 Gentoo Authors
+# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: tree-sitter-grammar.eclass
# @MAINTAINER:
# Matthew Smith <matthew@gentoo.org>
# Nick Sarnie <sarnex@gentoo.org>
+# Arthur Zamarin <arthurzam@gentoo.org>
# @AUTHOR:
# Matthew Smith <matthew@gentoo.org>
# @SUPPORTED_EAPIS: 8
@@ -22,7 +23,7 @@ inherit edo multilib toolchain-funcs
SRC_URI="https://github.com/tree-sitter/${PN}/archive/${TS_PV:-v${PV}}.tar.gz
-> ${P}.tar.gz"
-S="${WORKDIR}"/${PN}-${TS_PV:-${PV}}/src
+S="${WORKDIR}"/${PN}-${TS_PV:-${PV}}
BDEPEND+=" test? ( dev-util/tree-sitter-cli )"
IUSE+=" test"
@@ -35,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:
@@ -44,33 +83,62 @@ _get_tsg_abi_ver() {
# This sed script finds ABI definition string in parser source file,
# substitutes all the string until the ABI number, and prints remains
# (the ABI number itself)
- sed -n 's/#define LANGUAGE_VERSION //p' "${S}"/parser.c ||
+ sed -n 's/#define LANGUAGE_VERSION //p' "${S}"/src/parser.c ||
die "Unable to extract ABI version for this grammar"
}
-# @FUNCTION: tree-sitter-grammar_src_compile
-# @DESCRIPTION:
-# Compiles the Tree Sitter parser as a shared library.
-tree-sitter-grammar_src_compile() {
+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:
+# Compiles the Tree Sitter parser as a shared library, the legacy way.
+_tree-sitter-grammar_legacy_compile() {
+ cd "${S}/src" || die
+
# Grammars always contain parser.c, and sometimes a scanner.c,
# or scanner.cc.
tc-export CC CXX
# We want to use the bundled parser.h, not anything lurking on the system, hence -I
# See https://github.com/tree-sitter/tree-sitter-bash/issues/199#issuecomment-1694416505
- export CFLAGS="${CFLAGS} -fPIC -I. -Itree_sitter"
- export CXXFLAGS="${CXXFLAGS} -fPIC -I. -Itree_sitter"
+ local -x CFLAGS="${CFLAGS} -fPIC -I. -Itree_sitter"
+ local -x CXXFLAGS="${CXXFLAGS} -fPIC -I. -Itree_sitter"
local objects=( parser.o )
- if [[ -f "${S}"/scanner.c || -f "${S}"/scanner.cc ]]; then
+ if [[ -f "${S}"/src/scanner.c || -f "${S}"/src/scanner.cc ]]; then
objects+=( scanner.o )
fi
emake "${objects[@]}"
local link="$(tc-getCC) ${CFLAGS}"
- if [[ -f "${S}/scanner.cc" ]]; then
+ if [[ -f "${S}/src/scanner.cc" ]]; then
link="$(tc-getCXX) ${CXXFLAGS}"
fi
@@ -84,10 +152,33 @@ tree-sitter-grammar_src_compile() {
edo ${link} ${LDFLAGS} \
-shared \
*.o \
- ${soname_args} \
+ "${soname_args}" \
-o "${WORKDIR}"/${soname}
}
+tree-sitter-grammar_src_compile() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ # legacy grammars don't have a pyproject.toml
+ if [[ -f "${S}/pyproject.toml" ]]; then
+ sed -e "/SONAME_MINOR :=/s/:=.*$/:= $(_get_tsg_abi_ver)/" -i "${S}/Makefile" || die
+ emake \
+ PREFIX="${EPREFIX}/usr" \
+ LIBDIR="${EPREFIX}/usr/$(get_libdir)"
+ 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
# @DESCRIPTION:
# Runs the Tree Sitter parser's test suite.
@@ -95,22 +186,37 @@ tree-sitter-grammar_src_compile() {
tree-sitter-grammar_src_test() {
debug-print-function ${FUNCNAME} "${@}"
- (cd .. && tree-sitter test) || die "Test suite failed"
+ tree-sitter test || die "Test suite failed"
}
-# @FUNCTION: tree-sitter-grammar_src_install
-# @DESCRIPTION:
-# Installs the Tree Sitter parser library.
tree-sitter-grammar_src_install() {
debug-print-function ${FUNCNAME} "${@}"
- local soname=lib${PN}$(get_libname $(_get_tsg_abi_ver))
+ # legacy grammars don't have a pyproject.toml
+ if [[ -f "${S}/pyproject.toml" ]]; then
+ emake \
+ PREFIX="${EPREFIX}/usr" \
+ LIBDIR="${EPREFIX}/usr/$(get_libdir)" \
+ DESTDIR="${D}/" \
+ install
+ find "${D}" -name '*.a' -delete || die "failed to remove static libraries"
+ else
+ local soname=lib${PN}$(get_libname $(_get_tsg_abi_ver))
+
+ dolib.so "${WORKDIR}/${soname}"
+ dosym "${soname}" /usr/$(get_libdir)/lib${PN}$(get_libname)
+ fi
- dolib.so "${WORKDIR}/${soname}"
- dosym "${soname}" \
- /usr/$(get_libdir)/lib${PN}$(get_libname)
+ 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