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