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