blob: 74059600b9a206c6d8dad13e1c012ed0d4aea5d3 [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 Frysinger0e245162021-02-19 15:39:45 -05004EAPI="7"
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 Frysinger0e245162021-02-19 15:39:45 -050010PYVER=$(ver_cut 1-2)
11PATCHSET="python-gentoo-patches-3.6.10"
Chad Versace9c71f3c2018-10-24 16:49:31 -070012
13DESCRIPTION="An interpreted, interactive, object-oriented programming language"
14HOMEPAGE="https://www.python.org/"
15SRC_URI="https://www.python.org/ftp/python/${PV}/${MY_P}.tar.xz
Mike Frysinger0e245162021-02-19 15:39:45 -050016 https://dev.gentoo.org/~mgorny/dist/python/${PATCHSET}.tar.xz"
17S="${WORKDIR}/${MY_P}"
Chad Versace9c71f3c2018-10-24 16:49:31 -070018
19LICENSE="PSF-2"
Mike Frysinger0e245162021-02-19 15:39:45 -050020SLOT="${PYVER}/${PYVER}m"
Daniel Campello7ded4e32019-02-06 11:03:46 -070021KEYWORDS="*"
Mike Frysinger432f2892021-02-19 15:22:02 -050022IUSE="bluetooth build examples gdbm hardened ipv6 libressl +ncurses +readline sqlite +ssl test +threads tk wininst +xml"
Chad Versace9c71f3c2018-10-24 16:49:31 -070023RESTRICT="!test? ( test )"
24
25# Do not add a dependency on dev-lang/python to this ebuild.
26# If you need to apply a patch which requires python for bootstrapping, please
27# run the bootstrap code on your dev box and include the results in the
28# patchset. See bug 447752.
29
Mike Frysinger0e245162021-02-19 15:39:45 -050030RDEPEND="app-arch/bzip2:=
31 app-arch/xz-utils:=
Mike Frysinger432f2892021-02-19 15:22:02 -050032 dev-libs/libffi:=
Mike Frysinger0e245162021-02-19 15:39:45 -050033 >=sys-libs/zlib-1.1.3:=
34 virtual/libcrypt:=
Chad Versace9c71f3c2018-10-24 16:49:31 -070035 virtual/libintl
Mike Frysinger0e245162021-02-19 15:39:45 -050036 gdbm? ( sys-libs/gdbm:=[berkdb] )
37 ncurses? ( >=sys-libs/ncurses-5.2:= )
38 readline? ( >=sys-libs/readline-4.1:= )
Chad Versace9c71f3c2018-10-24 16:49:31 -070039 sqlite? ( >=dev-db/sqlite-3.3.8:3= )
40 ssl? (
Mike Frysinger0e245162021-02-19 15:39:45 -050041 !libressl? ( dev-libs/openssl:= )
42 libressl? ( dev-libs/libressl:= )
Chad Versace9c71f3c2018-10-24 16:49:31 -070043 )
44 tk? (
Mike Frysinger0e245162021-02-19 15:39:45 -050045 >=dev-lang/tcl-8.0:=
46 >=dev-lang/tk-8.0:=
47 dev-tcltk/blt:=
Chad Versace9c71f3c2018-10-24 16:49:31 -070048 dev-tcltk/tix
49 )
Mike Frysinger0e245162021-02-19 15:39:45 -050050 xml? ( >=dev-libs/expat-2.1:= )"
Mike Frysinger432f2892021-02-19 15:22:02 -050051# bluetooth requires headers from bluez
Chad Versace9c71f3c2018-10-24 16:49:31 -070052DEPEND="${RDEPEND}
Mike Frysinger432f2892021-02-19 15:22:02 -050053 bluetooth? ( net-wireless/bluez )
Chad Versace9c71f3c2018-10-24 16:49:31 -070054 test? ( app-arch/xz-utils[extra-filters(+)] )
55 virtual/pkgconfig
56 !sys-devel/gcc[libffi(-)]"
57RDEPEND+=" !build? ( app-misc/mime-types )"
58PDEPEND=">=app-eselect/eselect-python-20140125-r1"
59
Chad Versace9c71f3c2018-10-24 16:49:31 -070060src_prepare() {
61 # Ensure that internal copies of expat, libffi and zlib are not used.
Mike Frysinger0e245162021-02-19 15:39:45 -050062 rm -fr Modules/expat || die
63 rm -fr Modules/_ctypes/libffi* || die
64 rm -fr Modules/zlib || die
Chad Versace9c71f3c2018-10-24 16:49:31 -070065
Mike Frysinger95c720e2021-02-19 15:09:00 -050066 local PATCHES=(
Mike Frysinger0e245162021-02-19 15:39:45 -050067 "${WORKDIR}/${PATCHSET}"
68 "${FILESDIR}/test.support.unlink-ignore-PermissionError.patch"
Mike Frysinger95c720e2021-02-19 15:09:00 -050069 )
Chad Versace9c71f3c2018-10-24 16:49:31 -070070
Mike Frysinger95c720e2021-02-19 15:09:00 -050071 default
Chad Versace9c71f3c2018-10-24 16:49:31 -070072
73 # START: Chromium OS
Mike Frysingerce0b8c02019-07-11 00:40:18 -040074 if tc-is-cross-compiler ; then
Mike Frysinger0e245162021-02-19 15:39:45 -050075 eapply "${FILESDIR}/python-3.6.5-cross-h2py.patch"
76 eapply "${FILESDIR}/python-3.6.5-cross-hack-compiler.patch"
Mike Frysingerce0b8c02019-07-11 00:40:18 -040077 fi
Mike Frysinger0e245162021-02-19 15:39:45 -050078 eapply "${FILESDIR}/python-3.6.5-cross-python-config.patch"
79 eapply "${FILESDIR}/python-3.6.5-cross-setup-sysroot.patch"
80 eapply "${FILESDIR}/python-3.6.5-cross-distutils.patch"
81 eapply "${FILESDIR}/python-3.6.5-cross-sysconfig.patch"
82 eapply "${FILESDIR}/python-3.6.5-ldshared.patch"
83 eapply "${FILESDIR}/python-3.6.5-system-libffi.patch"
84 eapply "${FILESDIR}/python-3.6.5-sigint-handler.patch"
Chad Versace9c71f3c2018-10-24 16:49:31 -070085
86 # Undo the @libdir@ change for portage's pym folder as it is always
87 # installed into /usr/lib/ and not the abi libdir.
88 sed -i \
89 -e '/portage.*pym/s:@@GENTOO_LIBDIR@@:lib:g' \
90 Lib/site.py || die
91
92 sed -i -e "s:sys.exec_prefix]:sys.exec_prefix, '/usr/local']:g" \
93 Lib/site.py || die "sed failed to add /usr/local to prefixes"
94 # END: Chromium OS
95
96 sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
97 Lib/distutils/command/install.py \
98 Lib/distutils/sysconfig.py \
99 Lib/site.py \
100 Lib/sysconfig.py \
101 Lib/test/test_site.py \
102 Makefile.pre.in \
103 Modules/Setup.dist \
104 Modules/getpath.c \
105 configure.ac \
106 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
107
108 eautoreconf
109}
110
111src_configure() {
112 local disable
Mike Frysinger432f2892021-02-19 15:22:02 -0500113 # disable automagic bluetooth headers detection
114 use bluetooth || export ac_cv_header_bluetooth_bluetooth_h=no
Mike Frysinger0e245162021-02-19 15:39:45 -0500115 use gdbm || disable+=" gdbm"
116 use ncurses || disable+=" _curses _curses_panel"
117 use readline || disable+=" readline"
118 use sqlite || disable+=" _sqlite3"
119 use ssl || export PYTHON_DISABLE_SSL="1"
120 use tk || disable+=" _tkinter"
121 use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
Chad Versace9c71f3c2018-10-24 16:49:31 -0700122 export PYTHON_DISABLE_MODULES="${disable}"
123
124 if ! use xml; then
125 ewarn "You have configured Python without XML support."
126 ewarn "This is NOT a recommended configuration as you"
127 ewarn "may face problems parsing any XML documents."
128 fi
129
130 if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
131 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
132 fi
133
134 if [[ "$(gcc-major-version)" -ge 4 ]]; then
135 append-flags -fwrapv
136 fi
137
138 filter-flags -malign-double
139
140 # https://bugs.gentoo.org/show_bug.cgi?id=50309
141 if is-flagq -O3; then
142 is-flagq -fstack-protector-all && replace-flags -O3 -O2
143 use hardened && replace-flags -O3 -O2
144 fi
145
146 # Export CXX so it ends up in /usr/lib/python3.X/config/Makefile.
147 tc-export CXX
148
149 # Set LDFLAGS so we link modules with -lpython3.2 correctly.
150 # Needed on FreeBSD unless Python 3.2 is already installed.
151 # Please query BSD team before removing this!
152 append-ldflags "-L."
153
Mike Frysingerce0b8c02019-07-11 00:40:18 -0400154 tc-export CC
155
Chad Versace9c71f3c2018-10-24 16:49:31 -0700156 local dbmliborder
157 if use gdbm; then
158 dbmliborder+="${dbmliborder:+:}gdbm"
159 fi
160
161 local myeconfargs=(
Mike Frysinger0e245162021-02-19 15:39:45 -0500162 # glibc-2.30 removes it; since we can't cleanly force-rebuild
163 # Python on glibc upgrade, remove it proactively to give
164 # a chance for users rebuilding python before glibc
165 ac_cv_header_stropts_h=no
166
Chad Versace9c71f3c2018-10-24 16:49:31 -0700167 --with-fpectl
168 --enable-shared
169 $(use_enable ipv6)
170 $(use_with threads)
171 --infodir='${prefix}/share/info'
172 --mandir='${prefix}/share/man'
173 --with-computed-gotos
174 --with-dbmliborder="${dbmliborder}"
175 --with-libc=
176 --enable-loadable-sqlite-extensions
177 --without-ensurepip
178 --with-system-expat
179 --with-system-ffi
180 )
181
182 OPT="" econf "${myeconfargs[@]}"
183
184 if use threads && grep -q "#define POSIX_SEMAPHORES_NOT_ENABLED 1" pyconfig.h; then
185 eerror "configure has detected that the sem_open function is broken."
186 eerror "Please ensure that /dev/shm is mounted as a tmpfs with mode 1777."
187 die "Broken sem_open function (bug 496328)"
188 fi
189}
190
191src_compile() {
192 # Ensure sed works as expected
193 # https://bugs.gentoo.org/594768
194 local -x LC_ALL=C
195
196 emake CPPFLAGS= CFLAGS= LDFLAGS=
197
198 # Work around bug 329499. See also bug 413751 and 457194.
199 if has_version dev-libs/libffi[pax_kernel]; then
200 pax-mark E python
201 else
202 pax-mark m python
203 fi
204}
205
206src_test() {
207 # Tests will not work when cross compiling.
208 if tc-is-cross-compiler; then
209 elog "Disabling tests due to crosscompiling."
210 return
211 fi
212
213 # Skip failing tests.
214 local skipped_tests="gdb"
215
216 for test in ${skipped_tests}; do
217 mv "${S}"/Lib/test/test_${test}.py "${T}"
218 done
219
Mike Frysinger432f2892021-02-19 15:22:02 -0500220 # bug 660358
221 local -x COLUMNS=80
222
Chad Versace9c71f3c2018-10-24 16:49:31 -0700223 local -x PYTHONDONTWRITEBYTECODE=
224
225 emake test EXTRATESTOPTS="-u-network" CPPFLAGS= CFLAGS= LDFLAGS= < /dev/tty
226 local result=$?
227
228 for test in ${skipped_tests}; do
229 mv "${T}/test_${test}.py" "${S}"/Lib/test
230 done
231
232 elog "The following tests have been skipped:"
233 for test in ${skipped_tests}; do
234 elog "test_${test}.py"
235 done
236
237 elog "If you would like to run them, you may:"
238 elog "cd '${EPREFIX}/usr/$(get_libdir)/python${PYVER}/test'"
239 elog "and run the tests separately."
240
241 if [[ ${result} -ne 0 ]]; then
242 die "emake test failed"
243 fi
244}
245
246src_install() {
247 local libdir=${ED}/usr/$(get_libdir)/python${PYVER}
248
249 emake DESTDIR="${D}" altinstall
250
Mike Frysinger0e245162021-02-19 15:39:45 -0500251 # Remove static library
252 rm "${ED}"/usr/$(get_libdir)/libpython*.a || die
253
Chad Versace9c71f3c2018-10-24 16:49:31 -0700254 sed \
255 -e "s/\(CONFIGURE_LDFLAGS=\).*/\1/" \
256 -e "s/\(PY_LDFLAGS=\).*/\1/" \
257 -i "${libdir}/config-${PYVER}"*/Makefile || die "sed failed"
258
259 # Fix collisions between different slots of Python.
Mike Frysinger0e245162021-02-19 15:39:45 -0500260 rm "${ED}/usr/$(get_libdir)/libpython3.so" || die
Chad Versace9c71f3c2018-10-24 16:49:31 -0700261
262 # Cheap hack to get version with ABIFLAGS
Mike Frysinger0e245162021-02-19 15:39:45 -0500263 local abiver=$(cd "${ED}/usr/include"; echo python*)
Chad Versace9c71f3c2018-10-24 16:49:31 -0700264 if [[ ${abiver} != python${PYVER} ]]; then
265 # Replace python3.X with a symlink to python3.Xm
Mike Frysinger0e245162021-02-19 15:39:45 -0500266 rm "${ED}/usr/bin/python${PYVER}" || die
Chad Versace9c71f3c2018-10-24 16:49:31 -0700267 dosym "${abiver}" "/usr/bin/python${PYVER}"
268 # Create python3.X-config symlink
269 dosym "${abiver}-config" "/usr/bin/python${PYVER}-config"
270 # Create python-3.5m.pc symlink
271 dosym "python-${PYVER}.pc" "/usr/$(get_libdir)/pkgconfig/${abiver/${PYVER}/-${PYVER}}.pc"
272 fi
273
274 # python seems to get rebuilt in src_install (bug 569908)
275 # Work around it for now.
276 if has_version dev-libs/libffi[pax_kernel]; then
Mike Frysinger0e245162021-02-19 15:39:45 -0500277 pax-mark E "${ED}/usr/bin/${abiver}"
Chad Versace9c71f3c2018-10-24 16:49:31 -0700278 else
Mike Frysinger0e245162021-02-19 15:39:45 -0500279 pax-mark m "${ED}/usr/bin/${abiver}"
Chad Versace9c71f3c2018-10-24 16:49:31 -0700280 fi
281
282 use sqlite || rm -r "${libdir}/"{sqlite3,test/test_sqlite*} || die
Mike Frysinger0e245162021-02-19 15:39:45 -0500283 use tk || rm -r "${ED}/usr/bin/idle${PYVER}" "${libdir}/"{idlelib,tkinter,test/test_tk*} || die
Chad Versace9c71f3c2018-10-24 16:49:31 -0700284
285 use threads || rm -r "${libdir}/multiprocessing" || die
286 use wininst || rm "${libdir}/distutils/command/"wininst-*.exe || die
287
Mike Frysinger0e245162021-02-19 15:39:45 -0500288 dodoc Misc/{ACKS,HISTORY,NEWS}
Chad Versace9c71f3c2018-10-24 16:49:31 -0700289
290 if use examples; then
Mike Frysinger0e245162021-02-19 15:39:45 -0500291 docinto examples
292 find Tools -name __pycache__ -exec rm -fr {} + || die
293 dodoc -r Tools
Chad Versace9c71f3c2018-10-24 16:49:31 -0700294 fi
295 insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
296 local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
297 emake --no-print-directory -s -f - 2>/dev/null)
298 newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
299
300 newconfd "${FILESDIR}/pydoc.conf" pydoc-${PYVER}
301 newinitd "${FILESDIR}/pydoc.init" pydoc-${PYVER}
302 sed \
303 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${PYVER/./_}_PORT:" \
304 -e "s:@PYDOC@:pydoc${PYVER}:" \
Mike Frysinger0e245162021-02-19 15:39:45 -0500305 -i "${ED}/etc/conf.d/pydoc-${PYVER}" \
306 "${ED}/etc/init.d/pydoc-${PYVER}" || die "sed failed"
Chad Versace9c71f3c2018-10-24 16:49:31 -0700307
308 # for python-exec
309 local vars=( EPYTHON PYTHON_SITEDIR PYTHON_SCRIPTDIR )
310
311 # if not using a cross-compiler, use the fresh binary
312 if ! tc-is-cross-compiler; then
313 local -x PYTHON=./python
314 local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}${PWD}
315 else
316 vars=( PYTHON "${vars[@]}" )
317 fi
318
319 python_export "python${PYVER}" "${vars[@]}"
320 echo "EPYTHON='${EPYTHON}'" > epython.py || die
321 python_domodule epython.py
322
323 # python-exec wrapping support
324 local pymajor=${PYVER%.*}
325 mkdir -p "${D}${PYTHON_SCRIPTDIR}" || die
326 # python and pythonX
327 ln -s "../../../bin/${abiver}" \
328 "${D}${PYTHON_SCRIPTDIR}/python${pymajor}" || die
Mike Frysinger0e245162021-02-19 15:39:45 -0500329 ln -s "python${pymajor}" "${D}${PYTHON_SCRIPTDIR}/python" || die
Chad Versace9c71f3c2018-10-24 16:49:31 -0700330 # python-config and pythonX-config
331 # note: we need to create a wrapper rather than symlinking it due
332 # to some random dirname(argv[0]) magic performed by python-config
333 cat > "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" <<-EOF || die
334 #!/bin/sh
335 exec "${abiver}-config" "\${@}"
336 EOF
337 chmod +x "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" || die
338 ln -s "python${pymajor}-config" \
339 "${D}${PYTHON_SCRIPTDIR}/python-config" || die
340 # 2to3, pydoc, pyvenv
341 ln -s "../../../bin/2to3-${PYVER}" \
342 "${D}${PYTHON_SCRIPTDIR}/2to3" || die
343 ln -s "../../../bin/pydoc${PYVER}" \
344 "${D}${PYTHON_SCRIPTDIR}/pydoc" || die
345 ln -s "../../../bin/pyvenv-${PYVER}" \
346 "${D}${PYTHON_SCRIPTDIR}/pyvenv" || die
347 # idle
348 if use tk; then
349 ln -s "../../../bin/idle${PYVER}" \
350 "${D}${PYTHON_SCRIPTDIR}/idle" || die
351 fi
Mike Frysinger12f1f692021-02-13 18:32:43 -0500352
353 # Delete unittests as they are a waste of space and are unused.
354 rm -rf "${libdir}/test" "${libdir}"/{ctypes,email,sqlite3,unittest}/test || die
Chad Versace9c71f3c2018-10-24 16:49:31 -0700355}
356
357pkg_preinst() {
358 if has_version "<${CATEGORY}/${PN}-${PYVER}" && ! has_version ">=${CATEGORY}/${PN}-${PYVER}_alpha"; then
359 python_updater_warning="1"
360 fi
361}
362
363eselect_python_update() {
Mike Frysinger0e245162021-02-19 15:39:45 -0500364 if [[ -z "$(eselect python show)" || \
365 ! -f "${EROOT}/usr/bin/$(eselect python show)" ]]; then
Chad Versace9c71f3c2018-10-24 16:49:31 -0700366 eselect python update
367 fi
368
Mike Frysinger0e245162021-02-19 15:39:45 -0500369 if [[ -z "$(eselect python show --python${PV%%.*})" || \
370 ! -f "${EROOT}/usr/bin/$(eselect python show --python${PV%%.*})" ]]
371 then
Chad Versace9c71f3c2018-10-24 16:49:31 -0700372 eselect python update --python${PV%%.*}
373 fi
374}
375
376pkg_postinst() {
377 eselect_python_update
378
379 if [[ "${python_updater_warning}" == "1" ]]; then
380 ewarn "You have just upgraded from an older version of Python."
381 ewarn
382 ewarn "Please adjust PYTHON_TARGETS (if so desired), and run emerge with the --newuse or --changed-use option to rebuild packages installing python modules."
383 fi
384}
385
386pkg_postrm() {
387 eselect_python_update
388}