Gentoo Archives: gentoo-commits

From: "Michał Górny" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: dev-python/pypy3/
Date: Sun, 26 Feb 2023 20:11:25
Message-Id: 1677442276.7ecd2c2d85b898277bb08f2e09d5ab2eefbdafc5.mgorny@gentoo
1 commit: 7ecd2c2d85b898277bb08f2e09d5ab2eefbdafc5
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Sun Feb 26 20:03:12 2023 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Sun Feb 26 20:11:16 2023 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=7ecd2c2d
7
8 dev-python/pypy3: Backport CVE-2023-24329 fix to 7.3.11_p1
9
10 Bug: https://bugs.gentoo.org/897958
11 Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
12
13 dev-python/pypy3/Manifest | 1 +
14 dev-python/pypy3/pypy3-7.3.11_p1.ebuild | 205 ++++++++++++++++++++++++++++++++
15 2 files changed, 206 insertions(+)
16
17 diff --git a/dev-python/pypy3/Manifest b/dev-python/pypy3/Manifest
18 index de5d9083b178..c6ec081e1ddd 100644
19 --- a/dev-python/pypy3/Manifest
20 +++ b/dev-python/pypy3/Manifest
21 @@ -1,2 +1,3 @@
22 DIST pypy3.9-gentoo-patches-7.3.11.tar.xz 6444 BLAKE2B adcc1ae4c3ae2c5317a05d6de51785945625d8bcc7cb35bd6608fa80f09b37c483c95663eacb0353013a5abec308d25b12666699c65512f5f3a6d7345f2b5b18 SHA512 f2064ecffa09ba23f5f8c281ca4c8c0740cb6b57185d66c02eec2bcb77cfb566b1a2db4f52c472bcaf0d5fb759ee8003b27761af37785d12465c2010fd73c49d
23 +DIST pypy3.9-gentoo-patches-7.3.11_p1.tar.xz 7480 BLAKE2B ffb478402e82244af25dd67bb9e21abb4bb186d98495899f8ca8f323bdf27a77356e40efd33217a5238ef86f6156fc7d85c681a747ea5a35bd73bab659972986 SHA512 6c3ee21b51145907c2434f740e9849ac02ad83203fdcb2802b97ba199f37d08297d8016f659069bea3f0854ace30aefb947af4f057cbc91332106d9fc1389cf4
24 DIST pypy3.9-v7.3.11-src.tar.bz2 23460769 BLAKE2B fa8a827c28813243926c8689addb008c0a43acdc3f81a18749a8f2c1926b6294f2c0c95a4c315e3b77ce84b4f337af7a0bce5daf8dcb60ead965532d4af183cb SHA512 33c978ffbeeb39453028d1d1646ccfdace062ce48a5d939245bea41643038dd3687e80e34f88fa0622bcb175d7dd78f75cbe36b24229c8052f09d2d17dcdfd8c
25
26 diff --git a/dev-python/pypy3/pypy3-7.3.11_p1.ebuild b/dev-python/pypy3/pypy3-7.3.11_p1.ebuild
27 new file mode 100644
28 index 000000000000..d0f7918e6b5f
29 --- /dev/null
30 +++ b/dev-python/pypy3/pypy3-7.3.11_p1.ebuild
31 @@ -0,0 +1,205 @@
32 +# Copyright 1999-2023 Gentoo Authors
33 +# Distributed under the terms of the GNU General Public License v2
34 +
35 +EAPI=8
36 +
37 +inherit pax-utils python-utils-r1 toolchain-funcs
38 +
39 +PYPY_PV=${PV%_p*}
40 +MY_P=pypy3.9-v${PYPY_PV/_rc/rc}
41 +PATCHSET="pypy3.9-gentoo-patches-${PV/_rc/rc}"
42 +
43 +DESCRIPTION="A fast, compliant alternative implementation of the Python (3.9) language"
44 +HOMEPAGE="
45 + https://www.pypy.org/
46 + https://foss.heptapod.net/pypy/pypy/
47 +"
48 +SRC_URI="
49 + https://buildbot.pypy.org/pypy/${MY_P}-src.tar.bz2
50 + https://dev.gentoo.org/~mgorny/dist/python/${PATCHSET}.tar.xz
51 +"
52 +S="${WORKDIR}/${MY_P}-src"
53 +
54 +LICENSE="MIT"
55 +# pypy3 -c 'import sysconfig; print(sysconfig.get_config_var("SOABI"))'
56 +# also check pypy/interpreter/pycode.py -> pypy_incremental_magic
57 +SLOT="0/pypy39-pp73-336"
58 +KEYWORDS="~amd64 ~arm64 ~ppc64 ~x86 ~amd64-linux ~x86-linux"
59 +IUSE="+ensurepip gdbm +jit ncurses sqlite tk"
60 +# many tests are failing upstream
61 +# see https://buildbot.pypy.org/summary?branch=py3.9
62 +RESTRICT="test"
63 +
64 +RDEPEND="
65 + || (
66 + >=dev-python/pypy3-exe-${PYPY_PV}:3.9-${PYPY_PV}[bzip2(+),ncurses?]
67 + >=dev-python/pypy3-exe-bin-${PYPY_PV}:3.9-${PYPY_PV}
68 + )
69 + dev-lang/python-exec[python_targets_pypy3(-)]
70 + dev-libs/openssl:0=
71 + dev-python/gentoo-common
72 + ensurepip? ( dev-python/ensurepip-wheels )
73 + gdbm? ( sys-libs/gdbm:0= )
74 + sqlite? ( dev-db/sqlite:3= )
75 + tk? (
76 + dev-lang/tk:0=
77 + dev-tcltk/tix:0=
78 + )
79 +"
80 +DEPEND="
81 + ${RDEPEND}
82 +"
83 +
84 +src_prepare() {
85 + local PATCHES=(
86 + "${WORKDIR}/${PATCHSET}"
87 + )
88 + default
89 +
90 + eapply_user
91 +}
92 +
93 +src_configure() {
94 + tc-export CC
95 +}
96 +
97 +src_compile() {
98 + mkdir bin || die
99 + # switch to the layout expected for cffi module builds
100 + mkdir include/pypy3.9 || die
101 + # copy over to make sys.prefix happy
102 + cp -p "${BROOT}"/usr/bin/pypy3.9-c-${PYPY_PV} pypy3.9-c || die
103 + cp -p "${BROOT}"/usr/include/pypy3.9/${PYPY_PV}/* include/pypy3.9/ || die
104 + # (not installed by pypy-exe)
105 + rm pypy/module/cpyext/include/_numpypy/numpy/README || die
106 + mv pypy/module/cpyext/include/* include/pypy3.9/ || die
107 + mv pypy/module/cpyext/parse/*.h include/pypy3.9/ || die
108 + pax-mark m pypy3.9-c
109 +
110 + # verify the subslot
111 + local soabi=$(
112 + ./pypy3.9-c - <<-EOF
113 + import importlib.util
114 + import sysconfig
115 + soabi = sysconfig.get_config_var("SOABI")
116 + magic = importlib.util._RAW_MAGIC_NUMBER & 0xffff
117 + print(f"{soabi}-{magic}")
118 + EOF
119 + )
120 + [[ ${soabi} == ${SLOT#*/} ]] || die "update subslot to ${soabi}"
121 +
122 + # Add epython.py to the distribution
123 + echo 'EPYTHON="pypy3"' > lib-python/3/epython.py || die
124 +
125 + einfo "Generating caches and CFFI modules ..."
126 +
127 + # Generate sysconfig data
128 + local host_gnu_type=$(sh pypy/tool/release/config.guess)
129 + local overrides=(
130 + HOST_GNU_TYPE "${host_gnu_type:-unknown}"
131 + INCLUDEPY "${EPREFIX}/usr/include/pypy3.9"
132 + LIBDIR "${EPREFIX}/usr/$(get_libdir)"
133 + TZPATH "${EPREFIX}/usr/share/zoneinfo"
134 + WHEEL_PKG_DIR "${EPREFIX}/usr/lib/python/ensurepip"
135 + )
136 + ./pypy3.9-c -m sysconfig --generate-posix-vars "${overrides[@]}" || die
137 + local outdir
138 + outdir=$(<pybuilddir.txt) || die
139 + cp "${outdir}"/_sysconfigdata__*.py lib-python/3/ || die
140 +
141 + # Generate Grammar and PatternGrammar pickles.
142 + ./pypy3.9-c - <<-EOF || die "Generation of Grammar and PatternGrammar pickles failed"
143 + import lib2to3.pygram
144 + import lib2to3.patcomp
145 + lib2to3.patcomp.PatternCompiler()
146 + EOF
147 +
148 + # Generate cffi modules
149 + # Please keep in sync with pypy/tool/build_cffi_imports.py!
150 + # (NB: we build CFFI modules first to avoid error log when importing
151 + # build_cffi_imports).
152 + cffi_targets=( pypy_util blake2/_blake2 sha3/_sha3 ssl
153 + audioop syslog pwdgrp resource lzma posixshmem )
154 + use gdbm && cffi_targets+=( gdbm )
155 + use ncurses && cffi_targets+=( curses )
156 + use sqlite && cffi_targets+=( sqlite3 )
157 + use tk && cffi_targets+=( tkinter/tklib )
158 +
159 + local t
160 + # all modules except tkinter output to .
161 + # tkinter outputs to the correct dir ...
162 + cd lib_pypy || die
163 + for t in "${cffi_targets[@]}"; do
164 + # tkinter doesn't work via -m
165 + ../pypy3.9-c "_${t}_build.py" || die "Failed to build CFFI bindings for ${t}"
166 + done
167 +
168 + # Verify that CFFI module list is up-to-date
169 + local expected_cksum=63d4659f
170 + local local_cksum=$(
171 + ../pypy3.9-c - <<-EOF
172 + import binascii
173 + import json
174 + from pypy_tools.build_cffi_imports import cffi_build_scripts as x
175 + print("%08x" % (binascii.crc32(json.dumps(x).encode()),))
176 + EOF
177 + )
178 + if [[ ${local_cksum} != ${expected_cksum} ]]; then
179 + die "Please verify cffi_targets and update checksum to ${local_cksum}"
180 + fi
181 +
182 + # Cleanup temporary objects
183 + find -name "*_cffi.[co]" -delete || die
184 + find -type d -empty -delete || die
185 +}
186 +
187 +src_install() {
188 + einfo "Installing PyPy ..."
189 + dodir /usr/bin
190 + dosym pypy3.9-c-${PYPY_PV} /usr/bin/pypy3.9
191 + dosym pypy3.9 /usr/bin/pypy3
192 + insinto /usr/lib/pypy3.9
193 + # preserve mtimes to avoid obsoleting caches
194 + insopts -p
195 + doins -r lib-python/3/. lib_pypy/.
196 + insinto /usr/include
197 + doins -r include/pypy3.9
198 +
199 + # replace copied headers with symlinks
200 + for x in "${BROOT}"/usr/include/pypy3.9/${PYPY_PV}/*; do
201 + dosym "${PYPY_PV}/${x##*/}" "/usr/include/pypy3.9/${x##*/}"
202 + done
203 +
204 + dodoc README.rst
205 +
206 + local dest=/usr/lib/pypy3.9
207 + rm -r "${ED}${dest}"/ensurepip/_bundled || die
208 + if ! use ensurepip; then
209 + rm -r "${ED}${dest}"/ensurepip || die
210 + fi
211 + if ! use gdbm; then
212 + rm -r "${ED}${dest}"/_gdbm* || die
213 + fi
214 + if ! use sqlite; then
215 + rm -r "${ED}${dest}"/sqlite3 \
216 + "${ED}${dest}"/_sqlite3* \
217 + "${ED}${dest}"/test/test_sqlite.py || die
218 + fi
219 + if ! use tk; then
220 + rm -r "${ED}${dest}"/{idlelib,tkinter} \
221 + "${ED}${dest}"/_tkinter \
222 + "${ED}${dest}"/test/test_{tcl,tk,ttk*}.py || die
223 + fi
224 + dosym ../python/EXTERNALLY-MANAGED "${dest}/EXTERNALLY-MANAGED"
225 +
226 + local -x EPYTHON=pypy3
227 + local -x PYTHON=${ED}/usr/bin/pypy3.9-c-${PYPY_PV}
228 + # temporarily copy to build tree to facilitate module builds
229 + cp -p "${BROOT}/usr/bin/pypy3.9-c-${PYPY_PV}" "${PYTHON}" || die
230 +
231 + einfo "Byte-compiling Python standard library..."
232 + python_optimize "${ED}${dest}"
233 +
234 + # remove to avoid collisions
235 + rm "${PYTHON}" || die
236 +}