python3_3.5.6.bb 13 KB

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