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