blob: 9c674614938a78ce13f3d317da06f2f0c388cdef [file] [log] [blame]
Andrew Geissler595f6302022-01-24 19:11:47 +00001SUMMARY = "The Python Programming Language"
2HOMEPAGE = "http://www.python.org"
3DESCRIPTION = "Python is a programming language that lets you work more quickly and integrate your systems more effectively."
4LICENSE = "PSFv2"
5SECTION = "devel/python"
6
7LIC_FILES_CHKSUM = "file://LICENSE;md5=4b8801e752a2c70ac41a5f9aa243f766"
8
9SRC_URI = "http://www.python.org/ftp/python/${PV}/Python-${PV}.tar.xz \
10 file://run-ptest \
11 file://create_manifest3.py \
12 file://get_module_deps3.py \
13 file://python3-manifest.json \
14 file://check_build_completeness.py \
15 file://reformat_sysconfig.py \
16 file://cgi_py.patch \
17 file://0001-Do-not-add-usr-lib-termcap-to-linker-flags-to-avoid-.patch \
18 ${@bb.utils.contains('PACKAGECONFIG', 'tk', '', 'file://avoid_warning_about_tkinter.patch', d)} \
19 file://0001-Do-not-use-the-shell-version-of-python-config-that-w.patch \
20 file://python-config.patch \
21 file://0001-Makefile.pre-use-qemu-wrapper-when-gathering-profile.patch \
22 file://0001-python3-use-cc_basename-to-replace-CC-for-checking-c.patch \
23 file://0001-bpo-36852-proper-detection-of-mips-architecture-for-.patch \
24 file://crosspythonpath.patch \
25 file://0001-Use-FLAG_REF-always-for-interned-strings.patch \
26 file://0001-test_locale.py-correct-the-test-output-format.patch \
27 file://0017-setup.py-do-not-report-missing-dependencies-for-disa.patch \
28 file://0001-Makefile-do-not-compile-.pyc-in-parallel.patch \
29 file://0020-configure.ac-setup.py-do-not-add-a-curses-include-pa.patch \
30 file://0001-Skip-failing-tests-due-to-load-variability-on-YP-AB.patch \
31 file://0001-test_ctypes.test_find-skip-without-tools-sdk.patch \
32 file://makerace.patch \
33 file://0001-sysconfig.py-use-platlibdir-also-for-purelib.patch \
34 file://0001-Lib-pty.py-handle-stdin-I-O-errors-same-way-as-maste.patch \
35 "
36
37SRC_URI:append:class-native = " \
38 file://0001-Lib-sysconfig.py-use-prefix-value-from-build-configu.patch \
39 file://0001-distutils-sysconfig-append-STAGING_LIBDIR-python-sys.patch \
40 file://12-distutils-prefix-is-inside-staging-area.patch \
41 file://0001-Don-t-search-system-for-headers-libraries.patch \
42 "
43SRC_URI[sha256sum] = "17de3ac7da9f2519aa9d64378c603a73a0e9ad58dffa8812e45160c086de64c7"
44
45# exclude pre-releases for both python 2.x and 3.x
46UPSTREAM_CHECK_REGEX = "[Pp]ython-(?P<pver>\d+(\.\d+)+).tar"
47UPSTREAM_CHECK_URI = "https://www.python.org/downloads/source/"
48
49CVE_PRODUCT = "python"
50
51# Upstream consider this expected behaviour
52CVE_CHECK_WHITELIST += "CVE-2007-4559"
53# This is not exploitable when glibc has CVE-2016-10739 fixed.
54CVE_CHECK_WHITELIST += "CVE-2019-18348"
55
56# This is windows only issue.
57CVE_CHECK_WHITELIST += "CVE-2020-15523"
58
59PYTHON_MAJMIN = "3.10"
60
61S = "${WORKDIR}/Python-${PV}"
62
63BBCLASSEXTEND = "native nativesdk"
64
65inherit autotools pkgconfig qemu ptest multilib_header update-alternatives
66
67MULTILIB_SUFFIX = "${@d.getVar('base_libdir',1).split('/')[-1]}"
68
69ALTERNATIVE:${PN}-dev = "python3-config"
70ALTERNATIVE_LINK_NAME[python3-config] = "${bindir}/python${PYTHON_MAJMIN}-config"
71ALTERNATIVE_TARGET[python3-config] = "${bindir}/python${PYTHON_MAJMIN}-config-${MULTILIB_SUFFIX}"
72
73
74DEPENDS = "bzip2-replacement-native libffi bzip2 openssl sqlite3 zlib virtual/libintl xz virtual/crypt util-linux libtirpc libnsl2 autoconf-archive-native"
75DEPENDS:append:class-target = " python3-native"
76DEPENDS:append:class-nativesdk = " python3-native"
77
78# force to use the mutex+cond implementation (https://bugs.python.org/issue41710)
79CFLAGS += "-DHAVE_BROKEN_POSIX_SEMAPHORES"
80
81EXTRA_OECONF = " --without-ensurepip --enable-shared --with-platlibdir=${baselib}"
82EXTRA_OECONF:append:class-native = " --bindir=${bindir}/${PN}"
83
84export CROSSPYTHONPATH="${STAGING_LIBDIR_NATIVE}/python${PYTHON_MAJMIN}/lib-dynload/"
85
86EXTRANATIVEPATH += "python3-native"
87
88# LTO will be enabled via packageconfig depending upong distro features
89LTO:class-target = ""
90
91CACHED_CONFIGUREVARS = " \
92 ac_cv_file__dev_ptmx=yes \
93 ac_cv_file__dev_ptc=no \
94 ac_cv_working_tzset=yes \
95"
96
97# PGO currently causes builds to not be reproducible so disable by default, see YOCTO #13407
98PACKAGECONFIG:class-target ??= "readline gdbm ${@bb.utils.filter('DISTRO_FEATURES', 'lto', d)}"
99PACKAGECONFIG:class-native ??= "readline gdbm"
100PACKAGECONFIG:class-nativesdk ??= "readline gdbm"
101PACKAGECONFIG[readline] = ",,readline"
102# Use profile guided optimisation by running PyBench inside qemu-user
103PACKAGECONFIG[pgo] = "--enable-optimizations,,qemu-native"
104PACKAGECONFIG[tk] = ",,tk"
105PACKAGECONFIG[gdbm] = ",,gdbm"
106PACKAGECONFIG[lto] = "--with-lto,,"
107
108do_configure:prepend () {
109 mkdir -p ${B}/Modules
110 cat > ${B}/Modules/Setup.local << EOF
111*disabled*
112${@bb.utils.contains('PACKAGECONFIG', 'gdbm', '', '_gdbm _dbm', d)}
113${@bb.utils.contains('PACKAGECONFIG', 'readline', '', 'readline', d)}
114EOF
115}
116
117CPPFLAGS:append = " -I${STAGING_INCDIR}/ncursesw -I${STAGING_INCDIR}/uuid"
118
119EXTRA_OEMAKE = '\
120 STAGING_LIBDIR=${STAGING_LIBDIR} \
121 STAGING_INCDIR=${STAGING_INCDIR} \
122 LIB=${baselib} \
123'
124
125do_compile:prepend:class-target() {
126 if ${@bb.utils.contains('PACKAGECONFIG', 'pgo', 'true', 'false', d)}; then
127 qemu_binary="${@qemu_wrapper_cmdline(d, '${STAGING_DIR_TARGET}', ['${B}', '${STAGING_DIR_TARGET}/${base_libdir}'])}"
128 cat >pgo-wrapper <<EOF
129#!/bin/sh
130cd ${B}
131$qemu_binary "\$@"
132EOF
133 chmod +x pgo-wrapper
134 fi
135}
136
137do_install:prepend() {
138 ${WORKDIR}/check_build_completeness.py ${T}/log.do_compile
139}
140
141do_install:append:class-target() {
142 oe_multilib_header python${PYTHON_MAJMIN}/pyconfig.h
143}
144
145do_install:append:class-native() {
146 # Make sure we use /usr/bin/env python
147 for PYTHSCRIPT in `grep -rIl ${bindir}/${PN}/python ${D}${bindir}/${PN}`; do
148 sed -i -e '1s|^#!.*|#!/usr/bin/env python3|' $PYTHSCRIPT
149 done
150 # Add a symlink to the native Python so that scripts can just invoke
151 # "nativepython" and get the right one without needing absolute paths
152 # (these often end up too long for the #! parser in the kernel as the
153 # buffer is 128 bytes long).
154 ln -s python3-native/python3 ${D}${bindir}/nativepython3
155}
156
157do_install:append() {
158 for c in ${D}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata*.py; do
159 python3 ${WORKDIR}/reformat_sysconfig.py $c
160 done
161 rm ${D}${libdir}/python${PYTHON_MAJMIN}/__pycache__/_sysconfigdata*.cpython*
162
163 mkdir -p ${D}${libdir}/python-sysconfigdata
164 sysconfigfile=`find ${D} -name _sysconfig*.py`
165 cp $sysconfigfile ${D}${libdir}/python-sysconfigdata/_sysconfigdata.py
166
167 sed -i \
168 -e "s,^ 'LIBDIR'.*, 'LIBDIR': '${STAGING_LIBDIR}'\,,g" \
169 -e "s,^ 'INCLUDEDIR'.*, 'INCLUDEDIR': '${STAGING_INCDIR}'\,,g" \
170 -e "s,^ 'CONFINCLUDEDIR'.*, 'CONFINCLUDEDIR': '${STAGING_INCDIR}'\,,g" \
171 -e "/^ 'INCLDIRSTOMAKE'/{N; s,/usr/include,${STAGING_INCDIR},g}" \
172 -e "/^ 'INCLUDEPY'/s,/usr/include,${STAGING_INCDIR},g" \
173 ${D}${libdir}/python-sysconfigdata/_sysconfigdata.py
174
175 # Unfortunately the following pyc files are non-deterministc due to 'frozenset'
176 # being written without strict ordering, even with PYTHONHASHSEED = 0
177 # Upstream is discussing ways to solve the issue properly, until then let's
178 # just not install the problematic files.
179 # More info: http://benno.id.au/blog/2013/01/15/python-determinism
180 rm ${D}${libdir}/python${PYTHON_MAJMIN}/test/__pycache__/test_range.cpython*
181 rm ${D}${libdir}/python${PYTHON_MAJMIN}/test/__pycache__/test_xml_etree.cpython*
182}
183
184do_install:append:class-nativesdk () {
185 # Make sure we use /usr/bin/env python
186 for PYTHSCRIPT in `grep -rIl ${bindir}/python ${D}${bindir}`; do
187 sed -i -e '1s|^#!.*|#!/usr/bin/env python3|' $PYTHSCRIPT
188 done
189 create_wrapper ${D}${bindir}/python${PYTHON_MAJMIN} TERMINFO_DIRS='${sysconfdir}/terminfo:/etc/terminfo:/usr/share/terminfo:/usr/share/misc/terminfo:/lib/terminfo' PYTHONNOUSERSITE='1'
190}
191
192SSTATE_SCAN_FILES += "Makefile _sysconfigdata.py"
193SSTATE_HASHEQUIV_FILEMAP = " \
194 populate_sysroot:*/lib*/python3*/_sysconfigdata*.py:${TMPDIR} \
195 populate_sysroot:*/lib*/python3*/_sysconfigdata*.py:${COREBASE} \
196 populate_sysroot:*/lib*/python3*/config-*/Makefile:${TMPDIR} \
197 populate_sysroot:*/lib*/python3*/config-*/Makefile:${COREBASE} \
198 populate_sysroot:*/lib*/python-sysconfigdata/_sysconfigdata.py:${TMPDIR} \
199 populate_sysroot:*/lib*/python-sysconfigdata/_sysconfigdata.py:${COREBASE} \
200 "
201PACKAGE_PREPROCESS_FUNCS += "py_package_preprocess"
202
203py_package_preprocess () {
204 # Remove references to buildmachine paths in target Makefile and _sysconfigdata
205 sed -i -e 's:--sysroot=${STAGING_DIR_TARGET}::g' -e s:'--with-libtool-sysroot=${STAGING_DIR_TARGET}'::g \
206 -e 's|${DEBUG_PREFIX_MAP}||g' \
207 -e 's:${HOSTTOOLS_DIR}/::g' \
208 -e 's:${RECIPE_SYSROOT_NATIVE}::g' \
209 -e 's:${RECIPE_SYSROOT}::g' \
210 -e 's:${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}::g' \
211 ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_MAJMIN}${PYTHON_ABI}*/Makefile \
212 ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata*.py \
213 ${PKGD}/${bindir}/python${PYTHON_MAJMIN}-config
214
215 # Reformat _sysconfigdata after modifying it so that it remains
216 # reproducible
217 for c in ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata*.py; do
218 python3 ${WORKDIR}/reformat_sysconfig.py $c
219 done
220
221 # Recompile _sysconfigdata after modifying it
222 cd ${PKGD}
223 sysconfigfile=`find . -name _sysconfigdata_*.py`
224 ${STAGING_BINDIR_NATIVE}/python3-native/python3 \
225 -c "from py_compile import compile; compile('$sysconfigfile')"
226 ${STAGING_BINDIR_NATIVE}/python3-native/python3 \
227 -c "from py_compile import compile; compile('$sysconfigfile', optimize=1)"
228 ${STAGING_BINDIR_NATIVE}/python3-native/python3 \
229 -c "from py_compile import compile; compile('$sysconfigfile', optimize=2)"
230 cd -
231
232 mv ${PKGD}/${bindir}/python${PYTHON_MAJMIN}-config ${PKGD}/${bindir}/python${PYTHON_MAJMIN}-config-${MULTILIB_SUFFIX}
233
234 #Remove the unneeded copy of target sysconfig data
235 rm -rf ${PKGD}/${libdir}/python-sysconfigdata
236}
237
238# We want bytecode precompiled .py files (.pyc's) by default
239# but the user may set it on their own conf
240INCLUDE_PYCS ?= "1"
241
242python(){
243 import collections, json
244
245 filename = os.path.join(d.getVar('THISDIR'), 'python3', 'python3-manifest.json')
246 # This python changes the datastore based on the contents of a file, so mark
247 # that dependency.
248 bb.parse.mark_dependency(d, filename)
249
250 with open(filename) as manifest_file:
251 manifest_str = manifest_file.read()
252 json_start = manifest_str.find('# EOC') + 6
253 manifest_file.seek(json_start)
254 manifest_str = manifest_file.read()
255 python_manifest = json.loads(manifest_str, object_pairs_hook=collections.OrderedDict)
256
257 # First set RPROVIDES for -native case
258 # Hardcoded since it cant be python3-native-foo, should be python3-foo-native
259 pn = 'python3'
260 rprovides = (d.getVar('RPROVIDES') or "").split()
261
262 # ${PN}-misc-native is not in the manifest
263 rprovides.append(pn + '-misc-native')
264
265 for key in python_manifest:
266 pypackage = pn + '-' + key + '-native'
267 if pypackage not in rprovides:
268 rprovides.append(pypackage)
269
270 d.setVar('RPROVIDES:class-native', ' '.join(rprovides))
271
272 # Then work on the target
273 include_pycs = d.getVar('INCLUDE_PYCS')
274
275 packages = d.getVar('PACKAGES').split()
276 pn = d.getVar('PN')
277
278 newpackages=[]
279 for key in python_manifest:
280 pypackage = pn + '-' + key
281
282 if pypackage not in packages:
283 # We need to prepend, otherwise python-misc gets everything
284 # so we use a new variable
285 newpackages.append(pypackage)
286
287 # "Build" python's manifest FILES, RDEPENDS and SUMMARY
288 d.setVar('FILES:' + pypackage, '')
289 for value in python_manifest[key]['files']:
290 d.appendVar('FILES:' + pypackage, ' ' + value)
291
292 # Add cached files
293 if include_pycs == '1':
294 for value in python_manifest[key]['cached']:
295 d.appendVar('FILES:' + pypackage, ' ' + value)
296
297 for value in python_manifest[key]['rdepends']:
298 # Make it work with or without $PN
299 if '${PN}' in value:
300 value=value.split('-', 1)[1]
301 d.appendVar('RDEPENDS:' + pypackage, ' ' + pn + '-' + value)
302
303 for value in python_manifest[key].get('rrecommends', ()):
304 if '${PN}' in value:
305 value=value.split('-', 1)[1]
306 d.appendVar('RRECOMMENDS:' + pypackage, ' ' + pn + '-' + value)
307
308 d.setVar('SUMMARY:' + pypackage, python_manifest[key]['summary'])
309
310 # Prepending so to avoid python-misc getting everything
311 packages = newpackages + packages
312 d.setVar('PACKAGES', ' '.join(packages))
313 d.setVar('ALLOW_EMPTY:${PN}-modules', '1')
314 d.setVar('ALLOW_EMPTY:${PN}-pkgutil', '1')
315
316 if "pgo" in d.getVar("PACKAGECONFIG").split() and not bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', True, False, d):
317 bb.fatal("pgo cannot be enabled as there is no qemu-usermode support for this architecture/machine")
318}
319
320# Files needed to create a new manifest
321
322do_create_manifest() {
323 # This task should be run with every new release of Python.
324 # We must ensure that PACKAGECONFIG enables everything when creating
325 # a new manifest, this is to base our new manifest on a complete
326 # native python build, containing all dependencies, otherwise the task
327 # wont be able to find the required files.
328 # e.g. BerkeleyDB is an optional build dependency so it may or may not
329 # be present, we must ensure it is.
330
331 cd ${WORKDIR}
332 # This needs to be executed by python-native and NOT by HOST's python
333 nativepython3 create_manifest3.py ${PYTHON_MAJMIN}
334 cp python3-manifest.json.new ${THISDIR}/python3/python3-manifest.json
335}
336
337# bitbake python -c create_manifest
338# Make sure we have native python ready when we create a new manifest
339addtask do_create_manifest after do_patch do_prepare_recipe_sysroot
340
341# manual dependency additions
342RRECOMMENDS:${PN}-core:append:class-nativesdk = " nativesdk-python3-modules"
343RRECOMMENDS:${PN}-crypt:append:class-target = " ${MLPREFIX}openssl ${MLPREFIX}ca-certificates"
344RRECOMMENDS:${PN}-crypt:append:class-nativesdk = " ${MLPREFIX}openssl ${MLPREFIX}ca-certificates"
345
346# For historical reasons PN is empty and provided by python3-modules
347FILES:${PN} = ""
348RPROVIDES:${PN}-modules = "${PN}"
349
350FILES:${PN}-pydoc += "${bindir}/pydoc${PYTHON_MAJMIN} ${bindir}/pydoc3"
351FILES:${PN}-idle += "${bindir}/idle3 ${bindir}/idle${PYTHON_MAJMIN}"
352
353# provide python-pyvenv from python3-venv
354RPROVIDES:${PN}-venv += "${MLPREFIX}python3-pyvenv"
355
356# package libpython3
357PACKAGES =+ "libpython3 libpython3-staticdev"
358FILES:libpython3 = "${libdir}/libpython*.so.*"
359FILES:libpython3-staticdev += "${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_MAJMIN}-*/libpython${PYTHON_MAJMIN}.a"
360INSANE_SKIP:${PN}-dev += "dev-elf"
361INSANE_SKIP:${PN}-ptest = "dev-deps"
362
363# catch all the rest (unsorted)
364PACKAGES += "${PN}-misc"
365RDEPENDS:${PN}-misc += "\
366 ${PN}-core \
367 ${PN}-email \
368 ${PN}-codecs \
369 ${PN}-pydoc \
370 ${PN}-pickle \
371 ${PN}-audio \
372 ${PN}-numbers \
373"
374RDEPENDS:${PN}-modules:append:class-target = " ${MLPREFIX}python3-misc"
375RDEPENDS:${PN}-modules:append:class-nativesdk = " ${MLPREFIX}python3-misc"
376FILES:${PN}-misc = "${libdir}/python${PYTHON_MAJMIN} ${libdir}/python${PYTHON_MAJMIN}/lib-dynload"
377
378# catch manpage
379PACKAGES += "${PN}-man"
380FILES:${PN}-man = "${datadir}/man"
381
382# See https://bugs.python.org/issue18748 and https://bugs.python.org/issue37395
383RDEPENDS:libpython3:append:libc-glibc = " libgcc"
384RDEPENDS:${PN}-ctypes:append:libc-glibc = " ${MLPREFIX}ldconfig"
385RDEPENDS:${PN}-ptest = "${PN}-modules ${PN}-tests ${PN}-dev unzip bzip2 libgcc tzdata-europe coreutils sed"
386RDEPENDS:${PN}-ptest:append:libc-glibc = " locale-base-tr-tr.iso-8859-9"
387RDEPENDS:${PN}-tkinter += "${@bb.utils.contains('PACKAGECONFIG', 'tk', '${MLPREFIX}tk ${MLPREFIX}tk-lib', '', d)}"
388RDEPENDS:${PN}-idle += "${@bb.utils.contains('PACKAGECONFIG', 'tk', '${PN}-tkinter ${MLPREFIX}tcl', '', d)}"
389RDEPENDS:${PN}-dev = ""
390RDEPENDS:${PN}-pydoc += "${PN}-io"
391
392RDEPENDS:${PN}-tests:append:class-target = " ${MLPREFIX}bash"
393RDEPENDS:${PN}-tests:append:class-nativesdk = " ${MLPREFIX}bash"
394
395# Python's tests contain large numbers of files we don't need in the recipe sysroots
396SYSROOT_PREPROCESS_FUNCS += " py3_sysroot_cleanup"
397py3_sysroot_cleanup () {
398 rm -rf ${SYSROOT_DESTDIR}${libdir}/python${PYTHON_MAJMIN}/test
399}