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