dev-python/click-default-group: keyworded 1.2.2 for ia64, bug #700918
[gentoo.git] / dev-python / shiboken2 / shiboken2-5.14.2.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
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} )
16
17 inherit cmake-utils llvm python-r1 toolchain-funcs
18
19 MY_P=pyside-setup-opensource-src-${PV}
20
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"
24
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"
30 SLOT="0"
31 KEYWORDS="~amd64 ~x86"
32 IUSE="+docstrings numpy test vulkan"
33 REQUIRED_USE="${PYTHON_REQUIRED_USE}"
34
35 #tests fail pretty bad and I'm not fixing them right now
36 RESTRICT="test"
37
38 # Minimal supported version of Qt.
39 QT_PV="$(ver_cut 1-2):5"
40
41 # Since Clang is required at both build- and runtime, BDEPEND is omitted here.
42 RDEPEND="${PYTHON_DEPS}
43         >=dev-qt/qtcore-${QT_PV}
44         >=sys-devel/clang-6:=
45         docstrings? (
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}
50         )
51         numpy? ( dev-python/numpy[${PYTHON_USEDEP}] )
52         vulkan? ( dev-util/vulkan-headers )
53 "
54 DEPEND="${RDEPEND}
55         test? ( >=dev-qt/qttest-${QT_PV} )
56 "
57
58 S=${WORKDIR}/${MY_P}/sources/shiboken2
59 DOCS=( AUTHORS )
60
61 # Ensure the path returned by get_llvm_prefix() contains clang as well.
62 llvm_check_deps() {
63         has_version "sys-devel/clang:${LLVM_SLOT}"
64 }
65
66 src_prepare() {
67         # TODO: File upstream issue requesting a sane way to disable NumPy support.
68         if ! use numpy; then
69                 sed -i -e '/\bprint(os\.path\.realpath(numpy))/d' \
70                         libshiboken/CMakeLists.txt || die
71         fi
72
73         # Shiboken2 assumes Vulkan headers live under either "$VULKAN_SDK/include"
74         # or "$VK_SDK_PATH/include" rather than "${EPREFIX}/usr/include/vulkan".
75         if use vulkan; then
76                 sed -i -e 's~\bdetectVulkan(&headerPaths);~headerPaths.append(HeaderPath{QByteArrayLiteral("'${EPREFIX}'/usr/include/vulkan"), HeaderType::System});~' \
77                         ApiExtractor/clangparser/compilersupport.cpp || die
78         fi
79
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
88         #
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)"
101         CPP=clang
102         sed -i -e 's~(findClangBuiltInIncludesDir())~(QStringLiteral("'${EPREFIX}'/usr/lib/clang/'$(clang-fullversion)'/include"))~' \
103                 ApiExtractor/clangparser/compilersupport.cpp || die
104         CPP="${_CPP_old}"
105
106         cmake-utils_src_prepare
107 }
108
109 src_configure() {
110         local mycmakeargs=(
111                 -DBUILD_TESTS=$(usex test)
112                 -DDISABLE_DOCSTRINGS=$(usex !docstrings)
113         )
114
115         shiboken2_configure() {
116                 local mycmakeargs=(
117                         "${mycmakeargs[@]}"
118                         -DPYTHON_CONFIG_SUFFIX="-${EPYTHON}"
119                         -DPYTHON_EXECUTABLE="${PYTHON}"
120                         -DUSE_PYTHON_VERSION="${EPYTHON#python}"
121                 )
122                 # CMakeLists.txt expects LLVM_INSTALL_DIR as an environment variable.
123                 LLVM_INSTALL_DIR="$(get_llvm_prefix)" cmake-utils_src_configure
124         }
125         python_foreach_impl shiboken2_configure
126 }
127
128 src_compile() {
129         python_foreach_impl cmake-utils_src_compile
130 }
131
132 src_test() {
133         python_foreach_impl cmake-utils_src_test
134 }
135
136 src_install() {
137         shiboken2_install() {
138                 cmake-utils_src_install
139                 python_optimize
140
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
145
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
151         }
152         python_foreach_impl shiboken2_install
153
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.
157         # See also:
158         #     https://bugreports.qt.io/browse/PYSIDE-1053
159         #     https://github.com/leycec/raiagent/issues/74
160         sed -i \
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
164
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
169 }