*/*: Discontinue Gentoo SuperH port
[gentoo.git] / dev-lang / python / python-3.9.0_alpha5.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI="7"
5 WANT_LIBTOOL="none"
6
7 inherit autotools check-reqs flag-o-matic pax-utils python-utils-r1 \
8         toolchain-funcs
9
10 MY_P="Python-${PV/_alpha/a}"
11 PYVER=$(ver_cut 1-2)
12 PATCHSET="python-gentoo-patches-3.9.0_alpha2"
13
14 DESCRIPTION="An interpreted, interactive, object-oriented programming language"
15 HOMEPAGE="https://www.python.org/"
16 SRC_URI="https://www.python.org/ftp/python/${PV%_*}/${MY_P}.tar.xz
17         https://dev.gentoo.org/~mgorny/dist/python/${PATCHSET}.tar.xz"
18 S="${WORKDIR}/${MY_P}"
19
20 LICENSE="PSF-2"
21 SLOT="${PYVER}"
22 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86"
23 IUSE="bluetooth build examples gdbm hardened ipv6 libressl +ncurses +readline sqlite +ssl test tk wininst +xml"
24 RESTRICT="!test? ( test )"
25
26 # Do not add a dependency on dev-lang/python to this ebuild.
27 # If you need to apply a patch which requires python for bootstrapping, please
28 # run the bootstrap code on your dev box and include the results in the
29 # patchset. See bug 447752.
30
31 RDEPEND="app-arch/bzip2:=
32         app-arch/xz-utils:=
33         dev-libs/libffi:=
34         sys-apps/util-linux:=
35         >=sys-libs/zlib-1.1.3:=
36         virtual/libcrypt:=
37         virtual/libintl
38         gdbm? ( sys-libs/gdbm:=[berkdb] )
39         ncurses? ( >=sys-libs/ncurses-5.2:= )
40         readline? ( >=sys-libs/readline-4.1:= )
41         sqlite? ( >=dev-db/sqlite-3.3.8:3= )
42         ssl? (
43                 !libressl? ( dev-libs/openssl:= )
44                 libressl? ( dev-libs/libressl:= )
45         )
46         tk? (
47                 >=dev-lang/tcl-8.0:=
48                 >=dev-lang/tk-8.0:=
49                 dev-tcltk/blt:=
50                 dev-tcltk/tix
51         )
52         xml? ( >=dev-libs/expat-2.1:= )"
53 # bluetooth requires headers from bluez
54 DEPEND="${RDEPEND}
55         bluetooth? ( net-wireless/bluez )
56         test? ( app-arch/xz-utils[extra-filters(+)] )
57         virtual/pkgconfig
58         !sys-devel/gcc[libffi(-)]"
59 RDEPEND+=" !build? ( app-misc/mime-types )"
60 PDEPEND=">=app-eselect/eselect-python-20140125-r1"
61
62 # large file tests involve a 2.5G file being copied (duplicated)
63 CHECKREQS_DISK_BUILD=5500M
64
65 pkg_pretend() {
66         use test && check-reqs_pkg_pretend
67
68         ewarn "This is an early developer preview of Python 3.9.  New features"
69         ewarn "can still be added up to 2020-05-18.  It's not suitable for production"
70         ewarn "use, and it is not supported for Gentoo packages."
71 }
72
73 pkg_setup() {
74         use test && check-reqs_pkg_setup
75 }
76
77 src_prepare() {
78         # Ensure that internal copies of expat, libffi and zlib are not used.
79         rm -fr Modules/expat || die
80         rm -fr Modules/_ctypes/libffi* || die
81         rm -fr Modules/zlib || die
82
83         local PATCHES=(
84                 "${WORKDIR}/${PATCHSET}"
85         )
86
87         default
88
89         sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
90                 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
91
92         eautoreconf
93 }
94
95 src_configure() {
96         local disable
97         # disable automagic bluetooth headers detection
98         use bluetooth || export ac_cv_header_bluetooth_bluetooth_h=no
99         use gdbm      || disable+=" gdbm"
100         use ncurses   || disable+=" _curses _curses_panel"
101         use readline  || disable+=" readline"
102         use sqlite    || disable+=" _sqlite3"
103         use ssl       || export PYTHON_DISABLE_SSL="1"
104         use tk        || disable+=" _tkinter"
105         use xml       || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
106         export PYTHON_DISABLE_MODULES="${disable}"
107
108         if ! use xml; then
109                 ewarn "You have configured Python without XML support."
110                 ewarn "This is NOT a recommended configuration as you"
111                 ewarn "may face problems parsing any XML documents."
112         fi
113
114         if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
115                 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
116         fi
117
118         if [[ "$(gcc-major-version)" -ge 4 ]]; then
119                 append-flags -fwrapv
120         fi
121
122         filter-flags -malign-double
123
124         # https://bugs.gentoo.org/show_bug.cgi?id=50309
125         if is-flagq -O3; then
126                 is-flagq -fstack-protector-all && replace-flags -O3 -O2
127                 use hardened && replace-flags -O3 -O2
128         fi
129
130         # https://bugs.gentoo.org/700012
131         if is-flagq -flto || is-flagq '-flto=*'; then
132                 append-cflags $(test-flags-CC -ffat-lto-objects)
133         fi
134
135         # Export CXX so it ends up in /usr/lib/python3.X/config/Makefile.
136         tc-export CXX
137
138         # Set LDFLAGS so we link modules with -lpython3.2 correctly.
139         # Needed on FreeBSD unless Python 3.2 is already installed.
140         # Please query BSD team before removing this!
141         append-ldflags "-L."
142
143         # Fix implicit declarations on cross and prefix builds. Bug #674070.
144         use ncurses && append-cppflags -I"${ESYSROOT}"/usr/include/ncursesw
145
146         local dbmliborder
147         if use gdbm; then
148                 dbmliborder+="${dbmliborder:+:}gdbm"
149         fi
150
151         local myeconfargs=(
152                 # glibc-2.30 removes it; since we can't cleanly force-rebuild
153                 # Python on glibc upgrade, remove it proactively to give
154                 # a chance for users rebuilding python before glibc
155                 ac_cv_header_stropts_h=no
156
157                 --enable-shared
158                 $(use_enable ipv6)
159                 --infodir='${prefix}/share/info'
160                 --mandir='${prefix}/share/man'
161                 --with-computed-gotos
162                 --with-dbmliborder="${dbmliborder}"
163                 --with-libc=
164                 --enable-loadable-sqlite-extensions
165                 --without-ensurepip
166                 --with-system-expat
167                 --with-system-ffi
168         )
169
170         OPT="" econf "${myeconfargs[@]}"
171 }
172
173 src_compile() {
174         # Ensure sed works as expected
175         # https://bugs.gentoo.org/594768
176         local -x LC_ALL=C
177
178         emake CPPFLAGS= CFLAGS= LDFLAGS=
179
180         # Work around bug 329499. See also bug 413751 and 457194.
181         if has_version dev-libs/libffi[pax_kernel]; then
182                 pax-mark E python
183         else
184                 pax-mark m python
185         fi
186 }
187
188 src_test() {
189         # Tests will not work when cross compiling.
190         if tc-is-cross-compiler; then
191                 elog "Disabling tests due to crosscompiling."
192                 return
193         fi
194
195         # Skip failing tests.
196         local skipped_tests="gdb"
197
198         for test in ${skipped_tests}; do
199                 mv "${S}"/Lib/test/test_${test}.py "${T}"
200         done
201
202         # bug 660358
203         local -x COLUMNS=80
204
205         local -x PYTHONDONTWRITEBYTECODE=
206
207         emake test EXTRATESTOPTS="-u-network" CPPFLAGS= CFLAGS= LDFLAGS= < /dev/tty
208         local result=$?
209
210         for test in ${skipped_tests}; do
211                 mv "${T}/test_${test}.py" "${S}"/Lib/test
212         done
213
214         elog "The following tests have been skipped:"
215         for test in ${skipped_tests}; do
216                 elog "test_${test}.py"
217         done
218
219         elog "If you would like to run them, you may:"
220         elog "cd '${EPREFIX}/usr/lib/python${PYVER}/test'"
221         elog "and run the tests separately."
222
223         if [[ ${result} -ne 0 ]]; then
224                 die "emake test failed"
225         fi
226 }
227
228 src_install() {
229         local libdir=${ED}/usr/lib/python${PYVER}
230
231         emake DESTDIR="${D}" altinstall
232
233         # Remove static library
234         rm "${ED}"/usr/$(get_libdir)/libpython*.a || die
235
236         sed \
237                 -e "s/\(CONFIGURE_LDFLAGS=\).*/\1/" \
238                 -e "s/\(PY_LDFLAGS=\).*/\1/" \
239                 -i "${libdir}/config-${PYVER}"*/Makefile || die "sed failed"
240
241         # Fix collisions between different slots of Python.
242         rm "${ED}/usr/$(get_libdir)/libpython3.so" || die
243
244         # Cheap hack to get version with ABIFLAGS
245         local abiver=$(cd "${ED}/usr/include"; echo python*)
246         if [[ ${abiver} != python${PYVER} ]]; then
247                 # Replace python3.X with a symlink to python3.Xm
248                 rm "${ED}/usr/bin/python${PYVER}" || die
249                 dosym "${abiver}" "/usr/bin/python${PYVER}"
250                 # Create python3.X-config symlink
251                 dosym "${abiver}-config" "/usr/bin/python${PYVER}-config"
252                 # Create python-3.5m.pc symlink
253                 dosym "python-${PYVER}.pc" "/usr/$(get_libdir)/pkgconfig/${abiver/${PYVER}/-${PYVER}}.pc"
254         fi
255
256         # python seems to get rebuilt in src_install (bug 569908)
257         # Work around it for now.
258         if has_version dev-libs/libffi[pax_kernel]; then
259                 pax-mark E "${ED}/usr/bin/${abiver}"
260         else
261                 pax-mark m "${ED}/usr/bin/${abiver}"
262         fi
263
264         use sqlite || rm -r "${libdir}/"{sqlite3,test/test_sqlite*} || die
265         use tk || rm -r "${ED}/usr/bin/idle${PYVER}" "${libdir}/"{idlelib,tkinter,test/test_tk*} || die
266
267         dodoc Misc/{ACKS,HISTORY,NEWS}
268
269         if use examples; then
270                 docinto examples
271                 find Tools -name __pycache__ -exec rm -fr {} + || die
272                 dodoc -r Tools
273         fi
274         insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
275         local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
276                 emake --no-print-directory -s -f - 2>/dev/null)
277         newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
278
279         newconfd "${FILESDIR}/pydoc.conf" pydoc-${PYVER}
280         newinitd "${FILESDIR}/pydoc.init" pydoc-${PYVER}
281         sed \
282                 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${PYVER/./_}_PORT:" \
283                 -e "s:@PYDOC@:pydoc${PYVER}:" \
284                 -i "${ED}/etc/conf.d/pydoc-${PYVER}" \
285                 "${ED}/etc/init.d/pydoc-${PYVER}" || die "sed failed"
286
287         # for python-exec
288         local vars=( EPYTHON PYTHON_SITEDIR PYTHON_SCRIPTDIR )
289
290         # if not using a cross-compiler, use the fresh binary
291         if ! tc-is-cross-compiler; then
292                 local -x PYTHON=./python
293                 local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}${PWD}
294         else
295                 vars=( PYTHON "${vars[@]}" )
296         fi
297
298         python_export "python${PYVER}" "${vars[@]}"
299         echo "EPYTHON='${EPYTHON}'" > epython.py || die
300         python_domodule epython.py
301
302         # python-exec wrapping support
303         local pymajor=${PYVER%.*}
304         mkdir -p "${D}${PYTHON_SCRIPTDIR}" || die
305         # python and pythonX
306         ln -s "../../../bin/${abiver}" \
307                 "${D}${PYTHON_SCRIPTDIR}/python${pymajor}" || die
308         ln -s "python${pymajor}" "${D}${PYTHON_SCRIPTDIR}/python" || die
309         # python-config and pythonX-config
310         # note: we need to create a wrapper rather than symlinking it due
311         # to some random dirname(argv[0]) magic performed by python-config
312         cat > "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" <<-EOF || die
313                 #!/bin/sh
314                 exec "${abiver}-config" "\${@}"
315         EOF
316         chmod +x "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" || die
317         ln -s "python${pymajor}-config" \
318                 "${D}${PYTHON_SCRIPTDIR}/python-config" || die
319         # 2to3, pydoc
320         ln -s "../../../bin/2to3-${PYVER}" \
321                 "${D}${PYTHON_SCRIPTDIR}/2to3" || die
322         ln -s "../../../bin/pydoc${PYVER}" \
323                 "${D}${PYTHON_SCRIPTDIR}/pydoc" || die
324         # idle
325         if use tk; then
326                 ln -s "../../../bin/idle${PYVER}" \
327                         "${D}${PYTHON_SCRIPTDIR}/idle" || die
328         fi
329 }