blob: 31f8eada11cbf213fa1a3c2579a4c809bc7e742e [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001require recipes-devtools/python/python3.inc
2
3DEPENDS = "python3-native libffi bzip2 gdbm openssl \
4 sqlite3 zlib virtual/libintl xz qemu-native \
5 qemu-helper-native virtual/crypt"
6
7DISTRO_SRC_URI ?= "file://sitecustomize.py"
8DISTRO_SRC_URI_linuxstdbase = ""
9SRC_URI = "http://www.python.org/ftp/python/${PV}/Python-${PV}.tar.xz \
10file://python-config.patch \
11file://030-fixup-include-dirs.patch \
12file://070-dont-clean-ipkg-install.patch \
13file://080-distutils-dont_adjust_files.patch \
14file://130-readline-setup.patch \
15file://150-fix-setupterm.patch \
16file://0001-h2py-Fix-issue-13032-where-it-fails-with-UnicodeDeco.patch \
17file://tweak-MULTIARCH-for-powerpc-linux-gnuspe.patch \
18file://support_SOURCE_DATE_EPOCH_in_py_compile.patch \
19${DISTRO_SRC_URI} \
20"
21
22SRC_URI += "\
23 file://03-fix-tkinter-detection.patch \
24 file://avoid_warning_about_tkinter.patch \
25 file://cgi_py.patch \
26 file://host_include_contamination.patch \
27 file://python-3.3-multilib.patch \
28 file://sysroot-include-headers.patch \
29 file://unixccompiler.patch \
30 file://avoid-ncursesw-include-path.patch \
31 file://python3-use-CROSSPYTHONPATH-for-PYTHON_FOR_BUILD.patch \
32 file://sysconfig.py-add-_PYTHON_PROJECT_SRC.patch \
33 file://setup.py-check-cross_compiling-when-get-FLAGS.patch \
34 file://configure.ac-fix-LIBPL.patch \
35 file://0001-Issue-21272-Use-_sysconfigdata.py-to-initialize-dist.patch \
36 file://pass-missing-libraries-to-Extension-for-mul.patch \
37 file://Use-correct-CFLAGS-for-extensions-when-cross-compili.patch \
38 file://0002-Makefile-add-target-to-split-profile-generation.patch \
39 file://float-endian.patch \
40 file://ftplib.patch \
41 file://signal.patch \
42 file://0001-Issue-28043-SSLContext-has-improved-default-settings.patch \
43 file://0002-bpo-29136-Add-TLS-1.3-cipher-suites-and-OP_NO_TLSv1_.patch \
44 file://0003-bpo-32947-Fixes-for-TLS-1.3-and-OpenSSL-1.1.1-GH-876.patch \
45 file://0004-bpo-33570-TLS-1.3-ciphers-for-OpenSSL-1.1.1-GH-6976.patch \
46 file://0005-bpo-30714-ALPN-changes-for-OpenSSL-1.1.0f-2305.patch \
47 file://run-ptest \
48 "
49
50inherit multilib_header python3native update-alternatives qemu ptest
51
52MULTILIB_SUFFIX = "${@d.getVar('base_libdir',1).split('/')[-1]}"
53
54ALTERNATIVE_${PN}-dev = "python-config"
55ALTERNATIVE_LINK_NAME[python-config] = "${bindir}/python${PYTHON_BINABI}-config"
56ALTERNATIVE_TARGET[python-config] = "${bindir}/python${PYTHON_BINABI}-config-${MULTILIB_SUFFIX}"
57
58CONFIGUREOPTS += " --with-system-ffi "
59
60CACHED_CONFIGUREVARS = "ac_cv_have_chflags=no \
61 ac_cv_have_lchflags=no \
62 ac_cv_have_long_long_format=yes \
63 ac_cv_buggy_getaddrinfo=no \
64 ac_cv_file__dev_ptmx=yes \
65 ac_cv_file__dev_ptc=no \
66"
67
68TARGET_CC_ARCH += "-DNDEBUG -fno-inline"
69SDK_CC_ARCH += "-DNDEBUG -fno-inline"
70EXTRA_OEMAKE += "CROSS_COMPILE=yes"
71EXTRA_OECONF += "CROSSPYTHONPATH=${STAGING_LIBDIR_NATIVE}/python${PYTHON_MAJMIN}/lib-dynload/ --without-ensurepip"
72
73PYTHON3_PROFILE_TASK ?= "./python -m test.regrtest --pgo test_grammar test_opcodes test_dict test_builtin test_exceptions test_types test_support || true"
74
75export CROSS_COMPILE = "${TARGET_PREFIX}"
76export CCSHARED = "-fPIC"
77
78# Fix cross compilation of different modules
79export CROSSPYTHONPATH = "${STAGING_LIBDIR_NATIVE}/python${PYTHON_MAJMIN}/lib-dynload/:${B}/build/lib.linux-${TARGET_ARCH}-${PYTHON_MAJMIN}:${S}/Lib:${S}/Lib/plat-linux"
80
81PACKAGECONFIG ??= "readline ${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'pgo', '', d)}"
82PACKAGECONFIG[readline] = ",,readline"
83# Use profile guided optimisation by running PyBench inside qemu-user
84PACKAGECONFIG[pgo] = "--enable-optimizations"
85
86do_configure_append() {
87 rm -f ${S}/Makefile.orig
88}
89
90run_make() {
91 oe_runmake PGEN=${STAGING_BINDIR_NATIVE}/python3-native/pgen \
92 HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python3-native/python3 \
93 STAGING_LIBDIR=${STAGING_LIBDIR} \
94 STAGING_INCDIR=${STAGING_INCDIR} \
95 STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \
96 LIB=${baselib} \
97 ARCH=${TARGET_ARCH} \
98 OPT="${CFLAGS}" \
99 "$@"
100}
101
102do_compile() {
103 # regenerate platform specific files, because they depend on system headers
104 cd ${S}/Lib/plat-linux*
105 include=${STAGING_INCDIR} ${STAGING_BINDIR_NATIVE}/python3-native/python3 \
106 ${S}/Tools/scripts/h2py.py -i '(u_long)' \
107 ${STAGING_INCDIR}/dlfcn.h \
108 ${STAGING_INCDIR}/linux/cdrom.h \
109 ${STAGING_INCDIR}/netinet/in.h \
110 ${STAGING_INCDIR}/sys/types.h
111 sed -e 's,${STAGING_DIR_HOST},,g' -i *.py
112 cd -
113
114 # remove any bogus LD_LIBRARY_PATH
115 sed -i -e s,RUNSHARED=.*,RUNSHARED=, Makefile
116
117 if [ ! -f Makefile.orig ]; then
118 install -m 0644 Makefile Makefile.orig
119 fi
120 sed -i -e 's,^CONFIGURE_LDFLAGS=.*,CONFIGURE_LDFLAGS=-L. -L${STAGING_LIBDIR},g' \
121 -e 's,libdir=${libdir},libdir=${STAGING_LIBDIR},g' \
122 -e 's,libexecdir=${libexecdir},libexecdir=${STAGING_DIR_HOST}${libexecdir},g' \
123 -e 's,^LIBDIR=.*,LIBDIR=${STAGING_LIBDIR},g' \
124 -e 's,includedir=${includedir},includedir=${STAGING_INCDIR},g' \
125 -e 's,^INCLUDEDIR=.*,INCLUDE=${STAGING_INCDIR},g' \
126 -e 's,^CONFINCLUDEDIR=.*,CONFINCLUDE=${STAGING_INCDIR},g' \
127 Makefile
128 # save copy of it now, because if we do it in do_install and
129 # then call do_install twice we get Makefile.orig == Makefile.sysroot
130 install -m 0644 Makefile Makefile.sysroot
131
132 if ${@bb.utils.contains('PACKAGECONFIG', 'pgo', 'true', 'false', d)}; then
133 run_make profile-opt
134 qemu_binary="${@qemu_wrapper_cmdline(d, '${STAGING_DIR_TARGET}', ['${B}', '${STAGING_DIR_TARGET}/${base_libdir}'])}"
135 cat >pgo-wrapper <<EOF
136#!/bin/sh
137cd ${B}
138$qemu_binary "\$@"
139EOF
140 chmod +x pgo-wrapper
141 bbnote Gathering profiling data
142 ./pgo-wrapper ${PYTHON3_PROFILE_TASK}
143 bbnote Profiling data gathered, rebuilding
144 run_make clean_and_use_profile
145 else
146 run_make libpython3.so
147 run_make
148 fi
149}
150
151do_install() {
152 # make install needs the original Makefile, or otherwise the inclues would
153 # go to ${D}${STAGING...}/...
154 install -m 0644 Makefile.orig Makefile
155
156 install -d ${D}${libdir}/pkgconfig
157 install -d ${D}${libdir}/python${PYTHON_MAJMIN}/config
158
159 # rerun the build once again with original makefile this time
160 # run install in a separate step to avoid compile/install race
161 if ${@bb.utils.contains('PACKAGECONFIG', 'pgo', 'true', 'false', d)}; then
162 run_make DESTDIR=${D} LIBDIR=${libdir} build_all_use_profile
163 else
164 run_make DESTDIR=${D} LIBDIR=${libdir}
165 fi
166
167 run_make DESTDIR=${D} LIBDIR=${libdir} install
168
169 # avoid conflict with 2to3 from Python 2
170 rm -f ${D}/${bindir}/2to3
171
172 install -m 0644 Makefile.sysroot ${D}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile
173 install -m 0644 Makefile.sysroot ${D}/${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_MAJMIN}${PYTHON_ABI}/Makefile
174
175 if [ -e ${WORKDIR}/sitecustomize.py ]; then
176 install -m 0644 ${WORKDIR}/sitecustomize.py ${D}/${libdir}/python${PYTHON_MAJMIN}
177 fi
178
179 oe_multilib_header python${PYTHON_BINABI}/pyconfig.h
180}
181
182do_install_append_class-nativesdk () {
183 create_wrapper ${D}${bindir}/python${PYTHON_MAJMIN} PYTHONHOME='${prefix}' TERMINFO_DIRS='${sysconfdir}/terminfo:/etc/terminfo:/usr/share/terminfo:/usr/share/misc/terminfo:/lib/terminfo' PYTHONNOUSERSITE='1'
184}
185
186SSTATE_SCAN_FILES += "Makefile"
187PACKAGE_PREPROCESS_FUNCS += "py_package_preprocess"
188
189py_package_preprocess () {
190 # copy back the old Makefile to fix target package
191 install -m 0644 ${B}/Makefile.orig ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile
192 install -m 0644 ${B}/Makefile.orig ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_MAJMIN}${PYTHON_ABI}/Makefile
193 # Remove references to buildmachine paths in target Makefile and _sysconfigdata
194 sed -i -e 's:--sysroot=${STAGING_DIR_TARGET}::g' -e s:'--with-libtool-sysroot=${STAGING_DIR_TARGET}'::g \
195 -e 's|${DEBUG_PREFIX_MAP}||g' \
196 -e 's:${HOSTTOOLS_DIR}/::g' \
197 -e 's:${RECIPE_SYSROOT_NATIVE}::g' \
198 -e 's:${RECIPE_SYSROOT}::g' \
199 -e 's:${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}::g' \
200 ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile \
201 ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_MAJMIN}${PYTHON_ABI}/Makefile \
202 ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py \
203 ${PKGD}/${bindir}/python${PYTHON_BINABI}-config
204
205 # Recompile _sysconfigdata after modifying it
206 cd ${PKGD}
207 ${STAGING_BINDIR_NATIVE}/${PYTHON_PN}-native/${PYTHON_PN} \
208 -c "from py_compile import compile; compile('./${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py')"
209 ${STAGING_BINDIR_NATIVE}/${PYTHON_PN}-native/${PYTHON_PN} \
210 -c "from py_compile import compile; compile('./${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py', optimize=1)"
211 ${STAGING_BINDIR_NATIVE}/${PYTHON_PN}-native/${PYTHON_PN} \
212 -c "from py_compile import compile; compile('./${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py', optimize=2)"
213 cd -
214
215 mv ${PKGD}/${bindir}/python${PYTHON_BINABI}-config ${PKGD}/${bindir}/python${PYTHON_BINABI}-config-${MULTILIB_SUFFIX}
216}
217
218PACKAGES_remove = "${PN}"
219
220# manual dependency additions
221RPROVIDES_${PN}-modules = "${PN}"
222RRECOMMENDS_${PN}-core_append_class-nativesdk = " nativesdk-python3-modules"
223RRECOMMENDS_${PN}-crypt = "openssl ca-certificates"
224
225FILES_${PN}-2to3 += "${bindir}/2to3-${PYTHON_MAJMIN}"
226FILES_${PN}-pydoc += "${bindir}/pydoc${PYTHON_MAJMIN} ${bindir}/pydoc3"
227FILES_${PN}-idle += "${bindir}/idle3 ${bindir}/idle${PYTHON_MAJMIN}"
228
229# provide python-pyvenv from python3-venv
230RPROVIDES_${PN}-venv += "${PN}-pyvenv"
231
232# package libpython3
233PACKAGES =+ "libpython3 libpython3-staticdev"
234FILES_libpython3 = "${libdir}/libpython*.so.*"
235FILES_libpython3-staticdev += "${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_BINABI}/libpython${PYTHON_BINABI}.a"
236INSANE_SKIP_${PN}-dev += "dev-elf"
237
238# catch all the rest (unsorted)
239PACKAGES += "${PN}-misc"
240RDEPENDS_${PN}-misc += "${PN}-core ${PN}-email ${PN}-codecs"
241RDEPENDS_${PN}-modules += "${PN}-misc"
242FILES_${PN}-misc = "${libdir}/python${PYTHON_MAJMIN}"
243
244# catch manpage
245PACKAGES += "${PN}-man"
246FILES_${PN}-man = "${datadir}/man"
247
248RDEPENDS_${PN}-ptest = "${PN}-modules ${PN}-tests unzip bzip2"
249
250RDEPENDS_${PN}-dev = ""
251
252BBCLASSEXTEND = "nativesdk"
253
254# We want bytecode precompiled .py files (.pyc's) by default
255# but the user may set it on their own conf
256INCLUDE_PYCS ?= "1"
257
258python(){
259 import collections, json
260
261 filename = os.path.join(d.getVar('THISDIR'), 'python3', 'python3-manifest.json')
262 # This python changes the datastore based on the contents of a file, so mark
263 # that dependency.
264 bb.parse.mark_dependency(d, filename)
265
266 with open(filename) as manifest_file:
267 python_manifest=json.load(manifest_file, object_pairs_hook=collections.OrderedDict)
268
269 include_pycs = d.getVar('INCLUDE_PYCS')
270
271 packages = d.getVar('PACKAGES').split()
272 pn = d.getVar('PN')
273
274 newpackages=[]
275 for key in python_manifest:
276 pypackage= pn + '-' + key
277
278 if pypackage not in packages:
279 # We need to prepend, otherwise python-misc gets everything
280 # so we use a new variable
281 newpackages.append(pypackage)
282
283 # "Build" python's manifest FILES, RDEPENDS and SUMMARY
284 d.setVar('FILES_' + pypackage, '')
285 for value in python_manifest[key]['files']:
286 d.appendVar('FILES_' + pypackage, ' ' + value)
287
288 # Add cached files
289 if include_pycs == '1':
290 for value in python_manifest[key]['cached']:
291 d.appendVar('FILES_' + pypackage, ' ' + value)
292
293 for value in python_manifest[key]['rdepends']:
294 # Make it work with or without $PN
295 if '${PN}' in value:
296 value=value.split('-')[1]
297 d.appendVar('RDEPENDS_' + pypackage, ' ' + pn + '-' + value)
298 d.setVar('SUMMARY_' + pypackage, python_manifest[key]['summary'])
299
300 # Prepending so to avoid python-misc getting everything
301 packages = newpackages + packages
302 d.setVar('PACKAGES', ' '.join(packages))
303 d.setVar('ALLOW_EMPTY_${PN}-modules', '1')
304}
305
306# Files needed to create a new manifest
307SRC_URI += "file://create_manifest3.py file://get_module_deps3.py file://python3-manifest.json"
308
309do_create_manifest() {
310 # This task should be run with every new release of Python.
311 # We must ensure that PACKAGECONFIG enables everything when creating
312 # a new manifest, this is to base our new manifest on a complete
313 # native python build, containing all dependencies, otherwise the task
314 # wont be able to find the required files.
315 # e.g. BerkeleyDB is an optional build dependency so it may or may not
316 # be present, we must ensure it is.
317
318 cd ${WORKDIR}
319 # This needs to be executed by python-native and NOT by HOST's python
320 nativepython3 create_manifest3.py ${PYTHON_MAJMIN}
321 cp python3-manifest.json.new ${THISDIR}/python3/python3-manifest.json
322}
323
324# bitbake python -c create_manifest
325addtask do_create_manifest
326
327# Make sure we have native python ready when we create a new manifest
328do_create_manifest[depends] += "python3:do_prepare_recipe_sysroot"
329do_create_manifest[depends] += "python3:do_patch"