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