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