python3_3.5.6.bb 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. "
  44. inherit multilib_header python3native update-alternatives qemu ptest
  45. MULTILIB_SUFFIX = "${@d.getVar('base_libdir',1).split('/')[-1]}"
  46. ALTERNATIVE_${PN}-dev = "python-config"
  47. ALTERNATIVE_LINK_NAME[python-config] = "${bindir}/python${PYTHON_BINABI}-config"
  48. ALTERNATIVE_TARGET[python-config] = "${bindir}/python${PYTHON_BINABI}-config-${MULTILIB_SUFFIX}"
  49. CONFIGUREOPTS += " --with-system-ffi "
  50. CACHED_CONFIGUREVARS = "ac_cv_have_chflags=no \
  51. ac_cv_have_lchflags=no \
  52. ac_cv_have_long_long_format=yes \
  53. ac_cv_buggy_getaddrinfo=no \
  54. ac_cv_file__dev_ptmx=yes \
  55. ac_cv_file__dev_ptc=no \
  56. ac_cv_working_tzset=yes \
  57. "
  58. TARGET_CC_ARCH += "-DNDEBUG -fno-inline"
  59. SDK_CC_ARCH += "-DNDEBUG -fno-inline"
  60. EXTRA_OEMAKE += "CROSS_COMPILE=yes"
  61. EXTRA_OECONF += "CROSSPYTHONPATH=${STAGING_LIBDIR_NATIVE}/python${PYTHON_MAJMIN}/lib-dynload/ --without-ensurepip"
  62. PYTHON3_PROFILE_TASK ?= "./python -m test.regrtest --pgo test_grammar test_opcodes test_dict test_builtin test_exceptions test_types test_support || true"
  63. export CROSS_COMPILE = "${TARGET_PREFIX}"
  64. export CCSHARED = "-fPIC"
  65. # Fix cross compilation of different modules
  66. export CROSSPYTHONPATH = "${STAGING_LIBDIR_NATIVE}/python${PYTHON_MAJMIN}/lib-dynload/:${B}/build/lib.linux-${TARGET_ARCH}-${PYTHON_MAJMIN}:${S}/Lib:${S}/Lib/plat-linux"
  67. PACKAGECONFIG ??= "readline ${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'pgo', '', d)}"
  68. PACKAGECONFIG[readline] = ",,readline"
  69. # Use profile guided optimisation by running PyBench inside qemu-user
  70. PACKAGECONFIG[pgo] = "--enable-optimizations"
  71. do_configure_append() {
  72. rm -f ${S}/Makefile.orig
  73. }
  74. run_make() {
  75. oe_runmake PGEN=${STAGING_BINDIR_NATIVE}/python3-native/pgen \
  76. HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python3-native/python3 \
  77. STAGING_LIBDIR=${STAGING_LIBDIR} \
  78. STAGING_INCDIR=${STAGING_INCDIR} \
  79. STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \
  80. LIB=${baselib} \
  81. ARCH=${TARGET_ARCH} \
  82. OPT="${CFLAGS}" \
  83. "$@"
  84. }
  85. do_compile() {
  86. # regenerate platform specific files, because they depend on system headers
  87. cd ${S}/Lib/plat-linux*
  88. include=${STAGING_INCDIR} ${STAGING_BINDIR_NATIVE}/python3-native/python3 \
  89. ${S}/Tools/scripts/h2py.py -i '(u_long)' \
  90. ${STAGING_INCDIR}/dlfcn.h \
  91. ${STAGING_INCDIR}/linux/cdrom.h \
  92. ${STAGING_INCDIR}/netinet/in.h \
  93. ${STAGING_INCDIR}/sys/types.h
  94. sed -e 's,${STAGING_DIR_HOST},,g' -i *.py
  95. cd -
  96. # remove any bogus LD_LIBRARY_PATH
  97. sed -i -e s,RUNSHARED=.*,RUNSHARED=, Makefile
  98. if [ ! -f Makefile.orig ]; then
  99. install -m 0644 Makefile Makefile.orig
  100. fi
  101. sed -i -e 's,^CONFIGURE_LDFLAGS=.*,CONFIGURE_LDFLAGS=-L. -L${STAGING_LIBDIR},g' \
  102. -e 's,libdir=${libdir},libdir=${STAGING_LIBDIR},g' \
  103. -e 's,libexecdir=${libexecdir},libexecdir=${STAGING_DIR_HOST}${libexecdir},g' \
  104. -e 's,^LIBDIR=.*,LIBDIR=${STAGING_LIBDIR},g' \
  105. -e 's,includedir=${includedir},includedir=${STAGING_INCDIR},g' \
  106. -e 's,^INCLUDEDIR=.*,INCLUDE=${STAGING_INCDIR},g' \
  107. -e 's,^CONFINCLUDEDIR=.*,CONFINCLUDE=${STAGING_INCDIR},g' \
  108. Makefile
  109. # save copy of it now, because if we do it in do_install and
  110. # then call do_install twice we get Makefile.orig == Makefile.sysroot
  111. install -m 0644 Makefile Makefile.sysroot
  112. if ${@bb.utils.contains('PACKAGECONFIG', 'pgo', 'true', 'false', d)}; then
  113. run_make profile-opt
  114. qemu_binary="${@qemu_wrapper_cmdline(d, '${STAGING_DIR_TARGET}', ['${B}', '${STAGING_DIR_TARGET}/${base_libdir}'])}"
  115. cat >pgo-wrapper <<EOF
  116. #!/bin/sh
  117. cd ${B}
  118. $qemu_binary "\$@"
  119. EOF
  120. chmod +x pgo-wrapper
  121. bbnote Gathering profiling data
  122. ./pgo-wrapper ${PYTHON3_PROFILE_TASK}
  123. bbnote Profiling data gathered, rebuilding
  124. run_make clean_and_use_profile
  125. else
  126. run_make libpython3.so
  127. run_make
  128. fi
  129. }
  130. do_install() {
  131. # make install needs the original Makefile, or otherwise the inclues would
  132. # go to ${D}${STAGING...}/...
  133. install -m 0644 Makefile.orig Makefile
  134. install -d ${D}${libdir}/pkgconfig
  135. install -d ${D}${libdir}/python${PYTHON_MAJMIN}/config
  136. # rerun the build once again with original makefile this time
  137. # run install in a separate step to avoid compile/install race
  138. if ${@bb.utils.contains('PACKAGECONFIG', 'pgo', 'true', 'false', d)}; then
  139. run_make DESTDIR=${D} LIBDIR=${libdir} build_all_use_profile
  140. else
  141. run_make DESTDIR=${D} LIBDIR=${libdir}
  142. fi
  143. run_make DESTDIR=${D} LIBDIR=${libdir} install
  144. # avoid conflict with 2to3 from Python 2
  145. rm -f ${D}/${bindir}/2to3
  146. install -m 0644 Makefile.sysroot ${D}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile
  147. install -m 0644 Makefile.sysroot ${D}/${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_MAJMIN}${PYTHON_ABI}/Makefile
  148. if [ -e ${WORKDIR}/sitecustomize.py ]; then
  149. install -m 0644 ${WORKDIR}/sitecustomize.py ${D}/${libdir}/python${PYTHON_MAJMIN}
  150. fi
  151. oe_multilib_header python${PYTHON_BINABI}/pyconfig.h
  152. }
  153. do_install_append_class-nativesdk () {
  154. 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'
  155. }
  156. SSTATE_SCAN_FILES += "Makefile"
  157. PACKAGE_PREPROCESS_FUNCS += "py_package_preprocess"
  158. py_package_preprocess () {
  159. # copy back the old Makefile to fix target package
  160. install -m 0644 ${B}/Makefile.orig ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile
  161. install -m 0644 ${B}/Makefile.orig ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_MAJMIN}${PYTHON_ABI}/Makefile
  162. # Remove references to buildmachine paths in target Makefile and _sysconfigdata
  163. sed -i -e 's:--sysroot=${STAGING_DIR_TARGET}::g' -e s:'--with-libtool-sysroot=${STAGING_DIR_TARGET}'::g \
  164. -e 's|${DEBUG_PREFIX_MAP}||g' \
  165. -e 's:${HOSTTOOLS_DIR}/::g' \
  166. -e 's:${RECIPE_SYSROOT_NATIVE}::g' \
  167. -e 's:${RECIPE_SYSROOT}::g' \
  168. -e 's:${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}::g' \
  169. ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile \
  170. ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_MAJMIN}${PYTHON_ABI}/Makefile \
  171. ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py \
  172. ${PKGD}/${bindir}/python${PYTHON_BINABI}-config
  173. # Recompile _sysconfigdata after modifying it
  174. cd ${PKGD}
  175. ${STAGING_BINDIR_NATIVE}/${PYTHON_PN}-native/${PYTHON_PN} \
  176. -c "from py_compile import compile; compile('./${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py')"
  177. ${STAGING_BINDIR_NATIVE}/${PYTHON_PN}-native/${PYTHON_PN} \
  178. -c "from py_compile import compile; compile('./${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py', optimize=1)"
  179. ${STAGING_BINDIR_NATIVE}/${PYTHON_PN}-native/${PYTHON_PN} \
  180. -c "from py_compile import compile; compile('./${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py', optimize=2)"
  181. cd -
  182. mv ${PKGD}/${bindir}/python${PYTHON_BINABI}-config ${PKGD}/${bindir}/python${PYTHON_BINABI}-config-${MULTILIB_SUFFIX}
  183. }
  184. PACKAGES_remove = "${PN}"
  185. # manual dependency additions
  186. RPROVIDES_${PN}-modules = "${PN}"
  187. RRECOMMENDS_${PN}-core_append_class-nativesdk = " nativesdk-python3-modules"
  188. RRECOMMENDS_${PN}-crypt = "openssl ca-certificates"
  189. FILES_${PN}-2to3 += "${bindir}/2to3-${PYTHON_MAJMIN}"
  190. FILES_${PN}-pydoc += "${bindir}/pydoc${PYTHON_MAJMIN} ${bindir}/pydoc3"
  191. FILES_${PN}-idle += "${bindir}/idle3 ${bindir}/idle${PYTHON_MAJMIN}"
  192. # provide python-pyvenv from python3-venv
  193. RPROVIDES_${PN}-venv += "${PN}-pyvenv"
  194. # package libpython3
  195. PACKAGES =+ "libpython3 libpython3-staticdev"
  196. FILES_libpython3 = "${libdir}/libpython*.so.*"
  197. FILES_libpython3-staticdev += "${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_BINABI}/libpython${PYTHON_BINABI}.a"
  198. INSANE_SKIP_${PN}-dev += "dev-elf"
  199. # catch all the rest (unsorted)
  200. PACKAGES += "${PN}-misc"
  201. RDEPENDS_${PN}-misc += "${PN}-core ${PN}-email ${PN}-codecs"
  202. RDEPENDS_${PN}-modules += "${PN}-misc"
  203. FILES_${PN}-misc = "${libdir}/python${PYTHON_MAJMIN}"
  204. # catch manpage
  205. PACKAGES += "${PN}-man"
  206. FILES_${PN}-man = "${datadir}/man"
  207. RDEPENDS_${PN}-ptest = "${PN}-modules ${PN}-tests unzip bzip2"
  208. RDEPENDS_${PN}-dev = ""
  209. BBCLASSEXTEND = "nativesdk"
  210. # We want bytecode precompiled .py files (.pyc's) by default
  211. # but the user may set it on their own conf
  212. INCLUDE_PYCS ?= "1"
  213. python(){
  214. import collections, json
  215. filename = os.path.join(d.getVar('THISDIR'), 'python3', 'python3-manifest.json')
  216. # This python changes the datastore based on the contents of a file, so mark
  217. # that dependency.
  218. bb.parse.mark_dependency(d, filename)
  219. with open(filename) as manifest_file:
  220. python_manifest=json.load(manifest_file, object_pairs_hook=collections.OrderedDict)
  221. include_pycs = d.getVar('INCLUDE_PYCS')
  222. packages = d.getVar('PACKAGES').split()
  223. pn = d.getVar('PN')
  224. newpackages=[]
  225. for key in python_manifest:
  226. pypackage= pn + '-' + key
  227. if pypackage not in packages:
  228. # We need to prepend, otherwise python-misc gets everything
  229. # so we use a new variable
  230. newpackages.append(pypackage)
  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. # Add cached files
  236. if include_pycs == '1':
  237. for value in python_manifest[key]['cached']:
  238. d.appendVar('FILES_' + pypackage, ' ' + value)
  239. for value in python_manifest[key]['rdepends']:
  240. # Make it work with or without $PN
  241. if '${PN}' in value:
  242. value=value.split('-')[1]
  243. d.appendVar('RDEPENDS_' + pypackage, ' ' + pn + '-' + value)
  244. d.setVar('SUMMARY_' + pypackage, python_manifest[key]['summary'])
  245. # Prepending so to avoid python-misc getting everything
  246. packages = newpackages + packages
  247. d.setVar('PACKAGES', ' '.join(packages))
  248. d.setVar('ALLOW_EMPTY_${PN}-modules', '1')
  249. }
  250. # Files needed to create a new manifest
  251. SRC_URI += "file://create_manifest3.py file://get_module_deps3.py file://python3-manifest.json"
  252. do_create_manifest() {
  253. # This task should be run with every new release of Python.
  254. # We must ensure that PACKAGECONFIG enables everything when creating
  255. # a new manifest, this is to base our new manifest on a complete
  256. # native python build, containing all dependencies, otherwise the task
  257. # wont be able to find the required files.
  258. # e.g. BerkeleyDB is an optional build dependency so it may or may not
  259. # be present, we must ensure it is.
  260. cd ${WORKDIR}
  261. # This needs to be executed by python-native and NOT by HOST's python
  262. nativepython3 create_manifest3.py ${PYTHON_MAJMIN}
  263. cp python3-manifest.json.new ${THISDIR}/python3/python3-manifest.json
  264. }
  265. # bitbake python -c create_manifest
  266. addtask do_create_manifest
  267. # Make sure we have native python ready when we create a new manifest
  268. do_create_manifest[depends] += "python3:do_prepare_recipe_sysroot"
  269. do_create_manifest[depends] += "python3:do_patch"