1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 # TODO: Split the "/usr/bin/shiboken2" binding generator from the
7 # "/usr/lib64/libshiboken2-*.so" family of shared libraries. The former
8 # requires everything (including Clang) at runtime; the latter only requires
9 # Qt and Python at runtime. Note that "pip" separates these two as well. See:
10 # https://doc.qt.io/qtforpython/shiboken2/faq.html#is-there-any-runtime-dependency-on-the-generated-binding
11 # Once split, the PySide2 ebuild should be revised to require
12 # "/usr/bin/shiboken2" at build time and "libshiboken2-*.so" at runtime.
13 # TODO: Add PyPy once officially supported. See also:
14 # https://bugreports.qt.io/browse/PYSIDE-535
15 PYTHON_COMPAT=( python3_{6,7,8} )
17 inherit cmake-utils llvm python-r1 toolchain-funcs
19 MY_P=pyside-setup-opensource-src-${PV}
21 DESCRIPTION="Python binding generator for C++ libraries"
22 HOMEPAGE="https://wiki.qt.io/PySide2"
23 SRC_URI="https://download.qt.io/official_releases/QtForPython/pyside2/PySide2-${PV}-src/${MY_P}.tar.xz"
25 # The "sources/shiboken2/libshiboken" directory is triple-licensed under the
26 # GPL v2, v3+, and LGPL v3. All remaining files are licensed under the GPL v3
27 # with version 1.0 of a Qt-specific exception enabling shiboken2 output to be
28 # arbitrarily relicensed. (TODO)
29 LICENSE="|| ( GPL-2 GPL-3+ LGPL-3 ) GPL-3"
31 KEYWORDS="~amd64 ~x86"
32 IUSE="+docstrings numpy test vulkan"
33 REQUIRED_USE="${PYTHON_REQUIRED_USE}"
35 #tests fail pretty bad and I'm not fixing them right now
38 # Minimal supported version of Qt.
39 QT_PV="$(ver_cut 1-2):5"
41 # Since Clang is required at both build- and runtime, BDEPEND is omitted here.
42 RDEPEND="${PYTHON_DEPS}
43 >=dev-qt/qtcore-${QT_PV}
46 >=dev-libs/libxml2-2.6.32
47 >=dev-libs/libxslt-1.1.19
48 >=dev-qt/qtxml-${QT_PV}
49 >=dev-qt/qtxmlpatterns-${QT_PV}
51 numpy? ( dev-python/numpy[${PYTHON_USEDEP}] )
52 vulkan? ( dev-util/vulkan-headers )
55 test? ( >=dev-qt/qttest-${QT_PV} )
58 S=${WORKDIR}/${MY_P}/sources/shiboken2
61 # Ensure the path returned by get_llvm_prefix() contains clang as well.
63 has_version "sys-devel/clang:${LLVM_SLOT}"
67 # TODO: File upstream issue requesting a sane way to disable NumPy support.
69 sed -i -e '/\bprint(os\.path\.realpath(numpy))/d' \
70 libshiboken/CMakeLists.txt || die
73 # Shiboken2 assumes Vulkan headers live under either "$VULKAN_SDK/include"
74 # or "$VK_SDK_PATH/include" rather than "${EPREFIX}/usr/include/vulkan".
76 sed -i -e 's~\bdetectVulkan(&headerPaths);~headerPaths.append(HeaderPath{QByteArrayLiteral("'${EPREFIX}'/usr/include/vulkan"), HeaderType::System});~' \
77 ApiExtractor/clangparser/compilersupport.cpp || die
80 # Shiboken2 assumes the "/usr/lib/clang/${CLANG_NEWEST_VERSION}/include/"
81 # subdirectory provides Clang builtin includes (e.g., "stddef.h") for the
82 # currently installed version of Clang, where ${CLANG_NEWEST_VERSION} is
83 # the largest version specifier that exists under the "/usr/lib/clang/"
84 # subdirectory. This assumption is false in edge cases, including when
85 # users downgrade from newer Clang versions but fail to remove those
86 # versions with "emerge --depclean". See also:
87 # https://github.com/leycec/raiagent/issues/85
89 # Sadly, the clang-* family of functions exported by the "toolchain-funcs"
90 # eclass are defective, returning nonsensical placeholder strings if the
91 # end user has *NOT* explicitly configured their C++ compiler to be Clang.
92 # PySide2 does *NOT* care whether the end user has done so or not, as
93 # PySide2 unconditionally requires Clang in either case. This requires us
94 # to temporarily coerce the "${CPP}" environment variable identifying the
95 # current C++ compiler to "clang" immediately *BEFORE* calling such a
96 # function and then restoring that variable to its prior state immediately
97 # *AFTER* returning from that function call merely to force the
98 # clang-fullversion() function called below to return sanity. See also:
99 # https://bugs.gentoo.org/619490
100 _CPP_old="$(tc-getCPP)"
102 sed -i -e 's~(findClangBuiltInIncludesDir())~(QStringLiteral("'${EPREFIX}'/usr/lib/clang/'$(clang-fullversion)'/include"))~' \
103 ApiExtractor/clangparser/compilersupport.cpp || die
106 cmake-utils_src_prepare
111 -DBUILD_TESTS=$(usex test)
112 -DDISABLE_DOCSTRINGS=$(usex !docstrings)
115 shiboken2_configure() {
118 -DPYTHON_CONFIG_SUFFIX="-${EPYTHON}"
119 -DPYTHON_EXECUTABLE="${PYTHON}"
120 -DUSE_PYTHON_VERSION="${EPYTHON#python}"
122 # CMakeLists.txt expects LLVM_INSTALL_DIR as an environment variable.
123 LLVM_INSTALL_DIR="$(get_llvm_prefix)" cmake-utils_src_configure
125 python_foreach_impl shiboken2_configure
129 python_foreach_impl cmake-utils_src_compile
133 python_foreach_impl cmake-utils_src_test
137 shiboken2_install() {
138 cmake-utils_src_install
141 # Uniquify the "shiboken2" executable for the current Python target,
142 # preserving an unversioned "shiboken2" file arbitrarily associated
143 # with the last Python target.
144 cp "${ED}"/usr/bin/${PN}{,-${EPYTHON}} || die
146 # Uniquify the Shiboken2 pkgconfig file for the current Python target,
147 # preserving an unversioned "shiboken2.pc" file arbitrarily associated
148 # with the last Python target. See also:
149 # https://github.com/leycec/raiagent/issues/73
150 cp "${ED}/usr/$(get_libdir)"/pkgconfig/${PN}{,-${EPYTHON}}.pc || die
152 python_foreach_impl shiboken2_install
154 # CMakeLists.txt installs a "Shiboken2Targets-gentoo.cmake" file forcing
155 # downstream consumers (e.g., PySide2) to target one "libshiboken2-*.so"
156 # library and one "shiboken2" executable linked to one Python interpreter.
158 # https://bugreports.qt.io/browse/PYSIDE-1053
159 # https://github.com/leycec/raiagent/issues/74
161 -e 's~shiboken2-python[[:digit:]]\+\.[[:digit:]]\+~shiboken2${PYTHON_CONFIG_SUFFIX}~g' \
162 -e 's~/bin/shiboken2~/bin/shiboken2${PYTHON_CONFIG_SUFFIX}~g' \
163 "${ED}/usr/$(get_libdir)"/cmake/Shiboken2-${PV}/Shiboken2Targets-gentoo.cmake || die
165 # Remove the broken "shiboken_tool.py" script. By inspection, this script
166 # reduces to a noop. Moreover, this script raises the following exception:
167 # FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/../shiboken_tool.py': '/usr/bin/../shiboken_tool.py'
168 rm "${ED}"/usr/bin/shiboken_tool.py