Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 1 | # Copyright 1999-2015 Gentoo Foundation |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 2 | # Distributed under the terms of the GNU General Public License v2 |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 3 | # $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 Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 4 | |
Cheng-Yi Chiang | b88f696 | 2015-08-06 13:49:23 +0000 | [diff] [blame] | 5 | # ******************************* README *************************************** |
| 6 | # WARNING! ANY CHANGE TO THIS FILE *MUST* BE ACCOMPANIED BY A CHANGE TO |
| 7 | # chromeos-base/dev-install's ebuild, which depends on python indirectly. |
| 8 | # Otherwise, incremental builds will break. See crbug.com/489895. |
| 9 | # ****************************************************************************** |
| 10 | |
George Burgess IV | b2459ff | 2019-02-05 13:04:40 -0800 | [diff] [blame^] | 11 | EAPI="5" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 12 | WANT_LIBTOOL="none" |
| 13 | |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 14 | inherit autotools eutils flag-o-matic multilib pax-utils python-utils-r1 toolchain-funcs multiprocessing |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 15 | |
| 16 | MY_P="Python-${PV}" |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 17 | PATCHSET_VERSION="2.7.10-0" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 18 | |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 19 | DESCRIPTION="An interpreted, interactive, object-oriented programming language" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 20 | HOMEPAGE="http://www.python.org/" |
George Burgess IV | b2459ff | 2019-02-05 13:04:40 -0800 | [diff] [blame^] | 21 | |
| 22 | # The version of Python our PGO profile was generated with. Using ${PV} makes |
| 23 | # updates difficult, and we have tricks below to catch a mismatched profile |
| 24 | # version. |
| 25 | PROF_VERSION="2.7.10" |
| 26 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 27 | SRC_URI="http://www.python.org/ftp/python/${PV}/${MY_P}.tar.xz |
George Burgess IV | b2459ff | 2019-02-05 13:04:40 -0800 | [diff] [blame^] | 28 | http://dev.gentoo.org/~floppym/python/python-gentoo-patches-${PATCHSET_VERSION}.tar.xz |
| 29 | pgo_use? ( gs://chromeos-localmirror/distfiles/python-${PROF_VERSION}-pgo-prof.profdata.tar.xz )" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 30 | |
| 31 | LICENSE="PSF-2" |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 32 | SLOT="2.7" |
Mike Frysinger | 6533215 | 2014-02-14 13:55:27 -0500 | [diff] [blame] | 33 | KEYWORDS="*" |
George Burgess IV | b2459ff | 2019-02-05 13:04:40 -0800 | [diff] [blame^] | 34 | IUSE="-berkdb build doc elibc_uclibc examples gdbm hardened ipv6 pgo_generate +pgo_use +ncurses +readline sqlite +ssl +threads tk +wide-unicode wininst +xml" |
| 35 | |
| 36 | REQUIRED_USE="pgo_generate? ( !pgo_use )" |
| 37 | |
| 38 | # Workaround: re-emerging this after emerging a `pgo_generate` Python gives us |
| 39 | # a really bad time, since we'll try to write to profiles in "restricted" |
| 40 | # places somehow. Specifying this profile file has LLVM write profiles to |
| 41 | # /dev/null, which is always available. |
| 42 | export LLVM_PROFILE_FILE="/dev/null" |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 43 | |
| 44 | # Do not add a dependency on dev-lang/python to this ebuild. |
| 45 | # If you need to apply a patch which requires python for bootstrapping, please |
| 46 | # run the bootstrap code on your dev box and include the results in the |
| 47 | # patchset. See bug 447752. |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 48 | |
| 49 | RDEPEND="app-arch/bzip2 |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 50 | >=sys-libs/zlib-1.1.3 |
| 51 | virtual/libffi |
| 52 | virtual/libintl |
| 53 | !build? ( |
| 54 | berkdb? ( || ( |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 55 | sys-libs/db:5.3 |
| 56 | sys-libs/db:5.2 |
| 57 | sys-libs/db:5.1 |
| 58 | sys-libs/db:5.0 |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 59 | sys-libs/db:4.8 |
| 60 | sys-libs/db:4.7 |
| 61 | sys-libs/db:4.6 |
| 62 | sys-libs/db:4.5 |
| 63 | sys-libs/db:4.4 |
| 64 | sys-libs/db:4.3 |
| 65 | sys-libs/db:4.2 |
| 66 | ) ) |
| 67 | gdbm? ( sys-libs/gdbm ) |
| 68 | ncurses? ( |
| 69 | >=sys-libs/ncurses-5.2 |
| 70 | readline? ( >=sys-libs/readline-4.1 ) |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 71 | ) |
Ryan Sleevi | 1a74516 | 2014-10-27 18:14:49 -0700 | [diff] [blame] | 72 | sqlite? ( >=dev-db/sqlite-3.3.8:3 ) |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 73 | ssl? ( dev-libs/openssl ) |
| 74 | tk? ( |
| 75 | >=dev-lang/tk-8.0 |
| 76 | dev-tcltk/blt |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 77 | dev-tcltk/tix |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 78 | ) |
| 79 | xml? ( >=dev-libs/expat-2.1 ) |
| 80 | ) |
| 81 | !!<sys-apps/portage-2.1.9" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 82 | DEPEND="${RDEPEND} |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 83 | virtual/pkgconfig |
| 84 | >=sys-devel/autoconf-2.65 |
| 85 | !sys-devel/gcc[libffi]" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 86 | RDEPEND+=" !build? ( app-misc/mime-types ) |
| 87 | doc? ( dev-python/python-docs:${SLOT} )" |
Daniel Kurtz | d47b292 | 2017-07-17 17:47:39 +0800 | [diff] [blame] | 88 | PDEPEND="app-eselect/eselect-python |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 89 | app-admin/python-updater" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 90 | |
| 91 | S="${WORKDIR}/${MY_P}" |
| 92 | |
| 93 | pkg_setup() { |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 94 | if use berkdb; then |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 95 | ewarn "'bsddb' module is out-of-date and no longer maintained inside" |
| 96 | ewarn "dev-lang/python. 'bsddb' and 'dbhash' modules have been additionally" |
| 97 | ewarn "removed in Python 3. A maintained alternative of 'bsddb3' module" |
| 98 | ewarn "is provided by dev-python/bsddb3." |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 99 | else |
| 100 | if has_version "=${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"; then |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 101 | ewarn "You are migrating from =${CATEGORY}/${PN}-${PV%%.*}*[berkdb]" |
| 102 | ewarn "to =${CATEGORY}/${PN}-${PV%%.*}*[-berkdb]." |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 103 | ewarn "You might need to migrate your databases." |
| 104 | fi |
| 105 | fi |
| 106 | } |
| 107 | |
| 108 | src_prepare() { |
Tim Zwiebel | ab07eb2 | 2017-06-03 03:19:57 -0700 | [diff] [blame] | 109 | # According to the comments at the top of cgi.py, Linux vendors need to |
| 110 | # patch the shebang in cgi.py. We'll ignore the comment about not using |
| 111 | # "/usr/bin/env python" and use it anyway. |
| 112 | sed -i -e '1 s:^#!.*$:#! /usr/bin/env python:' Lib/cgi.py || die |
| 113 | |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 114 | # Ensure that internal copies of expat, libffi and zlib are not used. |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 115 | rm -r Modules/expat || die |
| 116 | rm -r Modules/_ctypes/libffi* || die |
| 117 | rm -r Modules/zlib || die |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 118 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 119 | if tc-is-cross-compiler; then |
| 120 | local EPATCH_EXCLUDE="*_regenerate_platform-specific_modules.patch" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 121 | fi |
| 122 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 123 | EPATCH_SUFFIX="patch" epatch "${WORKDIR}/patches" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 124 | |
| 125 | # |
| 126 | # START: ChromiumOS specific changes |
| 127 | # |
| 128 | if tc-is-cross-compiler ; then |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 129 | epatch "${FILESDIR}"/python-2.7.10-cross-h2py.patch |
| 130 | epatch "${FILESDIR}"/python-2.7.10-cross-hack-compiler.patch |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 131 | sed -i 's:^python$EXE:${HOSTPYTHON}:' Lib/*/regen || die |
| 132 | fi |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 133 | epatch "${FILESDIR}"/python-2.7.10-cross-setup-sysroot.patch |
| 134 | epatch "${FILESDIR}"/python-2.7.10-cross-distutils.patch |
Paul Hobbs | 43d07e6 | 2015-05-14 16:43:16 -0700 | [diff] [blame] | 135 | epatch "${FILESDIR}"/python-2.7.3-unique-semaphore-name.patch |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 136 | epatch "${FILESDIR}"/python-2.7.10-ldshared.patch |
Manoj Gupta | 8565770 | 2018-11-05 18:26:27 -0800 | [diff] [blame] | 137 | epatch "${FILESDIR}"/python-2.7.17-getentropy.patch |
Yunlian Jiang | 871d007 | 2018-07-24 11:11:01 -0700 | [diff] [blame] | 138 | epatch "${FILESDIR}"/2.7-disable-nis.patch |
Mike Frysinger | eb04796 | 2014-04-06 10:08:56 -0400 | [diff] [blame] | 139 | # Undo the @libdir@ change for portage's pym folder as it is always |
| 140 | # installed into /usr/lib/ and not the abi libdir. |
| 141 | sed -i \ |
| 142 | -e '/portage.*pym/s:@@GENTOO_LIBDIR@@:lib:g' \ |
| 143 | Lib/site.py || die |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 144 | |
| 145 | sed -i -e "s:sys.exec_prefix]:sys.exec_prefix, '/usr/local']:g" \ |
| 146 | Lib/site.py || die "sed failed to add /usr/local to prefixes" |
George Burgess IV | b2459ff | 2019-02-05 13:04:40 -0800 | [diff] [blame^] | 147 | |
| 148 | # Enable stealthy profile application; with this, `sysconfig` won't |
| 149 | # report on any CFLAGS in EXTRA_CFLAGS |
| 150 | epatch "${FILESDIR}"/python-2.7-clear-extra-cflags.patch |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 151 | # |
| 152 | # END: ChromiumOS specific changes |
| 153 | # |
| 154 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 155 | # Fix for cross-compiling. |
| 156 | epatch "${FILESDIR}/python-2.7.5-nonfatal-compileall.patch" |
| 157 | epatch "${FILESDIR}/python-2.7.9-ncurses-pkg-config.patch" |
| 158 | |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 159 | sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \ |
| 160 | Lib/distutils/command/install.py \ |
| 161 | Lib/distutils/sysconfig.py \ |
| 162 | Lib/site.py \ |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 163 | Lib/sysconfig.py \ |
| 164 | Lib/test/test_site.py \ |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 165 | Makefile.pre.in \ |
| 166 | Modules/Setup.dist \ |
| 167 | Modules/getpath.c \ |
| 168 | setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@" |
| 169 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 170 | epatch_user |
| 171 | |
| 172 | eautoreconf |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 173 | } |
| 174 | |
George Burgess IV | b2459ff | 2019-02-05 13:04:40 -0800 | [diff] [blame^] | 175 | # There's a sad story behind this. When we've built our `python` and |
| 176 | # `libpython.so` objects, we'll go to build all of our Python modules. This is |
| 177 | # done with LD_LIBRARY_PATH set to our workdir, and is generally |
| 178 | # well-sandboxed. Sadly, the compiler is a wrapper written in Python and |
| 179 | # invoked via #!/usr/bin/python2, so **the compiler invocations will link to |
| 180 | # the new, not-yet-installed libpython.so**. |
| 181 | # |
| 182 | # Usually, this isn't much of a problem. However, when we're building Python |
| 183 | # with instrumentation enabled, libpython.so is where some of the key |
| 184 | # instrumentation functions end up. Since everything links to libpython.so, and |
| 185 | # since libpython.so shows up in link lines before libclang_rt.profile (where |
| 186 | # these "key instrumentation functions" come from), the only binary we built |
| 187 | # with USE=pgo_generate that has an actual definition for these functions is |
| 188 | # libpython.so. |
| 189 | # |
| 190 | # Hence, the old python invoked by the wrapper looks for its profiling symbols |
| 191 | # in the *new* libpython.so, doesn't find them, and gets sad. |
| 192 | # |
| 193 | # This can all be fixed by moving libclang_rt.profiles up before -lpython2.7 in |
| 194 | # the commandline, which is easily doable. Doing so puts these profiling |
| 195 | # symbols in every binary we produce, but only in pgo_generate builds. They're |
| 196 | # all dynamic symbols, so keeping multiple definitions around should be OK. |
| 197 | # |
| 198 | # Clang is good about moving libclangrt_profile around, so we just parse its |
| 199 | # output to determine where this static lib is located today. |
| 200 | detect_libprofile_rt_location() { |
| 201 | local result |
| 202 | # Clang always gives quoted output. We're picking out the single arg |
| 203 | # with libclang_rt.profile from it, and discarding the quotes. |
| 204 | result=$(echo | \ |
| 205 | $(tc-getCC) -### -fprofile-generate -x c - |& \ |
| 206 | grep -oE '"[^"]+libclang_rt.profile[^"]+"' | \ |
| 207 | tr -d '"') |
| 208 | [[ -n "${result}" ]] || die "libclangrt detection failed" |
| 209 | echo "${result}" |
| 210 | } |
| 211 | |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 212 | src_configure() { |
| 213 | if use build; then |
| 214 | # Disable extraneous modules with extra dependencies. |
| 215 | export PYTHON_DISABLE_MODULES="dbm _bsddb gdbm _curses _curses_panel readline _sqlite3 _tkinter _elementtree pyexpat" |
| 216 | export PYTHON_DISABLE_SSL="1" |
| 217 | else |
| 218 | # dbm module can be linked against berkdb or gdbm. |
| 219 | # Defaults to gdbm when both are enabled, #204343. |
| 220 | local disable |
| 221 | use berkdb || use gdbm || disable+=" dbm" |
| 222 | use berkdb || disable+=" _bsddb" |
| 223 | use gdbm || disable+=" gdbm" |
| 224 | use ncurses || disable+=" _curses _curses_panel" |
| 225 | use readline || disable+=" readline" |
| 226 | use sqlite || disable+=" _sqlite3" |
| 227 | use ssl || export PYTHON_DISABLE_SSL="1" |
| 228 | use tk || disable+=" _tkinter" |
| 229 | use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat. |
| 230 | export PYTHON_DISABLE_MODULES="${disable}" |
| 231 | |
| 232 | if ! use xml; then |
| 233 | ewarn "You have configured Python without XML support." |
| 234 | ewarn "This is NOT a recommended configuration as you" |
| 235 | ewarn "may face problems parsing any XML documents." |
| 236 | fi |
| 237 | fi |
| 238 | |
| 239 | if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then |
| 240 | einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}" |
| 241 | fi |
| 242 | |
| 243 | if [[ "$(gcc-major-version)" -ge 4 ]]; then |
| 244 | append-flags -fwrapv |
| 245 | fi |
| 246 | |
| 247 | filter-flags -malign-double |
| 248 | |
| 249 | [[ "${ARCH}" == "alpha" ]] && append-flags -fPIC |
| 250 | |
| 251 | # https://bugs.gentoo.org/show_bug.cgi?id=50309 |
| 252 | if is-flagq -O3; then |
| 253 | is-flagq -fstack-protector-all && replace-flags -O3 -O2 |
| 254 | use hardened && replace-flags -O3 -O2 |
| 255 | fi |
| 256 | |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 257 | if tc-is-cross-compiler; then |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 258 | # Force some tests that try to poke fs paths. |
| 259 | export ac_cv_file__dev_ptc=no |
| 260 | export ac_cv_file__dev_ptmx=yes |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 261 | fi |
| 262 | |
| 263 | # Export CXX so it ends up in /usr/lib/python2.X/config/Makefile. |
| 264 | tc-export CXX |
| 265 | # The configure script fails to use pkg-config correctly. |
| 266 | # http://bugs.python.org/issue15506 |
| 267 | export ac_cv_path_PKG_CONFIG=$(tc-getPKG_CONFIG) |
| 268 | |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 269 | # Set LDFLAGS so we link modules with -lpython2.7 correctly. |
| 270 | # Needed on FreeBSD unless Python 2.7 is already installed. |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 271 | # Please query BSD team before removing this! |
| 272 | append-ldflags "-L." |
| 273 | |
George Burgess IV | b2459ff | 2019-02-05 13:04:40 -0800 | [diff] [blame^] | 274 | tc-export CC |
| 275 | if use pgo_generate; then |
| 276 | tc-is-clang || die "Instrumentation is only supported when using clang" |
| 277 | # tc_extra_flags is an invention used to make cflags apply |
| 278 | # equally to Python's C modules and Python itself. This also |
| 279 | # prevents duplication between CFLAGS and LDFLAGS, which is a |
| 280 | # build error with -mllvm -options. |
| 281 | # |
| 282 | # This is a functional change in Python that breaks subversion |
| 283 | # (SWIG Python bindings rely on distutils.sysconfigs' ${CC}), |
| 284 | # so you should consider re-emerge'ing before trying to emerge |
| 285 | # anything else. |
| 286 | # |
| 287 | # We explicitly use /tmp here because this path is *baked into |
| 288 | # Python* as the place where profiles should go when Python is |
| 289 | # run. Hence, it has to be a well-known place that lives after |
| 290 | # `emerge`. |
| 291 | CC+=" -fprofile-generate=/tmp/python_profiles" |
| 292 | |
| 293 | # LLVM intentionally low-balls vp-counters-per-site to save some |
| 294 | # binary size. If left to its default of 1, we get a diagnostic |
| 295 | # asking for it to be raised. Instead of tweaking it and having |
| 296 | # the issue silently appear again in the future, force dynamic |
| 297 | # allocation of counters. It's marginally slower, but less |
| 298 | # error-prone. |
| 299 | CC+=" -mllvm -vp-static-alloc=false" |
| 300 | |
| 301 | append-ldflags "$(detect_libprofile_rt_location)" |
| 302 | fi |
| 303 | |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 304 | local dbmliborder |
| 305 | if use gdbm; then |
| 306 | dbmliborder+="${dbmliborder:+:}gdbm" |
| 307 | fi |
| 308 | if use berkdb; then |
| 309 | dbmliborder+="${dbmliborder:+:}bdb" |
| 310 | fi |
| 311 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 312 | BUILD_DIR="${WORKDIR}/${CHOST}" |
| 313 | mkdir -p "${BUILD_DIR}" || die |
| 314 | cd "${BUILD_DIR}" || die |
| 315 | |
| 316 | ECONF_SOURCE="${S}" OPT="" \ |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 317 | econf \ |
| 318 | --with-fpectl \ |
| 319 | --enable-shared \ |
| 320 | $(use_enable ipv6) \ |
| 321 | $(use_with threads) \ |
| 322 | $(use wide-unicode && echo "--enable-unicode=ucs4" || echo "--enable-unicode=ucs2") \ |
| 323 | --infodir='${prefix}/share/info' \ |
| 324 | --mandir='${prefix}/share/man' \ |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 325 | --with-dbmliborder="${dbmliborder}" \ |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 326 | --with-libc="" \ |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 327 | --enable-loadable-sqlite-extensions \ |
| 328 | --with-system-expat \ |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 329 | --with-system-ffi \ |
| 330 | --without-ensurepip |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 331 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 332 | if use threads && grep -q "#define POSIX_SEMAPHORES_NOT_ENABLED 1" pyconfig.h; then |
| 333 | eerror "configure has detected that the sem_open function is broken." |
| 334 | eerror "Please ensure that /dev/shm is mounted as a tmpfs with mode 1777." |
| 335 | die "Broken sem_open function (bug 496328)" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 336 | fi |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | src_compile() { |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 340 | # Avoid invoking pgen for cross-compiles. |
| 341 | touch Include/graminit.h Python/graminit.c |
| 342 | |
George Burgess IV | b2459ff | 2019-02-05 13:04:40 -0800 | [diff] [blame^] | 343 | # CFLAGS specified in configure get baked into the `sysconfig` module, |
| 344 | # which is consulted when building e.g. SWIG bindings for subversion. |
| 345 | # OPT, which we wiped out during configuration time anyway, allows us |
| 346 | # to pass flags that `sysconfig` doesn't see. |
| 347 | local extra_cflags=() |
| 348 | if use pgo_use && tc-is-clang; then |
| 349 | # If you're upgrading Python, please also run |
| 350 | # ./files/python2_gen_pgo.sh to build a new PGO profile. |
| 351 | if [[ "${PV}" != "${PROF_VERSION}" ]]; then |
| 352 | die "Please generate a new profile. Details in comments." |
| 353 | fi |
| 354 | |
| 355 | extra_cflags=( |
| 356 | "-fprofile-use=${WORKDIR}/python-${PROF_VERSION}-pgo-prof.profdata" |
| 357 | "-Wno-backend-plugin" |
| 358 | ) |
| 359 | |
| 360 | # LTO only buys us ~2%, it increases binary size around 750KB, |
| 361 | # and it's entirely broken on aarch64 (LTO prompts clang to use |
| 362 | # its built-in assembler, which has issues with inline assembly |
| 363 | # in Python, apparently.) |
| 364 | fi |
| 365 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 366 | cd "${BUILD_DIR}" || die |
George Burgess IV | b2459ff | 2019-02-05 13:04:40 -0800 | [diff] [blame^] | 367 | EXTRA_CFLAGS="${extra_cflags[*]}" emake |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 368 | |
| 369 | # Work around bug 329499. See also bug 413751 and 457194. |
| 370 | if has_version dev-libs/libffi[pax_kernel]; then |
| 371 | pax-mark E python |
| 372 | else |
| 373 | pax-mark m python |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 374 | fi |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | src_test() { |
| 378 | # Tests will not work when cross compiling. |
| 379 | if tc-is-cross-compiler; then |
| 380 | elog "Disabling tests due to crosscompiling." |
| 381 | return |
| 382 | fi |
| 383 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 384 | cd "${BUILD_DIR}" || die |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 385 | |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 386 | # Skip failing tests. |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 387 | local skipped_tests="distutils gdb" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 388 | |
| 389 | for test in ${skipped_tests}; do |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 390 | mv "${S}"/Lib/test/test_${test}.py "${T}" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 391 | done |
| 392 | |
| 393 | # Rerun failed tests in verbose mode (regrtest -w). |
| 394 | emake test EXTRATESTOPTS="-w" < /dev/tty |
| 395 | local result="$?" |
| 396 | |
| 397 | for test in ${skipped_tests}; do |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 398 | mv "${T}/test_${test}.py" "${S}"/Lib/test |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 399 | done |
| 400 | |
| 401 | elog "The following tests have been skipped:" |
| 402 | for test in ${skipped_tests}; do |
| 403 | elog "test_${test}.py" |
| 404 | done |
| 405 | |
| 406 | elog "If you would like to run them, you may:" |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 407 | elog "cd '${EPREFIX}/usr/$(get_libdir)/python${SLOT}/test'" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 408 | elog "and run the tests separately." |
| 409 | |
| 410 | python_disable_pyc |
| 411 | |
| 412 | if [[ "${result}" -ne 0 ]]; then |
| 413 | die "emake test failed" |
| 414 | fi |
| 415 | } |
| 416 | |
| 417 | src_install() { |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 418 | local libdir=${ED}/usr/$(get_libdir)/python${SLOT} |
| 419 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 420 | cd "${BUILD_DIR}" || die |
| 421 | emake DESTDIR="${D}" altinstall |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 422 | |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 423 | sed -e "s/\(LDFLAGS=\).*/\1/" -i "${libdir}/config/Makefile" || die "sed failed" |
| 424 | |
| 425 | # Backwards compat with Gentoo divergence. |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 426 | dosym python${SLOT}-config /usr/bin/python-config-${SLOT} |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 427 | |
| 428 | # Fix collisions between different slots of Python. |
| 429 | mv "${ED}usr/bin/2to3" "${ED}usr/bin/2to3-${SLOT}" |
| 430 | mv "${ED}usr/bin/pydoc" "${ED}usr/bin/pydoc${SLOT}" |
| 431 | mv "${ED}usr/bin/idle" "${ED}usr/bin/idle${SLOT}" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 432 | rm -f "${ED}usr/bin/smtpd.py" |
| 433 | |
Chad Versace | 016e873 | 2018-10-26 12:55:13 -0700 | [diff] [blame] | 434 | local abiver="python2.7" |
| 435 | |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 436 | if use build; then |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 437 | rm -fr "${ED}usr/bin/idle${SLOT}" "${libdir}/"{bsddb,dbhash.py,idlelib,lib-tk,sqlite3,test} |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 438 | else |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 439 | use berkdb || rm -r "${libdir}/"{bsddb,dbhash.py,test/test_bsddb*} || die |
| 440 | use sqlite || rm -r "${libdir}/"{sqlite3,test/test_sqlite*} || die |
| 441 | use tk || rm -r "${ED}usr/bin/idle${SLOT}" "${libdir}/"{idlelib,lib-tk} || die |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 442 | use elibc_uclibc && rm -fr "${libdir}/"{bsddb/test,test} |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 443 | fi |
| 444 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 445 | use threads || rm -r "${libdir}/multiprocessing" || die |
| 446 | use wininst || rm -r "${libdir}/distutils/command/"wininst-*.exe || die |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 447 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 448 | dodoc "${S}"/Misc/{ACKS,HISTORY,NEWS} |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 449 | |
| 450 | if use examples; then |
| 451 | insinto /usr/share/doc/${PF}/examples |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 452 | doins -r "${S}"/Tools |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 453 | fi |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 454 | insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510 |
| 455 | local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \ |
| 456 | emake --no-print-directory -s -f - 2>/dev/null) |
| 457 | newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 458 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 459 | newconfd "${FILESDIR}/pydoc.conf" pydoc-${SLOT} |
| 460 | newinitd "${FILESDIR}/pydoc.init" pydoc-${SLOT} |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 461 | sed \ |
| 462 | -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${SLOT/./_}_PORT:" \ |
| 463 | -e "s:@PYDOC@:pydoc${SLOT}:" \ |
| 464 | -i "${ED}etc/conf.d/pydoc-${SLOT}" "${ED}etc/init.d/pydoc-${SLOT}" || die "sed failed" |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 465 | |
| 466 | # for python-exec |
Chad Versace | 016e873 | 2018-10-26 12:55:13 -0700 | [diff] [blame] | 467 | python_export python${SLOT} EPYTHON PYTHON PYTHON_SITEDIR PYTHON_SCRIPTDIR |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 468 | |
| 469 | # if not using a cross-compiler, use the fresh binary |
| 470 | if ! tc-is-cross-compiler; then |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 471 | local PYTHON=./python |
| 472 | local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}. |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 473 | fi |
| 474 | |
| 475 | echo "EPYTHON='${EPYTHON}'" > epython.py |
| 476 | python_domodule epython.py |
| 477 | |
Chad Versace | 016e873 | 2018-10-26 12:55:13 -0700 | [diff] [blame] | 478 | # python-exec wrapping support |
| 479 | local pymajor=${SLOT%.*} |
| 480 | mkdir -p "${D}${PYTHON_SCRIPTDIR}" || die |
| 481 | |
| 482 | # python-exec: python, pythonX |
| 483 | dosym "../../../bin/${abiver}" \ |
| 484 | "${PYTHON_SCRIPTDIR}/python${pymajor}" |
| 485 | dosym "python${pymajor}" "${PYTHON_SCRIPTDIR}/python" |
| 486 | |
| 487 | # python-exec: python-config, python-configX |
| 488 | # |
| 489 | # Note: we need to create a wrapper rather than symlinking it due |
| 490 | # to some random dirname(argv[0]) magic performed by python-config. |
| 491 | cat > "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" <<-EOF || die |
| 492 | #!/bin/sh |
| 493 | exec "${abiver}-config" "\${@}" |
| 494 | EOF |
| 495 | # Must strip EPREFIX because fperms prepends ED. |
| 496 | fperms 755 "${PYTHON_SCRIPTDIR#$EPREFIX}/python${pymajor}-config" |
| 497 | dosym "python${pymajor}-config" \ |
| 498 | "${PYTHON_SCRIPTDIR}/python-config" |
| 499 | |
| 500 | # python-exec: pydoc, pydocX |
| 501 | dosym "../../../bin/pydoc${SLOT}" \ |
| 502 | "${PYTHON_SCRIPTDIR}/pydoc${pymajor}" |
| 503 | dosym "pydoc${pymajor}" "${PYTHON_SCRIPTDIR}/pydoc" |
| 504 | |
| 505 | # python-exec: 2to3 |
| 506 | dosym "../../../bin/2to3-${SLOT}" \ |
| 507 | "${PYTHON_SCRIPTDIR}/2to3" |
| 508 | |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 509 | # The sysconfig module will actually read the pyconfig.h at runtime to see what kind |
| 510 | # of functionality is enabled in the build. Deploy it behind the back of portage as |
| 511 | # need be. |
Mike Frysinger | d7685db | 2013-04-06 02:03:53 -0400 | [diff] [blame] | 512 | ln "${ED}/usr/include/python${SLOT}/pyconfig.h" "${libdir}/pyconfig_h" || die |
| 513 | |
| 514 | # Workaround https://bugs.gentoo.org/380569 |
| 515 | keepdir /etc/env.d/python |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | pkg_preinst() { |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 519 | if has_version "<${CATEGORY}/${PN}-${SLOT}" && ! has_version "${CATEGORY}/${PN}:2.7"; then |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 520 | python_updater_warning="1" |
| 521 | fi |
| 522 | } |
| 523 | |
| 524 | eselect_python_update() { |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 525 | if [[ -z "$(eselect python show)" || ! -f "${EROOT}usr/bin/$(eselect python show)" ]]; then |
| 526 | eselect python update |
| 527 | fi |
| 528 | |
| 529 | if [[ -z "$(eselect python show --python${PV%%.*})" || ! -f "${EROOT}usr/bin/$(eselect python show --python${PV%%.*})" ]]; then |
| 530 | eselect python update --python${PV%%.*} |
| 531 | fi |
| 532 | } |
| 533 | |
| 534 | pkg_postinst() { |
| 535 | eselect_python_update |
| 536 | |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 537 | if [[ "${python_updater_warning}" == "1" ]]; then |
| 538 | ewarn "You have just upgraded from an older version of Python." |
| 539 | ewarn "You should switch active version of Python ${PV%%.*} and run" |
| 540 | ewarn "'python-updater [options]' to rebuild Python modules." |
| 541 | fi |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 542 | |
Mike Frysinger | d7685db | 2013-04-06 02:03:53 -0400 | [diff] [blame] | 543 | local pyconfig="${EROOT}/usr/$(get_libdir)/python${SLOT}/pyconfig_h" |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 544 | if [[ ! -e ${EROOT}/usr/include/python${SLOT}/pyconfig.h ]] ; then |
| 545 | # See pkg_preinst above for details. |
Mike Frysinger | d7685db | 2013-04-06 02:03:53 -0400 | [diff] [blame] | 546 | install -D -m644 "${pyconfig}" "${EROOT}/usr/include/python${SLOT}/pyconfig.h" || die |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 547 | fi |
Mike Frysinger | d7685db | 2013-04-06 02:03:53 -0400 | [diff] [blame] | 548 | rm "${pyconfig}" || die |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | pkg_postrm() { |
| 552 | eselect_python_update |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 553 | } |