blob: beec107e10997624125f14608f5d0f1f5b9636f1 [file] [log] [blame]
Mike Frysinger51f0d522015-11-21 00:11:17 +00001# Copyright 1999-2015 Gentoo Foundation
Mike Frysinger682d0652012-07-30 11:38:25 -04002# Distributed under the terms of the GNU General Public License v2
Mike Frysinger51f0d522015-11-21 00:11:17 +00003# $Header: /var/cvsroot/gentoo-x86/dev-lang/python/python-2.7.10.ebuild,v 1.2 2015/06/29 17:26:27 floppym Exp $
Mike Frysinger682d0652012-07-30 11:38:25 -04004
George Burgess IVb2459ff2019-02-05 13:04:40 -08005EAPI="5"
Mike Frysinger682d0652012-07-30 11:38:25 -04006WANT_LIBTOOL="none"
7
Mike Frysinger4cfb44a2013-03-18 22:37:33 -04008inherit autotools eutils flag-o-matic multilib pax-utils python-utils-r1 toolchain-funcs multiprocessing
Mike Frysinger682d0652012-07-30 11:38:25 -04009
10MY_P="Python-${PV}"
Mike Frysinger51f0d522015-11-21 00:11:17 +000011PATCHSET_VERSION="2.7.10-0"
Mike Frysinger682d0652012-07-30 11:38:25 -040012
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040013DESCRIPTION="An interpreted, interactive, object-oriented programming language"
Mike Frysinger682d0652012-07-30 11:38:25 -040014HOMEPAGE="http://www.python.org/"
George Burgess IVb2459ff2019-02-05 13:04:40 -080015
16# The version of Python our PGO profile was generated with. Using ${PV} makes
17# updates difficult, and we have tricks below to catch a mismatched profile
18# version.
19PROF_VERSION="2.7.10"
20
Mike Frysinger51f0d522015-11-21 00:11:17 +000021SRC_URI="http://www.python.org/ftp/python/${PV}/${MY_P}.tar.xz
Daniel Kurtz67551cf2019-05-21 13:45:52 -060022 https://dev.gentoo.org/~floppym/python/python-gentoo-patches-${PATCHSET_VERSION}.tar.xz
George Burgess IVb2459ff2019-02-05 13:04:40 -080023 pgo_use? ( gs://chromeos-localmirror/distfiles/python-${PROF_VERSION}-pgo-prof.profdata.tar.xz )"
Mike Frysinger682d0652012-07-30 11:38:25 -040024
25LICENSE="PSF-2"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040026SLOT="2.7"
Mike Frysinger65332152014-02-14 13:55:27 -050027KEYWORDS="*"
Daniel Kurtz548abea2019-05-21 13:27:37 -060028IUSE="-berkdb build doc elibc_uclibc examples gdbm hardened ipv6 pgo_generate +pgo_use libressl +ncurses +readline sqlite +ssl +threads tk +wide-unicode wininst +xml"
George Burgess IVb2459ff2019-02-05 13:04:40 -080029
30REQUIRED_USE="pgo_generate? ( !pgo_use )"
31
32# Workaround: re-emerging this after emerging a `pgo_generate` Python gives us
33# a really bad time, since we'll try to write to profiles in "restricted"
34# places somehow. Specifying this profile file has LLVM write profiles to
35# /dev/null, which is always available.
36export LLVM_PROFILE_FILE="/dev/null"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040037
38# Do not add a dependency on dev-lang/python to this ebuild.
39# If you need to apply a patch which requires python for bootstrapping, please
40# run the bootstrap code on your dev box and include the results in the
41# patchset. See bug 447752.
Mike Frysinger682d0652012-07-30 11:38:25 -040042
Daniel Kurtz60088872019-05-21 13:42:05 -060043RDEPEND="app-arch/bzip2:0=
44 >=sys-libs/zlib-1.1.3:0=
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040045 virtual/libffi
46 virtual/libintl
Daniel Kurtz006a1f52019-05-21 13:35:07 -060047 berkdb? ( || (
48 sys-libs/db:5.3
49 sys-libs/db:5.2
50 sys-libs/db:5.1
51 sys-libs/db:5.0
52 sys-libs/db:4.8
53 sys-libs/db:4.7
54 sys-libs/db:4.6
55 sys-libs/db:4.5
56 sys-libs/db:4.4
57 sys-libs/db:4.3
58 sys-libs/db:4.2
59 ) )
Daniel Kurtz60088872019-05-21 13:42:05 -060060 gdbm? ( sys-libs/gdbm:0=[berkdb] )
Daniel Kurtz006a1f52019-05-21 13:35:07 -060061 ncurses? (
Daniel Kurtz60088872019-05-21 13:42:05 -060062 >=sys-libs/ncurses-5.2:0=
63 readline? ( >=sys-libs/readline-4.1:0= )
Daniel Kurtz006a1f52019-05-21 13:35:07 -060064 )
Daniel Kurtz60088872019-05-21 13:42:05 -060065 sqlite? ( >=dev-db/sqlite-3.3.8:3= )
Daniel Kurtz006a1f52019-05-21 13:35:07 -060066 ssl? (
Daniel Kurtz60088872019-05-21 13:42:05 -060067 !libressl? ( dev-libs/openssl:0= )
68 libressl? ( dev-libs/libressl:= )
Daniel Kurtz006a1f52019-05-21 13:35:07 -060069 )
70 tk? (
Daniel Kurtz60088872019-05-21 13:42:05 -060071 >=dev-lang/tcl-8.0:0=
72 >=dev-lang/tk-8.0:0=
73 dev-tcltk/blt:0=
Daniel Kurtz006a1f52019-05-21 13:35:07 -060074 dev-tcltk/tix
75 )
Daniel Kurtz60088872019-05-21 13:42:05 -060076 xml? ( >=dev-libs/expat-2.1 )
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040077 !!<sys-apps/portage-2.1.9"
Mike Frysinger682d0652012-07-30 11:38:25 -040078DEPEND="${RDEPEND}
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040079 virtual/pkgconfig
80 >=sys-devel/autoconf-2.65
81 !sys-devel/gcc[libffi]"
Mike Frysinger682d0652012-07-30 11:38:25 -040082RDEPEND+=" !build? ( app-misc/mime-types )
83 doc? ( dev-python/python-docs:${SLOT} )"
Daniel Kurtzd47b2922017-07-17 17:47:39 +080084PDEPEND="app-eselect/eselect-python
Mike Frysinger51f0d522015-11-21 00:11:17 +000085 app-admin/python-updater"
Mike Frysinger682d0652012-07-30 11:38:25 -040086
87S="${WORKDIR}/${MY_P}"
88
89pkg_setup() {
Mike Frysinger682d0652012-07-30 11:38:25 -040090 if use berkdb; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040091 ewarn "'bsddb' module is out-of-date and no longer maintained inside"
92 ewarn "dev-lang/python. 'bsddb' and 'dbhash' modules have been additionally"
93 ewarn "removed in Python 3. A maintained alternative of 'bsddb3' module"
94 ewarn "is provided by dev-python/bsddb3."
Mike Frysinger682d0652012-07-30 11:38:25 -040095 else
96 if has_version "=${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040097 ewarn "You are migrating from =${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"
98 ewarn "to =${CATEGORY}/${PN}-${PV%%.*}*[-berkdb]."
Mike Frysinger682d0652012-07-30 11:38:25 -040099 ewarn "You might need to migrate your databases."
100 fi
101 fi
102}
103
104src_prepare() {
Tim Zwiebelab07eb22017-06-03 03:19:57 -0700105 # According to the comments at the top of cgi.py, Linux vendors need to
106 # patch the shebang in cgi.py. We'll ignore the comment about not using
107 # "/usr/bin/env python" and use it anyway.
108 sed -i -e '1 s:^#!.*$:#! /usr/bin/env python:' Lib/cgi.py || die
109
Mike Frysinger682d0652012-07-30 11:38:25 -0400110 # Ensure that internal copies of expat, libffi and zlib are not used.
Mike Frysinger51f0d522015-11-21 00:11:17 +0000111 rm -r Modules/expat || die
112 rm -r Modules/_ctypes/libffi* || die
113 rm -r Modules/zlib || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400114
Mike Frysinger51f0d522015-11-21 00:11:17 +0000115 if tc-is-cross-compiler; then
116 local EPATCH_EXCLUDE="*_regenerate_platform-specific_modules.patch"
Mike Frysinger682d0652012-07-30 11:38:25 -0400117 fi
118
Mike Frysinger51f0d522015-11-21 00:11:17 +0000119 EPATCH_SUFFIX="patch" epatch "${WORKDIR}/patches"
Mike Frysinger682d0652012-07-30 11:38:25 -0400120
121 #
122 # START: ChromiumOS specific changes
123 #
124 if tc-is-cross-compiler ; then
Mike Frysinger51f0d522015-11-21 00:11:17 +0000125 epatch "${FILESDIR}"/python-2.7.10-cross-h2py.patch
126 epatch "${FILESDIR}"/python-2.7.10-cross-hack-compiler.patch
Mike Frysinger682d0652012-07-30 11:38:25 -0400127 sed -i 's:^python$EXE:${HOSTPYTHON}:' Lib/*/regen || die
128 fi
Mike Frysinger51f0d522015-11-21 00:11:17 +0000129 epatch "${FILESDIR}"/python-2.7.10-cross-setup-sysroot.patch
130 epatch "${FILESDIR}"/python-2.7.10-cross-distutils.patch
Paul Hobbs43d07e62015-05-14 16:43:16 -0700131 epatch "${FILESDIR}"/python-2.7.3-unique-semaphore-name.patch
Mike Frysinger51f0d522015-11-21 00:11:17 +0000132 epatch "${FILESDIR}"/python-2.7.10-ldshared.patch
Manoj Gupta85657702018-11-05 18:26:27 -0800133 epatch "${FILESDIR}"/python-2.7.17-getentropy.patch
Yunlian Jiang871d0072018-07-24 11:11:01 -0700134 epatch "${FILESDIR}"/2.7-disable-nis.patch
Mike Frysingereb047962014-04-06 10:08:56 -0400135 # Undo the @libdir@ change for portage's pym folder as it is always
136 # installed into /usr/lib/ and not the abi libdir.
137 sed -i \
138 -e '/portage.*pym/s:@@GENTOO_LIBDIR@@:lib:g' \
139 Lib/site.py || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400140
141 sed -i -e "s:sys.exec_prefix]:sys.exec_prefix, '/usr/local']:g" \
142 Lib/site.py || die "sed failed to add /usr/local to prefixes"
George Burgess IVb2459ff2019-02-05 13:04:40 -0800143
144 # Enable stealthy profile application; with this, `sysconfig` won't
145 # report on any CFLAGS in EXTRA_CFLAGS
146 epatch "${FILESDIR}"/python-2.7-clear-extra-cflags.patch
Mike Frysinger682d0652012-07-30 11:38:25 -0400147 #
148 # END: ChromiumOS specific changes
149 #
150
Mike Frysinger51f0d522015-11-21 00:11:17 +0000151 # Fix for cross-compiling.
152 epatch "${FILESDIR}/python-2.7.5-nonfatal-compileall.patch"
153 epatch "${FILESDIR}/python-2.7.9-ncurses-pkg-config.patch"
Daniel Kurtz6e688d62019-05-21 13:31:42 -0600154 epatch "${FILESDIR}/python-2.7.10-cross-compile-warn-test.patch"
Daniel Kurtz7abe6f52019-05-21 17:41:24 -0600155 epatch "${FILESDIR}/python-2.7.10-system-libffi.patch"
Mike Frysinger51f0d522015-11-21 00:11:17 +0000156
Mike Frysinger682d0652012-07-30 11:38:25 -0400157 sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
158 Lib/distutils/command/install.py \
159 Lib/distutils/sysconfig.py \
160 Lib/site.py \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400161 Lib/sysconfig.py \
162 Lib/test/test_site.py \
Mike Frysinger682d0652012-07-30 11:38:25 -0400163 Makefile.pre.in \
164 Modules/Setup.dist \
165 Modules/getpath.c \
166 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
167
Mike Frysinger51f0d522015-11-21 00:11:17 +0000168 epatch_user
169
170 eautoreconf
Mike Frysinger682d0652012-07-30 11:38:25 -0400171}
172
George Burgess IVb2459ff2019-02-05 13:04:40 -0800173# There's a sad story behind this. When we've built our `python` and
174# `libpython.so` objects, we'll go to build all of our Python modules. This is
175# done with LD_LIBRARY_PATH set to our workdir, and is generally
176# well-sandboxed. Sadly, the compiler is a wrapper written in Python and
177# invoked via #!/usr/bin/python2, so **the compiler invocations will link to
178# the new, not-yet-installed libpython.so**.
179#
180# Usually, this isn't much of a problem. However, when we're building Python
181# with instrumentation enabled, libpython.so is where some of the key
182# instrumentation functions end up. Since everything links to libpython.so, and
183# since libpython.so shows up in link lines before libclang_rt.profile (where
184# these "key instrumentation functions" come from), the only binary we built
185# with USE=pgo_generate that has an actual definition for these functions is
186# libpython.so.
187#
188# Hence, the old python invoked by the wrapper looks for its profiling symbols
189# in the *new* libpython.so, doesn't find them, and gets sad.
190#
191# This can all be fixed by moving libclang_rt.profiles up before -lpython2.7 in
192# the commandline, which is easily doable. Doing so puts these profiling
193# symbols in every binary we produce, but only in pgo_generate builds. They're
194# all dynamic symbols, so keeping multiple definitions around should be OK.
195#
196# Clang is good about moving libclangrt_profile around, so we just parse its
197# output to determine where this static lib is located today.
198detect_libprofile_rt_location() {
199 local result
200 # Clang always gives quoted output. We're picking out the single arg
201 # with libclang_rt.profile from it, and discarding the quotes.
202 result=$(echo | \
203 $(tc-getCC) -### -fprofile-generate -x c - |& \
204 grep -oE '"[^"]+libclang_rt.profile[^"]+"' | \
205 tr -d '"')
206 [[ -n "${result}" ]] || die "libclangrt detection failed"
207 echo "${result}"
208}
209
Mike Frysinger682d0652012-07-30 11:38:25 -0400210src_configure() {
Mike Frysinger682d0652012-07-30 11:38:25 -0400211 # dbm module can be linked against berkdb or gdbm.
212 # Defaults to gdbm when both are enabled, #204343.
213 local disable
214 use berkdb || use gdbm || disable+=" dbm"
215 use berkdb || disable+=" _bsddb"
216 use gdbm || disable+=" gdbm"
217 use ncurses || disable+=" _curses _curses_panel"
218 use readline || disable+=" readline"
219 use sqlite || disable+=" _sqlite3"
220 use ssl || export PYTHON_DISABLE_SSL="1"
221 use tk || disable+=" _tkinter"
222 use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
223 export PYTHON_DISABLE_MODULES="${disable}"
224
225 if ! use xml; then
226 ewarn "You have configured Python without XML support."
227 ewarn "This is NOT a recommended configuration as you"
228 ewarn "may face problems parsing any XML documents."
229 fi
Mike Frysinger682d0652012-07-30 11:38:25 -0400230
231 if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
232 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
233 fi
234
235 if [[ "$(gcc-major-version)" -ge 4 ]]; then
236 append-flags -fwrapv
237 fi
238
239 filter-flags -malign-double
240
241 [[ "${ARCH}" == "alpha" ]] && append-flags -fPIC
242
243 # https://bugs.gentoo.org/show_bug.cgi?id=50309
244 if is-flagq -O3; then
245 is-flagq -fstack-protector-all && replace-flags -O3 -O2
246 use hardened && replace-flags -O3 -O2
247 fi
248
Mike Frysinger682d0652012-07-30 11:38:25 -0400249 if tc-is-cross-compiler; then
Mike Frysinger51f0d522015-11-21 00:11:17 +0000250 # Force some tests that try to poke fs paths.
251 export ac_cv_file__dev_ptc=no
252 export ac_cv_file__dev_ptmx=yes
Mike Frysinger682d0652012-07-30 11:38:25 -0400253 fi
254
255 # Export CXX so it ends up in /usr/lib/python2.X/config/Makefile.
256 tc-export CXX
257 # The configure script fails to use pkg-config correctly.
258 # http://bugs.python.org/issue15506
259 export ac_cv_path_PKG_CONFIG=$(tc-getPKG_CONFIG)
260
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400261 # Set LDFLAGS so we link modules with -lpython2.7 correctly.
262 # Needed on FreeBSD unless Python 2.7 is already installed.
Mike Frysinger682d0652012-07-30 11:38:25 -0400263 # Please query BSD team before removing this!
264 append-ldflags "-L."
265
George Burgess IVb2459ff2019-02-05 13:04:40 -0800266 tc-export CC
267 if use pgo_generate; then
268 tc-is-clang || die "Instrumentation is only supported when using clang"
269 # tc_extra_flags is an invention used to make cflags apply
270 # equally to Python's C modules and Python itself. This also
271 # prevents duplication between CFLAGS and LDFLAGS, which is a
272 # build error with -mllvm -options.
273 #
274 # This is a functional change in Python that breaks subversion
275 # (SWIG Python bindings rely on distutils.sysconfigs' ${CC}),
276 # so you should consider re-emerge'ing before trying to emerge
277 # anything else.
278 #
279 # We explicitly use /tmp here because this path is *baked into
280 # Python* as the place where profiles should go when Python is
281 # run. Hence, it has to be a well-known place that lives after
282 # `emerge`.
283 CC+=" -fprofile-generate=/tmp/python_profiles"
284
285 # LLVM intentionally low-balls vp-counters-per-site to save some
286 # binary size. If left to its default of 1, we get a diagnostic
287 # asking for it to be raised. Instead of tweaking it and having
288 # the issue silently appear again in the future, force dynamic
289 # allocation of counters. It's marginally slower, but less
290 # error-prone.
291 CC+=" -mllvm -vp-static-alloc=false"
292
293 append-ldflags "$(detect_libprofile_rt_location)"
294 fi
295
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400296 local dbmliborder
297 if use gdbm; then
298 dbmliborder+="${dbmliborder:+:}gdbm"
299 fi
300 if use berkdb; then
301 dbmliborder+="${dbmliborder:+:}bdb"
302 fi
303
Mike Frysinger51f0d522015-11-21 00:11:17 +0000304 BUILD_DIR="${WORKDIR}/${CHOST}"
305 mkdir -p "${BUILD_DIR}" || die
306 cd "${BUILD_DIR}" || die
307
308 ECONF_SOURCE="${S}" OPT="" \
Mike Frysinger682d0652012-07-30 11:38:25 -0400309 econf \
310 --with-fpectl \
311 --enable-shared \
312 $(use_enable ipv6) \
313 $(use_with threads) \
314 $(use wide-unicode && echo "--enable-unicode=ucs4" || echo "--enable-unicode=ucs2") \
315 --infodir='${prefix}/share/info' \
316 --mandir='${prefix}/share/man' \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400317 --with-dbmliborder="${dbmliborder}" \
Mike Frysinger682d0652012-07-30 11:38:25 -0400318 --with-libc="" \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400319 --enable-loadable-sqlite-extensions \
320 --with-system-expat \
Mike Frysinger51f0d522015-11-21 00:11:17 +0000321 --with-system-ffi \
322 --without-ensurepip
Mike Frysinger682d0652012-07-30 11:38:25 -0400323
Mike Frysinger51f0d522015-11-21 00:11:17 +0000324 if use threads && grep -q "#define POSIX_SEMAPHORES_NOT_ENABLED 1" pyconfig.h; then
325 eerror "configure has detected that the sem_open function is broken."
326 eerror "Please ensure that /dev/shm is mounted as a tmpfs with mode 1777."
327 die "Broken sem_open function (bug 496328)"
Mike Frysinger682d0652012-07-30 11:38:25 -0400328 fi
Mike Frysinger682d0652012-07-30 11:38:25 -0400329}
330
331src_compile() {
Mike Frysinger51f0d522015-11-21 00:11:17 +0000332 # Avoid invoking pgen for cross-compiles.
333 touch Include/graminit.h Python/graminit.c
334
George Burgess IVb2459ff2019-02-05 13:04:40 -0800335 # CFLAGS specified in configure get baked into the `sysconfig` module,
336 # which is consulted when building e.g. SWIG bindings for subversion.
337 # OPT, which we wiped out during configuration time anyway, allows us
338 # to pass flags that `sysconfig` doesn't see.
339 local extra_cflags=()
340 if use pgo_use && tc-is-clang; then
341 # If you're upgrading Python, please also run
342 # ./files/python2_gen_pgo.sh to build a new PGO profile.
343 if [[ "${PV}" != "${PROF_VERSION}" ]]; then
344 die "Please generate a new profile. Details in comments."
345 fi
346
347 extra_cflags=(
348 "-fprofile-use=${WORKDIR}/python-${PROF_VERSION}-pgo-prof.profdata"
349 "-Wno-backend-plugin"
350 )
351
352 # LTO only buys us ~2%, it increases binary size around 750KB,
353 # and it's entirely broken on aarch64 (LTO prompts clang to use
354 # its built-in assembler, which has issues with inline assembly
355 # in Python, apparently.)
356 fi
357
Mike Frysinger51f0d522015-11-21 00:11:17 +0000358 cd "${BUILD_DIR}" || die
George Burgess IVb2459ff2019-02-05 13:04:40 -0800359 EXTRA_CFLAGS="${extra_cflags[*]}" emake
Mike Frysinger51f0d522015-11-21 00:11:17 +0000360
361 # Work around bug 329499. See also bug 413751 and 457194.
362 if has_version dev-libs/libffi[pax_kernel]; then
363 pax-mark E python
364 else
365 pax-mark m python
Mike Frysinger682d0652012-07-30 11:38:25 -0400366 fi
Mike Frysinger682d0652012-07-30 11:38:25 -0400367}
368
369src_test() {
370 # Tests will not work when cross compiling.
371 if tc-is-cross-compiler; then
372 elog "Disabling tests due to crosscompiling."
373 return
374 fi
375
Mike Frysinger51f0d522015-11-21 00:11:17 +0000376 cd "${BUILD_DIR}" || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400377
Mike Frysinger682d0652012-07-30 11:38:25 -0400378 # Skip failing tests.
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400379 local skipped_tests="distutils gdb"
Mike Frysinger682d0652012-07-30 11:38:25 -0400380
381 for test in ${skipped_tests}; do
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400382 mv "${S}"/Lib/test/test_${test}.py "${T}"
Mike Frysinger682d0652012-07-30 11:38:25 -0400383 done
384
385 # Rerun failed tests in verbose mode (regrtest -w).
386 emake test EXTRATESTOPTS="-w" < /dev/tty
387 local result="$?"
388
389 for test in ${skipped_tests}; do
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400390 mv "${T}/test_${test}.py" "${S}"/Lib/test
Mike Frysinger682d0652012-07-30 11:38:25 -0400391 done
392
393 elog "The following tests have been skipped:"
394 for test in ${skipped_tests}; do
395 elog "test_${test}.py"
396 done
397
398 elog "If you would like to run them, you may:"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400399 elog "cd '${EPREFIX}/usr/$(get_libdir)/python${SLOT}/test'"
Mike Frysinger682d0652012-07-30 11:38:25 -0400400 elog "and run the tests separately."
401
402 python_disable_pyc
403
404 if [[ "${result}" -ne 0 ]]; then
405 die "emake test failed"
406 fi
407}
408
409src_install() {
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400410 local libdir=${ED}/usr/$(get_libdir)/python${SLOT}
411
Mike Frysinger51f0d522015-11-21 00:11:17 +0000412 cd "${BUILD_DIR}" || die
413 emake DESTDIR="${D}" altinstall
Mike Frysinger682d0652012-07-30 11:38:25 -0400414
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400415 sed -e "s/\(LDFLAGS=\).*/\1/" -i "${libdir}/config/Makefile" || die "sed failed"
416
Mike Frysinger682d0652012-07-30 11:38:25 -0400417 # Fix collisions between different slots of Python.
418 mv "${ED}usr/bin/2to3" "${ED}usr/bin/2to3-${SLOT}"
419 mv "${ED}usr/bin/pydoc" "${ED}usr/bin/pydoc${SLOT}"
420 mv "${ED}usr/bin/idle" "${ED}usr/bin/idle${SLOT}"
Mike Frysinger682d0652012-07-30 11:38:25 -0400421 rm -f "${ED}usr/bin/smtpd.py"
422
Mike Frysinger51f0d522015-11-21 00:11:17 +0000423 use berkdb || rm -r "${libdir}/"{bsddb,dbhash.py,test/test_bsddb*} || die
424 use sqlite || rm -r "${libdir}/"{sqlite3,test/test_sqlite*} || die
425 use tk || rm -r "${ED}usr/bin/idle${SLOT}" "${libdir}/"{idlelib,lib-tk} || die
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400426 use elibc_uclibc && rm -fr "${libdir}/"{bsddb/test,test}
Mike Frysinger682d0652012-07-30 11:38:25 -0400427
Mike Frysinger51f0d522015-11-21 00:11:17 +0000428 use threads || rm -r "${libdir}/multiprocessing" || die
429 use wininst || rm -r "${libdir}/distutils/command/"wininst-*.exe || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400430
Mike Frysinger51f0d522015-11-21 00:11:17 +0000431 dodoc "${S}"/Misc/{ACKS,HISTORY,NEWS}
Mike Frysinger682d0652012-07-30 11:38:25 -0400432
433 if use examples; then
434 insinto /usr/share/doc/${PF}/examples
Mike Frysinger51f0d522015-11-21 00:11:17 +0000435 doins -r "${S}"/Tools
Mike Frysinger682d0652012-07-30 11:38:25 -0400436 fi
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400437 insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
438 local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
439 emake --no-print-directory -s -f - 2>/dev/null)
440 newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
Mike Frysinger682d0652012-07-30 11:38:25 -0400441
Mike Frysinger51f0d522015-11-21 00:11:17 +0000442 newconfd "${FILESDIR}/pydoc.conf" pydoc-${SLOT}
443 newinitd "${FILESDIR}/pydoc.init" pydoc-${SLOT}
Mike Frysinger682d0652012-07-30 11:38:25 -0400444 sed \
445 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${SLOT/./_}_PORT:" \
446 -e "s:@PYDOC@:pydoc${SLOT}:" \
447 -i "${ED}etc/conf.d/pydoc-${SLOT}" "${ED}etc/init.d/pydoc-${SLOT}" || die "sed failed"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400448
449 # for python-exec
Daniel Kurtzfc1f14d2019-05-21 17:01:58 -0600450 local vars=( EPYTHON PYTHON_SITEDIR PYTHON_SCRIPTDIR )
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400451
452 # if not using a cross-compiler, use the fresh binary
453 if ! tc-is-cross-compiler; then
Daniel Kurtzfc1f14d2019-05-21 17:01:58 -0600454 local -x PYTHON=./python
Mike Frysinger51f0d522015-11-21 00:11:17 +0000455 local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}.
Daniel Kurtzfc1f14d2019-05-21 17:01:58 -0600456 else
457 vars=( PYTHON "${vars[@]}" )
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400458 fi
459
Daniel Kurtzee2f7282019-05-21 17:06:08 -0600460 python_export "python${SLOT}" "${vars[@]}"
Daniel Kurtzfc1f14d2019-05-21 17:01:58 -0600461 echo "EPYTHON='${EPYTHON}'" > epython.py || die
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400462 python_domodule epython.py
463
Chad Versace016e8732018-10-26 12:55:13 -0700464 # python-exec wrapping support
465 local pymajor=${SLOT%.*}
466 mkdir -p "${D}${PYTHON_SCRIPTDIR}" || die
Daniel Kurtz31ebeca2019-05-21 17:16:54 -0600467 # python and pythonX
468 ln -s "../../../bin/python${SLOT}" \
469 "${D}${PYTHON_SCRIPTDIR}/python${pymajor}" || die
470 ln -s "python${pymajor}" \
471 "${D}${PYTHON_SCRIPTDIR}/python" || die
472 # python-config and pythonX-config
473 ln -s "../../../bin/python${SLOT}-config" \
474 "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" || die
475 ln -s "python${pymajor}-config" \
476 "${D}${PYTHON_SCRIPTDIR}/python-config" || die
477 # 2to3, pydoc, pyvenv
478 ln -s "../../../bin/2to3-${SLOT}" \
479 "${D}${PYTHON_SCRIPTDIR}/2to3" || die
480 ln -s "../../../bin/pydoc${SLOT}" \
481 "${D}${PYTHON_SCRIPTDIR}/pydoc" || die
Daniel Kurtze1853102019-05-22 10:59:07 -0600482 # idle
483 if use tk; then
484 ln -s "../../../bin/idle${SLOT}" \
485 "${D}${PYTHON_SCRIPTDIR}/idle" || die
486 fi
Chad Versace016e8732018-10-26 12:55:13 -0700487
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400488 # The sysconfig module will actually read the pyconfig.h at runtime to see what kind
489 # of functionality is enabled in the build. Deploy it behind the back of portage as
490 # need be.
Mike Frysingerd7685db2013-04-06 02:03:53 -0400491 ln "${ED}/usr/include/python${SLOT}/pyconfig.h" "${libdir}/pyconfig_h" || die
492
493 # Workaround https://bugs.gentoo.org/380569
494 keepdir /etc/env.d/python
Mike Frysinger682d0652012-07-30 11:38:25 -0400495}
496
497pkg_preinst() {
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400498 if has_version "<${CATEGORY}/${PN}-${SLOT}" && ! has_version "${CATEGORY}/${PN}:2.7"; then
Mike Frysinger682d0652012-07-30 11:38:25 -0400499 python_updater_warning="1"
500 fi
501}
502
503eselect_python_update() {
Mike Frysinger682d0652012-07-30 11:38:25 -0400504 if [[ -z "$(eselect python show)" || ! -f "${EROOT}usr/bin/$(eselect python show)" ]]; then
505 eselect python update
506 fi
507
508 if [[ -z "$(eselect python show --python${PV%%.*})" || ! -f "${EROOT}usr/bin/$(eselect python show --python${PV%%.*})" ]]; then
509 eselect python update --python${PV%%.*}
510 fi
511}
512
513pkg_postinst() {
514 eselect_python_update
515
Mike Frysinger682d0652012-07-30 11:38:25 -0400516 if [[ "${python_updater_warning}" == "1" ]]; then
517 ewarn "You have just upgraded from an older version of Python."
518 ewarn "You should switch active version of Python ${PV%%.*} and run"
519 ewarn "'python-updater [options]' to rebuild Python modules."
520 fi
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400521
Mike Frysingerd7685db2013-04-06 02:03:53 -0400522 local pyconfig="${EROOT}/usr/$(get_libdir)/python${SLOT}/pyconfig_h"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400523 if [[ ! -e ${EROOT}/usr/include/python${SLOT}/pyconfig.h ]] ; then
524 # See pkg_preinst above for details.
Mike Frysingerd7685db2013-04-06 02:03:53 -0400525 install -D -m644 "${pyconfig}" "${EROOT}/usr/include/python${SLOT}/pyconfig.h" || die
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400526 fi
Mike Frysingerd7685db2013-04-06 02:03:53 -0400527 rm "${pyconfig}" || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400528}
529
530pkg_postrm() {
531 eselect_python_update
Mike Frysinger682d0652012-07-30 11:38:25 -0400532}