blob: 1b2453f1780867a2fc2c4116cf0c940e76bf6e3e [file] [log] [blame]
Daniel Kurtzb5dc7832019-05-22 16:06:45 -06001# Copyright 1999-2018 Gentoo Authors
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}"
Daniel Kurtzb5dc7832019-05-22 16:06:45 -060011PATCHSET_VERSION="2.7.15"
Mike Frysinger682d0652012-07-30 11:38:25 -040012
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040013DESCRIPTION="An interpreted, interactive, object-oriented programming language"
Daniel Kurtzdb138892019-05-22 11:48:20 -060014HOMEPAGE="https://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.
Daniel Kurtzb5dc7832019-05-22 16:06:45 -060019PROF_VERSION="2.7.15"
George Burgess IVb2459ff2019-02-05 13:04:40 -080020
Daniel Kurtzdb138892019-05-22 11:48:20 -060021SRC_URI="https://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 Kurtz68ac7de2019-05-22 12:29:24 -060028IUSE="-berkdb bluetooth 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=
Daniel Kurtze1131312019-05-22 14:45:16 -060045 virtual/libffi:=
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040046 virtual/libintl
Daniel Kurtz006a1f52019-05-21 13:35:07 -060047 berkdb? ( || (
48 sys-libs/db:5.3
Daniel Kurtz006a1f52019-05-21 13:35:07 -060049 sys-libs/db:5.1
Daniel Kurtz006a1f52019-05-21 13:35:07 -060050 sys-libs/db:4.8
51 sys-libs/db:4.7
52 sys-libs/db:4.6
53 sys-libs/db:4.5
54 sys-libs/db:4.4
55 sys-libs/db:4.3
56 sys-libs/db:4.2
57 ) )
Daniel Kurtz60088872019-05-21 13:42:05 -060058 gdbm? ( sys-libs/gdbm:0=[berkdb] )
Daniel Kurtz37f84502019-05-22 12:13:01 -060059 ncurses? ( >=sys-libs/ncurses-5.2:0= )
60 readline? ( >=sys-libs/readline-4.1:0= )
Daniel Kurtz60088872019-05-21 13:42:05 -060061 sqlite? ( >=dev-db/sqlite-3.3.8:3= )
Daniel Kurtz006a1f52019-05-21 13:35:07 -060062 ssl? (
Daniel Kurtz60088872019-05-21 13:42:05 -060063 !libressl? ( dev-libs/openssl:0= )
Daniel Kurtzb5dc7832019-05-22 16:06:45 -060064 libressl? ( dev-libs/libressl:0= )
Daniel Kurtz006a1f52019-05-21 13:35:07 -060065 )
66 tk? (
Daniel Kurtz60088872019-05-21 13:42:05 -060067 >=dev-lang/tcl-8.0:0=
68 >=dev-lang/tk-8.0:0=
69 dev-tcltk/blt:0=
Daniel Kurtz006a1f52019-05-21 13:35:07 -060070 dev-tcltk/tix
71 )
Daniel Kurtz60088872019-05-21 13:42:05 -060072 xml? ( >=dev-libs/expat-2.1 )
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040073 !!<sys-apps/portage-2.1.9"
Daniel Kurtz68ac7de2019-05-22 12:29:24 -060074# bluetooth requires headers from bluez
Mike Frysinger682d0652012-07-30 11:38:25 -040075DEPEND="${RDEPEND}
Daniel Kurtz68ac7de2019-05-22 12:29:24 -060076 bluetooth? ( net-wireless/bluez )
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040077 virtual/pkgconfig
78 >=sys-devel/autoconf-2.65
Daniel Kurtzaceb8df2019-05-22 11:39:28 -060079 !sys-devel/gcc[libffi(-)]"
Mike Frysinger682d0652012-07-30 11:38:25 -040080RDEPEND+=" !build? ( app-misc/mime-types )
81 doc? ( dev-python/python-docs:${SLOT} )"
Daniel Kurtz7f55c262019-05-22 11:23:41 -060082PDEPEND=">=app-eselect/eselect-python-20140125-r1"
Mike Frysinger682d0652012-07-30 11:38:25 -040083
84S="${WORKDIR}/${MY_P}"
85
86pkg_setup() {
Mike Frysinger682d0652012-07-30 11:38:25 -040087 if use berkdb; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040088 ewarn "'bsddb' module is out-of-date and no longer maintained inside"
89 ewarn "dev-lang/python. 'bsddb' and 'dbhash' modules have been additionally"
90 ewarn "removed in Python 3. A maintained alternative of 'bsddb3' module"
91 ewarn "is provided by dev-python/bsddb3."
Mike Frysinger682d0652012-07-30 11:38:25 -040092 else
93 if has_version "=${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040094 ewarn "You are migrating from =${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"
95 ewarn "to =${CATEGORY}/${PN}-${PV%%.*}*[-berkdb]."
Mike Frysinger682d0652012-07-30 11:38:25 -040096 ewarn "You might need to migrate your databases."
97 fi
98 fi
99}
100
101src_prepare() {
Tim Zwiebelab07eb22017-06-03 03:19:57 -0700102 # According to the comments at the top of cgi.py, Linux vendors need to
103 # patch the shebang in cgi.py. We'll ignore the comment about not using
104 # "/usr/bin/env python" and use it anyway.
105 sed -i -e '1 s:^#!.*$:#! /usr/bin/env python:' Lib/cgi.py || die
106
Mike Frysinger682d0652012-07-30 11:38:25 -0400107 # Ensure that internal copies of expat, libffi and zlib are not used.
Mike Frysinger51f0d522015-11-21 00:11:17 +0000108 rm -r Modules/expat || die
109 rm -r Modules/_ctypes/libffi* || die
110 rm -r Modules/zlib || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400111
Mike Frysinger51f0d522015-11-21 00:11:17 +0000112 if tc-is-cross-compiler; then
Daniel Kurtzb5dc7832019-05-22 16:06:45 -0600113 local EPATCH_EXCLUDE="*-Regenerate-platform-specific-modules.patch"
Mike Frysinger682d0652012-07-30 11:38:25 -0400114 fi
115
Daniel Kurtzb5dc7832019-05-22 16:06:45 -0600116 EPATCH_SUFFIX="patch" EPATCH_FORCE="yes" epatch "${WORKDIR}/patches"
Mike Frysinger682d0652012-07-30 11:38:25 -0400117
118 #
119 # START: ChromiumOS specific changes
120 #
121 if tc-is-cross-compiler ; then
Mike Frysinger51f0d522015-11-21 00:11:17 +0000122 epatch "${FILESDIR}"/python-2.7.10-cross-h2py.patch
123 epatch "${FILESDIR}"/python-2.7.10-cross-hack-compiler.patch
Mike Frysinger682d0652012-07-30 11:38:25 -0400124 sed -i 's:^python$EXE:${HOSTPYTHON}:' Lib/*/regen || die
125 fi
Mike Frysinger51f0d522015-11-21 00:11:17 +0000126 epatch "${FILESDIR}"/python-2.7.10-cross-setup-sysroot.patch
127 epatch "${FILESDIR}"/python-2.7.10-cross-distutils.patch
Mike Frysinger935ee6f2019-09-06 14:38:15 -0400128 epatch "${FILESDIR}"/python-2.7.10-cross-sysconfig.patch
Mike Frysinger51f0d522015-11-21 00:11:17 +0000129 epatch "${FILESDIR}"/python-2.7.10-ldshared.patch
Mike Frysingereb047962014-04-06 10:08:56 -0400130 # Undo the @libdir@ change for portage's pym folder as it is always
131 # installed into /usr/lib/ and not the abi libdir.
132 sed -i \
133 -e '/portage.*pym/s:@@GENTOO_LIBDIR@@:lib:g' \
134 Lib/site.py || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400135
136 sed -i -e "s:sys.exec_prefix]:sys.exec_prefix, '/usr/local']:g" \
137 Lib/site.py || die "sed failed to add /usr/local to prefixes"
George Burgess IVb2459ff2019-02-05 13:04:40 -0800138
139 # Enable stealthy profile application; with this, `sysconfig` won't
140 # report on any CFLAGS in EXTRA_CFLAGS
141 epatch "${FILESDIR}"/python-2.7-clear-extra-cflags.patch
Mike Frysinger682d0652012-07-30 11:38:25 -0400142 #
143 # END: ChromiumOS specific changes
144 #
145
Mike Frysinger51f0d522015-11-21 00:11:17 +0000146 # Fix for cross-compiling.
147 epatch "${FILESDIR}/python-2.7.5-nonfatal-compileall.patch"
148 epatch "${FILESDIR}/python-2.7.9-ncurses-pkg-config.patch"
Daniel Kurtz6e688d62019-05-21 13:31:42 -0600149 epatch "${FILESDIR}/python-2.7.10-cross-compile-warn-test.patch"
Daniel Kurtz7abe6f52019-05-21 17:41:24 -0600150 epatch "${FILESDIR}/python-2.7.10-system-libffi.patch"
Chris McDonald5ca5bf22019-08-07 14:53:57 -0600151 epatch "${FILESDIR}/python-2.7.15-sigint-handler.patch"
Mike Frysinger51f0d522015-11-21 00:11:17 +0000152
Daniel Kurtz2b445142019-05-22 11:08:15 -0600153 epatch_user
154
Mike Frysinger682d0652012-07-30 11:38:25 -0400155 sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
156 Lib/distutils/command/install.py \
157 Lib/distutils/sysconfig.py \
158 Lib/site.py \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400159 Lib/sysconfig.py \
160 Lib/test/test_site.py \
Mike Frysinger682d0652012-07-30 11:38:25 -0400161 Makefile.pre.in \
162 Modules/Setup.dist \
163 Modules/getpath.c \
164 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
165
Mike Frysinger51f0d522015-11-21 00:11:17 +0000166 eautoreconf
Mike Frysinger682d0652012-07-30 11:38:25 -0400167}
168
George Burgess IVb2459ff2019-02-05 13:04:40 -0800169# There's a sad story behind this. When we've built our `python` and
170# `libpython.so` objects, we'll go to build all of our Python modules. This is
171# done with LD_LIBRARY_PATH set to our workdir, and is generally
172# well-sandboxed. Sadly, the compiler is a wrapper written in Python and
173# invoked via #!/usr/bin/python2, so **the compiler invocations will link to
174# the new, not-yet-installed libpython.so**.
175#
176# Usually, this isn't much of a problem. However, when we're building Python
177# with instrumentation enabled, libpython.so is where some of the key
178# instrumentation functions end up. Since everything links to libpython.so, and
179# since libpython.so shows up in link lines before libclang_rt.profile (where
180# these "key instrumentation functions" come from), the only binary we built
181# with USE=pgo_generate that has an actual definition for these functions is
182# libpython.so.
183#
184# Hence, the old python invoked by the wrapper looks for its profiling symbols
185# in the *new* libpython.so, doesn't find them, and gets sad.
186#
187# This can all be fixed by moving libclang_rt.profiles up before -lpython2.7 in
188# the commandline, which is easily doable. Doing so puts these profiling
189# symbols in every binary we produce, but only in pgo_generate builds. They're
190# all dynamic symbols, so keeping multiple definitions around should be OK.
191#
192# Clang is good about moving libclangrt_profile around, so we just parse its
193# output to determine where this static lib is located today.
194detect_libprofile_rt_location() {
195 local result
196 # Clang always gives quoted output. We're picking out the single arg
197 # with libclang_rt.profile from it, and discarding the quotes.
198 result=$(echo | \
199 $(tc-getCC) -### -fprofile-generate -x c - |& \
200 grep -oE '"[^"]+libclang_rt.profile[^"]+"' | \
201 tr -d '"')
202 [[ -n "${result}" ]] || die "libclangrt detection failed"
203 echo "${result}"
204}
205
Mike Frysinger682d0652012-07-30 11:38:25 -0400206src_configure() {
Mike Frysinger682d0652012-07-30 11:38:25 -0400207 # dbm module can be linked against berkdb or gdbm.
208 # Defaults to gdbm when both are enabled, #204343.
209 local disable
210 use berkdb || use gdbm || disable+=" dbm"
211 use berkdb || disable+=" _bsddb"
Daniel Kurtz68ac7de2019-05-22 12:29:24 -0600212 # disable automagic bluetooth headers detection
213 use bluetooth || export ac_cv_header_bluetooth_bluetooth_h=no
Mike Frysinger682d0652012-07-30 11:38:25 -0400214 use gdbm || disable+=" gdbm"
215 use ncurses || disable+=" _curses _curses_panel"
216 use readline || disable+=" readline"
217 use sqlite || disable+=" _sqlite3"
218 use ssl || export PYTHON_DISABLE_SSL="1"
219 use tk || disable+=" _tkinter"
220 use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
221 export PYTHON_DISABLE_MODULES="${disable}"
222
223 if ! use xml; then
224 ewarn "You have configured Python without XML support."
225 ewarn "This is NOT a recommended configuration as you"
226 ewarn "may face problems parsing any XML documents."
227 fi
Mike Frysinger682d0652012-07-30 11:38:25 -0400228
229 if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
230 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
231 fi
232
233 if [[ "$(gcc-major-version)" -ge 4 ]]; then
234 append-flags -fwrapv
235 fi
236
237 filter-flags -malign-double
238
Mike Frysinger682d0652012-07-30 11:38:25 -0400239 # https://bugs.gentoo.org/show_bug.cgi?id=50309
240 if is-flagq -O3; then
241 is-flagq -fstack-protector-all && replace-flags -O3 -O2
242 use hardened && replace-flags -O3 -O2
243 fi
244
Manoj Guptafb92eaba2020-06-18 09:59:43 -0700245 # python2 build is running cross-compiled x86_64 binaries on build
246 # machine that may not have same ISA. Filter architecture specific
247 # flags as a workaround, https://crbug.com/1091706 .
248 if use amd64 && tc-is-cross-compiler; then
249 filter-flags '-march=*'
250 fi
251
Mike Frysinger682d0652012-07-30 11:38:25 -0400252 if tc-is-cross-compiler; then
Mike Frysinger51f0d522015-11-21 00:11:17 +0000253 # Force some tests that try to poke fs paths.
254 export ac_cv_file__dev_ptc=no
255 export ac_cv_file__dev_ptmx=yes
Mike Frysinger682d0652012-07-30 11:38:25 -0400256 fi
257
258 # Export CXX so it ends up in /usr/lib/python2.X/config/Makefile.
259 tc-export CXX
260 # The configure script fails to use pkg-config correctly.
261 # http://bugs.python.org/issue15506
262 export ac_cv_path_PKG_CONFIG=$(tc-getPKG_CONFIG)
263
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400264 # Set LDFLAGS so we link modules with -lpython2.7 correctly.
265 # Needed on FreeBSD unless Python 2.7 is already installed.
Mike Frysinger682d0652012-07-30 11:38:25 -0400266 # Please query BSD team before removing this!
267 append-ldflags "-L."
268
George Burgess IVb2459ff2019-02-05 13:04:40 -0800269 tc-export CC
270 if use pgo_generate; then
271 tc-is-clang || die "Instrumentation is only supported when using clang"
272 # tc_extra_flags is an invention used to make cflags apply
273 # equally to Python's C modules and Python itself. This also
274 # prevents duplication between CFLAGS and LDFLAGS, which is a
275 # build error with -mllvm -options.
276 #
277 # This is a functional change in Python that breaks subversion
278 # (SWIG Python bindings rely on distutils.sysconfigs' ${CC}),
279 # so you should consider re-emerge'ing before trying to emerge
280 # anything else.
281 #
282 # We explicitly use /tmp here because this path is *baked into
283 # Python* as the place where profiles should go when Python is
284 # run. Hence, it has to be a well-known place that lives after
285 # `emerge`.
286 CC+=" -fprofile-generate=/tmp/python_profiles"
287
288 # LLVM intentionally low-balls vp-counters-per-site to save some
289 # binary size. If left to its default of 1, we get a diagnostic
290 # asking for it to be raised. Instead of tweaking it and having
291 # the issue silently appear again in the future, force dynamic
292 # allocation of counters. It's marginally slower, but less
293 # error-prone.
294 CC+=" -mllvm -vp-static-alloc=false"
295
296 append-ldflags "$(detect_libprofile_rt_location)"
297 fi
298
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400299 local dbmliborder
300 if use gdbm; then
301 dbmliborder+="${dbmliborder:+:}gdbm"
302 fi
303 if use berkdb; then
304 dbmliborder+="${dbmliborder:+:}bdb"
305 fi
306
Mike Frysinger51f0d522015-11-21 00:11:17 +0000307 BUILD_DIR="${WORKDIR}/${CHOST}"
308 mkdir -p "${BUILD_DIR}" || die
309 cd "${BUILD_DIR}" || die
310
311 ECONF_SOURCE="${S}" OPT="" \
Mike Frysinger682d0652012-07-30 11:38:25 -0400312 econf \
313 --with-fpectl \
314 --enable-shared \
315 $(use_enable ipv6) \
316 $(use_with threads) \
317 $(use wide-unicode && echo "--enable-unicode=ucs4" || echo "--enable-unicode=ucs2") \
318 --infodir='${prefix}/share/info' \
319 --mandir='${prefix}/share/man' \
Daniel Kurtzb5dc7832019-05-22 16:06:45 -0600320 --with-computed-gotos \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400321 --with-dbmliborder="${dbmliborder}" \
Mike Frysinger682d0652012-07-30 11:38:25 -0400322 --with-libc="" \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400323 --enable-loadable-sqlite-extensions \
324 --with-system-expat \
Mike Frysinger51f0d522015-11-21 00:11:17 +0000325 --with-system-ffi \
326 --without-ensurepip
Mike Frysinger682d0652012-07-30 11:38:25 -0400327
Mike Frysinger51f0d522015-11-21 00:11:17 +0000328 if use threads && grep -q "#define POSIX_SEMAPHORES_NOT_ENABLED 1" pyconfig.h; then
329 eerror "configure has detected that the sem_open function is broken."
330 eerror "Please ensure that /dev/shm is mounted as a tmpfs with mode 1777."
331 die "Broken sem_open function (bug 496328)"
Mike Frysinger682d0652012-07-30 11:38:25 -0400332 fi
Mike Frysinger682d0652012-07-30 11:38:25 -0400333}
334
335src_compile() {
Mike Frysinger51f0d522015-11-21 00:11:17 +0000336 # Avoid invoking pgen for cross-compiles.
337 touch Include/graminit.h Python/graminit.c
338
George Burgess IVb2459ff2019-02-05 13:04:40 -0800339 # CFLAGS specified in configure get baked into the `sysconfig` module,
340 # which is consulted when building e.g. SWIG bindings for subversion.
341 # OPT, which we wiped out during configuration time anyway, allows us
342 # to pass flags that `sysconfig` doesn't see.
343 local extra_cflags=()
344 if use pgo_use && tc-is-clang; then
345 # If you're upgrading Python, please also run
346 # ./files/python2_gen_pgo.sh to build a new PGO profile.
347 if [[ "${PV}" != "${PROF_VERSION}" ]]; then
348 die "Please generate a new profile. Details in comments."
349 fi
350
351 extra_cflags=(
352 "-fprofile-use=${WORKDIR}/python-${PROF_VERSION}-pgo-prof.profdata"
353 "-Wno-backend-plugin"
354 )
355
356 # LTO only buys us ~2%, it increases binary size around 750KB,
357 # and it's entirely broken on aarch64 (LTO prompts clang to use
358 # its built-in assembler, which has issues with inline assembly
359 # in Python, apparently.)
360 fi
361
Mike Frysinger51f0d522015-11-21 00:11:17 +0000362 cd "${BUILD_DIR}" || die
George Burgess IVb2459ff2019-02-05 13:04:40 -0800363 EXTRA_CFLAGS="${extra_cflags[*]}" emake
Mike Frysinger51f0d522015-11-21 00:11:17 +0000364
365 # Work around bug 329499. See also bug 413751 and 457194.
366 if has_version dev-libs/libffi[pax_kernel]; then
367 pax-mark E python
368 else
369 pax-mark m python
Mike Frysinger682d0652012-07-30 11:38:25 -0400370 fi
Mike Frysinger682d0652012-07-30 11:38:25 -0400371}
372
373src_test() {
374 # Tests will not work when cross compiling.
375 if tc-is-cross-compiler; then
376 elog "Disabling tests due to crosscompiling."
377 return
378 fi
379
Mike Frysinger51f0d522015-11-21 00:11:17 +0000380 cd "${BUILD_DIR}" || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400381
Mike Frysinger682d0652012-07-30 11:38:25 -0400382 # Skip failing tests.
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400383 local skipped_tests="distutils gdb"
Mike Frysinger682d0652012-07-30 11:38:25 -0400384
385 for test in ${skipped_tests}; do
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400386 mv "${S}"/Lib/test/test_${test}.py "${T}"
Mike Frysinger682d0652012-07-30 11:38:25 -0400387 done
388
Daniel Kurtzbaa53772019-05-22 11:45:33 -0600389 # Daylight saving time problem
390 # https://bugs.python.org/issue22067
391 # https://bugs.gentoo.org/610628
392 local -x TZ=UTC
393
Mike Frysinger682d0652012-07-30 11:38:25 -0400394 # Rerun failed tests in verbose mode (regrtest -w).
395 emake test EXTRATESTOPTS="-w" < /dev/tty
396 local result="$?"
397
398 for test in ${skipped_tests}; do
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400399 mv "${T}/test_${test}.py" "${S}"/Lib/test
Mike Frysinger682d0652012-07-30 11:38:25 -0400400 done
401
402 elog "The following tests have been skipped:"
403 for test in ${skipped_tests}; do
404 elog "test_${test}.py"
405 done
406
407 elog "If you would like to run them, you may:"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400408 elog "cd '${EPREFIX}/usr/$(get_libdir)/python${SLOT}/test'"
Mike Frysinger682d0652012-07-30 11:38:25 -0400409 elog "and run the tests separately."
410
411 python_disable_pyc
412
413 if [[ "${result}" -ne 0 ]]; then
414 die "emake test failed"
415 fi
416}
417
418src_install() {
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400419 local libdir=${ED}/usr/$(get_libdir)/python${SLOT}
420
Mike Frysinger51f0d522015-11-21 00:11:17 +0000421 cd "${BUILD_DIR}" || die
422 emake DESTDIR="${D}" altinstall
Mike Frysinger682d0652012-07-30 11:38:25 -0400423
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400424 sed -e "s/\(LDFLAGS=\).*/\1/" -i "${libdir}/config/Makefile" || die "sed failed"
425
Mike Frysinger682d0652012-07-30 11:38:25 -0400426 # Fix collisions between different slots of Python.
427 mv "${ED}usr/bin/2to3" "${ED}usr/bin/2to3-${SLOT}"
428 mv "${ED}usr/bin/pydoc" "${ED}usr/bin/pydoc${SLOT}"
429 mv "${ED}usr/bin/idle" "${ED}usr/bin/idle${SLOT}"
Mike Frysinger682d0652012-07-30 11:38:25 -0400430 rm -f "${ED}usr/bin/smtpd.py"
431
Daniel Kurtzefb535c2019-05-22 11:44:24 -0600432 use berkdb || rm -r "${libdir}/"{bsddb,dbhash.py*,test/test_bsddb*} || die
Daniel Kurtz221b4612019-05-22 11:42:25 -0600433 use sqlite || rm -r "${libdir}/"{sqlite3,test/test_sqlite*} || die
434 use tk || rm -r "${ED}usr/bin/idle${SLOT}" "${libdir}/"{idlelib,lib-tk} || die
435 use elibc_uclibc && rm -fr "${libdir}/"{bsddb/test,test}
Mike Frysinger682d0652012-07-30 11:38:25 -0400436
Mike Frysinger51f0d522015-11-21 00:11:17 +0000437 use threads || rm -r "${libdir}/multiprocessing" || die
438 use wininst || rm -r "${libdir}/distutils/command/"wininst-*.exe || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400439
Mike Frysinger51f0d522015-11-21 00:11:17 +0000440 dodoc "${S}"/Misc/{ACKS,HISTORY,NEWS}
Mike Frysinger682d0652012-07-30 11:38:25 -0400441
442 if use examples; then
443 insinto /usr/share/doc/${PF}/examples
Mike Frysinger51f0d522015-11-21 00:11:17 +0000444 doins -r "${S}"/Tools
Mike Frysinger682d0652012-07-30 11:38:25 -0400445 fi
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400446 insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
447 local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
448 emake --no-print-directory -s -f - 2>/dev/null)
449 newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
Mike Frysinger682d0652012-07-30 11:38:25 -0400450
Mike Frysinger51f0d522015-11-21 00:11:17 +0000451 newconfd "${FILESDIR}/pydoc.conf" pydoc-${SLOT}
452 newinitd "${FILESDIR}/pydoc.init" pydoc-${SLOT}
Mike Frysinger682d0652012-07-30 11:38:25 -0400453 sed \
454 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${SLOT/./_}_PORT:" \
455 -e "s:@PYDOC@:pydoc${SLOT}:" \
456 -i "${ED}etc/conf.d/pydoc-${SLOT}" "${ED}etc/init.d/pydoc-${SLOT}" || die "sed failed"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400457
458 # for python-exec
Daniel Kurtzfc1f14d2019-05-21 17:01:58 -0600459 local vars=( EPYTHON PYTHON_SITEDIR PYTHON_SCRIPTDIR )
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400460
461 # if not using a cross-compiler, use the fresh binary
462 if ! tc-is-cross-compiler; then
Daniel Kurtzfc1f14d2019-05-21 17:01:58 -0600463 local -x PYTHON=./python
Daniel Kurtza22fd602019-05-22 11:52:20 -0600464 local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}${PWD}
Daniel Kurtzfc1f14d2019-05-21 17:01:58 -0600465 else
466 vars=( PYTHON "${vars[@]}" )
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400467 fi
468
Daniel Kurtzee2f7282019-05-21 17:06:08 -0600469 python_export "python${SLOT}" "${vars[@]}"
Daniel Kurtzfc1f14d2019-05-21 17:01:58 -0600470 echo "EPYTHON='${EPYTHON}'" > epython.py || die
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400471 python_domodule epython.py
472
Chad Versace016e8732018-10-26 12:55:13 -0700473 # python-exec wrapping support
474 local pymajor=${SLOT%.*}
475 mkdir -p "${D}${PYTHON_SCRIPTDIR}" || die
Daniel Kurtz31ebeca2019-05-21 17:16:54 -0600476 # python and pythonX
Daniel Kurtzb5dc7832019-05-22 16:06:45 -0600477 ln -s "../../../bin/python${SLOT}" "${D}${PYTHON_SCRIPTDIR}/python${pymajor}" || die
478 ln -s "python${pymajor}" "${D}${PYTHON_SCRIPTDIR}/python" || die
Daniel Kurtz31ebeca2019-05-21 17:16:54 -0600479 # python-config and pythonX-config
Daniel Kurtzb5dc7832019-05-22 16:06:45 -0600480 ln -s "../../../bin/python${SLOT}-config" "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" || die
481 ln -s "python${pymajor}-config" "${D}${PYTHON_SCRIPTDIR}/python-config" || die
Daniel Kurtz31ebeca2019-05-21 17:16:54 -0600482 # 2to3, pydoc, pyvenv
Daniel Kurtzb5dc7832019-05-22 16:06:45 -0600483 ln -s "../../../bin/2to3-${SLOT}" "${D}${PYTHON_SCRIPTDIR}/2to3" || die
484 ln -s "../../../bin/pydoc${SLOT}" "${D}${PYTHON_SCRIPTDIR}/pydoc" || die
Daniel Kurtze1853102019-05-22 10:59:07 -0600485 # idle
486 if use tk; then
Daniel Kurtzb5dc7832019-05-22 16:06:45 -0600487 ln -s "../../../bin/idle${SLOT}" "${D}${PYTHON_SCRIPTDIR}/idle" || die
Daniel Kurtze1853102019-05-22 10:59:07 -0600488 fi
Chad Versace016e8732018-10-26 12:55:13 -0700489
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400490 # The sysconfig module will actually read the pyconfig.h at runtime to see what kind
491 # of functionality is enabled in the build. Deploy it behind the back of portage as
492 # need be.
Mike Frysingerd7685db2013-04-06 02:03:53 -0400493 ln "${ED}/usr/include/python${SLOT}/pyconfig.h" "${libdir}/pyconfig_h" || die
494
495 # Workaround https://bugs.gentoo.org/380569
496 keepdir /etc/env.d/python
Mike Frysinger682d0652012-07-30 11:38:25 -0400497}
498
Mike Frysinger682d0652012-07-30 11:38:25 -0400499eselect_python_update() {
Mike Frysinger682d0652012-07-30 11:38:25 -0400500 if [[ -z "$(eselect python show)" || ! -f "${EROOT}usr/bin/$(eselect python show)" ]]; then
501 eselect python update
502 fi
503
504 if [[ -z "$(eselect python show --python${PV%%.*})" || ! -f "${EROOT}usr/bin/$(eselect python show --python${PV%%.*})" ]]; then
505 eselect python update --python${PV%%.*}
506 fi
507}
508
509pkg_postinst() {
510 eselect_python_update
511
Mike Frysingerd7685db2013-04-06 02:03:53 -0400512 local pyconfig="${EROOT}/usr/$(get_libdir)/python${SLOT}/pyconfig_h"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400513 if [[ ! -e ${EROOT}/usr/include/python${SLOT}/pyconfig.h ]] ; then
514 # See pkg_preinst above for details.
Mike Frysingerd7685db2013-04-06 02:03:53 -0400515 install -D -m644 "${pyconfig}" "${EROOT}/usr/include/python${SLOT}/pyconfig.h" || die
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400516 fi
Mike Frysingerd7685db2013-04-06 02:03:53 -0400517 rm "${pyconfig}" || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400518}
519
520pkg_postrm() {
521 eselect_python_update
Mike Frysinger682d0652012-07-30 11:38:25 -0400522}