blob: 5f387b8af11f01153ffcaa9939015d5346742d44 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001require python.inc
2
3DEPENDS = "python-native libffi bzip2 gdbm openssl \
4 readline sqlite3 zlib virtual/crypt"
5
6DISTRO_SRC_URI ?= "file://sitecustomize.py"
7DISTRO_SRC_URI_linuxstdbase = ""
8SRC_URI += " \
9 file://01-use-proper-tools-for-cross-build.patch \
10 file://03-fix-tkinter-detection.patch \
11 file://06-avoid_usr_lib_termcap_path_in_linking.patch \
12 ${DISTRO_SRC_URI} \
13 file://multilib.patch \
14 file://cgi_py.patch \
15 file://setup_py_skip_cross_import_check.patch \
16 file://add-md5module-support.patch \
17 file://host_include_contamination.patch \
18 file://fix_for_using_different_libdir.patch \
19 file://setuptweaks.patch \
20 file://check-if-target-is-64b-not-host.patch \
21 file://search_db_h_in_inc_dirs_and_avoid_warning.patch \
22 ${@bb.utils.contains('PACKAGECONFIG', 'tk', '', 'file://avoid_warning_about_tkinter.patch', d)} \
23 file://avoid_warning_for_sunos_specific_module.patch \
24 file://python-2.7.3-remove-bsdb-rpath.patch \
25 file://run-ptest \
26 file://parallel-makeinst-create-bindir.patch \
27 file://use_sysroot_ncurses_instead_of_host.patch \
28 file://add-CROSSPYTHONPATH-for-PYTHON_FOR_BUILD.patch \
29 file://pass-missing-libraries-to-Extension-for-mul.patch \
30 file://support_SOURCE_DATE_EPOCH_in_py_compile_2.7.patch \
31 file://float-endian.patch \
32 file://0001-python2-use-cc_basename-to-replace-CC-for-checking-c.patch \
Brad Bishop15ae2502019-06-18 21:44:24 -040033 file://bpo-35907-cve-2019-9948.patch \
34 file://bpo-35907-cve-2019-9948-fix.patch \
35 file://bpo-36216-cve-2019-9636.patch \
36 file://bpo-36216-cve-2019-9636-fix.patch \
37"
Brad Bishopc342db32019-05-15 21:57:59 -040038
39S = "${WORKDIR}/Python-${PV}"
40
41inherit autotools multilib_header python-dir pythonnative ptest
42
43CONFIGUREOPTS += " --with-system-ffi "
44
45EXTRA_OECONF += "ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no ac_cv_working_tzset=yes"
46
47PACKAGECONFIG ??= "bdb"
48PACKAGECONFIG[bdb] = ",,db"
49PACKAGECONFIG[tk] = ",,tk"
50
51do_configure_append() {
52 rm -f ${S}/Makefile.orig
53 autoreconf -Wcross --verbose --install --force --exclude=autopoint ../Python-${PV}/Modules/_ctypes/libffi
54}
55
56do_compile() {
57 # regenerate platform specific files, because they depend on system headers
58 cd ${S}/Lib/plat-linux2
59 include=${STAGING_INCDIR} ${STAGING_BINDIR_NATIVE}/python-native/python \
60 ${S}/Tools/scripts/h2py.py -i '(u_long)' \
61 ${STAGING_INCDIR}/dlfcn.h \
62 ${STAGING_INCDIR}/linux/cdrom.h \
63 ${STAGING_INCDIR}/netinet/in.h \
64 ${STAGING_INCDIR}/sys/types.h
65 sed -e 's,${STAGING_DIR_HOST},,g' -i *.py
66 cd -
67
68 # remove any bogus LD_LIBRARY_PATH
69 sed -i -e s,RUNSHARED=.*,RUNSHARED=, Makefile
70
71 if [ ! -f Makefile.orig ]; then
72 install -m 0644 Makefile Makefile.orig
73 fi
74 sed -i -e 's#^LDFLAGS=.*#LDFLAGS=${LDFLAGS} -L. -L${STAGING_LIBDIR}#g' \
75 -e 's,libdir=${libdir},libdir=${STAGING_LIBDIR},g' \
76 -e 's,libexecdir=${libexecdir},libexecdir=${STAGING_DIR_HOST}${libexecdir},g' \
77 -e 's,^LIBDIR=.*,LIBDIR=${STAGING_LIBDIR},g' \
78 -e 's,includedir=${includedir},includedir=${STAGING_INCDIR},g' \
79 -e 's,^INCLUDEDIR=.*,INCLUDE=${STAGING_INCDIR},g' \
80 -e 's,^CONFINCLUDEDIR=.*,CONFINCLUDE=${STAGING_INCDIR},g' \
81 Makefile
82 # save copy of it now, because if we do it in do_install and
83 # then call do_install twice we get Makefile.orig == Makefile.sysroot
84 install -m 0644 Makefile Makefile.sysroot
85
86 export CROSS_COMPILE="${TARGET_PREFIX}"
87 export PYTHONBUILDDIR="${B}"
88
89 oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python-native/pgen \
90 HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python-native/python \
91 STAGING_LIBDIR=${STAGING_LIBDIR} \
92 STAGING_INCDIR=${STAGING_INCDIR} \
93 STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \
94 OPT="${CFLAGS}"
95}
96
97do_install() {
98 # make install needs the original Makefile, or otherwise the inclues would
99 # go to ${D}${STAGING...}/...
100 install -m 0644 Makefile.orig Makefile
101
102 export CROSS_COMPILE="${TARGET_PREFIX}"
103 export PYTHONBUILDDIR="${B}"
104
105 # After swizzling the makefile, we need to run the build again.
106 # install can race with the build so we have to run this first, then install
107 oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python-native/pgen \
108 HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python-native/python \
109 CROSSPYTHONPATH=${STAGING_LIBDIR_NATIVE}/python${PYTHON_MAJMIN}/lib-dynload/ \
110 STAGING_LIBDIR=${STAGING_LIBDIR} \
111 STAGING_INCDIR=${STAGING_INCDIR} \
112 STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \
113 DESTDIR=${D} LIBDIR=${libdir}
114
115 oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python-native/pgen \
116 HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python-native/python \
117 CROSSPYTHONPATH=${STAGING_LIBDIR_NATIVE}/python${PYTHON_MAJMIN}/lib-dynload/ \
118 STAGING_LIBDIR=${STAGING_LIBDIR} \
119 STAGING_INCDIR=${STAGING_INCDIR} \
120 STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \
121 DESTDIR=${D} LIBDIR=${libdir} install
122
123 install -m 0644 Makefile.sysroot ${D}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile
124
125 if [ -e ${WORKDIR}/sitecustomize.py ]; then
126 install -m 0644 ${WORKDIR}/sitecustomize.py ${D}/${libdir}/python${PYTHON_MAJMIN}
127 fi
128
129 oe_multilib_header python${PYTHON_MAJMIN}/pyconfig.h
130
131 if [ -z "${@bb.utils.filter('PACKAGECONFIG', 'bdb', d)}" ]; then
132 rm -rf ${D}/${libdir}/python${PYTHON_MAJMIN}/bsddb
133 fi
134
135 # Python 3.x version of 2to3 is now the default
136 mv ${D}/${bindir}/2to3 ${D}/${bindir}/2to3-${PYTHON_MAJMIN}
137}
138
139do_install_append_class-nativesdk () {
140 create_wrapper ${D}${bindir}/python2.7 PYTHONHOME='${prefix}' TERMINFO_DIRS='${sysconfdir}/terminfo:/etc/terminfo:/usr/share/terminfo:/usr/share/misc/terminfo:/lib/terminfo' PYTHONNOUSERSITE='1'
141}
142
143SSTATE_SCAN_FILES += "Makefile"
144PACKAGE_PREPROCESS_FUNCS += "py_package_preprocess"
145
146py_package_preprocess () {
147 # copy back the old Makefile to fix target package
148 install -m 0644 ${B}/Makefile.orig ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile
149
150 # Remove references to buildmachine paths in target Makefile and _sysconfigdata
151 sed -i -e 's:--sysroot=${STAGING_DIR_TARGET}::g' -e s:'--with-libtool-sysroot=${STAGING_DIR_TARGET}'::g \
152 -e 's|${DEBUG_PREFIX_MAP}||g' \
153 -e 's:${HOSTTOOLS_DIR}/::g' \
154 -e 's:${RECIPE_SYSROOT_NATIVE}::g' \
155 -e 's:${RECIPE_SYSROOT}::g' \
156 -e 's:${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}::g' \
157 ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile \
158 ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py
159 (cd ${PKGD}; python -m py_compile ./${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py)
160}
161
162PACKAGES_remove = "${PN}"
163
164# manual dependency additions
Brad Bishopf3fd2882019-06-21 08:06:37 -0400165RPROVIDES_${PN}-modules = "${PN}"
Brad Bishopc342db32019-05-15 21:57:59 -0400166RRECOMMENDS_${PN}-core_append_class-nativesdk = " nativesdk-python-modules"
167RRECOMMENDS_${PN}-crypt = "openssl"
168
169# package libpython2
170PACKAGES =+ "lib${BPN}2"
171FILES_lib${BPN}2 = "${libdir}/libpython*.so.*"
172
173# catch all the rest (unsorted)
174PACKAGES += "${PN}-misc"
175FILES_${PN}-misc = "${libdir}/python${PYTHON_MAJMIN}"
176RDEPENDS_${PN}-modules += "${PN}-misc"
177
178# ptest
179RDEPENDS_${PN}-ptest = "${PN}-modules ${PN}-tests unzip tzdata-europe coreutils sed"
180RDEPENDS_${PN}-tkinter += "${@bb.utils.contains('PACKAGECONFIG', 'tk', 'tk', '', d)}"
181# catch manpage
182PACKAGES += "${PN}-man"
183FILES_${PN}-man = "${datadir}/man"
184
185# Nasty but if bdb isn't enabled the package won't be generated
186RDEPENDS_${PN}-modules_remove = "${@bb.utils.contains('PACKAGECONFIG', 'bdb', '', '${PN}-bsddb', d)}"
187
188RDEPENDS_${PN}-dev = ""
189
190BBCLASSEXTEND = "nativesdk"
191
192# We want bytecode precompiled .py files (.pyc's) by default
193# but the user may set it on their own conf
194
195INCLUDE_PYCS ?= "1"
196
197python(){
198 import collections, json
199
200 filename = os.path.join(d.getVar('THISDIR'), 'python', 'python2-manifest.json')
201 # This python changes the datastore based on the contents of a file, so mark
202 # that dependency.
203 bb.parse.mark_dependency(d, filename)
204
205 with open(filename) as manifest_file:
206 manifest_str = manifest_file.read()
207 json_start = manifest_str.find('# EOC') + 6
208 manifest_file.seek(json_start)
209 manifest_str = manifest_file.read()
210 python_manifest = json.loads(manifest_str, object_pairs_hook=collections.OrderedDict)
211
212 include_pycs = d.getVar('INCLUDE_PYCS')
213
214 packages = d.getVar('PACKAGES').split()
215 pn = d.getVar('PN')
216
217 newpackages=[]
218
219 for key in python_manifest:
220 pypackage= pn + '-' + key
221
222 if pypackage not in packages:
223 # We need to prepend, otherwise python-misc gets everything
224 # so we use a new variable
225 newpackages.append(pypackage)
226
227 # "Build" python's manifest FILES, RDEPENDS and SUMMARY
228 d.setVar('FILES_' + pypackage, '')
229 for value in python_manifest[key]['files']:
230 d.appendVar('FILES_' + pypackage, ' ' + value)
231 if include_pycs == '1':
232 if value.endswith('.py'):
233 d.appendVar('FILES_' + pypackage, ' ' + value + 'c')
234
235 for value in python_manifest[key]['rdepends']:
236 # Make it work with or without $PN
237 if '${PN}' in value:
238 value=value.split('-')[1]
239 d.appendVar('RDEPENDS_' + pypackage, ' ' + pn + '-' + value)
240 d.setVar('SUMMARY_' + pypackage, python_manifest[key]['summary'])
241
242 # Prepending so to avoid python-misc getting everything
243 packages = newpackages + packages
244 d.setVar('PACKAGES', ' '.join(packages))
245 d.setVar('ALLOW_EMPTY_${PN}-modules', '1')
246}
247
248# Files needed to create a new manifest
249SRC_URI += "file://create_manifest2.py file://get_module_deps2.py file://python2-manifest.json"
250
251do_create_manifest() {
252 # This task should be run with every new release of Python.
253 # We must ensure that PACKAGECONFIG enables everything when creating
254 # a new manifest, this is to base our new manifest on a complete
255 # native python build, containing all dependencies, otherwise the task
256 # wont be able to find the required files.
257 # e.g. BerkeleyDB is an optional build dependency so it may or may not
258 # be present, we must ensure it is.
259
260 cd ${WORKDIR}
261 # This needs to be executed by python-native and NOT by HOST's python
262 nativepython create_manifest2.py
263 cp python2-manifest.json.new ${THISDIR}/python/python2-manifest.json
264}
265
266# bitbake python -c create_manifest
267addtask do_create_manifest
268
269# Make sure we have native python ready when we create a new manifest
270do_create_manifest[depends] += "python:do_prepare_recipe_sysroot"
271do_create_manifest[depends] += "python:do_patch"