blob: fd1172335ad5e89ffce4896a63904bcb22d5d85c [file] [log] [blame]
Andrew Geissler82c905d2020-04-13 13:39:40 -05001SUMMARY = "The Python Programming Language"
2HOMEPAGE = "http://www.python.org"
Andrew Geissler90fd73c2021-03-05 15:25:55 -06003DESCRIPTION = "Python is a programming language that lets you work more quickly and integrate your systems more effectively."
Andrew Geissler82c905d2020-04-13 13:39:40 -05004LICENSE = "PSFv2"
5SECTION = "devel/python"
6
Andrew Geissler90fd73c2021-03-05 15:25:55 -06007LIC_FILES_CHKSUM = "file://LICENSE;md5=c22d2438294c784731bf9dd224a467b7"
Andrew Geissler82c905d2020-04-13 13:39:40 -05008
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 \
Andrew Geissler6ce62a22020-11-30 19:58:47 -060015 file://reformat_sysconfig.py \
Andrew Geissler82c905d2020-04-13 13:39:40 -050016 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 \
Andrew Geissler82c905d2020-04-13 13:39:40 -050022 file://0001-python3-use-cc_basename-to-replace-CC-for-checking-c.patch \
Andrew Geissler82c905d2020-04-13 13:39:40 -050023 file://0001-Makefile-fix-Issue36464-parallel-build-race-problem.patch \
24 file://0001-bpo-36852-proper-detection-of-mips-architecture-for-.patch \
25 file://crosspythonpath.patch \
Andrew Geissler82c905d2020-04-13 13:39:40 -050026 file://0001-Use-FLAG_REF-always-for-interned-strings.patch \
27 file://0001-test_locale.py-correct-the-test-output-format.patch \
28 file://0017-setup.py-do-not-report-missing-dependencies-for-disa.patch \
29 file://0001-setup.py-pass-missing-libraries-to-Extension-for-mul.patch \
30 file://0001-Makefile-do-not-compile-.pyc-in-parallel.patch \
Andrew Geissler82c905d2020-04-13 13:39:40 -050031 file://0020-configure.ac-setup.py-do-not-add-a-curses-include-pa.patch \
Andrew Geissler6ce62a22020-11-30 19:58:47 -060032 file://0001-Lib-sysconfig.py-use-libdir-values-from-configuratio.patch \
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050033 file://0001-Skip-failing-tests-due-to-load-variability-on-YP-AB.patch \
Andrew Geissler82c905d2020-04-13 13:39:40 -050034 "
35
36SRC_URI_append_class-native = " \
37 file://0001-distutils-sysconfig-append-STAGING_LIBDIR-python-sys.patch \
38 file://12-distutils-prefix-is-inside-staging-area.patch \
39 file://0001-Don-t-search-system-for-headers-libraries.patch \
40 "
Andrew Geissler90fd73c2021-03-05 15:25:55 -060041SRC_URI[sha256sum] = "3c2034c54f811448f516668dce09d24008a0716c3a794dd8639b5388cbde247d"
Andrew Geissler82c905d2020-04-13 13:39:40 -050042
43# exclude pre-releases for both python 2.x and 3.x
44UPSTREAM_CHECK_REGEX = "[Pp]ython-(?P<pver>\d+(\.\d+)+).tar"
Andrew Geissler4c19ea12020-10-27 13:52:24 -050045UPSTREAM_CHECK_URI = "https://www.python.org/downloads/source/"
Andrew Geissler82c905d2020-04-13 13:39:40 -050046
47CVE_PRODUCT = "python"
48
Andrew Geissler6ce62a22020-11-30 19:58:47 -060049# Upstream consider this expected behaviour
50CVE_CHECK_WHITELIST += "CVE-2007-4559"
Andrew Geissler82c905d2020-04-13 13:39:40 -050051# This is not exploitable when glibc has CVE-2016-10739 fixed.
52CVE_CHECK_WHITELIST += "CVE-2019-18348"
53
Andrew Geissler6ce62a22020-11-30 19:58:47 -060054# This is windows only issue.
55CVE_CHECK_WHITELIST += "CVE-2020-15523"
56
57PYTHON_MAJMIN = "3.9"
Andrew Geissler82c905d2020-04-13 13:39:40 -050058
59S = "${WORKDIR}/Python-${PV}"
60
61BBCLASSEXTEND = "native nativesdk"
62
63inherit autotools pkgconfig qemu ptest multilib_header update-alternatives
64
65MULTILIB_SUFFIX = "${@d.getVar('base_libdir',1).split('/')[-1]}"
66
67ALTERNATIVE_${PN}-dev = "python3-config"
68ALTERNATIVE_LINK_NAME[python3-config] = "${bindir}/python${PYTHON_MAJMIN}-config"
69ALTERNATIVE_TARGET[python3-config] = "${bindir}/python${PYTHON_MAJMIN}-config-${MULTILIB_SUFFIX}"
70
71
72DEPENDS = "bzip2-replacement-native libffi bzip2 openssl sqlite3 zlib virtual/libintl xz virtual/crypt util-linux libtirpc libnsl2"
73DEPENDS_append_class-target = " python3-native"
74DEPENDS_append_class-nativesdk = " python3-native"
75
Andrew Geissler6ce62a22020-11-30 19:58:47 -060076EXTRA_OECONF = " --without-ensurepip --enable-shared --with-platlibdir=${baselib}"
Andrew Geissler82c905d2020-04-13 13:39:40 -050077EXTRA_OECONF_append_class-native = " --bindir=${bindir}/${PN}"
78
79export CROSSPYTHONPATH="${STAGING_LIBDIR_NATIVE}/python${PYTHON_MAJMIN}/lib-dynload/"
80
81EXTRANATIVEPATH += "python3-native"
82
Andrew Geissler6ce62a22020-11-30 19:58:47 -060083# LTO will be enabled via packageconfig depending upong distro features
84LTO_class-target = ""
85
Andrew Geissler82c905d2020-04-13 13:39:40 -050086CACHED_CONFIGUREVARS = " \
87 ac_cv_file__dev_ptmx=yes \
88 ac_cv_file__dev_ptc=no \
89 ac_cv_working_tzset=yes \
90"
Andrew Geisslerd25ed322020-06-27 00:28:28 -050091
92def possibly_include_pgo(d):
Andrew Geissler82c905d2020-04-13 13:39:40 -050093 # PGO currently causes builds to not be reproducible, so disable it for
94 # now. See YOCTO #13407
95 if bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', True, False, d) and d.getVar('BUILD_REPRODUCIBLE_BINARIES') != '1':
Andrew Geisslerd25ed322020-06-27 00:28:28 -050096 return 'pgo'
97
98 return ''
Andrew Geissler82c905d2020-04-13 13:39:40 -050099
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600100PACKAGECONFIG_class-target ??= "readline ${@possibly_include_pgo(d)} gdbm ${@bb.utils.filter('DISTRO_FEATURES', 'lto', d)}"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500101PACKAGECONFIG_class-native ??= "readline gdbm"
102PACKAGECONFIG_class-nativesdk ??= "readline gdbm"
103PACKAGECONFIG[readline] = ",,readline"
104# Use profile guided optimisation by running PyBench inside qemu-user
105PACKAGECONFIG[pgo] = "--enable-optimizations,,qemu-native"
106PACKAGECONFIG[tk] = ",,tk"
107PACKAGECONFIG[gdbm] = ",,gdbm"
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600108PACKAGECONFIG[lto] = "--with-lto,,"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500109
110do_configure_prepend () {
111 mkdir -p ${B}/Modules
112 cat > ${B}/Modules/Setup.local << EOF
113*disabled*
114${@bb.utils.contains('PACKAGECONFIG', 'gdbm', '', '_gdbm _dbm', d)}
115${@bb.utils.contains('PACKAGECONFIG', 'readline', '', 'readline', d)}
116EOF
117}
118
119CPPFLAGS_append = " -I${STAGING_INCDIR}/ncursesw -I${STAGING_INCDIR}/uuid"
120
121EXTRA_OEMAKE = '\
122 STAGING_LIBDIR=${STAGING_LIBDIR} \
123 STAGING_INCDIR=${STAGING_INCDIR} \
124 LIB=${baselib} \
125'
126
127do_compile_prepend_class-target() {
128 if ${@bb.utils.contains('PACKAGECONFIG', 'pgo', 'true', 'false', d)}; then
129 qemu_binary="${@qemu_wrapper_cmdline(d, '${STAGING_DIR_TARGET}', ['${B}', '${STAGING_DIR_TARGET}/${base_libdir}'])}"
130 cat >pgo-wrapper <<EOF
131#!/bin/sh
132cd ${B}
133$qemu_binary "\$@"
134EOF
135 chmod +x pgo-wrapper
136 fi
137}
138
139do_install_prepend() {
140 ${WORKDIR}/check_build_completeness.py ${T}/log.do_compile
141}
142
143do_install_append_class-target() {
144 oe_multilib_header python${PYTHON_MAJMIN}/pyconfig.h
145}
146
147do_install_append_class-native() {
148 # Make sure we use /usr/bin/env python
149 for PYTHSCRIPT in `grep -rIl ${bindir}/${PN}/python ${D}${bindir}/${PN}`; do
150 sed -i -e '1s|^#!.*|#!/usr/bin/env python3|' $PYTHSCRIPT
151 done
152 # Add a symlink to the native Python so that scripts can just invoke
153 # "nativepython" and get the right one without needing absolute paths
154 # (these often end up too long for the #! parser in the kernel as the
155 # buffer is 128 bytes long).
156 ln -s python3-native/python3 ${D}${bindir}/nativepython3
157}
158
159do_install_append() {
160 mkdir -p ${D}${libdir}/python-sysconfigdata
161 sysconfigfile=`find ${D} -name _sysconfig*.py`
162 cp $sysconfigfile ${D}${libdir}/python-sysconfigdata/_sysconfigdata.py
163
164 sed -i \
165 -e "s,^ 'LIBDIR'.*, 'LIBDIR': '${STAGING_LIBDIR}'\,,g" \
166 -e "s,^ 'INCLUDEDIR'.*, 'INCLUDEDIR': '${STAGING_INCDIR}'\,,g" \
167 -e "s,^ 'CONFINCLUDEDIR'.*, 'CONFINCLUDEDIR': '${STAGING_INCDIR}'\,,g" \
168 -e "/^ 'INCLDIRSTOMAKE'/{N; s,/usr/include,${STAGING_INCDIR},g}" \
169 -e "/^ 'INCLUDEPY'/s,/usr/include,${STAGING_INCDIR},g" \
170 ${D}${libdir}/python-sysconfigdata/_sysconfigdata.py
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600171
172 # Unfortunately the following pyc files are non-deterministc due to 'frozenset'
173 # being written without strict ordering, even with PYTHONHASHSEED = 0
174 # Upstream is discussing ways to solve the issue properly, until then let's
175 # just not install the problematic files.
176 # More info: http://benno.id.au/blog/2013/01/15/python-determinism
177 rm ${D}${libdir}/python${PYTHON_MAJMIN}/test/__pycache__/test_range.cpython*
178 rm ${D}${libdir}/python${PYTHON_MAJMIN}/test/__pycache__/test_xml_etree.cpython*
Andrew Geissler82c905d2020-04-13 13:39:40 -0500179}
180
181do_install_append_class-nativesdk () {
Andrew Geissler90fd73c2021-03-05 15:25:55 -0600182 # Make sure we use /usr/bin/env python
183 for PYTHSCRIPT in `grep -rIl ${bindir}/python ${D}${bindir}`; do
184 sed -i -e '1s|^#!.*|#!/usr/bin/env python3|' $PYTHSCRIPT
185 done
Andrew Geissler82c905d2020-04-13 13:39:40 -0500186 create_wrapper ${D}${bindir}/python${PYTHON_MAJMIN} TERMINFO_DIRS='${sysconfdir}/terminfo:/etc/terminfo:/usr/share/terminfo:/usr/share/misc/terminfo:/lib/terminfo' PYTHONNOUSERSITE='1'
187}
188
189SSTATE_SCAN_FILES += "Makefile _sysconfigdata.py"
190PACKAGE_PREPROCESS_FUNCS += "py_package_preprocess"
191
192py_package_preprocess () {
193 # Remove references to buildmachine paths in target Makefile and _sysconfigdata
194 sed -i -e 's:--sysroot=${STAGING_DIR_TARGET}::g' -e s:'--with-libtool-sysroot=${STAGING_DIR_TARGET}'::g \
195 -e 's|${DEBUG_PREFIX_MAP}||g' \
196 -e 's:${HOSTTOOLS_DIR}/::g' \
197 -e 's:${RECIPE_SYSROOT_NATIVE}::g' \
198 -e 's:${RECIPE_SYSROOT}::g' \
199 -e 's:${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}::g' \
200 ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_MAJMIN}${PYTHON_ABI}*/Makefile \
201 ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata*.py \
202 ${PKGD}/${bindir}/python${PYTHON_MAJMIN}-config
203
204 # Reformat _sysconfigdata after modifying it so that it remains
205 # reproducible
206 for c in ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata*.py; do
207 python3 ${WORKDIR}/reformat_sysconfig.py $c
208 done
209
210 # Recompile _sysconfigdata after modifying it
211 cd ${PKGD}
212 sysconfigfile=`find . -name _sysconfigdata_*.py`
213 ${STAGING_BINDIR_NATIVE}/python3-native/python3 \
214 -c "from py_compile import compile; compile('$sysconfigfile')"
215 ${STAGING_BINDIR_NATIVE}/python3-native/python3 \
216 -c "from py_compile import compile; compile('$sysconfigfile', optimize=1)"
217 ${STAGING_BINDIR_NATIVE}/python3-native/python3 \
218 -c "from py_compile import compile; compile('$sysconfigfile', optimize=2)"
219 cd -
220
221 mv ${PKGD}/${bindir}/python${PYTHON_MAJMIN}-config ${PKGD}/${bindir}/python${PYTHON_MAJMIN}-config-${MULTILIB_SUFFIX}
222
223 #Remove the unneeded copy of target sysconfig data
224 rm -rf ${PKGD}/${libdir}/python-sysconfigdata
225}
226
227# We want bytecode precompiled .py files (.pyc's) by default
228# but the user may set it on their own conf
229INCLUDE_PYCS ?= "1"
230
231python(){
232 import collections, json
233
234 filename = os.path.join(d.getVar('THISDIR'), 'python3', 'python3-manifest.json')
235 # This python changes the datastore based on the contents of a file, so mark
236 # that dependency.
237 bb.parse.mark_dependency(d, filename)
238
239 with open(filename) as manifest_file:
240 manifest_str = manifest_file.read()
241 json_start = manifest_str.find('# EOC') + 6
242 manifest_file.seek(json_start)
243 manifest_str = manifest_file.read()
244 python_manifest = json.loads(manifest_str, object_pairs_hook=collections.OrderedDict)
245
246 # First set RPROVIDES for -native case
247 # Hardcoded since it cant be python3-native-foo, should be python3-foo-native
248 pn = 'python3'
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600249 rprovides = (d.getVar('RPROVIDES') or "").split()
Andrew Geissler82c905d2020-04-13 13:39:40 -0500250
251 # ${PN}-misc-native is not in the manifest
252 rprovides.append(pn + '-misc-native')
253
254 for key in python_manifest:
255 pypackage = pn + '-' + key + '-native'
256 if pypackage not in rprovides:
257 rprovides.append(pypackage)
258
259 d.setVar('RPROVIDES_class-native', ' '.join(rprovides))
260
261 # Then work on the target
262 include_pycs = d.getVar('INCLUDE_PYCS')
263
264 packages = d.getVar('PACKAGES').split()
265 pn = d.getVar('PN')
266
267 newpackages=[]
268 for key in python_manifest:
269 pypackage = pn + '-' + key
270
271 if pypackage not in packages:
272 # We need to prepend, otherwise python-misc gets everything
273 # so we use a new variable
274 newpackages.append(pypackage)
275
276 # "Build" python's manifest FILES, RDEPENDS and SUMMARY
277 d.setVar('FILES_' + pypackage, '')
278 for value in python_manifest[key]['files']:
279 d.appendVar('FILES_' + pypackage, ' ' + value)
280
281 # Add cached files
282 if include_pycs == '1':
283 for value in python_manifest[key]['cached']:
284 d.appendVar('FILES_' + pypackage, ' ' + value)
285
286 for value in python_manifest[key]['rdepends']:
287 # Make it work with or without $PN
288 if '${PN}' in value:
289 value=value.split('-', 1)[1]
290 d.appendVar('RDEPENDS_' + pypackage, ' ' + pn + '-' + value)
291
292 for value in python_manifest[key].get('rrecommends', ()):
293 if '${PN}' in value:
294 value=value.split('-', 1)[1]
295 d.appendVar('RRECOMMENDS_' + pypackage, ' ' + pn + '-' + value)
296
297 d.setVar('SUMMARY_' + pypackage, python_manifest[key]['summary'])
298
299 # Prepending so to avoid python-misc getting everything
300 packages = newpackages + packages
301 d.setVar('PACKAGES', ' '.join(packages))
302 d.setVar('ALLOW_EMPTY_${PN}-modules', '1')
303 d.setVar('ALLOW_EMPTY_${PN}-pkgutil', '1')
304}
305
306# Files needed to create a new manifest
307
308do_create_manifest() {
309 # This task should be run with every new release of Python.
310 # We must ensure that PACKAGECONFIG enables everything when creating
311 # a new manifest, this is to base our new manifest on a complete
312 # native python build, containing all dependencies, otherwise the task
313 # wont be able to find the required files.
314 # e.g. BerkeleyDB is an optional build dependency so it may or may not
315 # be present, we must ensure it is.
316
317 cd ${WORKDIR}
318 # This needs to be executed by python-native and NOT by HOST's python
319 nativepython3 create_manifest3.py ${PYTHON_MAJMIN}
320 cp python3-manifest.json.new ${THISDIR}/python3/python3-manifest.json
321}
322
323# bitbake python -c create_manifest
Andrew Geissler82c905d2020-04-13 13:39:40 -0500324# Make sure we have native python ready when we create a new manifest
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600325addtask do_create_manifest after do_patch do_prepare_recipe_sysroot
Andrew Geissler82c905d2020-04-13 13:39:40 -0500326
327# manual dependency additions
328RRECOMMENDS_${PN}-core_append_class-nativesdk = " nativesdk-python3-modules"
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500329RRECOMMENDS_${PN}-crypt_append_class-target = " ${MLPREFIX}openssl ${MLPREFIX}ca-certificates"
330RRECOMMENDS_${PN}-crypt_append_class-nativesdk = " ${MLPREFIX}openssl ${MLPREFIX}ca-certificates"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500331
332# For historical reasons PN is empty and provided by python3-modules
333FILES_${PN} = ""
334RPROVIDES_${PN}-modules = "${PN}"
335
336FILES_${PN}-pydoc += "${bindir}/pydoc${PYTHON_MAJMIN} ${bindir}/pydoc3"
337FILES_${PN}-idle += "${bindir}/idle3 ${bindir}/idle${PYTHON_MAJMIN}"
338
339# provide python-pyvenv from python3-venv
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500340RPROVIDES_${PN}-venv += "${MLPREFIX}python3-pyvenv"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500341
342# package libpython3
343PACKAGES =+ "libpython3 libpython3-staticdev"
344FILES_libpython3 = "${libdir}/libpython*.so.*"
345FILES_libpython3-staticdev += "${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_MAJMIN}-*/libpython${PYTHON_MAJMIN}.a"
346INSANE_SKIP_${PN}-dev += "dev-elf"
347
348# catch all the rest (unsorted)
349PACKAGES += "${PN}-misc"
Andrew Geisslerd25ed322020-06-27 00:28:28 -0500350RDEPENDS_${PN}-misc += "\
351 ${PN}-core \
352 ${PN}-email \
353 ${PN}-codecs \
354 ${PN}-pydoc \
355 ${PN}-pickle \
356 ${PN}-audio \
357 ${PN}-numbers \
358"
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500359RDEPENDS_${PN}-modules_append_class-target = " ${MLPREFIX}python3-misc"
360RDEPENDS_${PN}-modules_append_class-nativesdk = " ${MLPREFIX}python3-misc"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500361FILES_${PN}-misc = "${libdir}/python${PYTHON_MAJMIN} ${libdir}/python${PYTHON_MAJMIN}/lib-dynload"
362
363# catch manpage
364PACKAGES += "${PN}-man"
365FILES_${PN}-man = "${datadir}/man"
366
367# See https://bugs.python.org/issue18748 and https://bugs.python.org/issue37395
368RDEPENDS_libpython3_append_libc-glibc = " libgcc"
Andrew Geissler475cb722020-07-10 16:00:51 -0500369RDEPENDS_${PN}-ctypes_append_libc-glibc = " ${MLPREFIX}ldconfig"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500370RDEPENDS_${PN}-ptest = "${PN}-modules ${PN}-tests unzip bzip2 libgcc tzdata-europe coreutils sed"
371RDEPENDS_${PN}-ptest_append_libc-glibc = " locale-base-tr-tr.iso-8859-9"
372RDEPENDS_${PN}-tkinter += "${@bb.utils.contains('PACKAGECONFIG', 'tk', 'tk tk-lib', '', d)}"
Andrew Geisslerd25ed322020-06-27 00:28:28 -0500373RDEPENDS_${PN}-idle += "${@bb.utils.contains('PACKAGECONFIG', 'tk', '${PN}-tkinter tcl', '', d)}"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500374RDEPENDS_${PN}-dev = ""
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500375RDEPENDS_${PN}-pydoc += "${PN}-io"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500376
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500377RDEPENDS_${PN}-tests_append_class-target = " ${MLPREFIX}bash"
378RDEPENDS_${PN}-tests_append_class-nativesdk = " ${MLPREFIX}bash"
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600379
380# Python's tests contain large numbers of files we don't need in the recipe sysroots
381SYSROOT_PREPROCESS_FUNCS += " py3_sysroot_cleanup"
382py3_sysroot_cleanup () {
383 rm -rf ${SYSROOT_DESTDIR}${libdir}/python${PYTHON_MAJMIN}/test
384}