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