blob: c8b63fee9d5f23f0459dabf9049eaf232a0a1921 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001SUMMARY = "The Python Programming Language"
2HOMEPAGE = "http://www.python.org"
3LICENSE = "PSFv2"
4SECTION = "devel/python"
5
6LIC_FILES_CHKSUM = "file://LICENSE;md5=e466242989bd33c1bd2b6a526a742498"
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://0002-Don-t-do-runtime-test-to-get-float-byte-order.patch \
23 file://0003-setup.py-pass-missing-libraries-to-Extension-for-mul.patch \
24 file://0001-Lib-sysconfig.py-fix-another-place-where-lib-is-hard.patch \
25 file://0001-Makefile-fix-Issue36464-parallel-build-race-problem.patch \
Brad Bishopf3f93bb2019-10-16 14:33:32 -040026 file://0001-bpo-36852-proper-detection-of-mips-architecture-for-.patch \
27 file://crosspythonpath.patch \
Brad Bishopc8f47122019-06-24 09:36:18 -040028 file://reformat_sysconfig.py \
Brad Bishop96ff1982019-08-19 13:50:42 -040029 file://0001-Use-FLAG_REF-always-for-interned-strings.patch \
Brad Bishopc68388fc2019-08-26 01:33:31 -040030 file://0001-test_locale.py-correct-the-test-output-format.patch \
Brad Bishopf3f93bb2019-10-16 14:33:32 -040031 file://0017-setup.py-do-not-report-missing-dependencies-for-disa.patch \
32 file://0001-bpo-34155-Dont-parse-domains-containing-GH-13079.patch \
Brad Bishopc342db32019-05-15 21:57:59 -040033 "
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 "
39SRC_URI_append_class-nativesdk = " \
40 file://0001-main.c-if-OEPYTHON3HOME-is-set-use-instead-of-PYTHON.patch \
41 "
42
Brad Bishop96ff1982019-08-19 13:50:42 -040043SRC_URI[md5sum] = "d33e4aae66097051c2eca45ee3604803"
44SRC_URI[sha256sum] = "fb799134b868199930b75f26678f18932214042639cd52b16da7fd134cd9b13f"
Brad Bishopc342db32019-05-15 21:57:59 -040045
46# exclude pre-releases for both python 2.x and 3.x
47UPSTREAM_CHECK_REGEX = "[Pp]ython-(?P<pver>\d+(\.\d+)+).tar"
48
49CVE_PRODUCT = "python"
50
51PYTHON_MAJMIN = "3.7"
52PYTHON_BINABI = "${PYTHON_MAJMIN}m"
53
54S = "${WORKDIR}/Python-${PV}"
55
56BBCLASSEXTEND = "native nativesdk"
57
58inherit autotools pkgconfig qemu ptest multilib_header update-alternatives
59
60MULTILIB_SUFFIX = "${@d.getVar('base_libdir',1).split('/')[-1]}"
61
62ALTERNATIVE_${PN}-dev = "python-config"
63ALTERNATIVE_LINK_NAME[python-config] = "${bindir}/python${PYTHON_BINABI}-config"
64ALTERNATIVE_TARGET[python-config] = "${bindir}/python${PYTHON_BINABI}-config-${MULTILIB_SUFFIX}"
65
66
Brad Bishopf3f93bb2019-10-16 14:33:32 -040067DEPENDS = "bzip2-replacement-native libffi bzip2 openssl sqlite3 zlib virtual/libintl xz virtual/crypt util-linux libtirpc libnsl2"
Brad Bishopc342db32019-05-15 21:57:59 -040068DEPENDS_append_class-target = " python3-native"
69DEPENDS_append_class-nativesdk = " python3-native"
70
71EXTRA_OECONF = " --without-ensurepip --enable-shared"
72EXTRA_OECONF_append_class-native = " --bindir=${bindir}/${PN}"
73
Brad Bishopf3fd2882019-06-21 08:06:37 -040074export CROSSPYTHONPATH="${STAGING_LIBDIR_NATIVE}/python${PYTHON_MAJMIN}/lib-dynload/"
Brad Bishopc342db32019-05-15 21:57:59 -040075
76EXTRANATIVEPATH += "python3-native"
77
78CACHED_CONFIGUREVARS = " \
79 ac_cv_file__dev_ptmx=yes \
80 ac_cv_file__dev_ptc=no \
81 ac_cv_working_tzset=yes \
82"
Brad Bishopf3fd2882019-06-21 08:06:37 -040083python() {
84 # PGO currently causes builds to not be reproducible, so disable it for
85 # now. See YOCTO #13407
86 if bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', True, False, d) and d.getVar('BUILD_REPRODUCIBLE_BINARIES') != '1':
87 d.setVar('PACKAGECONFIG_PGO', 'pgo')
88 else:
89 d.setVar('PACKAGECONFIG_PGO', '')
90}
Brad Bishopc342db32019-05-15 21:57:59 -040091
Brad Bishopf3f93bb2019-10-16 14:33:32 -040092PACKAGECONFIG_class-target ??= "readline ${PACKAGECONFIG_PGO} gdbm"
93PACKAGECONFIG_class-native ??= "readline gdbm"
94PACKAGECONFIG_class-nativesdk ??= "readline gdbm"
Brad Bishopc342db32019-05-15 21:57:59 -040095PACKAGECONFIG[readline] = ",,readline"
96# Use profile guided optimisation by running PyBench inside qemu-user
97PACKAGECONFIG[pgo] = "--enable-optimizations,,qemu-native"
98PACKAGECONFIG[tk] = ",,tk"
Brad Bishopf3f93bb2019-10-16 14:33:32 -040099PACKAGECONFIG[gdbm] = ",,gdbm"
100
101do_configure_prepend () {
102 mkdir -p ${B}/Modules
103 cat > ${B}/Modules/Setup.local << EOF
104*disabled*
105${@bb.utils.contains('PACKAGECONFIG', 'gdbm', '', '_gdbm _dbm', d)}
106${@bb.utils.contains('PACKAGECONFIG', 'readline', '', 'readline', d)}
107EOF
108}
Brad Bishopc342db32019-05-15 21:57:59 -0400109
110CPPFLAGS_append = " -I${STAGING_INCDIR}/ncursesw -I${STAGING_INCDIR}/uuid"
111
112EXTRA_OEMAKE = '\
113 STAGING_LIBDIR=${STAGING_LIBDIR} \
114 STAGING_INCDIR=${STAGING_INCDIR} \
115 LIB=${baselib} \
116'
117
118do_compile_prepend_class-target() {
119 if ${@bb.utils.contains('PACKAGECONFIG', 'pgo', 'true', 'false', d)}; then
120 qemu_binary="${@qemu_wrapper_cmdline(d, '${STAGING_DIR_TARGET}', ['${B}', '${STAGING_DIR_TARGET}/${base_libdir}'])}"
121 cat >pgo-wrapper <<EOF
122#!/bin/sh
123cd ${B}
124$qemu_binary "\$@"
125EOF
126 chmod +x pgo-wrapper
127 fi
128}
129
130do_install_prepend() {
131 ${WORKDIR}/check_build_completeness.py ${T}/log.do_compile
132}
133
134do_install_append_class-target() {
135 oe_multilib_header python${PYTHON_BINABI}/pyconfig.h
136}
137
138do_install_append_class-native() {
139 # Make sure we use /usr/bin/env python
140 for PYTHSCRIPT in `grep -rIl ${bindir}/${PN}/python ${D}${bindir}/${PN}`; do
141 sed -i -e '1s|^#!.*|#!/usr/bin/env python3|' $PYTHSCRIPT
142 done
143 # Add a symlink to the native Python so that scripts can just invoke
144 # "nativepython" and get the right one without needing absolute paths
145 # (these often end up too long for the #! parser in the kernel as the
146 # buffer is 128 bytes long).
147 ln -s python3-native/python3 ${D}${bindir}/nativepython3
148}
149
150do_install_append() {
151 mkdir -p ${D}${libdir}/python-sysconfigdata
152 sysconfigfile=`find ${D} -name _sysconfig*.py`
153 cp $sysconfigfile ${D}${libdir}/python-sysconfigdata/_sysconfigdata.py
154
155 sed -i \
156 -e "s,^ 'LIBDIR'.*, 'LIBDIR': '${STAGING_LIBDIR}'\,,g" \
157 -e "s,^ 'INCLUDEDIR'.*, 'INCLUDEDIR': '${STAGING_INCDIR}'\,,g" \
158 -e "s,^ 'CONFINCLUDEDIR'.*, 'CONFINCLUDEDIR': '${STAGING_INCDIR}'\,,g" \
159 -e "/^ 'INCLDIRSTOMAKE'/{N; s,/usr/include,${STAGING_INCDIR},g}" \
160 -e "/^ 'INCLUDEPY'/s,/usr/include,${STAGING_INCDIR},g" \
161 ${D}${libdir}/python-sysconfigdata/_sysconfigdata.py
162}
163
164do_install_append_class-nativesdk () {
165 create_wrapper ${D}${bindir}/python${PYTHON_MAJMIN} OEPYTHON3HOME='${prefix}' TERMINFO_DIRS='${sysconfdir}/terminfo:/etc/terminfo:/usr/share/terminfo:/usr/share/misc/terminfo:/lib/terminfo' PYTHONNOUSERSITE='1'
166}
167
168SSTATE_SCAN_FILES += "Makefile _sysconfigdata.py"
169PACKAGE_PREPROCESS_FUNCS += "py_package_preprocess"
170
171py_package_preprocess () {
172 # Remove references to buildmachine paths in target Makefile and _sysconfigdata
173 sed -i -e 's:--sysroot=${STAGING_DIR_TARGET}::g' -e s:'--with-libtool-sysroot=${STAGING_DIR_TARGET}'::g \
174 -e 's|${DEBUG_PREFIX_MAP}||g' \
175 -e 's:${HOSTTOOLS_DIR}/::g' \
176 -e 's:${RECIPE_SYSROOT_NATIVE}::g' \
177 -e 's:${RECIPE_SYSROOT}::g' \
178 -e 's:${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}::g' \
179 ${PKGD}/${prefix}/lib/python${PYTHON_MAJMIN}/config-${PYTHON_MAJMIN}${PYTHON_ABI}*/Makefile \
180 ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata*.py \
181 ${PKGD}/${bindir}/python${PYTHON_BINABI}-config
182
Brad Bishopc8f47122019-06-24 09:36:18 -0400183 # Reformat _sysconfigdata after modifying it so that it remains
184 # reproducible
185 for c in ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata*.py; do
186 python3 ${WORKDIR}/reformat_sysconfig.py $c
187 done
188
Brad Bishopc342db32019-05-15 21:57:59 -0400189 # Recompile _sysconfigdata after modifying it
190 cd ${PKGD}
191 sysconfigfile=`find . -name _sysconfigdata_*.py`
192 ${STAGING_BINDIR_NATIVE}/python3-native/python3 \
193 -c "from py_compile import compile; compile('$sysconfigfile')"
194 ${STAGING_BINDIR_NATIVE}/python3-native/python3 \
195 -c "from py_compile import compile; compile('$sysconfigfile', optimize=1)"
196 ${STAGING_BINDIR_NATIVE}/python3-native/python3 \
197 -c "from py_compile import compile; compile('$sysconfigfile', optimize=2)"
198 cd -
199
200 mv ${PKGD}/${bindir}/python${PYTHON_BINABI}-config ${PKGD}/${bindir}/python${PYTHON_BINABI}-config-${MULTILIB_SUFFIX}
201
202 #Remove the unneeded copy of target sysconfig data
203 rm -rf ${PKGD}/${libdir}/python-sysconfigdata
204}
205
206# We want bytecode precompiled .py files (.pyc's) by default
207# but the user may set it on their own conf
208INCLUDE_PYCS ?= "1"
209
210python(){
211 import collections, json
212
213 filename = os.path.join(d.getVar('THISDIR'), 'python3', 'python3-manifest.json')
214 # This python changes the datastore based on the contents of a file, so mark
215 # that dependency.
216 bb.parse.mark_dependency(d, filename)
217
218 with open(filename) as manifest_file:
219 manifest_str = manifest_file.read()
220 json_start = manifest_str.find('# EOC') + 6
221 manifest_file.seek(json_start)
222 manifest_str = manifest_file.read()
223 python_manifest = json.loads(manifest_str, object_pairs_hook=collections.OrderedDict)
224
225 # First set RPROVIDES for -native case
226 # Hardcoded since it cant be python3-native-foo, should be python3-foo-native
227 pn = 'python3'
228 rprovides = d.getVar('RPROVIDES').split()
229
230 for key in python_manifest:
231 pypackage = pn + '-' + key + '-native'
232 if pypackage not in rprovides:
233 rprovides.append(pypackage)
234
235 d.setVar('RPROVIDES_class-native', ' '.join(rprovides))
236
237 # Then work on the target
238 include_pycs = d.getVar('INCLUDE_PYCS')
239
240 packages = d.getVar('PACKAGES').split()
241 pn = d.getVar('PN')
242
243 newpackages=[]
244 for key in python_manifest:
Brad Bishop08902b02019-08-20 09:16:51 -0400245 pypackage = pn + '-' + key
Brad Bishopc342db32019-05-15 21:57:59 -0400246
247 if pypackage not in packages:
248 # We need to prepend, otherwise python-misc gets everything
249 # so we use a new variable
250 newpackages.append(pypackage)
251
252 # "Build" python's manifest FILES, RDEPENDS and SUMMARY
253 d.setVar('FILES_' + pypackage, '')
254 for value in python_manifest[key]['files']:
255 d.appendVar('FILES_' + pypackage, ' ' + value)
256
257 # Add cached files
258 if include_pycs == '1':
259 for value in python_manifest[key]['cached']:
260 d.appendVar('FILES_' + pypackage, ' ' + value)
261
262 for value in python_manifest[key]['rdepends']:
263 # Make it work with or without $PN
264 if '${PN}' in value:
Brad Bishop08902b02019-08-20 09:16:51 -0400265 value=value.split('-', 1)[1]
Brad Bishopc342db32019-05-15 21:57:59 -0400266 d.appendVar('RDEPENDS_' + pypackage, ' ' + pn + '-' + value)
Brad Bishop08902b02019-08-20 09:16:51 -0400267
268 for value in python_manifest[key].get('rrecommends', ()):
269 if '${PN}' in value:
270 value=value.split('-', 1)[1]
271 d.appendVar('RRECOMMENDS_' + pypackage, ' ' + pn + '-' + value)
272
Brad Bishopc342db32019-05-15 21:57:59 -0400273 d.setVar('SUMMARY_' + pypackage, python_manifest[key]['summary'])
274
275 # Prepending so to avoid python-misc getting everything
276 packages = newpackages + packages
277 d.setVar('PACKAGES', ' '.join(packages))
278 d.setVar('ALLOW_EMPTY_${PN}-modules', '1')
279}
280
281# Files needed to create a new manifest
282
283do_create_manifest() {
284 # This task should be run with every new release of Python.
285 # We must ensure that PACKAGECONFIG enables everything when creating
286 # a new manifest, this is to base our new manifest on a complete
287 # native python build, containing all dependencies, otherwise the task
288 # wont be able to find the required files.
289 # e.g. BerkeleyDB is an optional build dependency so it may or may not
290 # be present, we must ensure it is.
291
292 cd ${WORKDIR}
293 # This needs to be executed by python-native and NOT by HOST's python
294 nativepython3 create_manifest3.py ${PYTHON_MAJMIN}
295 cp python3-manifest.json.new ${THISDIR}/python3/python3-manifest.json
296}
297
298# bitbake python -c create_manifest
299addtask do_create_manifest
300
301# Make sure we have native python ready when we create a new manifest
302do_create_manifest[depends] += "${PN}:do_prepare_recipe_sysroot"
303do_create_manifest[depends] += "${PN}:do_patch"
304
305# manual dependency additions
306RPROVIDES_${PN}-modules = "${PN}"
307RRECOMMENDS_${PN}-core_append_class-nativesdk = " nativesdk-python3-modules"
308RRECOMMENDS_${PN}-crypt_append_class-target = " openssl ca-certificates"
309RRECOMMENDS_${PN}-crypt_append_class-nativesdk = " openssl ca-certificates"
310
311FILES_${PN}-pydoc += "${bindir}/pydoc${PYTHON_MAJMIN} ${bindir}/pydoc3"
312FILES_${PN}-idle += "${bindir}/idle3 ${bindir}/idle${PYTHON_MAJMIN}"
313
314# provide python-pyvenv from python3-venv
315RPROVIDES_${PN}-venv += "python3-pyvenv"
316
317# package libpython3
318PACKAGES =+ "libpython3 libpython3-staticdev"
319FILES_libpython3 = "${libdir}/libpython*.so.*"
320FILES_libpython3-staticdev += "${prefix}/lib/python${PYTHON_MAJMIN}/config-${PYTHON_BINABI}-*/libpython${PYTHON_BINABI}.a"
321INSANE_SKIP_${PN}-dev += "dev-elf"
322
323# catch all the rest (unsorted)
324PACKAGES += "${PN}-misc"
Brad Bishop79641f22019-09-10 07:20:22 -0400325RDEPENDS_${PN}-misc += "python3-core python3-email python3-codecs python3-pydoc python3-pickle"
Brad Bishopc342db32019-05-15 21:57:59 -0400326RDEPENDS_${PN}-modules_append_class-target = " python3-misc"
327RDEPENDS_${PN}-modules_append_class-nativesdk = " python3-misc"
328FILES_${PN}-misc = "${libdir}/python${PYTHON_MAJMIN} ${libdir}/python${PYTHON_MAJMIN}/lib-dynload"
329
330# catch manpage
331PACKAGES += "${PN}-man"
332FILES_${PN}-man = "${datadir}/man"
333
334RDEPENDS_${PN}-ptest = "${PN}-modules ${PN}-tests unzip bzip2 libgcc tzdata-europe coreutils sed"
335RDEPENDS_${PN}-ptest_append_libc-glibc = " locale-base-tr-tr.iso-8859-9"
Brad Bishop00e122a2019-10-05 11:10:57 -0400336RDEPENDS_${PN}-tkinter += "${@bb.utils.contains('PACKAGECONFIG', 'tk', 'tk tk-lib', '', d)}"
Brad Bishopc342db32019-05-15 21:57:59 -0400337RDEPENDS_${PN}-dev = ""
338