blob: 7e0f35ce411c58da02a4ec77f90364edf7470d24 [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
6LIC_FILES_CHKSUM = "file://LICENSE;md5=203a6dbc802ee896020a47161e759642"
7
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 \
14 file://cgi_py.patch \
15 file://0001-Do-not-add-usr-lib-termcap-to-linker-flags-to-avoid-.patch \
16 ${@bb.utils.contains('PACKAGECONFIG', 'tk', '', 'file://avoid_warning_about_tkinter.patch', d)} \
17 file://0001-Do-not-use-the-shell-version-of-python-config-that-w.patch \
18 file://python-config.patch \
19 file://0001-Makefile.pre-use-qemu-wrapper-when-gathering-profile.patch \
20 file://0001-Do-not-hardcode-lib-as-location-for-site-packages-an.patch \
21 file://0001-python3-use-cc_basename-to-replace-CC-for-checking-c.patch \
22 file://0001-Lib-sysconfig.py-fix-another-place-where-lib-is-hard.patch \
23 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 \
26 file://reformat_sysconfig.py \
27 file://0001-Use-FLAG_REF-always-for-interned-strings.patch \
28 file://0001-test_locale.py-correct-the-test-output-format.patch \
29 file://0017-setup.py-do-not-report-missing-dependencies-for-disa.patch \
30 file://0001-setup.py-pass-missing-libraries-to-Extension-for-mul.patch \
31 file://0001-Makefile-do-not-compile-.pyc-in-parallel.patch \
32 file://0001-configure.ac-fix-LIBPL.patch \
33 file://0001-python3-Do-not-hardcode-lib-for-distutils.patch \
34 file://0020-configure.ac-setup.py-do-not-add-a-curses-include-pa.patch \
Andrew Geisslerb7d28612020-07-24 16:15:54 -050035 file://0001-configure.ac-define-a-path-for-profile-data.patch \
Andrew Geissler82c905d2020-04-13 13:39:40 -050036 "
37
38SRC_URI_append_class-native = " \
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 "
43
Andrew Geissler4ed12e12020-06-05 18:00:41 -050044SRC_URI[md5sum] = "3000cf50aaa413052aef82fd2122ca78"
45SRC_URI[sha256sum] = "dfab5ec723c218082fe3d5d7ae17ecbdebffa9a1aea4d64aa3a2ecdd2e795864"
Andrew Geissler82c905d2020-04-13 13:39:40 -050046
47# exclude pre-releases for both python 2.x and 3.x
48UPSTREAM_CHECK_REGEX = "[Pp]ython-(?P<pver>\d+(\.\d+)+).tar"
49
50CVE_PRODUCT = "python"
51
52# This is not exploitable when glibc has CVE-2016-10739 fixed.
53CVE_CHECK_WHITELIST += "CVE-2019-18348"
54
55PYTHON_MAJMIN = "3.8"
56
57S = "${WORKDIR}/Python-${PV}"
58
59BBCLASSEXTEND = "native nativesdk"
60
61inherit autotools pkgconfig qemu ptest multilib_header update-alternatives
62
63MULTILIB_SUFFIX = "${@d.getVar('base_libdir',1).split('/')[-1]}"
64
65ALTERNATIVE_${PN}-dev = "python3-config"
66ALTERNATIVE_LINK_NAME[python3-config] = "${bindir}/python${PYTHON_MAJMIN}-config"
67ALTERNATIVE_TARGET[python3-config] = "${bindir}/python${PYTHON_MAJMIN}-config-${MULTILIB_SUFFIX}"
68
69
70DEPENDS = "bzip2-replacement-native libffi bzip2 openssl sqlite3 zlib virtual/libintl xz virtual/crypt util-linux libtirpc libnsl2"
71DEPENDS_append_class-target = " python3-native"
72DEPENDS_append_class-nativesdk = " python3-native"
73
74EXTRA_OECONF = " --without-ensurepip --enable-shared"
75EXTRA_OECONF_append_class-native = " --bindir=${bindir}/${PN}"
76
77export CROSSPYTHONPATH="${STAGING_LIBDIR_NATIVE}/python${PYTHON_MAJMIN}/lib-dynload/"
78
79EXTRANATIVEPATH += "python3-native"
80
81CACHED_CONFIGUREVARS = " \
82 ac_cv_file__dev_ptmx=yes \
83 ac_cv_file__dev_ptc=no \
84 ac_cv_working_tzset=yes \
85"
Andrew Geisslerd25ed322020-06-27 00:28:28 -050086
87def possibly_include_pgo(d):
Andrew Geissler82c905d2020-04-13 13:39:40 -050088 # PGO currently causes builds to not be reproducible, so disable it for
89 # now. See YOCTO #13407
90 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 -050091 return 'pgo'
92
93 return ''
Andrew Geissler82c905d2020-04-13 13:39:40 -050094
Andrew Geisslerd25ed322020-06-27 00:28:28 -050095PACKAGECONFIG_class-target ??= "readline ${@possibly_include_pgo(d)} gdbm"
Andrew Geissler82c905d2020-04-13 13:39:40 -050096PACKAGECONFIG_class-native ??= "readline gdbm"
97PACKAGECONFIG_class-nativesdk ??= "readline gdbm"
98PACKAGECONFIG[readline] = ",,readline"
99# Use profile guided optimisation by running PyBench inside qemu-user
100PACKAGECONFIG[pgo] = "--enable-optimizations,,qemu-native"
101PACKAGECONFIG[tk] = ",,tk"
102PACKAGECONFIG[gdbm] = ",,gdbm"
103
104do_configure_prepend () {
105 mkdir -p ${B}/Modules
106 cat > ${B}/Modules/Setup.local << EOF
107*disabled*
108${@bb.utils.contains('PACKAGECONFIG', 'gdbm', '', '_gdbm _dbm', d)}
109${@bb.utils.contains('PACKAGECONFIG', 'readline', '', 'readline', d)}
110EOF
111}
112
113CPPFLAGS_append = " -I${STAGING_INCDIR}/ncursesw -I${STAGING_INCDIR}/uuid"
114
115EXTRA_OEMAKE = '\
116 STAGING_LIBDIR=${STAGING_LIBDIR} \
117 STAGING_INCDIR=${STAGING_INCDIR} \
118 LIB=${baselib} \
119'
120
121do_compile_prepend_class-target() {
122 if ${@bb.utils.contains('PACKAGECONFIG', 'pgo', 'true', 'false', d)}; then
123 qemu_binary="${@qemu_wrapper_cmdline(d, '${STAGING_DIR_TARGET}', ['${B}', '${STAGING_DIR_TARGET}/${base_libdir}'])}"
124 cat >pgo-wrapper <<EOF
125#!/bin/sh
126cd ${B}
127$qemu_binary "\$@"
128EOF
129 chmod +x pgo-wrapper
130 fi
131}
132
133do_install_prepend() {
134 ${WORKDIR}/check_build_completeness.py ${T}/log.do_compile
135}
136
137do_install_append_class-target() {
138 oe_multilib_header python${PYTHON_MAJMIN}/pyconfig.h
139}
140
141do_install_append_class-native() {
142 # Make sure we use /usr/bin/env python
143 for PYTHSCRIPT in `grep -rIl ${bindir}/${PN}/python ${D}${bindir}/${PN}`; do
144 sed -i -e '1s|^#!.*|#!/usr/bin/env python3|' $PYTHSCRIPT
145 done
146 # Add a symlink to the native Python so that scripts can just invoke
147 # "nativepython" and get the right one without needing absolute paths
148 # (these often end up too long for the #! parser in the kernel as the
149 # buffer is 128 bytes long).
150 ln -s python3-native/python3 ${D}${bindir}/nativepython3
151}
152
153do_install_append() {
154 mkdir -p ${D}${libdir}/python-sysconfigdata
155 sysconfigfile=`find ${D} -name _sysconfig*.py`
156 cp $sysconfigfile ${D}${libdir}/python-sysconfigdata/_sysconfigdata.py
157
158 sed -i \
159 -e "s,^ 'LIBDIR'.*, 'LIBDIR': '${STAGING_LIBDIR}'\,,g" \
160 -e "s,^ 'INCLUDEDIR'.*, 'INCLUDEDIR': '${STAGING_INCDIR}'\,,g" \
161 -e "s,^ 'CONFINCLUDEDIR'.*, 'CONFINCLUDEDIR': '${STAGING_INCDIR}'\,,g" \
162 -e "/^ 'INCLDIRSTOMAKE'/{N; s,/usr/include,${STAGING_INCDIR},g}" \
163 -e "/^ 'INCLUDEPY'/s,/usr/include,${STAGING_INCDIR},g" \
164 ${D}${libdir}/python-sysconfigdata/_sysconfigdata.py
165}
166
167do_install_append_class-nativesdk () {
168 create_wrapper ${D}${bindir}/python${PYTHON_MAJMIN} TERMINFO_DIRS='${sysconfdir}/terminfo:/etc/terminfo:/usr/share/terminfo:/usr/share/misc/terminfo:/lib/terminfo' PYTHONNOUSERSITE='1'
169}
170
171SSTATE_SCAN_FILES += "Makefile _sysconfigdata.py"
172PACKAGE_PREPROCESS_FUNCS += "py_package_preprocess"
173
174py_package_preprocess () {
175 # Remove references to buildmachine paths in target Makefile and _sysconfigdata
176 sed -i -e 's:--sysroot=${STAGING_DIR_TARGET}::g' -e s:'--with-libtool-sysroot=${STAGING_DIR_TARGET}'::g \
177 -e 's|${DEBUG_PREFIX_MAP}||g' \
178 -e 's:${HOSTTOOLS_DIR}/::g' \
179 -e 's:${RECIPE_SYSROOT_NATIVE}::g' \
180 -e 's:${RECIPE_SYSROOT}::g' \
181 -e 's:${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}::g' \
182 ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_MAJMIN}${PYTHON_ABI}*/Makefile \
183 ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata*.py \
184 ${PKGD}/${bindir}/python${PYTHON_MAJMIN}-config
185
186 # Reformat _sysconfigdata after modifying it so that it remains
187 # reproducible
188 for c in ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata*.py; do
189 python3 ${WORKDIR}/reformat_sysconfig.py $c
190 done
191
192 # Recompile _sysconfigdata after modifying it
193 cd ${PKGD}
194 sysconfigfile=`find . -name _sysconfigdata_*.py`
195 ${STAGING_BINDIR_NATIVE}/python3-native/python3 \
196 -c "from py_compile import compile; compile('$sysconfigfile')"
197 ${STAGING_BINDIR_NATIVE}/python3-native/python3 \
198 -c "from py_compile import compile; compile('$sysconfigfile', optimize=1)"
199 ${STAGING_BINDIR_NATIVE}/python3-native/python3 \
200 -c "from py_compile import compile; compile('$sysconfigfile', optimize=2)"
201 cd -
202
203 mv ${PKGD}/${bindir}/python${PYTHON_MAJMIN}-config ${PKGD}/${bindir}/python${PYTHON_MAJMIN}-config-${MULTILIB_SUFFIX}
204
205 #Remove the unneeded copy of target sysconfig data
206 rm -rf ${PKGD}/${libdir}/python-sysconfigdata
207}
208
209# We want bytecode precompiled .py files (.pyc's) by default
210# but the user may set it on their own conf
211INCLUDE_PYCS ?= "1"
212
213python(){
214 import collections, json
215
216 filename = os.path.join(d.getVar('THISDIR'), 'python3', 'python3-manifest.json')
217 # This python changes the datastore based on the contents of a file, so mark
218 # that dependency.
219 bb.parse.mark_dependency(d, filename)
220
221 with open(filename) as manifest_file:
222 manifest_str = manifest_file.read()
223 json_start = manifest_str.find('# EOC') + 6
224 manifest_file.seek(json_start)
225 manifest_str = manifest_file.read()
226 python_manifest = json.loads(manifest_str, object_pairs_hook=collections.OrderedDict)
227
228 # First set RPROVIDES for -native case
229 # Hardcoded since it cant be python3-native-foo, should be python3-foo-native
230 pn = 'python3'
231 rprovides = d.getVar('RPROVIDES').split()
232
233 # ${PN}-misc-native is not in the manifest
234 rprovides.append(pn + '-misc-native')
235
236 for key in python_manifest:
237 pypackage = pn + '-' + key + '-native'
238 if pypackage not in rprovides:
239 rprovides.append(pypackage)
240
241 d.setVar('RPROVIDES_class-native', ' '.join(rprovides))
242
243 # Then work on the target
244 include_pycs = d.getVar('INCLUDE_PYCS')
245
246 packages = d.getVar('PACKAGES').split()
247 pn = d.getVar('PN')
248
249 newpackages=[]
250 for key in python_manifest:
251 pypackage = pn + '-' + key
252
253 if pypackage not in packages:
254 # We need to prepend, otherwise python-misc gets everything
255 # so we use a new variable
256 newpackages.append(pypackage)
257
258 # "Build" python's manifest FILES, RDEPENDS and SUMMARY
259 d.setVar('FILES_' + pypackage, '')
260 for value in python_manifest[key]['files']:
261 d.appendVar('FILES_' + pypackage, ' ' + value)
262
263 # Add cached files
264 if include_pycs == '1':
265 for value in python_manifest[key]['cached']:
266 d.appendVar('FILES_' + pypackage, ' ' + value)
267
268 for value in python_manifest[key]['rdepends']:
269 # Make it work with or without $PN
270 if '${PN}' in value:
271 value=value.split('-', 1)[1]
272 d.appendVar('RDEPENDS_' + pypackage, ' ' + pn + '-' + value)
273
274 for value in python_manifest[key].get('rrecommends', ()):
275 if '${PN}' in value:
276 value=value.split('-', 1)[1]
277 d.appendVar('RRECOMMENDS_' + pypackage, ' ' + pn + '-' + value)
278
279 d.setVar('SUMMARY_' + pypackage, python_manifest[key]['summary'])
280
281 # Prepending so to avoid python-misc getting everything
282 packages = newpackages + packages
283 d.setVar('PACKAGES', ' '.join(packages))
284 d.setVar('ALLOW_EMPTY_${PN}-modules', '1')
285 d.setVar('ALLOW_EMPTY_${PN}-pkgutil', '1')
286}
287
288# Files needed to create a new manifest
289
290do_create_manifest() {
291 # This task should be run with every new release of Python.
292 # We must ensure that PACKAGECONFIG enables everything when creating
293 # a new manifest, this is to base our new manifest on a complete
294 # native python build, containing all dependencies, otherwise the task
295 # wont be able to find the required files.
296 # e.g. BerkeleyDB is an optional build dependency so it may or may not
297 # be present, we must ensure it is.
298
299 cd ${WORKDIR}
300 # This needs to be executed by python-native and NOT by HOST's python
301 nativepython3 create_manifest3.py ${PYTHON_MAJMIN}
302 cp python3-manifest.json.new ${THISDIR}/python3/python3-manifest.json
303}
304
305# bitbake python -c create_manifest
306addtask do_create_manifest
307
308# Make sure we have native python ready when we create a new manifest
309do_create_manifest[depends] += "${PN}:do_prepare_recipe_sysroot"
310do_create_manifest[depends] += "${PN}:do_patch"
311
312# manual dependency additions
313RRECOMMENDS_${PN}-core_append_class-nativesdk = " nativesdk-python3-modules"
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500314RRECOMMENDS_${PN}-crypt_append_class-target = " ${MLPREFIX}openssl ${MLPREFIX}ca-certificates"
315RRECOMMENDS_${PN}-crypt_append_class-nativesdk = " ${MLPREFIX}openssl ${MLPREFIX}ca-certificates"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500316
317# For historical reasons PN is empty and provided by python3-modules
318FILES_${PN} = ""
319RPROVIDES_${PN}-modules = "${PN}"
320
321FILES_${PN}-pydoc += "${bindir}/pydoc${PYTHON_MAJMIN} ${bindir}/pydoc3"
322FILES_${PN}-idle += "${bindir}/idle3 ${bindir}/idle${PYTHON_MAJMIN}"
323
324# provide python-pyvenv from python3-venv
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500325RPROVIDES_${PN}-venv += "${MLPREFIX}python3-pyvenv"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500326
327# package libpython3
328PACKAGES =+ "libpython3 libpython3-staticdev"
329FILES_libpython3 = "${libdir}/libpython*.so.*"
330FILES_libpython3-staticdev += "${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_MAJMIN}-*/libpython${PYTHON_MAJMIN}.a"
331INSANE_SKIP_${PN}-dev += "dev-elf"
332
333# catch all the rest (unsorted)
334PACKAGES += "${PN}-misc"
Andrew Geisslerd25ed322020-06-27 00:28:28 -0500335RDEPENDS_${PN}-misc += "\
336 ${PN}-core \
337 ${PN}-email \
338 ${PN}-codecs \
339 ${PN}-pydoc \
340 ${PN}-pickle \
341 ${PN}-audio \
342 ${PN}-numbers \
343"
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500344RDEPENDS_${PN}-modules_append_class-target = " ${MLPREFIX}python3-misc"
345RDEPENDS_${PN}-modules_append_class-nativesdk = " ${MLPREFIX}python3-misc"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500346FILES_${PN}-misc = "${libdir}/python${PYTHON_MAJMIN} ${libdir}/python${PYTHON_MAJMIN}/lib-dynload"
347
348# catch manpage
349PACKAGES += "${PN}-man"
350FILES_${PN}-man = "${datadir}/man"
351
352# See https://bugs.python.org/issue18748 and https://bugs.python.org/issue37395
353RDEPENDS_libpython3_append_libc-glibc = " libgcc"
Andrew Geissler475cb722020-07-10 16:00:51 -0500354RDEPENDS_${PN}-ctypes_append_libc-glibc = " ${MLPREFIX}ldconfig"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500355RDEPENDS_${PN}-ptest = "${PN}-modules ${PN}-tests unzip bzip2 libgcc tzdata-europe coreutils sed"
356RDEPENDS_${PN}-ptest_append_libc-glibc = " locale-base-tr-tr.iso-8859-9"
357RDEPENDS_${PN}-tkinter += "${@bb.utils.contains('PACKAGECONFIG', 'tk', 'tk tk-lib', '', d)}"
Andrew Geisslerd25ed322020-06-27 00:28:28 -0500358RDEPENDS_${PN}-idle += "${@bb.utils.contains('PACKAGECONFIG', 'tk', '${PN}-tkinter tcl', '', d)}"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500359RDEPENDS_${PN}-dev = ""
360
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500361RDEPENDS_${PN}-tests_append_class-target = " ${MLPREFIX}bash"
362RDEPENDS_${PN}-tests_append_class-nativesdk = " ${MLPREFIX}bash"