1*2f814a6dSPatrick WilliamsSUMMARY = "The Python Programming Language" 2*2f814a6dSPatrick WilliamsHOMEPAGE = "http://www.python.org" 3*2f814a6dSPatrick WilliamsDESCRIPTION = "Python is a programming language that lets you work more quickly and integrate your systems more effectively." 4*2f814a6dSPatrick WilliamsLICENSE = "PSF-2.0" 5*2f814a6dSPatrick WilliamsSECTION = "devel/python" 6*2f814a6dSPatrick Williams 7*2f814a6dSPatrick WilliamsLIC_FILES_CHKSUM = "file://LICENSE;md5=fcf6b249c2641540219a727f35d8d2c2" 8*2f814a6dSPatrick Williams 9*2f814a6dSPatrick WilliamsSRC_URI = "http://www.python.org/ftp/python/${PV}/Python-${PV}.tar.xz \ 10*2f814a6dSPatrick Williams file://run-ptest \ 11*2f814a6dSPatrick Williams file://create_manifest3.py \ 12*2f814a6dSPatrick Williams file://get_module_deps3.py \ 13*2f814a6dSPatrick Williams file://python3-manifest.json \ 14*2f814a6dSPatrick Williams file://check_build_completeness.py \ 15*2f814a6dSPatrick Williams file://reformat_sysconfig.py \ 16*2f814a6dSPatrick Williams file://cgi_py.patch \ 17*2f814a6dSPatrick Williams file://0001-Makefile.pre-use-qemu-wrapper-when-gathering-profile.patch \ 18*2f814a6dSPatrick Williams file://0001-python3-use-cc_basename-to-replace-CC-for-checking-c.patch \ 19*2f814a6dSPatrick Williams file://crosspythonpath.patch \ 20*2f814a6dSPatrick Williams file://0001-test_locale.py-correct-the-test-output-format.patch \ 21*2f814a6dSPatrick Williams file://0020-configure.ac-setup.py-do-not-add-a-curses-include-pa.patch \ 22*2f814a6dSPatrick Williams file://0001-Skip-failing-tests-due-to-load-variability-on-YP-AB.patch \ 23*2f814a6dSPatrick Williams file://0001-test_ctypes.test_find-skip-without-tools-sdk.patch \ 24*2f814a6dSPatrick Williams file://makerace.patch \ 25*2f814a6dSPatrick Williams file://0001-sysconfig.py-use-platlibdir-also-for-purelib.patch \ 26*2f814a6dSPatrick Williams file://0001-Lib-pty.py-handle-stdin-I-O-errors-same-way-as-maste.patch \ 27*2f814a6dSPatrick Williams file://deterministic_imports.patch \ 28*2f814a6dSPatrick Williams file://0001-Avoid-shebang-overflow-on-python-config.py.patch \ 29*2f814a6dSPatrick Williams file://0001-Update-test_sysconfig-for-posix_user-purelib.patch \ 30*2f814a6dSPatrick Williams file://0001-skip-no_stdout_fileno-test-due-to-load-variability.patch \ 31*2f814a6dSPatrick Williams file://0001-test_storlines-skip-due-to-load-variability.patch \ 32*2f814a6dSPatrick Williams file://0001-gh-114492-Initialize-struct-termios-before-calling-t.patch \ 33*2f814a6dSPatrick Williams " 34*2f814a6dSPatrick Williams 35*2f814a6dSPatrick WilliamsSRC_URI:append:class-native = " \ 36*2f814a6dSPatrick Williams file://0001-Lib-sysconfig.py-use-prefix-value-from-build-configu.patch \ 37*2f814a6dSPatrick Williams " 38*2f814a6dSPatrick Williams 39*2f814a6dSPatrick WilliamsSRC_URI[sha256sum] = "56bfef1fdfc1221ce6720e43a661e3eb41785dd914ce99698d8c7896af4bdaa1" 40*2f814a6dSPatrick Williams 41*2f814a6dSPatrick Williams# exclude pre-releases for both python 2.x and 3.x 42*2f814a6dSPatrick WilliamsUPSTREAM_CHECK_REGEX = "[Pp]ython-(?P<pver>\d+(\.\d+)+).tar" 43*2f814a6dSPatrick Williams 44*2f814a6dSPatrick WilliamsCVE_PRODUCT = "python cpython" 45*2f814a6dSPatrick Williams 46*2f814a6dSPatrick WilliamsCVE_STATUS[CVE-2007-4559] = "disputed: Upstream consider this expected behaviour" 47*2f814a6dSPatrick WilliamsCVE_STATUS[CVE-2019-18348] = "not-applicable-config: This is not exploitable when glibc has CVE-2016-10739 fixed" 48*2f814a6dSPatrick WilliamsCVE_STATUS[CVE-2020-15523] = "not-applicable-platform: Issue only applies on Windows" 49*2f814a6dSPatrick WilliamsCVE_STATUS[CVE-2022-26488] = "not-applicable-platform: Issue only applies on Windows" 50*2f814a6dSPatrick Williams# The module will be removed in the future and flaws documented. 51*2f814a6dSPatrick WilliamsCVE_STATUS[CVE-2015-20107] = "upstream-wontfix: The mailcap module is insecure by design, so this can't be fixed in a meaningful way" 52*2f814a6dSPatrick WilliamsCVE_STATUS[CVE-2023-36632] = "disputed: Not an issue, in fact expected behaviour" 53*2f814a6dSPatrick Williams 54*2f814a6dSPatrick WilliamsPYTHON_MAJMIN = "3.12" 55*2f814a6dSPatrick Williams 56*2f814a6dSPatrick WilliamsS = "${WORKDIR}/Python-${PV}" 57*2f814a6dSPatrick Williams 58*2f814a6dSPatrick WilliamsBBCLASSEXTEND = "native nativesdk" 59*2f814a6dSPatrick Williams 60*2f814a6dSPatrick Williamsinherit autotools pkgconfig qemu ptest multilib_header update-alternatives 61*2f814a6dSPatrick Williams 62*2f814a6dSPatrick WilliamsMULTILIB_SUFFIX = "${@d.getVar('base_libdir',1).split('/')[-1]}" 63*2f814a6dSPatrick Williams 64*2f814a6dSPatrick WilliamsALTERNATIVE:${PN}-dev = "python3-config" 65*2f814a6dSPatrick WilliamsALTERNATIVE_LINK_NAME[python3-config] = "${bindir}/python${PYTHON_MAJMIN}-config" 66*2f814a6dSPatrick WilliamsALTERNATIVE_TARGET[python3-config] = "${bindir}/python${PYTHON_MAJMIN}-config-${MULTILIB_SUFFIX}" 67*2f814a6dSPatrick Williams 68*2f814a6dSPatrick Williams 69*2f814a6dSPatrick WilliamsDEPENDS = "bzip2-replacement-native expat libffi bzip2 openssl sqlite3 zlib virtual/libintl xz virtual/crypt util-linux-libuuid libtirpc libnsl2 autoconf-archive-native ncurses" 70*2f814a6dSPatrick WilliamsDEPENDS:append:class-target = " python3-native" 71*2f814a6dSPatrick WilliamsDEPENDS:append:class-nativesdk = " python3-native" 72*2f814a6dSPatrick Williams 73*2f814a6dSPatrick WilliamsEXTRA_OECONF = " --without-ensurepip --enable-shared --with-platlibdir=${baselib} --with-system-expat" 74*2f814a6dSPatrick WilliamsEXTRA_OECONF:append:class-native = " --bindir=${bindir}/${PN}" 75*2f814a6dSPatrick WilliamsEXTRA_OECONF:append:class-target = " --with-build-python=nativepython3" 76*2f814a6dSPatrick WilliamsEXTRA_OECONF:append:class-nativesdk = " --with-build-python=nativepython3" 77*2f814a6dSPatrick Williams 78*2f814a6dSPatrick Williamsexport CROSSPYTHONPATH="${STAGING_LIBDIR_NATIVE}/python${PYTHON_MAJMIN}/lib-dynload/" 79*2f814a6dSPatrick Williams 80*2f814a6dSPatrick WilliamsEXTRANATIVEPATH += "python3-native" 81*2f814a6dSPatrick Williams 82*2f814a6dSPatrick Williams# LTO will be enabled via packageconfig depending upong distro features 83*2f814a6dSPatrick WilliamsLTO:class-target = "" 84*2f814a6dSPatrick Williams 85*2f814a6dSPatrick WilliamsCACHED_CONFIGUREVARS = " \ 86*2f814a6dSPatrick Williams ac_cv_file__dev_ptmx=yes \ 87*2f814a6dSPatrick Williams ac_cv_file__dev_ptc=no \ 88*2f814a6dSPatrick Williams ac_cv_working_tzset=yes \ 89*2f814a6dSPatrick Williams" 90*2f814a6dSPatrick Williams# set thread stack size to 2MB on musl for interpreter and stdlib C extensions 91*2f814a6dSPatrick Williams# so it does not run into stack limits due to musl's small thread stack 92*2f814a6dSPatrick Williams# This is only needed to build interpreter and not the subsequent modules 93*2f814a6dSPatrick Williams# Thats why CFLAGS_NODIST is modified instead of CFLAGS 94*2f814a6dSPatrick WilliamsCACHED_CONFIGUREVARS:append:libc-musl = "\ 95*2f814a6dSPatrick Williams CFLAGS_NODIST='${CFLAGS} -DTHREAD_STACK_SIZE=0x200000' \ 96*2f814a6dSPatrick Williams" 97*2f814a6dSPatrick Williams 98*2f814a6dSPatrick Williams# PGO currently causes builds to not be reproducible so disable by default, see YOCTO #13407 99*2f814a6dSPatrick WilliamsPACKAGECONFIG ??= "editline gdbm ${@bb.utils.filter('DISTRO_FEATURES', 'lto', d)}" 100*2f814a6dSPatrick WilliamsPACKAGECONFIG[readline] = "--with-readline=readline,,readline,,,editline" 101*2f814a6dSPatrick WilliamsPACKAGECONFIG[editline] = "--with-readline=editline,,libedit,,,readline" 102*2f814a6dSPatrick Williams# Use profile guided optimisation by running PyBench inside qemu-user 103*2f814a6dSPatrick WilliamsPACKAGECONFIG[pgo] = "--enable-optimizations,,qemu-native" 104*2f814a6dSPatrick WilliamsPACKAGECONFIG[tk] = ",,tk" 105*2f814a6dSPatrick WilliamsPACKAGECONFIG[tcl] = ",,tcl" 106*2f814a6dSPatrick WilliamsPACKAGECONFIG[gdbm] = ",,gdbm" 107*2f814a6dSPatrick WilliamsPACKAGECONFIG[lto] = "--with-lto,--without-lto" 108*2f814a6dSPatrick Williams 109*2f814a6dSPatrick Williamsdo_configure:prepend () { 110*2f814a6dSPatrick Williams mkdir -p ${B}/Modules 111*2f814a6dSPatrick Williams cat > ${B}/Modules/Setup.local << EOF 112*2f814a6dSPatrick Williams*disabled* 113*2f814a6dSPatrick Williams${@bb.utils.contains('PACKAGECONFIG', 'gdbm', '', '_gdbm _dbm', d)} 114*2f814a6dSPatrick Williams${@bb.utils.contains_any('PACKAGECONFIG', 'readline editline', '', 'readline', d)} 115*2f814a6dSPatrick Williams${@bb.utils.contains('PACKAGECONFIG', 'tk', '', '_tkinter', d)} 116*2f814a6dSPatrick WilliamsEOF 117*2f814a6dSPatrick Williams} 118*2f814a6dSPatrick Williams 119*2f814a6dSPatrick WilliamsCPPFLAGS:append = " -I${STAGING_INCDIR}/ncursesw -I${STAGING_INCDIR}/uuid" 120*2f814a6dSPatrick Williams 121*2f814a6dSPatrick Williams# COMPILEALL_OPTS= ensures that .pyc are not compiled in parallel 122*2f814a6dSPatrick Williams# This was found to lock up builds, break reproducibility, and produce strange file ownership 123*2f814a6dSPatrick Williams# races. 124*2f814a6dSPatrick Williams# 125*2f814a6dSPatrick Williams# The upstream commit introducing the change was: 126*2f814a6dSPatrick Williams# https://github.com/python/cpython/commit/1a2dd82f56bd813aacc570e172cefe55a8a41504 127*2f814a6dSPatrick Williams# 128*2f814a6dSPatrick Williams# The build lock up issue is reported here: 129*2f814a6dSPatrick Williams# https://bugs.python.org/issue45945 130*2f814a6dSPatrick Williams# 131*2f814a6dSPatrick Williams# The repro failures are documented here: 132*2f814a6dSPatrick Williams# https://autobuilder.yocto.io/pub/repro-fail/oe-reproducible-20211130-yr_o1a8d/packages/diff-html/ 133*2f814a6dSPatrick Williams 134*2f814a6dSPatrick WilliamsEXTRA_OEMAKE = '\ 135*2f814a6dSPatrick Williams STAGING_LIBDIR=${STAGING_LIBDIR} \ 136*2f814a6dSPatrick Williams STAGING_INCDIR=${STAGING_INCDIR} \ 137*2f814a6dSPatrick Williams LIB=${baselib} \ 138*2f814a6dSPatrick Williams COMPILEALL_OPTS= \ 139*2f814a6dSPatrick Williams' 140*2f814a6dSPatrick Williams 141*2f814a6dSPatrick Williams# Generate a Profile Guided Optimisation wrapper script that uses qemu-user for 142*2f814a6dSPatrick Williams# all cross builds. 143*2f814a6dSPatrick Williamswrite_pgo_wrapper:class-native = ":" 144*2f814a6dSPatrick Williamswrite_pgo_wrapper() { 145*2f814a6dSPatrick Williams if ${@bb.utils.contains('PACKAGECONFIG', 'pgo', 'true', 'false', d)}; then 146*2f814a6dSPatrick Williams cat >pgo-wrapper <<EOF 147*2f814a6dSPatrick Williams#!/bin/sh 148*2f814a6dSPatrick Williamscd ${B} 149*2f814a6dSPatrick Williams${@qemu_wrapper_cmdline(d, '${STAGING_DIR_TARGET}', ['${B}', '${STAGING_DIR_TARGET}/${base_libdir}'])} "\$@" 150*2f814a6dSPatrick WilliamsEOF 151*2f814a6dSPatrick Williams chmod +x pgo-wrapper 152*2f814a6dSPatrick Williams fi 153*2f814a6dSPatrick Williams} 154*2f814a6dSPatrick Williams 155*2f814a6dSPatrick Williamsdo_compile:prepend() { 156*2f814a6dSPatrick Williams write_pgo_wrapper 157*2f814a6dSPatrick Williams} 158*2f814a6dSPatrick Williams 159*2f814a6dSPatrick Williamsdo_install:prepend() { 160*2f814a6dSPatrick Williams ${WORKDIR}/check_build_completeness.py ${T}/log.do_compile 161*2f814a6dSPatrick Williams} 162*2f814a6dSPatrick Williams 163*2f814a6dSPatrick Williamsdo_install:append:class-target() { 164*2f814a6dSPatrick Williams oe_multilib_header python${PYTHON_MAJMIN}/pyconfig.h 165*2f814a6dSPatrick Williams} 166*2f814a6dSPatrick Williams 167*2f814a6dSPatrick Williamsdo_install:append:class-native() { 168*2f814a6dSPatrick Williams # Make sure we use /usr/bin/env python 169*2f814a6dSPatrick Williams for PYTHSCRIPT in `grep -rIl ${bindir}/${PN}/python ${D}${bindir}/${PN}`; do 170*2f814a6dSPatrick Williams sed -i -e '1s|^#!.*|#!/usr/bin/env python3|' $PYTHSCRIPT 171*2f814a6dSPatrick Williams done 172*2f814a6dSPatrick Williams # Add a symlink to the native Python so that scripts can just invoke 173*2f814a6dSPatrick Williams # "nativepython" and get the right one without needing absolute paths 174*2f814a6dSPatrick Williams # (these often end up too long for the #! parser in the kernel as the 175*2f814a6dSPatrick Williams # buffer is 128 bytes long). 176*2f814a6dSPatrick Williams ln -s python3-native/python3 ${D}${bindir}/nativepython3 177*2f814a6dSPatrick Williams 178*2f814a6dSPatrick Williams # Remove the opt-1.pyc and opt-2.pyc files. There are over 3,000 of them 179*2f814a6dSPatrick Williams # and the overhead in each recipe-sysroot-native isn't worth it, particularly 180*2f814a6dSPatrick Williams # when they're only used for python called with -O or -OO. 181*2f814a6dSPatrick Williams #find ${D} -name *opt-*.pyc -delete 182*2f814a6dSPatrick Williams # Remove all pyc files. There are a ton of them and it is probably faster to let 183*2f814a6dSPatrick Williams # python create the ones it wants at runtime rather than manage in the sstate 184*2f814a6dSPatrick Williams # tarballs and sysroot creation. 185*2f814a6dSPatrick Williams find ${D} -name *.pyc -delete 186*2f814a6dSPatrick Williams 187*2f814a6dSPatrick Williams # Nothing should be looking into ${B} for python3-native 188*2f814a6dSPatrick Williams sed -i -e 's:${B}:/build/path/unavailable/:g' \ 189*2f814a6dSPatrick Williams ${D}/${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_MAJMIN}${PYTHON_ABI}*/Makefile 190*2f814a6dSPatrick Williams 191*2f814a6dSPatrick Williams # disable the lookup in user's site-packages globally 192*2f814a6dSPatrick Williams sed -i 's#ENABLE_USER_SITE = None#ENABLE_USER_SITE = False#' ${D}${libdir}/python${PYTHON_MAJMIN}/site.py 193*2f814a6dSPatrick Williams 194*2f814a6dSPatrick Williams # python3-config needs to be in /usr/bin and not in a subdir of it to work properly 195*2f814a6dSPatrick Williams mv ${D}/${bindir}/${PN}/python*config ${D}/${bindir}/ 196*2f814a6dSPatrick Williams} 197*2f814a6dSPatrick Williams 198*2f814a6dSPatrick Williamsdo_install:append() { 199*2f814a6dSPatrick Williams for c in ${D}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata*.py; do 200*2f814a6dSPatrick Williams python3 ${WORKDIR}/reformat_sysconfig.py $c 201*2f814a6dSPatrick Williams done 202*2f814a6dSPatrick Williams rm -f ${D}${libdir}/python${PYTHON_MAJMIN}/__pycache__/_sysconfigdata*.cpython* 203*2f814a6dSPatrick Williams 204*2f814a6dSPatrick Williams mkdir -p ${D}${libdir}/python-sysconfigdata 205*2f814a6dSPatrick Williams sysconfigfile=`find ${D} -name _sysconfig*.py` 206*2f814a6dSPatrick Williams sed -i \ 207*2f814a6dSPatrick Williams -e "s,^ 'LIBDIR'.*, 'LIBDIR': '${STAGING_LIBDIR}'\,,g" \ 208*2f814a6dSPatrick Williams -e "s,^ 'INCLUDEDIR'.*, 'INCLUDEDIR': '${STAGING_INCDIR}'\,,g" \ 209*2f814a6dSPatrick Williams -e "s,^ 'CONFINCLUDEDIR'.*, 'CONFINCLUDEDIR': '${STAGING_INCDIR}'\,,g" \ 210*2f814a6dSPatrick Williams -e "s,^ 'INCLUDEPY'.*, 'INCLUDEPY': '${STAGING_INCDIR}/python${PYTHON_MAJMIN}'\,,g" \ 211*2f814a6dSPatrick Williams -e "s,^ 'CONFINCLUDEPY'.*, 'CONFINCLUDEPY': '${STAGING_INCDIR}/python${PYTHON_MAJMIN}'\,,g" \ 212*2f814a6dSPatrick Williams -e "s,${B},/build/path/unavailable/,g" \ 213*2f814a6dSPatrick Williams $sysconfigfile 214*2f814a6dSPatrick Williams cp $sysconfigfile ${D}${libdir}/python-sysconfigdata/_sysconfigdata.py 215*2f814a6dSPatrick Williams 216*2f814a6dSPatrick Williams 217*2f814a6dSPatrick Williams # Unfortunately the following pyc files are non-deterministc due to 'frozenset' 218*2f814a6dSPatrick Williams # being written without strict ordering, even with PYTHONHASHSEED = 0 219*2f814a6dSPatrick Williams # Upstream is discussing ways to solve the issue properly, until then let's 220*2f814a6dSPatrick Williams # just not install the problematic files. 221*2f814a6dSPatrick Williams # More info: http://benno.id.au/blog/2013/01/15/python-determinism 222*2f814a6dSPatrick Williams rm -f ${D}${libdir}/python${PYTHON_MAJMIN}/test/__pycache__/test_range.cpython* 223*2f814a6dSPatrick Williams rm -f ${D}${libdir}/python${PYTHON_MAJMIN}/test/__pycache__/test_xml_etree.cpython* 224*2f814a6dSPatrick Williams 225*2f814a6dSPatrick Williams # Similar to the above, we're getting reproducibility issues with 226*2f814a6dSPatrick Williams # /usr/lib/python3.10/__pycache__/traceback.cpython-310.pyc 227*2f814a6dSPatrick Williams # so remove it too 228*2f814a6dSPatrick Williams rm -f ${D}${libdir}/python${PYTHON_MAJMIN}/__pycache__/traceback.cpython* 229*2f814a6dSPatrick Williams 230*2f814a6dSPatrick Williams # Remove the opt-1.pyc and opt-2.pyc files. They effectively waste space on embedded 231*2f814a6dSPatrick Williams # style targets as they're only used when python is called with the -O or -OO options 232*2f814a6dSPatrick Williams # which is rare. 233*2f814a6dSPatrick Williams find ${D} -name *opt-*.pyc -delete 234*2f814a6dSPatrick Williams} 235*2f814a6dSPatrick Williams 236*2f814a6dSPatrick Williamsdo_install:append:class-nativesdk () { 237*2f814a6dSPatrick Williams # Make sure we use /usr/bin/env python 238*2f814a6dSPatrick Williams for PYTHSCRIPT in `grep -rIl ${bindir}/python ${D}${bindir}`; do 239*2f814a6dSPatrick Williams sed -i -e '1s|^#!.*|#!/usr/bin/env python3|' $PYTHSCRIPT 240*2f814a6dSPatrick Williams done 241*2f814a6dSPatrick Williams create_wrapper ${D}${bindir}/python${PYTHON_MAJMIN} TERMINFO_DIRS='${sysconfdir}/terminfo:/etc/terminfo:/usr/share/terminfo:/usr/share/misc/terminfo:/lib/terminfo' PYTHONNOUSERSITE='1' 242*2f814a6dSPatrick Williams} 243*2f814a6dSPatrick Williams 244*2f814a6dSPatrick Williamsdo_install_ptest:append:class-target:libc-musl () { 245*2f814a6dSPatrick Williams sed -i -e 's|SKIPPED_TESTS=|SKIPPED_TESTS="-x test__locale -x test_c_locale_coercion -x test_locale -x test_os test_re -x test__xxsubinterpreters -x test_threading"|' ${D}${PTEST_PATH}/run-ptest 246*2f814a6dSPatrick Williams} 247*2f814a6dSPatrick Williams 248*2f814a6dSPatrick WilliamsSYSROOT_PREPROCESS_FUNCS:append:class-target = " provide_target_config_script" 249*2f814a6dSPatrick WilliamsSYSROOT_PREPROCESS_FUNCS:append:class-nativesdk = " provide_target_config_script" 250*2f814a6dSPatrick Williams 251*2f814a6dSPatrick Williams# This is installed into /usr/python-target-config/ and not /usr/bin 252*2f814a6dSPatrick Williams# because adding target sysroot's /usr/bin/ to PATH has unwanted side effects 253*2f814a6dSPatrick Williams# in components erroneously picking up other target executables from it 254*2f814a6dSPatrick Williamsprovide_target_config_script() { 255*2f814a6dSPatrick Williams install -d ${SYSROOT_DESTDIR}${prefix}/python-target-config/ 256*2f814a6dSPatrick Williams install ${D}/${bindir}/python3-config ${SYSROOT_DESTDIR}/${prefix}/python-target-config/ 257*2f814a6dSPatrick Williams install ${D}/${bindir}/python${PYTHON_MAJMIN}-config ${SYSROOT_DESTDIR}/${prefix}/python-target-config/ 258*2f814a6dSPatrick Williams} 259*2f814a6dSPatrick WilliamsSYSROOT_DIRS += "${prefix}/python-target-config/" 260*2f814a6dSPatrick Williams 261*2f814a6dSPatrick WilliamsSSTATE_SCAN_FILES += "Makefile _sysconfigdata.py" 262*2f814a6dSPatrick WilliamsSSTATE_HASHEQUIV_FILEMAP = " \ 263*2f814a6dSPatrick Williams populate_sysroot:*/lib*/python3*/_sysconfigdata*.py:${TMPDIR} \ 264*2f814a6dSPatrick Williams populate_sysroot:*/lib*/python3*/_sysconfigdata*.py:${COREBASE} \ 265*2f814a6dSPatrick Williams populate_sysroot:*/lib*/python3*/config-*/Makefile:${TMPDIR} \ 266*2f814a6dSPatrick Williams populate_sysroot:*/lib*/python3*/config-*/Makefile:${COREBASE} \ 267*2f814a6dSPatrick Williams populate_sysroot:*/lib*/python-sysconfigdata/_sysconfigdata.py:${TMPDIR} \ 268*2f814a6dSPatrick Williams populate_sysroot:*/lib*/python-sysconfigdata/_sysconfigdata.py:${COREBASE} \ 269*2f814a6dSPatrick Williams " 270*2f814a6dSPatrick WilliamsPACKAGE_PREPROCESS_FUNCS += "py_package_preprocess" 271*2f814a6dSPatrick Williams 272*2f814a6dSPatrick Williamspy_package_preprocess () { 273*2f814a6dSPatrick Williams # Remove references to buildmachine paths in target Makefile and _sysconfigdata 274*2f814a6dSPatrick Williams sed -i -e 's:--sysroot=${STAGING_DIR_TARGET}::g' -e s:'--with-libtool-sysroot=${STAGING_DIR_TARGET}'::g \ 275*2f814a6dSPatrick Williams -e 's|${DEBUG_PREFIX_MAP}||g' \ 276*2f814a6dSPatrick Williams -e 's:${HOSTTOOLS_DIR}/::g' \ 277*2f814a6dSPatrick Williams -e 's:${RECIPE_SYSROOT_NATIVE}::g' \ 278*2f814a6dSPatrick Williams -e 's:${RECIPE_SYSROOT}::g' \ 279*2f814a6dSPatrick Williams -e 's:${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}::g' \ 280*2f814a6dSPatrick Williams ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_MAJMIN}${PYTHON_ABI}*/Makefile \ 281*2f814a6dSPatrick Williams ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata*.py \ 282*2f814a6dSPatrick Williams ${PKGD}/${bindir}/python${PYTHON_MAJMIN}-config 283*2f814a6dSPatrick Williams 284*2f814a6dSPatrick Williams # Reformat _sysconfigdata after modifying it so that it remains 285*2f814a6dSPatrick Williams # reproducible 286*2f814a6dSPatrick Williams for c in ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata*.py; do 287*2f814a6dSPatrick Williams python3 ${WORKDIR}/reformat_sysconfig.py $c 288*2f814a6dSPatrick Williams done 289*2f814a6dSPatrick Williams 290*2f814a6dSPatrick Williams # Recompile _sysconfigdata after modifying it 291*2f814a6dSPatrick Williams cd ${PKGD} 292*2f814a6dSPatrick Williams sysconfigfile=`find . -name _sysconfigdata_*.py` 293*2f814a6dSPatrick Williams ${STAGING_BINDIR_NATIVE}/python3-native/python3 \ 294*2f814a6dSPatrick Williams -c "from py_compile import compile; compile('$sysconfigfile')" 295*2f814a6dSPatrick Williams ${STAGING_BINDIR_NATIVE}/python3-native/python3 \ 296*2f814a6dSPatrick Williams -c "from py_compile import compile; compile('$sysconfigfile', optimize=1)" 297*2f814a6dSPatrick Williams ${STAGING_BINDIR_NATIVE}/python3-native/python3 \ 298*2f814a6dSPatrick Williams -c "from py_compile import compile; compile('$sysconfigfile', optimize=2)" 299*2f814a6dSPatrick Williams cd - 300*2f814a6dSPatrick Williams 301*2f814a6dSPatrick Williams mv ${PKGD}/${bindir}/python${PYTHON_MAJMIN}-config ${PKGD}/${bindir}/python${PYTHON_MAJMIN}-config-${MULTILIB_SUFFIX} 302*2f814a6dSPatrick Williams 303*2f814a6dSPatrick Williams #Remove the unneeded copy of target sysconfig data 304*2f814a6dSPatrick Williams rm -rf ${PKGD}/${libdir}/python-sysconfigdata 305*2f814a6dSPatrick Williams} 306*2f814a6dSPatrick Williams 307*2f814a6dSPatrick Williams# We want bytecode precompiled .py files (.pyc's) by default 308*2f814a6dSPatrick Williams# but the user may set it on their own conf 309*2f814a6dSPatrick WilliamsINCLUDE_PYCS ?= "1" 310*2f814a6dSPatrick Williams 311*2f814a6dSPatrick Williamspython(){ 312*2f814a6dSPatrick Williams import collections, json 313*2f814a6dSPatrick Williams 314*2f814a6dSPatrick Williams filename = os.path.join(d.getVar('THISDIR'), 'python3', 'python3-manifest.json') 315*2f814a6dSPatrick Williams # This python changes the datastore based on the contents of a file, so mark 316*2f814a6dSPatrick Williams # that dependency. 317*2f814a6dSPatrick Williams bb.parse.mark_dependency(d, filename) 318*2f814a6dSPatrick Williams 319*2f814a6dSPatrick Williams with open(filename) as manifest_file: 320*2f814a6dSPatrick Williams manifest_str = manifest_file.read() 321*2f814a6dSPatrick Williams json_start = manifest_str.find('# EOC') + 6 322*2f814a6dSPatrick Williams manifest_file.seek(json_start) 323*2f814a6dSPatrick Williams manifest_str = manifest_file.read() 324*2f814a6dSPatrick Williams python_manifest = json.loads(manifest_str, object_pairs_hook=collections.OrderedDict) 325*2f814a6dSPatrick Williams 326*2f814a6dSPatrick Williams # First set RPROVIDES for -native case 327*2f814a6dSPatrick Williams # Hardcoded since it cant be python3-native-foo, should be python3-foo-native 328*2f814a6dSPatrick Williams pn = 'python3' 329*2f814a6dSPatrick Williams rprovides = (d.getVar('RPROVIDES') or "").split() 330*2f814a6dSPatrick Williams 331*2f814a6dSPatrick Williams # ${PN}-misc-native is not in the manifest 332*2f814a6dSPatrick Williams rprovides.append(pn + '-misc-native') 333*2f814a6dSPatrick Williams 334*2f814a6dSPatrick Williams for key in python_manifest: 335*2f814a6dSPatrick Williams pypackage = pn + '-' + key + '-native' 336*2f814a6dSPatrick Williams if pypackage not in rprovides: 337*2f814a6dSPatrick Williams rprovides.append(pypackage) 338*2f814a6dSPatrick Williams 339*2f814a6dSPatrick Williams d.setVar('RPROVIDES:class-native', ' '.join(rprovides)) 340*2f814a6dSPatrick Williams 341*2f814a6dSPatrick Williams # Then work on the target 342*2f814a6dSPatrick Williams include_pycs = d.getVar('INCLUDE_PYCS') 343*2f814a6dSPatrick Williams 344*2f814a6dSPatrick Williams packages = d.getVar('PACKAGES').split() 345*2f814a6dSPatrick Williams pn = d.getVar('PN') 346*2f814a6dSPatrick Williams 347*2f814a6dSPatrick Williams newpackages=[] 348*2f814a6dSPatrick Williams for key in python_manifest: 349*2f814a6dSPatrick Williams pypackage = pn + '-' + key 350*2f814a6dSPatrick Williams 351*2f814a6dSPatrick Williams if pypackage not in packages: 352*2f814a6dSPatrick Williams # We need to prepend, otherwise python-misc gets everything 353*2f814a6dSPatrick Williams # so we use a new variable 354*2f814a6dSPatrick Williams newpackages.append(pypackage) 355*2f814a6dSPatrick Williams 356*2f814a6dSPatrick Williams # "Build" python's manifest FILES, RDEPENDS and SUMMARY 357*2f814a6dSPatrick Williams d.setVar('FILES:' + pypackage, '') 358*2f814a6dSPatrick Williams for value in python_manifest[key]['files']: 359*2f814a6dSPatrick Williams d.appendVar('FILES:' + pypackage, ' ' + value) 360*2f814a6dSPatrick Williams 361*2f814a6dSPatrick Williams # Add cached files 362*2f814a6dSPatrick Williams if include_pycs == '1': 363*2f814a6dSPatrick Williams for value in python_manifest[key]['cached']: 364*2f814a6dSPatrick Williams d.appendVar('FILES:' + pypackage, ' ' + value) 365*2f814a6dSPatrick Williams 366*2f814a6dSPatrick Williams for value in python_manifest[key]['rdepends']: 367*2f814a6dSPatrick Williams # Make it work with or without $PN 368*2f814a6dSPatrick Williams if '${PN}' in value: 369*2f814a6dSPatrick Williams value=value.split('-', 1)[1] 370*2f814a6dSPatrick Williams d.appendVar('RDEPENDS:' + pypackage, ' ' + pn + '-' + value) 371*2f814a6dSPatrick Williams 372*2f814a6dSPatrick Williams for value in python_manifest[key].get('rrecommends', ()): 373*2f814a6dSPatrick Williams if '${PN}' in value: 374*2f814a6dSPatrick Williams value=value.split('-', 1)[1] 375*2f814a6dSPatrick Williams d.appendVar('RRECOMMENDS:' + pypackage, ' ' + pn + '-' + value) 376*2f814a6dSPatrick Williams 377*2f814a6dSPatrick Williams d.setVar('SUMMARY:' + pypackage, python_manifest[key]['summary']) 378*2f814a6dSPatrick Williams 379*2f814a6dSPatrick Williams # Prepending so to avoid python-misc getting everything 380*2f814a6dSPatrick Williams packages = newpackages + packages 381*2f814a6dSPatrick Williams d.setVar('PACKAGES', ' '.join(packages)) 382*2f814a6dSPatrick Williams d.setVar('ALLOW_EMPTY:${PN}-modules', '1') 383*2f814a6dSPatrick Williams d.setVar('ALLOW_EMPTY:${PN}-pkgutil', '1') 384*2f814a6dSPatrick Williams 385*2f814a6dSPatrick Williams if "pgo" in d.getVar("PACKAGECONFIG").split() and not bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', True, False, d): 386*2f814a6dSPatrick Williams bb.fatal("pgo cannot be enabled as there is no qemu-usermode support for this architecture/machine") 387*2f814a6dSPatrick Williams} 388*2f814a6dSPatrick Williams 389*2f814a6dSPatrick Williams# Files needed to create a new manifest 390*2f814a6dSPatrick Williams 391*2f814a6dSPatrick Williamsdo_create_manifest() { 392*2f814a6dSPatrick Williams # This task should be run with every new release of Python. 393*2f814a6dSPatrick Williams # We must ensure that PACKAGECONFIG enables everything when creating 394*2f814a6dSPatrick Williams # a new manifest, this is to base our new manifest on a complete 395*2f814a6dSPatrick Williams # native python build, containing all dependencies, otherwise the task 396*2f814a6dSPatrick Williams # wont be able to find the required files. 397*2f814a6dSPatrick Williams # e.g. BerkeleyDB is an optional build dependency so it may or may not 398*2f814a6dSPatrick Williams # be present, we must ensure it is. 399*2f814a6dSPatrick Williams 400*2f814a6dSPatrick Williams cd ${WORKDIR} 401*2f814a6dSPatrick Williams # This needs to be executed by python-native and NOT by HOST's python 402*2f814a6dSPatrick Williams nativepython3 create_manifest3.py ${PYTHON_MAJMIN} 403*2f814a6dSPatrick Williams cp python3-manifest.json.new ${THISDIR}/python3/python3-manifest.json 404*2f814a6dSPatrick Williams} 405*2f814a6dSPatrick Williams 406*2f814a6dSPatrick Williams# bitbake python -c create_manifest 407*2f814a6dSPatrick Williams# Make sure we have native python ready when we create a new manifest 408*2f814a6dSPatrick Williamsaddtask do_create_manifest after do_patch do_prepare_recipe_sysroot 409*2f814a6dSPatrick Williams 410*2f814a6dSPatrick Williams# manual dependency additions 411*2f814a6dSPatrick WilliamsRRECOMMENDS:${PN}-core:append:class-nativesdk = " nativesdk-python3-modules" 412*2f814a6dSPatrick WilliamsRRECOMMENDS:${PN}-crypt:append:class-target = " ${MLPREFIX}openssl ${MLPREFIX}ca-certificates" 413*2f814a6dSPatrick WilliamsRRECOMMENDS:${PN}-crypt:append:class-nativesdk = " ${MLPREFIX}openssl ${MLPREFIX}ca-certificates" 414*2f814a6dSPatrick Williams 415*2f814a6dSPatrick Williams# For historical reasons PN is empty and provided by python3-modules 416*2f814a6dSPatrick WilliamsFILES:${PN} = "" 417*2f814a6dSPatrick WilliamsRPROVIDES:${PN}-modules = "${PN}" 418*2f814a6dSPatrick Williams 419*2f814a6dSPatrick WilliamsFILES:${PN}-pydoc += "${bindir}/pydoc${PYTHON_MAJMIN} ${bindir}/pydoc3" 420*2f814a6dSPatrick WilliamsFILES:${PN}-idle += "${bindir}/idle3 ${bindir}/idle${PYTHON_MAJMIN}" 421*2f814a6dSPatrick Williams 422*2f814a6dSPatrick Williams# provide python-pyvenv from python3-venv 423*2f814a6dSPatrick WilliamsRPROVIDES:${PN}-venv += "${MLPREFIX}python3-pyvenv" 424*2f814a6dSPatrick Williams 425*2f814a6dSPatrick Williams# package libpython3 426*2f814a6dSPatrick WilliamsPACKAGES =+ "libpython3 libpython3-staticdev" 427*2f814a6dSPatrick WilliamsFILES:libpython3 = "${libdir}/libpython*.so.*" 428*2f814a6dSPatrick WilliamsFILES:libpython3-staticdev += "${libdir}/python${PYTHON_MAJMIN}/config-${PYTHON_MAJMIN}-*/libpython${PYTHON_MAJMIN}.a" 429*2f814a6dSPatrick WilliamsINSANE_SKIP:${PN}-dev += "dev-elf" 430*2f814a6dSPatrick WilliamsINSANE_SKIP:${PN}-ptest = "dev-deps" 431*2f814a6dSPatrick Williams 432*2f814a6dSPatrick Williams# catch all the rest (unsorted) 433*2f814a6dSPatrick WilliamsPACKAGES += "${PN}-misc" 434*2f814a6dSPatrick WilliamsRDEPENDS:${PN}-misc += "\ 435*2f814a6dSPatrick Williams ${PN}-audio \ 436*2f814a6dSPatrick Williams ${PN}-codecs \ 437*2f814a6dSPatrick Williams ${PN}-core \ 438*2f814a6dSPatrick Williams ${PN}-email \ 439*2f814a6dSPatrick Williams ${PN}-numbers \ 440*2f814a6dSPatrick Williams ${PN}-pickle \ 441*2f814a6dSPatrick Williams ${PN}-pydoc \ 442*2f814a6dSPatrick Williams" 443*2f814a6dSPatrick WilliamsRDEPENDS:${PN}-modules:append:class-target = " ${MLPREFIX}python3-misc" 444*2f814a6dSPatrick WilliamsRDEPENDS:${PN}-modules:append:class-nativesdk = " ${MLPREFIX}python3-misc" 445*2f814a6dSPatrick WilliamsRDEPENDS:${PN}-modules:append:class-target = " ${@bb.utils.contains('PACKAGECONFIG', 'gdbm', '${MLPREFIX}python3-gdbm', '', d)}" 446*2f814a6dSPatrick WilliamsFILES:${PN}-misc = "${libdir}/python${PYTHON_MAJMIN} ${libdir}/python${PYTHON_MAJMIN}/lib-dynload" 447*2f814a6dSPatrick Williams 448*2f814a6dSPatrick Williams# catch manpage 449*2f814a6dSPatrick WilliamsPACKAGES += "${PN}-man" 450*2f814a6dSPatrick WilliamsFILES:${PN}-man = "${datadir}/man" 451*2f814a6dSPatrick Williams 452*2f814a6dSPatrick Williams# See https://bugs.python.org/issue18748 and https://bugs.python.org/issue37395 453*2f814a6dSPatrick WilliamsRDEPENDS:libpython3:append:libc-glibc = " libgcc" 454*2f814a6dSPatrick WilliamsRDEPENDS:${PN}-ctypes:append:libc-glibc = " ${MLPREFIX}ldconfig" 455*2f814a6dSPatrick WilliamsRDEPENDS:${PN}-ptest = "${PN}-modules ${PN}-tests ${PN}-dev ${PN}-cgitb ${PN}-zipapp unzip bzip2 libgcc tzdata coreutils sed gcc g++ binutils \ 456*2f814a6dSPatrick Williams locale-base-fr-fr locale-base-en-us locale-base-de-de" 457*2f814a6dSPatrick WilliamsRDEPENDS:${PN}-ptest:append:libc-glibc = " locale-base-tr-tr" 458*2f814a6dSPatrick WilliamsRDEPENDS:${PN}-tkinter += "${@bb.utils.contains('PACKAGECONFIG', 'tk', '${MLPREFIX}tk ${MLPREFIX}tk-lib', '', d)}" 459*2f814a6dSPatrick WilliamsRDEPENDS:${PN}-idle += "${@bb.utils.contains('PACKAGECONFIG', 'tk', '${PN}-tkinter ${MLPREFIX}tcl', '', d)}" 460*2f814a6dSPatrick WilliamsDEV_PKG_DEPENDENCY = "" 461*2f814a6dSPatrick WilliamsRDEPENDS:${PN}-pydoc += "${PN}-io" 462*2f814a6dSPatrick Williams 463*2f814a6dSPatrick WilliamsRDEPENDS:${PN}-tests:append:class-target = " ${MLPREFIX}bash" 464*2f814a6dSPatrick WilliamsRDEPENDS:${PN}-tests:append:class-nativesdk = " ${MLPREFIX}bash" 465*2f814a6dSPatrick Williams 466*2f814a6dSPatrick Williams# Python's tests contain large numbers of files we don't need in the recipe sysroots 467*2f814a6dSPatrick WilliamsSYSROOT_PREPROCESS_FUNCS += " py3_sysroot_cleanup" 468*2f814a6dSPatrick Williamspy3_sysroot_cleanup () { 469*2f814a6dSPatrick Williams rm -rf ${SYSROOT_DESTDIR}${libdir}/python${PYTHON_MAJMIN}/test 470*2f814a6dSPatrick Williams} 471