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