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