dev-lang/python: amd64 stable wrt bug #585946
[gentoo.git] / dev-lang / python / python-3.4.5.ebuild
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI="5"
6 WANT_LIBTOOL="none"
7
8 inherit autotools eutils flag-o-matic multilib pax-utils python-utils-r1 toolchain-funcs multiprocessing
9
10 MY_P="Python-${PV/_/}"
11 PATCHSET_VERSION="3.4.5-0"
12
13 DESCRIPTION="An interpreted, interactive, object-oriented programming language"
14 HOMEPAGE="http://www.python.org/"
15 SRC_URI="http://www.python.org/ftp/python/${PV%_rc*}/${MY_P}.tar.xz
16         https://dev.gentoo.org/~floppym/python/python-gentoo-patches-${PATCHSET_VERSION}.tar.xz"
17
18 LICENSE="PSF-2"
19 SLOT="3.4/3.4m"
20 KEYWORDS="~alpha amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~amd64-fbsd ~sparc-fbsd ~x86-fbsd"
21 IUSE="build elibc_uclibc examples gdbm hardened ipv6 libressl +ncurses +readline sqlite +ssl +threads tk wininst +xml"
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
28 RDEPEND="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? (
35                 >=sys-libs/ncurses-5.2:0=
36                 readline? ( >=sys-libs/readline-4.1:0= )
37         )
38         sqlite? ( >=dev-db/sqlite-3.3.8:3= )
39         ssl? (
40                 !libressl? ( dev-libs/openssl:0= )
41                 libressl? ( dev-libs/libressl:= )
42         )
43         tk? (
44                 >=dev-lang/tcl-8.0:0=
45                 >=dev-lang/tk-8.0:0=
46                 dev-tcltk/blt:0=
47                 dev-tcltk/tix
48         )
49         xml? ( >=dev-libs/expat-2.1:0= )
50         !!<sys-apps/sandbox-2.6-r1"
51 DEPEND="${RDEPEND}
52         virtual/pkgconfig
53         >=sys-devel/autoconf-2.65
54         !sys-devel/gcc[libffi(-)]"
55 RDEPEND+=" !build? ( app-misc/mime-types )"
56 PDEPEND=">=app-eselect/eselect-python-20140125-r1"
57
58 S="${WORKDIR}/${MY_P}"
59
60 PYVER=${SLOT%/*}
61
62 src_prepare() {
63         # Ensure that internal copies of expat, libffi and zlib are not used.
64         rm -fr Modules/expat
65         rm -fr Modules/_ctypes/libffi*
66         rm -fr Modules/zlib
67
68         if tc-is-cross-compiler; then
69                 # Invokes BUILDPYTHON, which is built for the host arch
70                 local EPATCH_EXCLUDE="*_regenerate_platform-specific_modules.patch"
71         fi
72
73         EPATCH_SUFFIX="patch" epatch "${WORKDIR}/patches"
74         epatch "${FILESDIR}/${PN}-3.4.3-ncurses-pkg-config.patch"
75         epatch "${FILESDIR}/${PN}-3.4.5-cross.patch"
76
77         epatch_user
78
79         sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
80                 configure.ac \
81                 Lib/distutils/command/install.py \
82                 Lib/distutils/sysconfig.py \
83                 Lib/site.py \
84                 Lib/sysconfig.py \
85                 Lib/test/test_site.py \
86                 Makefile.pre.in \
87                 Modules/Setup.dist \
88                 Modules/getpath.c \
89                 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
90
91         eautoreconf
92 }
93
94 src_configure() {
95         local disable
96         use gdbm     || disable+=" gdbm"
97         use ncurses  || disable+=" _curses _curses_panel"
98         use readline || disable+=" readline"
99         use sqlite   || disable+=" _sqlite3"
100         use ssl      || export PYTHON_DISABLE_SSL="1"
101         use tk       || disable+=" _tkinter"
102         use xml      || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
103         export PYTHON_DISABLE_MODULES="${disable}"
104
105         if ! use xml; then
106                 ewarn "You have configured Python without XML support."
107                 ewarn "This is NOT a recommended configuration as you"
108                 ewarn "may face problems parsing any XML documents."
109         fi
110
111         if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
112                 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
113         fi
114
115         if [[ "$(gcc-major-version)" -ge 4 ]]; then
116                 append-flags -fwrapv
117         fi
118
119         filter-flags -malign-double
120
121         # https://bugs.gentoo.org/show_bug.cgi?id=50309
122         if is-flagq -O3; then
123                 is-flagq -fstack-protector-all && replace-flags -O3 -O2
124                 use hardened && replace-flags -O3 -O2
125         fi
126
127         # Export CXX so it ends up in /usr/lib/python3.X/config/Makefile.
128         tc-export CXX
129
130         # The configure script fails to use pkg-config correctly.
131         # http://bugs.python.org/issue15506
132         export ac_cv_path_PKG_CONFIG=$(tc-getPKG_CONFIG)
133
134         # Set LDFLAGS so we link modules with -lpython3.2 correctly.
135         # Needed on FreeBSD unless Python 3.2 is already installed.
136         # Please query BSD team before removing this!
137         append-ldflags "-L."
138
139         local dbmliborder
140         if use gdbm; then
141                 dbmliborder+="${dbmliborder:+:}gdbm"
142         fi
143
144         BUILD_DIR="${WORKDIR}/${CHOST}"
145         mkdir -p "${BUILD_DIR}" || die
146         cd "${BUILD_DIR}" || die
147
148         ECONF_SOURCE="${S}" OPT="" \
149         econf \
150                 --with-fpectl \
151                 --enable-shared \
152                 $(use_enable ipv6) \
153                 $(use_with threads) \
154                 --infodir='${prefix}/share/info' \
155                 --mandir='${prefix}/share/man' \
156                 --with-computed-gotos \
157                 --with-dbmliborder="${dbmliborder}" \
158                 --with-libc="" \
159                 --enable-loadable-sqlite-extensions \
160                 --with-system-expat \
161                 --with-system-ffi \
162                 --without-ensurepip
163
164         if use threads && grep -q "#define POSIX_SEMAPHORES_NOT_ENABLED 1" pyconfig.h; then
165                 eerror "configure has detected that the sem_open function is broken."
166                 eerror "Please ensure that /dev/shm is mounted as a tmpfs with mode 1777."
167                 die "Broken sem_open function (bug 496328)"
168         fi
169 }
170
171 src_compile() {
172         # Ensure sed works as expected
173         # https://bugs.gentoo.org/594768
174         local -x LC_ALL=C
175
176         # Avoid invoking pgen for cross-compiles.
177         touch Include/graminit.h Python/graminit.c || die
178
179         cd "${BUILD_DIR}" || die
180
181         emake CPPFLAGS= CFLAGS= LDFLAGS=
182
183         # Work around bug 329499. See also bug 413751 and 457194.
184         if has_version dev-libs/libffi[pax_kernel]; then
185                 pax-mark E python
186         else
187                 pax-mark m python
188         fi
189 }
190
191 src_test() {
192         # Tests will not work when cross compiling.
193         if tc-is-cross-compiler; then
194                 elog "Disabling tests due to crosscompiling."
195                 return
196         fi
197
198         cd "${BUILD_DIR}" || die
199
200         # Skip failing tests.
201         local skipped_tests="gdb"
202
203         for test in ${skipped_tests}; do
204                 mv "${S}"/Lib/test/test_${test}.py "${T}"
205         done
206
207         local -x PYTHONDONTWRITEBYTECODE=
208         emake test EXTRATESTOPTS="-u-network" CPPFLAGS= CFLAGS= LDFLAGS= < /dev/tty
209         local result=$?
210
211         for test in ${skipped_tests}; do
212                 mv "${T}/test_${test}.py" "${S}"/Lib/test
213         done
214
215         elog "The following tests have been skipped:"
216         for test in ${skipped_tests}; do
217                 elog "test_${test}.py"
218         done
219
220         elog "If you would like to run them, you may:"
221         elog "cd '${EPREFIX}/usr/$(get_libdir)/python${PYVER}/test'"
222         elog "and run the tests separately."
223
224         if [[ ${result} -ne 0 ]]; then
225                 die "emake test failed"
226         fi
227 }
228
229 src_install() {
230         local libdir=${ED}/usr/$(get_libdir)/python${PYVER}
231
232         cd "${BUILD_DIR}" || die
233
234         emake DESTDIR="${D}" altinstall
235
236         sed \
237                 -e "s/\(CONFIGURE_LDFLAGS=\).*/\1/" \
238                 -e "s/\(PY_LDFLAGS=\).*/\1/" \
239                 -i "${libdir}/config-${PYVER}"*/Makefile || die "sed failed"
240
241         # Fix collisions between different slots of Python.
242         rm -f "${ED}usr/$(get_libdir)/libpython3.so"
243
244         # Cheap hack to get version with ABIFLAGS
245         local abiver=$(cd "${ED}usr/include"; echo python*)
246         if [[ ${abiver} != python${PYVER} ]]; then
247                 # Replace python3.X with a symlink to python3.Xm
248                 rm "${ED}usr/bin/python${PYVER}" || die
249                 dosym "${abiver}" "/usr/bin/python${PYVER}"
250                 # Create python3.X-config symlink
251                 dosym "${abiver}-config" "/usr/bin/python${PYVER}-config"
252                 # Create python-3.5m.pc symlink
253                 dosym "python-${PYVER}.pc" "/usr/$(get_libdir)/pkgconfig/${abiver/${PYVER}/-${PYVER}}.pc"
254         fi
255
256         use elibc_uclibc && rm -fr "${libdir}/test"
257         use sqlite || rm -fr "${libdir}/"{sqlite3,test/test_sqlite*}
258         use tk || rm -fr "${ED}usr/bin/idle${PYVER}" "${libdir}/"{idlelib,tkinter,test/test_tk*}
259
260         use threads || rm -fr "${libdir}/multiprocessing"
261         use wininst || rm -f "${libdir}/distutils/command/"wininst-*.exe
262
263         dodoc "${S}"/Misc/{ACKS,HISTORY,NEWS}
264
265         if use examples; then
266                 insinto /usr/share/doc/${PF}/examples
267                 find "${S}"/Tools -name __pycache__ -print0 | xargs -0 rm -fr
268                 doins -r "${S}"/Tools
269         fi
270         insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
271         local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
272                 emake --no-print-directory -s -f - 2>/dev/null)
273         newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
274
275         newconfd "${FILESDIR}/pydoc.conf" pydoc-${PYVER}
276         newinitd "${FILESDIR}/pydoc.init" pydoc-${PYVER}
277         sed \
278                 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${PYVER/./_}_PORT:" \
279                 -e "s:@PYDOC@:pydoc${PYVER}:" \
280                 -i "${ED}etc/conf.d/pydoc-${PYVER}" "${ED}etc/init.d/pydoc-${PYVER}" || die "sed failed"
281
282         # for python-exec
283         local vars=( EPYTHON PYTHON_SITEDIR PYTHON_SCRIPTDIR )
284
285         # if not using a cross-compiler, use the fresh binary
286         if ! tc-is-cross-compiler; then
287                 local -x PYTHON=./python
288                 local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}.
289         else
290                 vars=( PYTHON "${vars[@]}" )
291         fi
292
293         python_export "python${PYVER}" "${vars[@]}"
294         echo "EPYTHON='${EPYTHON}'" > epython.py || die
295         python_domodule epython.py
296
297         # python-exec wrapping support
298         local pymajor=${PYVER%.*}
299         mkdir -p "${D}${PYTHON_SCRIPTDIR}" || die
300         # python and pythonX
301         ln -s "../../../bin/${abiver}" \
302                 "${D}${PYTHON_SCRIPTDIR}/python${pymajor}" || die
303         ln -s "python${pymajor}" \
304                 "${D}${PYTHON_SCRIPTDIR}/python" || die
305         # python-config and pythonX-config
306         # note: we need to create a wrapper rather than symlinking it due
307         # to some random dirname(argv[0]) magic performed by python-config
308         cat > "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" <<-EOF || die
309                 #!/bin/sh
310                 exec "${abiver}-config" "\${@}"
311         EOF
312         chmod +x "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" || die
313         ln -s "python${pymajor}-config" \
314                 "${D}${PYTHON_SCRIPTDIR}/python-config" || die
315         # 2to3, pydoc, pyvenv
316         ln -s "../../../bin/2to3-${PYVER}" \
317                 "${D}${PYTHON_SCRIPTDIR}/2to3" || die
318         ln -s "../../../bin/pydoc${PYVER}" \
319                 "${D}${PYTHON_SCRIPTDIR}/pydoc" || die
320         ln -s "../../../bin/pyvenv-${PYVER}" \
321                 "${D}${PYTHON_SCRIPTDIR}/pyvenv" || die
322         # idle
323         if use tk; then
324                 ln -s "../../../bin/idle${PYVER}" \
325                         "${D}${PYTHON_SCRIPTDIR}/idle" || die
326         fi
327 }
328
329 pkg_preinst() {
330         if has_version "<${CATEGORY}/${PN}-${PYVER}" && ! has_version ">=${CATEGORY}/${PN}-${PYVER}_alpha"; then
331                 python_updater_warning="1"
332         fi
333 }
334
335 eselect_python_update() {
336         if [[ -z "$(eselect python show)" || ! -f "${EROOT}usr/bin/$(eselect python show)" ]]; then
337                 eselect python update
338         fi
339
340         if [[ -z "$(eselect python show --python${PV%%.*})" || ! -f "${EROOT}usr/bin/$(eselect python show --python${PV%%.*})" ]]; then
341                 eselect python update --python${PV%%.*}
342         fi
343 }
344
345 pkg_postinst() {
346         eselect_python_update
347
348         if [[ "${python_updater_warning}" == "1" ]]; then
349                 ewarn "You have just upgraded from an older version of Python."
350                 ewarn
351                 ewarn "Please adjust PYTHON_TARGETS (if so desired), and run emerge with the --newuse or --changed-use option to rebuild packages installing python modules."
352         fi
353 }
354
355 pkg_postrm() {
356         eselect_python_update
357 }