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