Gentoo Archives: gentoo-commits

From: Sam James <sam@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: dev-python/shiboken2/files/, dev-python/shiboken2/
Date: Thu, 30 Jun 2022 16:57:02
Message-Id: 1656608210.f83c31ac85f95b00b2ebce2e2fe026798983428e.sam@gentoo
1 commit: f83c31ac85f95b00b2ebce2e2fe026798983428e
2 Author: Sam James <sam <AT> gentoo <DOT> org>
3 AuthorDate: Thu Jun 30 13:58:29 2022 +0000
4 Commit: Sam James <sam <AT> gentoo <DOT> org>
5 CommitDate: Thu Jun 30 16:56:50 2022 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f83c31ac
7
8 dev-python/shiboken2: add Python 3.11 compatibility
9
10 Signed-off-by: Sam James <sam <AT> gentoo.org>
11
12 .../files/shiboken2-5.15.2-python311-fixups.patch | 47 ++++++
13 .../files/shiboken2-5.15.2-python311.patch | 125 +++++++++++++++
14 dev-python/shiboken2/shiboken2-5.15.2-r2.ebuild | 172 +++++++++++++++++++++
15 3 files changed, 344 insertions(+)
16
17 diff --git a/dev-python/shiboken2/files/shiboken2-5.15.2-python311-fixups.patch b/dev-python/shiboken2/files/shiboken2-5.15.2-python311-fixups.patch
18 new file mode 100644
19 index 000000000000..4ab435555591
20 --- /dev/null
21 +++ b/dev-python/shiboken2/files/shiboken2-5.15.2-python311-fixups.patch
22 @@ -0,0 +1,47 @@
23 +The Fedora / upstream fixes (shiboken2-5.15.2-python311.patch) end up breaking
24 +Python 3.8 compatibility (maybe 3.9 too, but didn't get that far).
25 +
26 +Wrap them with PY_VERSION_HEX for Python 3.11.
27 +--- a/libshiboken/basewrapper.cpp
28 ++++ b/libshiboken/basewrapper.cpp
29 +@@ -366,7 +366,11 @@ SbkObjectType *SbkObject_TypeF(void)
30 + static PyTypeObject *type = nullptr;
31 + if (!type) {
32 + type = reinterpret_cast<PyTypeObject *>(SbkType_FromSpec(&SbkObject_Type_spec));
33 +- Py_SET_TYPE(type, SbkObjectType_TypeF());
34 ++ #if PY_VERSION_HEX < 0x030B00A1
35 ++ Py_TYPE(type) = SbkObjectType_TypeF();
36 ++ #else
37 ++ Py_SET_TYPE(type, SbkObjectType_TypeF());
38 ++ #endif
39 + Py_INCREF(Py_TYPE(type));
40 + type->tp_weaklistoffset = offsetof(SbkObject, weakreflist);
41 + type->tp_dictoffset = offsetof(SbkObject, ob_dict);
42 +@@ -1110,7 +1114,11 @@ introduceWrapperType(PyObject *enclosingObject,
43 + typeSpec->slots[0].pfunc = reinterpret_cast<void *>(baseType ? baseType : SbkObject_TypeF());
44 +
45 + PyObject *heaptype = SbkType_FromSpecWithBases(typeSpec, baseTypes);
46 +- Py_SET_TYPE(heaptype, SbkObjectType_TypeF());
47 ++ #if PY_VERSION_HEX < 0x030B00A1
48 ++ Py_TYPE(heaptype) = SbkObjectType_TypeF();
49 ++ #else
50 ++ Py_SET_TYPE(heaptype, SbkObjectType_TypeF());
51 ++ #endif
52 + Py_INCREF(Py_TYPE(heaptype));
53 + auto *type = reinterpret_cast<SbkObjectType *>(heaptype);
54 + #if PY_VERSION_HEX < 0x03000000
55 +--- a/libshiboken/sbkenum.cpp
56 ++++ b/libshiboken/sbkenum.cpp
57 +@@ -741,7 +741,11 @@ newTypeWithName(const char *name,
58 + copyNumberMethods(numbers_fromFlag, newslots, &idx);
59 + newspec.slots = newslots;
60 + auto *type = reinterpret_cast<PyTypeObject *>(SbkType_FromSpec(&newspec));
61 +- Py_SET_TYPE(type, SbkEnumType_TypeF());
62 ++ #if PY_VERSION_HEX < 0x030B00A1
63 ++ Py_TYPE(type) = SbkEnumType_TypeF();
64 ++ #else
65 ++ Py_SET_TYPE(type, SbkEnumType_TypeF());
66 ++ #endif
67 +
68 + auto *enumType = reinterpret_cast<SbkEnumType *>(type);
69 + PepType_SETP(enumType)->cppName = cppName;
70
71 diff --git a/dev-python/shiboken2/files/shiboken2-5.15.2-python311.patch b/dev-python/shiboken2/files/shiboken2-5.15.2-python311.patch
72 new file mode 100644
73 index 000000000000..063861a1cb1a
74 --- /dev/null
75 +++ b/dev-python/shiboken2/files/shiboken2-5.15.2-python311.patch
76 @@ -0,0 +1,125 @@
77 +https://src.fedoraproject.org/fork/pviktori/rpms/python-pyside2/raw/5da9902bd8732b49eb722d71f306d4ab197c84b8/f/python3.11.patch
78 +https://code.qt.io/cgit/pyside/pyside-setup.git/patch/?id=52df3b8f64
79 +https://code.qt.io/cgit/pyside/pyside-setup.git/patch/?id=73adefe22f
80 +https://code.qt.io/cgit/pyside/pyside-setup.git/patch/?id=a09a1db839
81 +
82 +From b64ad27d8dfeeecaaa8a98051252a32c9d998df4 Mon Sep 17 00:00:00 2001
83 +From: Friedemann Kleint <Friedemann.Kleint@××.io>
84 +Date: Thu, 9 Jun 2022 16:50:41 +0200
85 +Subject: [PATCH] libshiboken: Fix a crash in Shiboken::Object::isValid() for
86 + Python 3.11
87 +
88 +The function is passed type objects for class methods, which caused
89 +it to crash.
90 +
91 +The first clause did not catch this, and so it was cast to SbkObject
92 +below.
93 +
94 +Add a type check to prevent this.
95 +
96 +Pick-to: 6.3 6.2 5.15
97 +Task-number: PYSIDE-1960
98 +Change-Id: Icfdd6fefb7156ac5961444bd5395109849a1d66e
99 +Reviewed-by: Christian Tismer <tismer@×××××××××.com>
100 +Reviewed-by: Qt CI Bot <qt_ci_bot@××××××××××.org>
101 +--- a/libshiboken/basewrapper.cpp
102 ++++ b/libshiboken/basewrapper.cpp
103 +@@ -1468,6 +1468,7 @@ bool setCppPointer(SbkObject *sbkObj, PyTypeObject *desiredType, void *cptr)
104 + bool isValid(PyObject *pyObj)
105 + {
106 + if (!pyObj || pyObj == Py_None
107 ++ || PyType_Check(pyObj) != 0
108 + || Py_TYPE(Py_TYPE(pyObj)) != SbkObjectType_TypeF()) {
109 + return true;
110 + }
111 +--- a/libshiboken/basewrapper.cpp
112 ++++ b/libshiboken/basewrapper.cpp
113 +@@ -366,7 +366,7 @@ SbkObjectType *SbkObject_TypeF(void)
114 + static PyTypeObject *type = nullptr;
115 + if (!type) {
116 + type = reinterpret_cast<PyTypeObject *>(SbkType_FromSpec(&SbkObject_Type_spec));
117 +- Py_TYPE(type) = SbkObjectType_TypeF();
118 ++ Py_SET_TYPE(type, SbkObjectType_TypeF());
119 + Py_INCREF(Py_TYPE(type));
120 + type->tp_weaklistoffset = offsetof(SbkObject, weakreflist);
121 + type->tp_dictoffset = offsetof(SbkObject, ob_dict);
122 +@@ -1110,7 +1110,7 @@ introduceWrapperType(PyObject *enclosingObject,
123 + typeSpec->slots[0].pfunc = reinterpret_cast<void *>(baseType ? baseType : SbkObject_TypeF());
124 +
125 + PyObject *heaptype = SbkType_FromSpecWithBases(typeSpec, baseTypes);
126 +- Py_TYPE(heaptype) = SbkObjectType_TypeF();
127 ++ Py_SET_TYPE(heaptype, SbkObjectType_TypeF());
128 + Py_INCREF(Py_TYPE(heaptype));
129 + auto *type = reinterpret_cast<SbkObjectType *>(heaptype);
130 + #if PY_VERSION_HEX < 0x03000000
131 +--- a/libshiboken/sbkenum.cpp
132 ++++ b/libshiboken/sbkenum.cpp
133 +@@ -741,7 +741,7 @@ newTypeWithName(const char *name,
134 + copyNumberMethods(numbers_fromFlag, newslots, &idx);
135 + newspec.slots = newslots;
136 + auto *type = reinterpret_cast<PyTypeObject *>(SbkType_FromSpec(&newspec));
137 +- Py_TYPE(type) = SbkEnumType_TypeF();
138 ++ Py_SET_TYPE(type, SbkEnumType_TypeF());
139 +
140 + auto *enumType = reinterpret_cast<SbkEnumType *>(type);
141 + PepType_SETP(enumType)->cppName = cppName;
142 +From a09a1db8391243e6bb290ee66bb6e3afbb114c61 Mon Sep 17 00:00:00 2001
143 +From: Friedemann Kleint <Friedemann.Kleint@××.io>
144 +Date: Fri, 24 Jun 2022 09:22:01 +0200
145 +Subject: libshiboken: Fix crashes with static strings in Python 3.11
146 +
147 +In Python 3.11, some strings come with a refcount above decimal
148 +1000000000, apparently indicating that they are interned. Replace the
149 +mechanism by PyUnicode_InternFromString().
150 +
151 +Task-number: PYSIDE-1960
152 +Pick-to: 6.3 6.2 5.15
153 +Change-Id: I6436afee351f89da5814b5d6bc76970b1b508168
154 +Reviewed-by: Qt CI Bot <qt_ci_bot@××××××××××.org>
155 +Reviewed-by: Christian Tismer <tismer@×××××××××.com>
156 +Upstream: https://code.qt.io/cgit/pyside/pyside-setup.git/commit/?id=a09a1db8391243e6bb290ee66bb6e3afbb114c61
157 +
158 +--- a/libshiboken/sbkstring.cpp
159 ++++ b/libshiboken/sbkstring.cpp
160 +@@ -5,8 +5,14 @@
161 + #include "sbkstaticstrings_p.h"
162 + #include "autodecref.h"
163 +
164 +-#include <vector>
165 +-#include <unordered_set>
166 ++#if PY_VERSION_HEX >= 0x030B0000 || defined(Py_LIMITED_API)
167 ++# define USE_INTERN_STRINGS
168 ++#endif
169 ++
170 ++#ifndef USE_INTERN_STRINGS
171 ++# include <vector>
172 ++# include <unordered_set>
173 ++#endif
174 +
175 + namespace Shiboken
176 + {
177 +@@ -179,6 +185,13 @@ Py_ssize_t len(PyObject *str)
178 + // PyObject *attr = PyObject_GetAttr(obj, name());
179 + //
180 +
181 ++#ifdef USE_INTERN_STRINGS
182 ++PyObject *createStaticString(const char *str)
183 ++{
184 ++ return PyUnicode_InternFromString(str);
185 ++}
186 ++#else
187 ++
188 + using StaticStrings = std::unordered_set<PyObject *>;
189 +
190 + static void finalizeStaticStrings(); // forward
191 +@@ -225,6 +238,8 @@ PyObject *createStaticString(const char *str)
192 + return result;
193 + }
194 +
195 ++#endif // !USE_INTERN_STRINGS
196 ++
197 + ///////////////////////////////////////////////////////////////////////
198 + //
199 + // PYSIDE-1019: Helper function for snake_case vs. camelCase names
200 +cgit v1.2.1
201 +
202
203 diff --git a/dev-python/shiboken2/shiboken2-5.15.2-r2.ebuild b/dev-python/shiboken2/shiboken2-5.15.2-r2.ebuild
204 new file mode 100644
205 index 000000000000..4ba580569103
206 --- /dev/null
207 +++ b/dev-python/shiboken2/shiboken2-5.15.2-r2.ebuild
208 @@ -0,0 +1,172 @@
209 +# Copyright 1999-2022 Gentoo Authors
210 +# Distributed under the terms of the GNU General Public License v2
211 +
212 +EAPI=8
213 +
214 +# TODO: Split the "/usr/bin/shiboken2" binding generator from the
215 +# "/usr/lib64/libshiboken2-*.so" family of shared libraries. The former
216 +# requires everything (including Clang) at runtime; the latter only requires
217 +# Qt and Python at runtime. Note that "pip" separates these two as well. See:
218 +# https://doc.qt.io/qtforpython/shiboken2/faq.html#is-there-any-runtime-dependency-on-the-generated-binding
219 +# Once split, the PySide2 ebuild should be revised to require
220 +# "/usr/bin/shiboken2" at build time and "libshiboken2-*.so" at runtime.
221 +# TODO: Add PyPy once officially supported. See also:
222 +# https://bugreports.qt.io/browse/PYSIDE-535
223 +PYTHON_COMPAT=( python3_{8..11} )
224 +
225 +inherit cmake llvm python-r1 toolchain-funcs
226 +
227 +MY_P=pyside-setup-opensource-src-${PV}
228 +
229 +DESCRIPTION="Python binding generator for C++ libraries"
230 +HOMEPAGE="https://wiki.qt.io/PySide2"
231 +SRC_URI="https://download.qt.io/official_releases/QtForPython/pyside2/PySide2-${PV}-src/${MY_P}.tar.xz"
232 +S="${WORKDIR}/${MY_P}/sources/shiboken2"
233 +
234 +# The "sources/shiboken2/libshiboken" directory is triple-licensed under the
235 +# GPL v2, v3+, and LGPL v3. All remaining files are licensed under the GPL v3
236 +# with version 1.0 of a Qt-specific exception enabling shiboken2 output to be
237 +# arbitrarily relicensed. (TODO)
238 +LICENSE="|| ( GPL-2 GPL-3+ LGPL-3 ) GPL-3"
239 +SLOT="0"
240 +KEYWORDS="~amd64 ~arm ~arm64 ~x86"
241 +IUSE="+docstrings numpy test vulkan"
242 +REQUIRED_USE="${PYTHON_REQUIRED_USE}"
243 +
244 +# Tests fail pretty bad and I'm not fixing them right now
245 +RESTRICT="test"
246 +
247 +# Minimal supported version of Qt.
248 +QT_PV="$(ver_cut 1-2):5"
249 +
250 +# Since Clang is required at both build- and runtime, BDEPEND is omitted here.
251 +RDEPEND="${PYTHON_DEPS}
252 + >=dev-qt/qtcore-${QT_PV}
253 + sys-devel/clang:=
254 + sys-devel/clang-runtime:=
255 + docstrings? (
256 + >=dev-libs/libxml2-2.6.32
257 + >=dev-libs/libxslt-1.1.19
258 + >=dev-qt/qtxml-${QT_PV}
259 + >=dev-qt/qtxmlpatterns-${QT_PV}
260 + )
261 + numpy? ( dev-python/numpy[${PYTHON_USEDEP}] )
262 + vulkan? ( dev-util/vulkan-headers )
263 +"
264 +DEPEND="${RDEPEND}
265 + test? ( >=dev-qt/qttest-${QT_PV} )
266 +"
267 +
268 +DOCS=( AUTHORS )
269 +
270 +PATCHES=(
271 + "${FILESDIR}/${P}-python310.patch"
272 + "${FILESDIR}/${P}-numpy-1.23.patch"
273 + "${FILESDIR}/${P}-python311.patch"
274 + "${FILESDIR}"/${PN}-5.15.2-python311-fixups.patch
275 +)
276 +
277 +# Ensure the path returned by get_llvm_prefix() contains clang as well.
278 +llvm_check_deps() {
279 + has_version "sys-devel/clang:${LLVM_SLOT}"
280 +}
281 +
282 +src_prepare() {
283 + # TODO: File upstream issue requesting a sane way to disable NumPy support.
284 + if ! use numpy; then
285 + sed -i -e '/\bprint(os\.path\.realpath(numpy))/d' \
286 + libshiboken/CMakeLists.txt || die
287 + fi
288 +
289 + # Shiboken2 assumes Vulkan headers live under either "$VULKAN_SDK/include"
290 + # or "$VK_SDK_PATH/include" rather than "${EPREFIX}/usr/include/vulkan".
291 + if use vulkan; then
292 + sed -i -e "s~\bdetectVulkan(&headerPaths);~headerPaths.append(HeaderPath{QByteArrayLiteral(\"${EPREFIX}/usr/include/vulkan\"), HeaderType::System});~" \
293 + ApiExtractor/clangparser/compilersupport.cpp || die
294 + fi
295 +
296 + # Shiboken2 assumes the "/usr/lib/clang/${CLANG_NEWEST_VERSION}/include/"
297 + # subdirectory provides Clang builtin includes (e.g., "stddef.h") for the
298 + # currently installed version of Clang, where ${CLANG_NEWEST_VERSION} is
299 + # the largest version specifier that exists under the "/usr/lib/clang/"
300 + # subdirectory. This assumption is false in edge cases, including when
301 + # users downgrade from newer Clang versions but fail to remove those
302 + # versions with "emerge --depclean". See also:
303 + # https://github.com/leycec/raiagent/issues/85
304 + #
305 + # Sadly, the clang-* family of functions exported by the "toolchain-funcs"
306 + # eclass are defective, returning nonsensical placeholder strings if the
307 + # end user has *NOT* explicitly configured their C++ compiler to be Clang.
308 + # PySide2 does *NOT* care whether the end user has done so or not, as
309 + # PySide2 unconditionally requires Clang in either case. See also:
310 + # https://bugs.gentoo.org/619490
311 + sed -i -e 's~(findClangBuiltInIncludesDir())~(QStringLiteral("'"${EPREFIX}"'/usr/lib/clang/'$(CPP=clang clang-fullversion)'/include"))~' \
312 + ApiExtractor/clangparser/compilersupport.cpp || die
313 +
314 + cmake_src_prepare
315 +}
316 +
317 +src_configure() {
318 + # Minimal tests for now, 2 failing with the extended version
319 + # FIXME Subscripted generics cannot be used with class and instance checks
320 + local mycmakeargs=(
321 + -DBUILD_TESTS=$(usex test)
322 + -DDISABLE_DOCSTRINGS=$(usex !docstrings)
323 + )
324 +
325 + shiboken2_configure() {
326 + local mycmakeargs=(
327 + "${mycmakeargs[@]}"
328 + -DPYTHON_CONFIG_SUFFIX="-${EPYTHON}"
329 + -DPYTHON_EXECUTABLE="${PYTHON}"
330 + -DUSE_PYTHON_VERSION="${EPYTHON#python}"
331 + )
332 + # CMakeLists.txt expects LLVM_INSTALL_DIR as an environment variable.
333 + local -x LLVM_INSTALL_DIR="$(get_llvm_prefix)"
334 + cmake_src_configure
335 + }
336 + python_foreach_impl shiboken2_configure
337 +}
338 +
339 +src_compile() {
340 + python_foreach_impl cmake_src_compile
341 +}
342 +
343 +src_test() {
344 + python_foreach_impl cmake_src_test
345 +}
346 +
347 +src_install() {
348 + shiboken2_install() {
349 + cmake_src_install
350 + python_optimize
351 +
352 + # Uniquify the "shiboken2" executable for the current Python target,
353 + # preserving an unversioned "shiboken2" file arbitrarily associated
354 + # with the last Python target.
355 + cp "${ED}"/usr/bin/${PN}{,-${EPYTHON}} || die
356 +
357 + # Uniquify the Shiboken2 pkgconfig file for the current Python target,
358 + # preserving an unversioned "shiboken2.pc" file arbitrarily associated
359 + # with the last Python target. See also:
360 + # https://github.com/leycec/raiagent/issues/73
361 + cp "${ED}/usr/$(get_libdir)"/pkgconfig/${PN}{,-${EPYTHON}}.pc || die
362 + }
363 + python_foreach_impl shiboken2_install
364 +
365 + # CMakeLists.txt installs a "Shiboken2Targets-gentoo.cmake" file forcing
366 + # downstream consumers (e.g., PySide2) to target one "libshiboken2-*.so"
367 + # library and one "shiboken2" executable linked to one Python interpreter.
368 + # See also:
369 + # https://bugreports.qt.io/browse/PYSIDE-1053
370 + # https://github.com/leycec/raiagent/issues/74
371 + sed -i \
372 + -e 's~shiboken2-python[[:digit:]]\+\.[[:digit:]]\+~shiboken2${PYTHON_CONFIG_SUFFIX}~g' \
373 + -e 's~/bin/shiboken2~/bin/shiboken2${PYTHON_CONFIG_SUFFIX}~g' \
374 + "${ED}/usr/$(get_libdir)"/cmake/Shiboken2-${PV}/Shiboken2Targets-${CMAKE_BUILD_TYPE,,}.cmake || die
375 +
376 + # Remove the broken "shiboken_tool.py" script. By inspection, this script
377 + # reduces to a noop. Moreover, this script raises the following exception:
378 + # FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/../shiboken_tool.py': '/usr/bin/../shiboken_tool.py'
379 + rm "${ED}"/usr/bin/shiboken_tool.py || die
380 +}