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 \ |
| 40 | " |
| 41 | SRC_URI[md5sum] = "f3763edf9824d5d3a15f5f646083b6e0" |
| 42 | SRC_URI[sha256sum] = "063d2c3b0402d6191b90731e0f735c64830e7522348aeb7ed382a83165d45009" |
| 43 | |
| 44 | LIC_FILES_CHKSUM = "file://LICENSE;md5=b6ec515b22618f55fa07276b897bacea" |
| 45 | |
| 46 | # exclude pre-releases for both python 2.x and 3.x |
| 47 | UPSTREAM_CHECK_REGEX = "[Pp]ython-(?P<pver>\d+(\.\d+)+).tar" |
| 48 | |
| 49 | S = "${WORKDIR}/Python-${PV}" |
| 50 | |
| 51 | inherit autotools multilib_header python3native pkgconfig |
| 52 | |
| 53 | CONFIGUREOPTS += " --with-system-ffi " |
| 54 | |
| 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 | " |
| 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 | |
| 68 | export CROSS_COMPILE = "${TARGET_PREFIX}" |
| 69 | export _PYTHON_PROJECT_BASE = "${B}" |
| 70 | export _PYTHON_PROJECT_SRC = "${S}" |
| 71 | export CCSHARED = "-fPIC" |
| 72 | |
| 73 | # Fix cross compilation of different modules |
| 74 | export CROSSPYTHONPATH = "${STAGING_LIBDIR_NATIVE}/python${PYTHON_MAJMIN}/lib-dynload/:${B}/build/lib.linux-${TARGET_ARCH}-${PYTHON_MAJMIN}:${S}/Lib:${S}/Lib/plat-linux" |
| 75 | |
| 76 | # No ctypes option for python 3 |
| 77 | PYTHONLSBOPTS = "" |
| 78 | |
| 79 | PACKAGECONFIG ??= "readline" |
| 80 | PACKAGECONFIG[readline] = ",,readline" |
| 81 | |
| 82 | do_configure_append() { |
| 83 | rm -f ${S}/Makefile.orig |
| 84 | autoreconf -Wcross --verbose --install --force --exclude=autopoint ../Python-${PV}/Modules/_ctypes/libffi |
| 85 | } |
| 86 | |
| 87 | do_compile() { |
| 88 | # regenerate platform specific files, because they depend on system headers |
| 89 | cd ${S}/Lib/plat-linux* |
| 90 | include=${STAGING_INCDIR} ${STAGING_BINDIR_NATIVE}/python3-native/python3 \ |
| 91 | ${S}/Tools/scripts/h2py.py -i '(u_long)' \ |
| 92 | ${STAGING_INCDIR}/dlfcn.h \ |
| 93 | ${STAGING_INCDIR}/linux/cdrom.h \ |
| 94 | ${STAGING_INCDIR}/netinet/in.h \ |
| 95 | ${STAGING_INCDIR}/sys/types.h |
| 96 | sed -e 's,${STAGING_DIR_HOST},,g' -i *.py |
| 97 | cd - |
| 98 | |
| 99 | |
| 100 | # remove any bogus LD_LIBRARY_PATH |
| 101 | sed -i -e s,RUNSHARED=.*,RUNSHARED=, Makefile |
| 102 | |
| 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 | |
| 118 | oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python3-native/pgen \ |
| 119 | HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python3-native/python3 \ |
| 120 | STAGING_LIBDIR=${STAGING_LIBDIR} \ |
| 121 | STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \ |
| 122 | STAGING_INCDIR=${STAGING_INCDIR} \ |
| 123 | LIB=${baselib} \ |
| 124 | ARCH=${TARGET_ARCH} \ |
| 125 | OPT="${CFLAGS}" libpython3.so |
| 126 | |
| 127 | oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python3-native/pgen \ |
| 128 | HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python3-native/python3 \ |
| 129 | STAGING_LIBDIR=${STAGING_LIBDIR} \ |
| 130 | STAGING_INCDIR=${STAGING_INCDIR} \ |
| 131 | STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \ |
| 132 | LIB=${baselib} \ |
| 133 | ARCH=${TARGET_ARCH} \ |
| 134 | OPT="${CFLAGS}" |
| 135 | } |
| 136 | |
| 137 | do_install() { |
| 138 | # make install needs the original Makefile, or otherwise the inclues would |
| 139 | # go to ${D}${STAGING...}/... |
| 140 | install -m 0644 Makefile.orig Makefile |
| 141 | |
| 142 | install -d ${D}${libdir}/pkgconfig |
| 143 | install -d ${D}${libdir}/python${PYTHON_MAJMIN}/config |
| 144 | |
| 145 | # rerun the build once again with original makefile this time |
| 146 | # run install in a separate step to avoid compile/install race |
| 147 | oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python3-native/pgen \ |
| 148 | HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python3-native/python3 \ |
| 149 | STAGING_LIBDIR=${STAGING_LIBDIR} \ |
| 150 | STAGING_INCDIR=${STAGING_INCDIR} \ |
| 151 | STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \ |
| 152 | LIB=${baselib} \ |
| 153 | ARCH=${TARGET_ARCH} \ |
| 154 | DESTDIR=${D} LIBDIR=${libdir} |
| 155 | |
| 156 | oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python3-native/pgen \ |
| 157 | HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python3-native/python3 \ |
| 158 | STAGING_LIBDIR=${STAGING_LIBDIR} \ |
| 159 | STAGING_INCDIR=${STAGING_INCDIR} \ |
| 160 | STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \ |
| 161 | LIB=${baselib} \ |
| 162 | ARCH=${TARGET_ARCH} \ |
| 163 | DESTDIR=${D} LIBDIR=${libdir} install |
| 164 | |
| 165 | # avoid conflict with 2to3 from Python 2 |
| 166 | rm -f ${D}/${bindir}/2to3 |
| 167 | |
| 168 | install -m 0644 Makefile.sysroot ${D}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile |
| 169 | install -m 0644 Makefile.sysroot ${D}/${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_MAJMIN}${PYTHON_ABI}/Makefile |
| 170 | |
| 171 | if [ -e ${WORKDIR}/sitecustomize.py ]; then |
| 172 | install -m 0644 ${WORKDIR}/sitecustomize.py ${D}/${libdir}/python${PYTHON_MAJMIN} |
| 173 | fi |
| 174 | |
| 175 | oe_multilib_header python${PYTHON_BINABI}/pyconfig.h |
| 176 | } |
| 177 | |
| 178 | do_install_append_class-nativesdk () { |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame^] | 179 | 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] | 180 | } |
| 181 | |
| 182 | SSTATE_SCAN_FILES += "Makefile" |
| 183 | PACKAGE_PREPROCESS_FUNCS += "py_package_preprocess" |
| 184 | |
| 185 | py_package_preprocess () { |
| 186 | # copy back the old Makefile to fix target package |
| 187 | install -m 0644 ${B}/Makefile.orig ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile |
| 188 | install -m 0644 ${B}/Makefile.orig ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_MAJMIN}${PYTHON_ABI}/Makefile |
| 189 | # Remove references to buildmachine paths in target Makefile and _sysconfigdata |
| 190 | sed -i -e 's:--sysroot=${STAGING_DIR_TARGET}::g' -e s:'--with-libtool-sysroot=${STAGING_DIR_TARGET}'::g \ |
| 191 | -e 's|${DEBUG_PREFIX_MAP}||g' \ |
| 192 | -e 's:${HOSTTOOLS_DIR}/::g' \ |
| 193 | -e 's:${RECIPE_SYSROOT_NATIVE}::g' \ |
| 194 | -e 's:${RECIPE_SYSROOT}::g' \ |
| 195 | -e 's:${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}::g' \ |
| 196 | ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile \ |
| 197 | ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_MAJMIN}${PYTHON_ABI}/Makefile \ |
| 198 | ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py \ |
| 199 | ${PKGD}/${bindir}/python${PYTHON_BINABI}-config |
| 200 | |
| 201 | # Recompile _sysconfigdata after modifying it |
| 202 | cd ${PKGD} |
| 203 | ${STAGING_BINDIR_NATIVE}/${PYTHON_PN}-native/${PYTHON_PN} \ |
| 204 | -c "from py_compile import compile; compile('./${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py')" |
| 205 | ${STAGING_BINDIR_NATIVE}/${PYTHON_PN}-native/${PYTHON_PN} \ |
| 206 | -c "from py_compile import compile; compile('./${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py', optimize=1)" |
| 207 | ${STAGING_BINDIR_NATIVE}/${PYTHON_PN}-native/${PYTHON_PN} \ |
| 208 | -c "from py_compile import compile; compile('./${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py', optimize=2)" |
| 209 | cd - |
| 210 | } |
| 211 | |
| 212 | # manual dependency additions |
| 213 | RPROVIDES_${PN}-modules = "${PN}" |
| 214 | RRECOMMENDS_${PN}-core_append_class-nativesdk = " nativesdk-python3-modules" |
| 215 | RRECOMMENDS_${PN}-crypt = "openssl" |
| 216 | RRECOMMENDS_${PN}-crypt_class-nativesdk = "nativesdk-openssl" |
| 217 | |
| 218 | FILES_${PN}-2to3 += "${bindir}/2to3-${PYTHON_MAJMIN}" |
| 219 | FILES_${PN}-pydoc += "${bindir}/pydoc${PYTHON_MAJMIN} ${bindir}/pydoc3" |
| 220 | FILES_${PN}-idle += "${bindir}/idle3 ${bindir}/idle${PYTHON_MAJMIN}" |
| 221 | |
| 222 | PACKAGES =+ "${PN}-pyvenv" |
| 223 | FILES_${PN}-pyvenv += "${bindir}/pyvenv-${PYTHON_MAJMIN} ${bindir}/pyvenv" |
| 224 | |
| 225 | # package libpython3 |
| 226 | PACKAGES =+ "libpython3 libpython3-staticdev" |
| 227 | FILES_libpython3 = "${libdir}/libpython*.so.*" |
| 228 | FILES_libpython3-staticdev += "${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_BINABI}/libpython${PYTHON_BINABI}.a" |
| 229 | INSANE_SKIP_${PN}-dev += "dev-elf" |
| 230 | |
| 231 | # catch all the rest (unsorted) |
| 232 | PACKAGES += "${PN}-misc" |
| 233 | RDEPENDS_${PN}-misc += "${PN}-core ${PN}-email ${PN}-codecs" |
| 234 | RDEPENDS_${PN}-modules += "${PN}-misc" |
| 235 | FILES_${PN}-misc = "${libdir}/python${PYTHON_MAJMIN}" |
| 236 | |
| 237 | # catch manpage |
| 238 | PACKAGES += "${PN}-man" |
| 239 | FILES_${PN}-man = "${datadir}/man" |
| 240 | |
| 241 | BBCLASSEXTEND = "nativesdk" |
| 242 | |
| 243 | RPROVIDES_${PN} += "${PN}-modules" |
| 244 | |
| 245 | # We want bytecode precompiled .py files (.pyc's) by default |
| 246 | # but the user may set it on their own conf |
| 247 | INCLUDE_PYCS ?= "1" |
| 248 | |
| 249 | python(){ |
| 250 | import json |
| 251 | |
| 252 | filename = os.path.join(d.getVar('THISDIR'), 'python3', 'python3-manifest.json') |
| 253 | # This python changes the datastore based on the contents of a file, so mark |
| 254 | # that dependency. |
| 255 | bb.parse.mark_dependency(d, filename) |
| 256 | |
| 257 | with open(filename) as manifest_file: |
| 258 | python_manifest=json.load(manifest_file) |
| 259 | |
| 260 | include_pycs = d.getVar('INCLUDE_PYCS') |
| 261 | |
| 262 | packages = d.getVar('PACKAGES').split() |
| 263 | pn = d.getVar('PN') |
| 264 | |
| 265 | newpackages=[] |
| 266 | for key in python_manifest: |
| 267 | pypackage= pn + '-' + key |
| 268 | |
| 269 | if pypackage not in packages: |
| 270 | # We need to prepend, otherwise python-misc gets everything |
| 271 | # so we use a new variable |
| 272 | newpackages.append(pypackage) |
| 273 | |
| 274 | # "Build" python's manifest FILES, RDEPENDS and SUMMARY |
| 275 | d.setVar('FILES_' + pypackage, '') |
| 276 | for value in python_manifest[key]['files']: |
| 277 | d.appendVar('FILES_' + pypackage, ' ' + value) |
| 278 | |
| 279 | # Add cached files |
| 280 | if include_pycs == '1': |
| 281 | for value in python_manifest[key]['cached']: |
| 282 | d.appendVar('FILES_' + pypackage, ' ' + value) |
| 283 | |
| 284 | d.setVar('RDEPENDS_' + pypackage, '') |
| 285 | for value in python_manifest[key]['rdepends']: |
| 286 | # Make it work with or without $PN |
| 287 | if '${PN}' in value: |
| 288 | value=value.split('-')[1] |
| 289 | d.appendVar('RDEPENDS_' + pypackage, ' ' + pn + '-' + value) |
| 290 | d.setVar('SUMMARY_' + pypackage, python_manifest[key]['summary']) |
| 291 | |
| 292 | # We need to ensure staticdev packages match for files first so we sort in reverse |
| 293 | newpackages.sort(reverse=True) |
| 294 | # Prepending so to avoid python-misc getting everything |
| 295 | packages = newpackages + packages |
| 296 | d.setVar('PACKAGES', ' '.join(packages)) |
| 297 | d.setVar('ALLOW_EMPTY_${PN}-modules', '1') |
| 298 | } |
| 299 | |
| 300 | # Files needed to create a new manifest |
| 301 | SRC_URI += "file://create_manifest3.py file://get_module_deps3.py file://python3-manifest.json" |
| 302 | |
| 303 | do_create_manifest() { |
| 304 | # This task should be run with every new release of Python. |
| 305 | # We must ensure that PACKAGECONFIG enables everything when creating |
| 306 | # a new manifest, this is to base our new manifest on a complete |
| 307 | # native python build, containing all dependencies, otherwise the task |
| 308 | # wont be able to find the required files. |
| 309 | # e.g. BerkeleyDB is an optional build dependency so it may or may not |
| 310 | # be present, we must ensure it is. |
| 311 | |
| 312 | cd ${WORKDIR} |
| 313 | # This needs to be executed by python-native and NOT by HOST's python |
| 314 | nativepython3 create_manifest3.py |
| 315 | cp python3-manifest.json.new ${THISDIR}/python3/python3-manifest.json |
| 316 | } |
| 317 | |
| 318 | # bitbake python -c create_manifest |
| 319 | addtask do_create_manifest |
| 320 | |
| 321 | # Make sure we have native python ready when we create a new manifest |
| 322 | do_create_manifest[depends] += "python3:do_prepare_recipe_sysroot" |
| 323 | do_create_manifest[depends] += "python3:do_patch" |