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