Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 1 | SUMMARY = "The Python Programming Language" |
| 2 | HOMEPAGE = "http://www.python.org" |
| 3 | LICENSE = "PSFv2" |
| 4 | SECTION = "devel/python" |
| 5 | |
| 6 | LIC_FILES_CHKSUM = "file://LICENSE;md5=e466242989bd33c1bd2b6a526a742498" |
| 7 | |
| 8 | SRC_URI = "http://www.python.org/ftp/python/${PV}/Python-${PV}.tar.xz \ |
| 9 | file://run-ptest \ |
| 10 | file://create_manifest3.py \ |
| 11 | file://get_module_deps3.py \ |
| 12 | file://python3-manifest.json \ |
| 13 | file://check_build_completeness.py \ |
| 14 | file://cgi_py.patch \ |
| 15 | file://0001-Do-not-add-usr-lib-termcap-to-linker-flags-to-avoid-.patch \ |
| 16 | ${@bb.utils.contains('PACKAGECONFIG', 'tk', '', 'file://avoid_warning_about_tkinter.patch', d)} \ |
| 17 | file://0001-Do-not-use-the-shell-version-of-python-config-that-w.patch \ |
| 18 | file://python-config.patch \ |
| 19 | file://0001-Makefile.pre-use-qemu-wrapper-when-gathering-profile.patch \ |
| 20 | file://0001-Do-not-hardcode-lib-as-location-for-site-packages-an.patch \ |
| 21 | file://0001-python3-use-cc_basename-to-replace-CC-for-checking-c.patch \ |
| 22 | file://0002-Don-t-do-runtime-test-to-get-float-byte-order.patch \ |
| 23 | file://0003-setup.py-pass-missing-libraries-to-Extension-for-mul.patch \ |
| 24 | file://0001-Lib-sysconfig.py-fix-another-place-where-lib-is-hard.patch \ |
| 25 | file://0001-Makefile-fix-Issue36464-parallel-build-race-problem.patch \ |
| 26 | " |
| 27 | |
| 28 | SRC_URI_append_class-native = " \ |
| 29 | file://0001-distutils-sysconfig-append-STAGING_LIBDIR-python-sys.patch \ |
| 30 | file://12-distutils-prefix-is-inside-staging-area.patch \ |
| 31 | " |
| 32 | SRC_URI_append_class-nativesdk = " \ |
| 33 | file://0001-main.c-if-OEPYTHON3HOME-is-set-use-instead-of-PYTHON.patch \ |
| 34 | " |
| 35 | |
| 36 | SRC_URI[md5sum] = "93df27aec0cd18d6d42173e601ffbbfd" |
| 37 | SRC_URI[sha256sum] = "da60b54064d4cfcd9c26576f6df2690e62085123826cff2e667e72a91952d318" |
| 38 | |
| 39 | # exclude pre-releases for both python 2.x and 3.x |
| 40 | UPSTREAM_CHECK_REGEX = "[Pp]ython-(?P<pver>\d+(\.\d+)+).tar" |
| 41 | |
| 42 | CVE_PRODUCT = "python" |
| 43 | |
| 44 | PYTHON_MAJMIN = "3.7" |
| 45 | PYTHON_BINABI = "${PYTHON_MAJMIN}m" |
| 46 | |
| 47 | S = "${WORKDIR}/Python-${PV}" |
| 48 | |
| 49 | BBCLASSEXTEND = "native nativesdk" |
| 50 | |
| 51 | inherit autotools pkgconfig qemu ptest multilib_header update-alternatives |
| 52 | |
| 53 | MULTILIB_SUFFIX = "${@d.getVar('base_libdir',1).split('/')[-1]}" |
| 54 | |
| 55 | ALTERNATIVE_${PN}-dev = "python-config" |
| 56 | ALTERNATIVE_LINK_NAME[python-config] = "${bindir}/python${PYTHON_BINABI}-config" |
| 57 | ALTERNATIVE_TARGET[python-config] = "${bindir}/python${PYTHON_BINABI}-config-${MULTILIB_SUFFIX}" |
| 58 | |
| 59 | |
| 60 | DEPENDS = "bzip2-replacement-native libffi bzip2 gdbm openssl sqlite3 zlib virtual/libintl xz virtual/crypt util-linux libtirpc libnsl2" |
| 61 | DEPENDS_append_class-target = " python3-native" |
| 62 | DEPENDS_append_class-nativesdk = " python3-native" |
| 63 | |
| 64 | EXTRA_OECONF = " --without-ensurepip --enable-shared" |
| 65 | EXTRA_OECONF_append_class-native = " --bindir=${bindir}/${PN}" |
| 66 | |
| 67 | |
| 68 | EXTRANATIVEPATH += "python3-native" |
| 69 | |
| 70 | CACHED_CONFIGUREVARS = " \ |
| 71 | ac_cv_file__dev_ptmx=yes \ |
| 72 | ac_cv_file__dev_ptc=no \ |
| 73 | ac_cv_working_tzset=yes \ |
| 74 | " |
| 75 | |
| 76 | PACKAGECONFIG_class-target ??= "readline ${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'pgo', '', d)}" |
| 77 | PACKAGECONFIG_class-native ??= "readline" |
| 78 | PACKAGECONFIG_class-nativesdk ??= "readline" |
| 79 | PACKAGECONFIG[readline] = ",,readline" |
| 80 | # Use profile guided optimisation by running PyBench inside qemu-user |
| 81 | PACKAGECONFIG[pgo] = "--enable-optimizations,,qemu-native" |
| 82 | PACKAGECONFIG[tk] = ",,tk" |
| 83 | |
| 84 | CPPFLAGS_append = " -I${STAGING_INCDIR}/ncursesw -I${STAGING_INCDIR}/uuid" |
| 85 | |
| 86 | EXTRA_OEMAKE = '\ |
| 87 | STAGING_LIBDIR=${STAGING_LIBDIR} \ |
| 88 | STAGING_INCDIR=${STAGING_INCDIR} \ |
| 89 | LIB=${baselib} \ |
| 90 | ' |
| 91 | |
| 92 | do_compile_prepend_class-target() { |
| 93 | if ${@bb.utils.contains('PACKAGECONFIG', 'pgo', 'true', 'false', d)}; then |
| 94 | qemu_binary="${@qemu_wrapper_cmdline(d, '${STAGING_DIR_TARGET}', ['${B}', '${STAGING_DIR_TARGET}/${base_libdir}'])}" |
| 95 | cat >pgo-wrapper <<EOF |
| 96 | #!/bin/sh |
| 97 | cd ${B} |
| 98 | $qemu_binary "\$@" |
| 99 | EOF |
| 100 | chmod +x pgo-wrapper |
| 101 | fi |
| 102 | } |
| 103 | |
| 104 | do_install_prepend() { |
| 105 | ${WORKDIR}/check_build_completeness.py ${T}/log.do_compile |
| 106 | } |
| 107 | |
| 108 | do_install_append_class-target() { |
| 109 | oe_multilib_header python${PYTHON_BINABI}/pyconfig.h |
| 110 | } |
| 111 | |
| 112 | do_install_append_class-native() { |
| 113 | # Make sure we use /usr/bin/env python |
| 114 | for PYTHSCRIPT in `grep -rIl ${bindir}/${PN}/python ${D}${bindir}/${PN}`; do |
| 115 | sed -i -e '1s|^#!.*|#!/usr/bin/env python3|' $PYTHSCRIPT |
| 116 | done |
| 117 | # Add a symlink to the native Python so that scripts can just invoke |
| 118 | # "nativepython" and get the right one without needing absolute paths |
| 119 | # (these often end up too long for the #! parser in the kernel as the |
| 120 | # buffer is 128 bytes long). |
| 121 | ln -s python3-native/python3 ${D}${bindir}/nativepython3 |
| 122 | } |
| 123 | |
| 124 | do_install_append() { |
| 125 | mkdir -p ${D}${libdir}/python-sysconfigdata |
| 126 | sysconfigfile=`find ${D} -name _sysconfig*.py` |
| 127 | cp $sysconfigfile ${D}${libdir}/python-sysconfigdata/_sysconfigdata.py |
| 128 | |
| 129 | sed -i \ |
| 130 | -e "s,^ 'LIBDIR'.*, 'LIBDIR': '${STAGING_LIBDIR}'\,,g" \ |
| 131 | -e "s,^ 'INCLUDEDIR'.*, 'INCLUDEDIR': '${STAGING_INCDIR}'\,,g" \ |
| 132 | -e "s,^ 'CONFINCLUDEDIR'.*, 'CONFINCLUDEDIR': '${STAGING_INCDIR}'\,,g" \ |
| 133 | -e "/^ 'INCLDIRSTOMAKE'/{N; s,/usr/include,${STAGING_INCDIR},g}" \ |
| 134 | -e "/^ 'INCLUDEPY'/s,/usr/include,${STAGING_INCDIR},g" \ |
| 135 | ${D}${libdir}/python-sysconfigdata/_sysconfigdata.py |
| 136 | } |
| 137 | |
| 138 | do_install_append_class-nativesdk () { |
| 139 | create_wrapper ${D}${bindir}/python${PYTHON_MAJMIN} OEPYTHON3HOME='${prefix}' TERMINFO_DIRS='${sysconfdir}/terminfo:/etc/terminfo:/usr/share/terminfo:/usr/share/misc/terminfo:/lib/terminfo' PYTHONNOUSERSITE='1' |
| 140 | } |
| 141 | |
| 142 | SSTATE_SCAN_FILES += "Makefile _sysconfigdata.py" |
| 143 | PACKAGE_PREPROCESS_FUNCS += "py_package_preprocess" |
| 144 | |
| 145 | py_package_preprocess () { |
| 146 | # Remove references to buildmachine paths in target Makefile and _sysconfigdata |
| 147 | sed -i -e 's:--sysroot=${STAGING_DIR_TARGET}::g' -e s:'--with-libtool-sysroot=${STAGING_DIR_TARGET}'::g \ |
| 148 | -e 's|${DEBUG_PREFIX_MAP}||g' \ |
| 149 | -e 's:${HOSTTOOLS_DIR}/::g' \ |
| 150 | -e 's:${RECIPE_SYSROOT_NATIVE}::g' \ |
| 151 | -e 's:${RECIPE_SYSROOT}::g' \ |
| 152 | -e 's:${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}::g' \ |
| 153 | ${PKGD}/${prefix}/lib/python${PYTHON_MAJMIN}/config-${PYTHON_MAJMIN}${PYTHON_ABI}*/Makefile \ |
| 154 | ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata*.py \ |
| 155 | ${PKGD}/${bindir}/python${PYTHON_BINABI}-config |
| 156 | |
| 157 | # Recompile _sysconfigdata after modifying it |
| 158 | cd ${PKGD} |
| 159 | sysconfigfile=`find . -name _sysconfigdata_*.py` |
| 160 | ${STAGING_BINDIR_NATIVE}/python3-native/python3 \ |
| 161 | -c "from py_compile import compile; compile('$sysconfigfile')" |
| 162 | ${STAGING_BINDIR_NATIVE}/python3-native/python3 \ |
| 163 | -c "from py_compile import compile; compile('$sysconfigfile', optimize=1)" |
| 164 | ${STAGING_BINDIR_NATIVE}/python3-native/python3 \ |
| 165 | -c "from py_compile import compile; compile('$sysconfigfile', optimize=2)" |
| 166 | cd - |
| 167 | |
| 168 | mv ${PKGD}/${bindir}/python${PYTHON_BINABI}-config ${PKGD}/${bindir}/python${PYTHON_BINABI}-config-${MULTILIB_SUFFIX} |
| 169 | |
| 170 | #Remove the unneeded copy of target sysconfig data |
| 171 | rm -rf ${PKGD}/${libdir}/python-sysconfigdata |
| 172 | } |
| 173 | |
| 174 | # We want bytecode precompiled .py files (.pyc's) by default |
| 175 | # but the user may set it on their own conf |
| 176 | INCLUDE_PYCS ?= "1" |
| 177 | |
| 178 | python(){ |
| 179 | import collections, json |
| 180 | |
| 181 | filename = os.path.join(d.getVar('THISDIR'), 'python3', 'python3-manifest.json') |
| 182 | # This python changes the datastore based on the contents of a file, so mark |
| 183 | # that dependency. |
| 184 | bb.parse.mark_dependency(d, filename) |
| 185 | |
| 186 | with open(filename) as manifest_file: |
| 187 | manifest_str = manifest_file.read() |
| 188 | json_start = manifest_str.find('# EOC') + 6 |
| 189 | manifest_file.seek(json_start) |
| 190 | manifest_str = manifest_file.read() |
| 191 | python_manifest = json.loads(manifest_str, object_pairs_hook=collections.OrderedDict) |
| 192 | |
| 193 | # First set RPROVIDES for -native case |
| 194 | # Hardcoded since it cant be python3-native-foo, should be python3-foo-native |
| 195 | pn = 'python3' |
| 196 | rprovides = d.getVar('RPROVIDES').split() |
| 197 | |
| 198 | for key in python_manifest: |
| 199 | pypackage = pn + '-' + key + '-native' |
| 200 | if pypackage not in rprovides: |
| 201 | rprovides.append(pypackage) |
| 202 | |
| 203 | d.setVar('RPROVIDES_class-native', ' '.join(rprovides)) |
| 204 | |
| 205 | # Then work on the target |
| 206 | include_pycs = d.getVar('INCLUDE_PYCS') |
| 207 | |
| 208 | packages = d.getVar('PACKAGES').split() |
| 209 | pn = d.getVar('PN') |
| 210 | |
| 211 | newpackages=[] |
| 212 | for key in python_manifest: |
| 213 | pypackage= pn + '-' + key |
| 214 | |
| 215 | if pypackage not in packages: |
| 216 | # We need to prepend, otherwise python-misc gets everything |
| 217 | # so we use a new variable |
| 218 | newpackages.append(pypackage) |
| 219 | |
| 220 | # "Build" python's manifest FILES, RDEPENDS and SUMMARY |
| 221 | d.setVar('FILES_' + pypackage, '') |
| 222 | for value in python_manifest[key]['files']: |
| 223 | d.appendVar('FILES_' + pypackage, ' ' + value) |
| 224 | |
| 225 | # Add cached files |
| 226 | if include_pycs == '1': |
| 227 | for value in python_manifest[key]['cached']: |
| 228 | d.appendVar('FILES_' + pypackage, ' ' + value) |
| 229 | |
| 230 | for value in python_manifest[key]['rdepends']: |
| 231 | # Make it work with or without $PN |
| 232 | if '${PN}' in value: |
| 233 | value=value.split('-')[1] |
| 234 | d.appendVar('RDEPENDS_' + pypackage, ' ' + pn + '-' + value) |
| 235 | d.setVar('SUMMARY_' + pypackage, python_manifest[key]['summary']) |
| 236 | |
| 237 | # Prepending so to avoid python-misc getting everything |
| 238 | packages = newpackages + packages |
| 239 | d.setVar('PACKAGES', ' '.join(packages)) |
| 240 | d.setVar('ALLOW_EMPTY_${PN}-modules', '1') |
| 241 | } |
| 242 | |
| 243 | # Files needed to create a new manifest |
| 244 | |
| 245 | do_create_manifest() { |
| 246 | # This task should be run with every new release of Python. |
| 247 | # We must ensure that PACKAGECONFIG enables everything when creating |
| 248 | # a new manifest, this is to base our new manifest on a complete |
| 249 | # native python build, containing all dependencies, otherwise the task |
| 250 | # wont be able to find the required files. |
| 251 | # e.g. BerkeleyDB is an optional build dependency so it may or may not |
| 252 | # be present, we must ensure it is. |
| 253 | |
| 254 | cd ${WORKDIR} |
| 255 | # This needs to be executed by python-native and NOT by HOST's python |
| 256 | nativepython3 create_manifest3.py ${PYTHON_MAJMIN} |
| 257 | cp python3-manifest.json.new ${THISDIR}/python3/python3-manifest.json |
| 258 | } |
| 259 | |
| 260 | # bitbake python -c create_manifest |
| 261 | addtask do_create_manifest |
| 262 | |
| 263 | # Make sure we have native python ready when we create a new manifest |
| 264 | do_create_manifest[depends] += "${PN}:do_prepare_recipe_sysroot" |
| 265 | do_create_manifest[depends] += "${PN}:do_patch" |
| 266 | |
| 267 | # manual dependency additions |
| 268 | RPROVIDES_${PN}-modules = "${PN}" |
| 269 | RRECOMMENDS_${PN}-core_append_class-nativesdk = " nativesdk-python3-modules" |
| 270 | RRECOMMENDS_${PN}-crypt_append_class-target = " openssl ca-certificates" |
| 271 | RRECOMMENDS_${PN}-crypt_append_class-nativesdk = " openssl ca-certificates" |
| 272 | |
| 273 | FILES_${PN}-pydoc += "${bindir}/pydoc${PYTHON_MAJMIN} ${bindir}/pydoc3" |
| 274 | FILES_${PN}-idle += "${bindir}/idle3 ${bindir}/idle${PYTHON_MAJMIN}" |
| 275 | |
| 276 | # provide python-pyvenv from python3-venv |
| 277 | RPROVIDES_${PN}-venv += "python3-pyvenv" |
| 278 | |
| 279 | # package libpython3 |
| 280 | PACKAGES =+ "libpython3 libpython3-staticdev" |
| 281 | FILES_libpython3 = "${libdir}/libpython*.so.*" |
| 282 | FILES_libpython3-staticdev += "${prefix}/lib/python${PYTHON_MAJMIN}/config-${PYTHON_BINABI}-*/libpython${PYTHON_BINABI}.a" |
| 283 | INSANE_SKIP_${PN}-dev += "dev-elf" |
| 284 | |
| 285 | # catch all the rest (unsorted) |
| 286 | PACKAGES += "${PN}-misc" |
| 287 | RDEPENDS_${PN}-misc += "python3-core python3-email python3-codecs" |
| 288 | RDEPENDS_${PN}-modules_append_class-target = " python3-misc" |
| 289 | RDEPENDS_${PN}-modules_append_class-nativesdk = " python3-misc" |
| 290 | FILES_${PN}-misc = "${libdir}/python${PYTHON_MAJMIN} ${libdir}/python${PYTHON_MAJMIN}/lib-dynload" |
| 291 | |
| 292 | # catch manpage |
| 293 | PACKAGES += "${PN}-man" |
| 294 | FILES_${PN}-man = "${datadir}/man" |
| 295 | |
| 296 | RDEPENDS_${PN}-ptest = "${PN}-modules ${PN}-tests unzip bzip2 libgcc tzdata-europe coreutils sed" |
| 297 | RDEPENDS_${PN}-ptest_append_libc-glibc = " locale-base-tr-tr.iso-8859-9" |
| 298 | RDEPENDS_${PN}-tkinter += "${@bb.utils.contains('PACKAGECONFIG', 'tk', 'tk', '', d)}" |
| 299 | RDEPENDS_${PN}-dev = "" |
| 300 | |