blob: 33b4020ade64d7c8e39ac59d0e8ee5c4f1ed71e6 [file] [log] [blame]
Mike Frysinger432f2892021-02-19 15:22:02 -05001# Copyright 1999-2020 Gentoo Authors
Chad Versace9c71f3c2018-10-24 16:49:31 -07002# Distributed under the terms of the GNU General Public License v2
3
Mike Frysinger95c720e2021-02-19 15:09:00 -05004EAPI="6"
Chad Versace9c71f3c2018-10-24 16:49:31 -07005WANT_LIBTOOL="none"
6
7inherit autotools flag-o-matic pax-utils python-utils-r1 toolchain-funcs
8
9MY_P="Python-${PV}"
Mike Frysinger432f2892021-02-19 15:22:02 -050010PATCHSET_VERSION="3.6.8"
Chad Versace9c71f3c2018-10-24 16:49:31 -070011
12DESCRIPTION="An interpreted, interactive, object-oriented programming language"
13HOMEPAGE="https://www.python.org/"
14SRC_URI="https://www.python.org/ftp/python/${PV}/${MY_P}.tar.xz
15 https://dev.gentoo.org/~floppym/python/python-gentoo-patches-${PATCHSET_VERSION}.tar.xz"
16
17LICENSE="PSF-2"
18SLOT="3.6/3.6m"
Daniel Campello7ded4e32019-02-06 11:03:46 -070019KEYWORDS="*"
Mike Frysinger432f2892021-02-19 15:22:02 -050020IUSE="bluetooth build examples gdbm hardened ipv6 libressl +ncurses +readline sqlite +ssl test +threads tk wininst +xml"
Chad Versace9c71f3c2018-10-24 16:49:31 -070021RESTRICT="!test? ( test )"
22
23# Do not add a dependency on dev-lang/python to this ebuild.
24# If you need to apply a patch which requires python for bootstrapping, please
25# run the bootstrap code on your dev box and include the results in the
26# patchset. See bug 447752.
27
28RDEPEND="app-arch/bzip2:0=
29 app-arch/xz-utils:0=
Mike Frysinger432f2892021-02-19 15:22:02 -050030 dev-libs/libffi:=
Chad Versace9c71f3c2018-10-24 16:49:31 -070031 >=sys-libs/zlib-1.1.3:0=
Chad Versace9c71f3c2018-10-24 16:49:31 -070032 virtual/libintl
33 gdbm? ( sys-libs/gdbm:0=[berkdb] )
34 ncurses? ( >=sys-libs/ncurses-5.2:0= )
35 readline? ( >=sys-libs/readline-4.1:0= )
36 sqlite? ( >=dev-db/sqlite-3.3.8:3= )
37 ssl? (
38 !libressl? ( dev-libs/openssl:0= )
39 libressl? ( dev-libs/libressl:0= )
40 )
41 tk? (
42 >=dev-lang/tcl-8.0:0=
43 >=dev-lang/tk-8.0:0=
44 dev-tcltk/blt:0=
45 dev-tcltk/tix
46 )
Mike Frysinger432f2892021-02-19 15:22:02 -050047 xml? ( >=dev-libs/expat-2.1:0= )"
48# bluetooth requires headers from bluez
Chad Versace9c71f3c2018-10-24 16:49:31 -070049DEPEND="${RDEPEND}
Mike Frysinger432f2892021-02-19 15:22:02 -050050 bluetooth? ( net-wireless/bluez )
Chad Versace9c71f3c2018-10-24 16:49:31 -070051 test? ( app-arch/xz-utils[extra-filters(+)] )
52 virtual/pkgconfig
53 !sys-devel/gcc[libffi(-)]"
54RDEPEND+=" !build? ( app-misc/mime-types )"
55PDEPEND=">=app-eselect/eselect-python-20140125-r1"
56
57S="${WORKDIR}/${MY_P}"
58PYVER=${SLOT%/*}
59
60src_prepare() {
61 # Ensure that internal copies of expat, libffi and zlib are not used.
62 rm -fr Modules/expat
63 rm -fr Modules/_ctypes/libffi*
64 rm -fr Modules/zlib
65
Mike Frysinger95c720e2021-02-19 15:09:00 -050066 local PATCHES=(
67 "${WORKDIR}/patches"
Mike Frysinger95c720e2021-02-19 15:09:00 -050068 )
Chad Versace9c71f3c2018-10-24 16:49:31 -070069
Mike Frysinger95c720e2021-02-19 15:09:00 -050070 default
Chad Versace9c71f3c2018-10-24 16:49:31 -070071
72 # START: Chromium OS
Mike Frysingerce0b8c02019-07-11 00:40:18 -040073 if tc-is-cross-compiler ; then
74 epatch "${FILESDIR}/python-3.6.5-cross-h2py.patch"
75 epatch "${FILESDIR}/python-3.6.5-cross-hack-compiler.patch"
76 fi
77 epatch "${FILESDIR}/python-3.6.5-cross-python-config.patch"
78 epatch "${FILESDIR}/python-3.6.5-cross-setup-sysroot.patch"
79 epatch "${FILESDIR}/python-3.6.5-cross-distutils.patch"
Mike Frysinger935ee6f2019-09-06 14:38:15 -040080 epatch "${FILESDIR}/python-3.6.5-cross-sysconfig.patch"
Mike Frysingerce0b8c02019-07-11 00:40:18 -040081 epatch "${FILESDIR}/python-3.6.5-ldshared.patch"
82 epatch "${FILESDIR}/python-3.6.5-system-libffi.patch"
Chris McDonald5ca5bf22019-08-07 14:53:57 -060083 epatch "${FILESDIR}/python-3.6.5-sigint-handler.patch"
Chad Versace9c71f3c2018-10-24 16:49:31 -070084
85 # Undo the @libdir@ change for portage's pym folder as it is always
86 # installed into /usr/lib/ and not the abi libdir.
87 sed -i \
88 -e '/portage.*pym/s:@@GENTOO_LIBDIR@@:lib:g' \
89 Lib/site.py || die
90
91 sed -i -e "s:sys.exec_prefix]:sys.exec_prefix, '/usr/local']:g" \
92 Lib/site.py || die "sed failed to add /usr/local to prefixes"
93 # END: Chromium OS
94
95 sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
96 Lib/distutils/command/install.py \
97 Lib/distutils/sysconfig.py \
98 Lib/site.py \
99 Lib/sysconfig.py \
100 Lib/test/test_site.py \
101 Makefile.pre.in \
102 Modules/Setup.dist \
103 Modules/getpath.c \
104 configure.ac \
105 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
106
107 eautoreconf
108}
109
110src_configure() {
111 local disable
Mike Frysinger432f2892021-02-19 15:22:02 -0500112 # disable automagic bluetooth headers detection
113 use bluetooth || export ac_cv_header_bluetooth_bluetooth_h=no
Chad Versace9c71f3c2018-10-24 16:49:31 -0700114 use gdbm || disable+=" gdbm"
115 use ncurses || disable+=" _curses _curses_panel"
116 use readline || disable+=" readline"
117 use sqlite || disable+=" _sqlite3"
118 use ssl || export PYTHON_DISABLE_SSL="1"
119 use tk || disable+=" _tkinter"
120 use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
121 export PYTHON_DISABLE_MODULES="${disable}"
122
123 if ! use xml; then
124 ewarn "You have configured Python without XML support."
125 ewarn "This is NOT a recommended configuration as you"
126 ewarn "may face problems parsing any XML documents."
127 fi
128
129 if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
130 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
131 fi
132
133 if [[ "$(gcc-major-version)" -ge 4 ]]; then
134 append-flags -fwrapv
135 fi
136
137 filter-flags -malign-double
138
139 # https://bugs.gentoo.org/show_bug.cgi?id=50309
140 if is-flagq -O3; then
141 is-flagq -fstack-protector-all && replace-flags -O3 -O2
142 use hardened && replace-flags -O3 -O2
143 fi
144
145 # Export CXX so it ends up in /usr/lib/python3.X/config/Makefile.
146 tc-export CXX
147
148 # Set LDFLAGS so we link modules with -lpython3.2 correctly.
149 # Needed on FreeBSD unless Python 3.2 is already installed.
150 # Please query BSD team before removing this!
151 append-ldflags "-L."
152
Mike Frysingerce0b8c02019-07-11 00:40:18 -0400153 tc-export CC
154
Chad Versace9c71f3c2018-10-24 16:49:31 -0700155 local dbmliborder
156 if use gdbm; then
157 dbmliborder+="${dbmliborder:+:}gdbm"
158 fi
159
160 local myeconfargs=(
161 --with-fpectl
162 --enable-shared
163 $(use_enable ipv6)
164 $(use_with threads)
165 --infodir='${prefix}/share/info'
166 --mandir='${prefix}/share/man'
167 --with-computed-gotos
168 --with-dbmliborder="${dbmliborder}"
169 --with-libc=
170 --enable-loadable-sqlite-extensions
171 --without-ensurepip
172 --with-system-expat
173 --with-system-ffi
174 )
175
176 OPT="" econf "${myeconfargs[@]}"
177
178 if use threads && grep -q "#define POSIX_SEMAPHORES_NOT_ENABLED 1" pyconfig.h; then
179 eerror "configure has detected that the sem_open function is broken."
180 eerror "Please ensure that /dev/shm is mounted as a tmpfs with mode 1777."
181 die "Broken sem_open function (bug 496328)"
182 fi
183}
184
185src_compile() {
186 # Ensure sed works as expected
187 # https://bugs.gentoo.org/594768
188 local -x LC_ALL=C
189
190 emake CPPFLAGS= CFLAGS= LDFLAGS=
191
192 # Work around bug 329499. See also bug 413751 and 457194.
193 if has_version dev-libs/libffi[pax_kernel]; then
194 pax-mark E python
195 else
196 pax-mark m python
197 fi
198}
199
200src_test() {
201 # Tests will not work when cross compiling.
202 if tc-is-cross-compiler; then
203 elog "Disabling tests due to crosscompiling."
204 return
205 fi
206
207 # Skip failing tests.
208 local skipped_tests="gdb"
209
210 for test in ${skipped_tests}; do
211 mv "${S}"/Lib/test/test_${test}.py "${T}"
212 done
213
Mike Frysinger432f2892021-02-19 15:22:02 -0500214 # bug 660358
215 local -x COLUMNS=80
216
Chad Versace9c71f3c2018-10-24 16:49:31 -0700217 local -x PYTHONDONTWRITEBYTECODE=
218
219 emake test EXTRATESTOPTS="-u-network" CPPFLAGS= CFLAGS= LDFLAGS= < /dev/tty
220 local result=$?
221
222 for test in ${skipped_tests}; do
223 mv "${T}/test_${test}.py" "${S}"/Lib/test
224 done
225
226 elog "The following tests have been skipped:"
227 for test in ${skipped_tests}; do
228 elog "test_${test}.py"
229 done
230
231 elog "If you would like to run them, you may:"
232 elog "cd '${EPREFIX}/usr/$(get_libdir)/python${PYVER}/test'"
233 elog "and run the tests separately."
234
235 if [[ ${result} -ne 0 ]]; then
236 die "emake test failed"
237 fi
238}
239
240src_install() {
241 local libdir=${ED}/usr/$(get_libdir)/python${PYVER}
242
243 emake DESTDIR="${D}" altinstall
244
245 sed \
246 -e "s/\(CONFIGURE_LDFLAGS=\).*/\1/" \
247 -e "s/\(PY_LDFLAGS=\).*/\1/" \
248 -i "${libdir}/config-${PYVER}"*/Makefile || die "sed failed"
249
250 # Fix collisions between different slots of Python.
251 rm -f "${ED}usr/$(get_libdir)/libpython3.so"
252
253 # Cheap hack to get version with ABIFLAGS
254 local abiver=$(cd "${ED}usr/include"; echo python*)
255 if [[ ${abiver} != python${PYVER} ]]; then
256 # Replace python3.X with a symlink to python3.Xm
257 rm "${ED}usr/bin/python${PYVER}" || die
258 dosym "${abiver}" "/usr/bin/python${PYVER}"
259 # Create python3.X-config symlink
260 dosym "${abiver}-config" "/usr/bin/python${PYVER}-config"
261 # Create python-3.5m.pc symlink
262 dosym "python-${PYVER}.pc" "/usr/$(get_libdir)/pkgconfig/${abiver/${PYVER}/-${PYVER}}.pc"
263 fi
264
265 # python seems to get rebuilt in src_install (bug 569908)
266 # Work around it for now.
267 if has_version dev-libs/libffi[pax_kernel]; then
268 pax-mark E "${ED}usr/bin/${abiver}"
269 else
270 pax-mark m "${ED}usr/bin/${abiver}"
271 fi
272
273 use sqlite || rm -r "${libdir}/"{sqlite3,test/test_sqlite*} || die
274 use tk || rm -r "${ED}usr/bin/idle${PYVER}" "${libdir}/"{idlelib,tkinter,test/test_tk*} || die
275
276 use threads || rm -r "${libdir}/multiprocessing" || die
277 use wininst || rm "${libdir}/distutils/command/"wininst-*.exe || die
278
279 dodoc "${S}"/Misc/{ACKS,HISTORY,NEWS}
280
281 if use examples; then
282 insinto /usr/share/doc/${PF}/examples
283 find "${S}"/Tools -name __pycache__ -print0 | xargs -0 rm -fr
284 doins -r "${S}"/Tools
285 fi
286 insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
287 local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
288 emake --no-print-directory -s -f - 2>/dev/null)
289 newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
290
291 newconfd "${FILESDIR}/pydoc.conf" pydoc-${PYVER}
292 newinitd "${FILESDIR}/pydoc.init" pydoc-${PYVER}
293 sed \
294 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${PYVER/./_}_PORT:" \
295 -e "s:@PYDOC@:pydoc${PYVER}:" \
296 -i "${ED}etc/conf.d/pydoc-${PYVER}" "${ED}etc/init.d/pydoc-${PYVER}" || die "sed failed"
297
298 # for python-exec
299 local vars=( EPYTHON PYTHON_SITEDIR PYTHON_SCRIPTDIR )
300
301 # if not using a cross-compiler, use the fresh binary
302 if ! tc-is-cross-compiler; then
303 local -x PYTHON=./python
304 local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}${PWD}
305 else
306 vars=( PYTHON "${vars[@]}" )
307 fi
308
309 python_export "python${PYVER}" "${vars[@]}"
310 echo "EPYTHON='${EPYTHON}'" > epython.py || die
311 python_domodule epython.py
312
313 # python-exec wrapping support
314 local pymajor=${PYVER%.*}
315 mkdir -p "${D}${PYTHON_SCRIPTDIR}" || die
316 # python and pythonX
317 ln -s "../../../bin/${abiver}" \
318 "${D}${PYTHON_SCRIPTDIR}/python${pymajor}" || die
319 ln -s "python${pymajor}" \
320 "${D}${PYTHON_SCRIPTDIR}/python" || die
321 # python-config and pythonX-config
322 # note: we need to create a wrapper rather than symlinking it due
323 # to some random dirname(argv[0]) magic performed by python-config
324 cat > "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" <<-EOF || die
325 #!/bin/sh
326 exec "${abiver}-config" "\${@}"
327 EOF
328 chmod +x "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" || die
329 ln -s "python${pymajor}-config" \
330 "${D}${PYTHON_SCRIPTDIR}/python-config" || die
331 # 2to3, pydoc, pyvenv
332 ln -s "../../../bin/2to3-${PYVER}" \
333 "${D}${PYTHON_SCRIPTDIR}/2to3" || die
334 ln -s "../../../bin/pydoc${PYVER}" \
335 "${D}${PYTHON_SCRIPTDIR}/pydoc" || die
336 ln -s "../../../bin/pyvenv-${PYVER}" \
337 "${D}${PYTHON_SCRIPTDIR}/pyvenv" || die
338 # idle
339 if use tk; then
340 ln -s "../../../bin/idle${PYVER}" \
341 "${D}${PYTHON_SCRIPTDIR}/idle" || die
342 fi
Mike Frysinger12f1f692021-02-13 18:32:43 -0500343
344 # Delete unittests as they are a waste of space and are unused.
345 rm -rf "${libdir}/test" "${libdir}"/{ctypes,email,sqlite3,unittest}/test || die
Chad Versace9c71f3c2018-10-24 16:49:31 -0700346}
347
348pkg_preinst() {
349 if has_version "<${CATEGORY}/${PN}-${PYVER}" && ! has_version ">=${CATEGORY}/${PN}-${PYVER}_alpha"; then
350 python_updater_warning="1"
351 fi
352}
353
354eselect_python_update() {
355 if [[ -z "$(eselect python show)" || ! -f "${EROOT}usr/bin/$(eselect python show)" ]]; then
356 eselect python update
357 fi
358
359 if [[ -z "$(eselect python show --python${PV%%.*})" || ! -f "${EROOT}usr/bin/$(eselect python show --python${PV%%.*})" ]]; then
360 eselect python update --python${PV%%.*}
361 fi
362}
363
364pkg_postinst() {
365 eselect_python_update
366
367 if [[ "${python_updater_warning}" == "1" ]]; then
368 ewarn "You have just upgraded from an older version of Python."
369 ewarn
370 ewarn "Please adjust PYTHON_TARGETS (if so desired), and run emerge with the --newuse or --changed-use option to rebuild packages installing python modules."
371 fi
372}
373
374pkg_postrm() {
375 eselect_python_update
376}