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