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