blob: 6e5bdf3d6af2308dc4ba9848b82b07483bfea3d1 [file] [log] [blame]
Mike Frysinger95c720e2021-02-19 15:09:00 -05001# Copyright 1999-2019 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}"
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
Mike Frysinger95c720e2021-02-19 15:09:00 -050065 local PATCHES=(
66 "${WORKDIR}/patches"
67 "${FILESDIR}/${PN}-3.5-distutils-OO-build.patch"
68 "${FILESDIR}/3.6.5-disable-nis.patch"
69 "${FILESDIR}/python-3.6.5-libressl-compatibility.patch"
70 "${FILESDIR}/python-3.6.5-hash-unaligned.patch"
71 )
Chad Versace9c71f3c2018-10-24 16:49:31 -070072
Mike Frysinger95c720e2021-02-19 15:09:00 -050073 default
Chad Versace9c71f3c2018-10-24 16:49:31 -070074
75 # START: Chromium OS
Mike Frysingerce0b8c02019-07-11 00:40:18 -040076 if tc-is-cross-compiler ; then
77 epatch "${FILESDIR}/python-3.6.5-cross-h2py.patch"
78 epatch "${FILESDIR}/python-3.6.5-cross-hack-compiler.patch"
79 fi
80 epatch "${FILESDIR}/python-3.6.5-cross-python-config.patch"
81 epatch "${FILESDIR}/python-3.6.5-cross-setup-sysroot.patch"
82 epatch "${FILESDIR}/python-3.6.5-cross-distutils.patch"
Mike Frysinger935ee6f2019-09-06 14:38:15 -040083 epatch "${FILESDIR}/python-3.6.5-cross-sysconfig.patch"
Mike Frysingerce0b8c02019-07-11 00:40:18 -040084 epatch "${FILESDIR}/python-3.6.5-ldshared.patch"
85 epatch "${FILESDIR}/python-3.6.5-system-libffi.patch"
Chris McDonald5ca5bf22019-08-07 14:53:57 -060086 epatch "${FILESDIR}/python-3.6.5-sigint-handler.patch"
Chad Versace9c71f3c2018-10-24 16:49:31 -070087
88 # Undo the @libdir@ change for portage's pym folder as it is always
89 # installed into /usr/lib/ and not the abi libdir.
90 sed -i \
91 -e '/portage.*pym/s:@@GENTOO_LIBDIR@@:lib:g' \
92 Lib/site.py || die
93
94 sed -i -e "s:sys.exec_prefix]:sys.exec_prefix, '/usr/local']:g" \
95 Lib/site.py || die "sed failed to add /usr/local to prefixes"
96 # END: Chromium OS
97
98 sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
99 Lib/distutils/command/install.py \
100 Lib/distutils/sysconfig.py \
101 Lib/site.py \
102 Lib/sysconfig.py \
103 Lib/test/test_site.py \
104 Makefile.pre.in \
105 Modules/Setup.dist \
106 Modules/getpath.c \
107 configure.ac \
108 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
109
110 eautoreconf
111}
112
113src_configure() {
114 local disable
115 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.
122 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=(
162 --with-fpectl
163 --enable-shared
164 $(use_enable ipv6)
165 $(use_with threads)
166 --infodir='${prefix}/share/info'
167 --mandir='${prefix}/share/man'
168 --with-computed-gotos
169 --with-dbmliborder="${dbmliborder}"
170 --with-libc=
171 --enable-loadable-sqlite-extensions
172 --without-ensurepip
173 --with-system-expat
174 --with-system-ffi
175 )
176
177 OPT="" econf "${myeconfargs[@]}"
178
179 if use threads && grep -q "#define POSIX_SEMAPHORES_NOT_ENABLED 1" pyconfig.h; then
180 eerror "configure has detected that the sem_open function is broken."
181 eerror "Please ensure that /dev/shm is mounted as a tmpfs with mode 1777."
182 die "Broken sem_open function (bug 496328)"
183 fi
184}
185
186src_compile() {
187 # Ensure sed works as expected
188 # https://bugs.gentoo.org/594768
189 local -x LC_ALL=C
190
191 emake CPPFLAGS= CFLAGS= LDFLAGS=
192
193 # Work around bug 329499. See also bug 413751 and 457194.
194 if has_version dev-libs/libffi[pax_kernel]; then
195 pax-mark E python
196 else
197 pax-mark m python
198 fi
199}
200
201src_test() {
202 # Tests will not work when cross compiling.
203 if tc-is-cross-compiler; then
204 elog "Disabling tests due to crosscompiling."
205 return
206 fi
207
208 # Skip failing tests.
209 local skipped_tests="gdb"
210
211 for test in ${skipped_tests}; do
212 mv "${S}"/Lib/test/test_${test}.py "${T}"
213 done
214
215 local -x PYTHONDONTWRITEBYTECODE=
216
217 emake test EXTRATESTOPTS="-u-network" CPPFLAGS= CFLAGS= LDFLAGS= < /dev/tty
218 local result=$?
219
220 for test in ${skipped_tests}; do
221 mv "${T}/test_${test}.py" "${S}"/Lib/test
222 done
223
224 elog "The following tests have been skipped:"
225 for test in ${skipped_tests}; do
226 elog "test_${test}.py"
227 done
228
229 elog "If you would like to run them, you may:"
230 elog "cd '${EPREFIX}/usr/$(get_libdir)/python${PYVER}/test'"
231 elog "and run the tests separately."
232
233 if [[ ${result} -ne 0 ]]; then
234 die "emake test failed"
235 fi
236}
237
238src_install() {
239 local libdir=${ED}/usr/$(get_libdir)/python${PYVER}
240
241 emake DESTDIR="${D}" altinstall
242
243 sed \
244 -e "s/\(CONFIGURE_LDFLAGS=\).*/\1/" \
245 -e "s/\(PY_LDFLAGS=\).*/\1/" \
246 -i "${libdir}/config-${PYVER}"*/Makefile || die "sed failed"
247
248 # Fix collisions between different slots of Python.
249 rm -f "${ED}usr/$(get_libdir)/libpython3.so"
250
251 # Cheap hack to get version with ABIFLAGS
252 local abiver=$(cd "${ED}usr/include"; echo python*)
253 if [[ ${abiver} != python${PYVER} ]]; then
254 # Replace python3.X with a symlink to python3.Xm
255 rm "${ED}usr/bin/python${PYVER}" || die
256 dosym "${abiver}" "/usr/bin/python${PYVER}"
257 # Create python3.X-config symlink
258 dosym "${abiver}-config" "/usr/bin/python${PYVER}-config"
259 # Create python-3.5m.pc symlink
260 dosym "python-${PYVER}.pc" "/usr/$(get_libdir)/pkgconfig/${abiver/${PYVER}/-${PYVER}}.pc"
261 fi
262
263 # python seems to get rebuilt in src_install (bug 569908)
264 # Work around it for now.
265 if has_version dev-libs/libffi[pax_kernel]; then
266 pax-mark E "${ED}usr/bin/${abiver}"
267 else
268 pax-mark m "${ED}usr/bin/${abiver}"
269 fi
270
271 use sqlite || rm -r "${libdir}/"{sqlite3,test/test_sqlite*} || die
272 use tk || rm -r "${ED}usr/bin/idle${PYVER}" "${libdir}/"{idlelib,tkinter,test/test_tk*} || die
273
274 use threads || rm -r "${libdir}/multiprocessing" || die
275 use wininst || rm "${libdir}/distutils/command/"wininst-*.exe || die
276
277 dodoc "${S}"/Misc/{ACKS,HISTORY,NEWS}
278
279 if use examples; then
280 insinto /usr/share/doc/${PF}/examples
281 find "${S}"/Tools -name __pycache__ -print0 | xargs -0 rm -fr
282 doins -r "${S}"/Tools
283 fi
284 insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
285 local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
286 emake --no-print-directory -s -f - 2>/dev/null)
287 newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
288
289 newconfd "${FILESDIR}/pydoc.conf" pydoc-${PYVER}
290 newinitd "${FILESDIR}/pydoc.init" pydoc-${PYVER}
291 sed \
292 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${PYVER/./_}_PORT:" \
293 -e "s:@PYDOC@:pydoc${PYVER}:" \
294 -i "${ED}etc/conf.d/pydoc-${PYVER}" "${ED}etc/init.d/pydoc-${PYVER}" || die "sed failed"
295
296 # for python-exec
297 local vars=( EPYTHON PYTHON_SITEDIR PYTHON_SCRIPTDIR )
298
299 # if not using a cross-compiler, use the fresh binary
300 if ! tc-is-cross-compiler; then
301 local -x PYTHON=./python
302 local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}${PWD}
303 else
304 vars=( PYTHON "${vars[@]}" )
305 fi
306
307 python_export "python${PYVER}" "${vars[@]}"
308 echo "EPYTHON='${EPYTHON}'" > epython.py || die
309 python_domodule epython.py
310
311 # python-exec wrapping support
312 local pymajor=${PYVER%.*}
313 mkdir -p "${D}${PYTHON_SCRIPTDIR}" || die
314 # python and pythonX
315 ln -s "../../../bin/${abiver}" \
316 "${D}${PYTHON_SCRIPTDIR}/python${pymajor}" || die
317 ln -s "python${pymajor}" \
318 "${D}${PYTHON_SCRIPTDIR}/python" || die
319 # python-config and pythonX-config
320 # note: we need to create a wrapper rather than symlinking it due
321 # to some random dirname(argv[0]) magic performed by python-config
322 cat > "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" <<-EOF || die
323 #!/bin/sh
324 exec "${abiver}-config" "\${@}"
325 EOF
326 chmod +x "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" || die
327 ln -s "python${pymajor}-config" \
328 "${D}${PYTHON_SCRIPTDIR}/python-config" || die
329 # 2to3, pydoc, pyvenv
330 ln -s "../../../bin/2to3-${PYVER}" \
331 "${D}${PYTHON_SCRIPTDIR}/2to3" || die
332 ln -s "../../../bin/pydoc${PYVER}" \
333 "${D}${PYTHON_SCRIPTDIR}/pydoc" || die
334 ln -s "../../../bin/pyvenv-${PYVER}" \
335 "${D}${PYTHON_SCRIPTDIR}/pyvenv" || die
336 # idle
337 if use tk; then
338 ln -s "../../../bin/idle${PYVER}" \
339 "${D}${PYTHON_SCRIPTDIR}/idle" || die
340 fi
Mike Frysinger12f1f692021-02-13 18:32:43 -0500341
342 # Delete unittests as they are a waste of space and are unused.
343 rm -rf "${libdir}/test" "${libdir}"/{ctypes,email,sqlite3,unittest}/test || die
Chad Versace9c71f3c2018-10-24 16:49:31 -0700344}
345
346pkg_preinst() {
347 if has_version "<${CATEGORY}/${PN}-${PYVER}" && ! has_version ">=${CATEGORY}/${PN}-${PYVER}_alpha"; then
348 python_updater_warning="1"
349 fi
350}
351
352eselect_python_update() {
353 if [[ -z "$(eselect python show)" || ! -f "${EROOT}usr/bin/$(eselect python show)" ]]; then
354 eselect python update
355 fi
356
357 if [[ -z "$(eselect python show --python${PV%%.*})" || ! -f "${EROOT}usr/bin/$(eselect python show --python${PV%%.*})" ]]; then
358 eselect python update --python${PV%%.*}
359 fi
360}
361
362pkg_postinst() {
363 eselect_python_update
364
365 if [[ "${python_updater_warning}" == "1" ]]; then
366 ewarn "You have just upgraded from an older version of Python."
367 ewarn
368 ewarn "Please adjust PYTHON_TARGETS (if so desired), and run emerge with the --newuse or --changed-use option to rebuild packages installing python modules."
369 fi
370}
371
372pkg_postrm() {
373 eselect_python_update
374}