xref: /OK3568_Linux_fs/yocto/poky/meta/classes/setuptools3_legacy.bbclass (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1# This class is for packages which use the deprecated setuptools behaviour,
2# specifically custom install tasks which don't work correctly with bdist_wheel.
3# This behaviour is deprecated in setuptools[1] and won't work in the future, so
4# all users of this should consider their options: pure Python modules can use a
5# modern Python tool such as build[2], or packages which are doing more (such as
6# installing init scripts) should use a fully-featured build system such as Meson.
7#
8# [1] https://setuptools.pypa.io/en/latest/history.html#id142
9# [2] https://pypi.org/project/build/
10
11inherit setuptools3-base
12
13B = "${WORKDIR}/build"
14
15SETUPTOOLS_BUILD_ARGS ?= ""
16SETUPTOOLS_INSTALL_ARGS ?= "--root=${D} \
17    --prefix=${prefix} \
18    --install-lib=${PYTHON_SITEPACKAGES_DIR} \
19    --install-data=${datadir}"
20
21SETUPTOOLS_PYTHON = "python3"
22SETUPTOOLS_PYTHON:class-native = "nativepython3"
23
24SETUPTOOLS_SETUP_PATH ?= "${S}"
25
26setuptools3_legacy_do_configure() {
27    :
28}
29
30setuptools3_legacy_do_compile() {
31        cd ${SETUPTOOLS_SETUP_PATH}
32        NO_FETCH_BUILD=1 \
33        STAGING_INCDIR=${STAGING_INCDIR} \
34        STAGING_LIBDIR=${STAGING_LIBDIR} \
35        ${STAGING_BINDIR_NATIVE}/${PYTHON_PN}-native/${PYTHON_PN} setup.py \
36        build --build-base=${B} ${SETUPTOOLS_BUILD_ARGS} || \
37        bbfatal_log "'${PYTHON_PN} setup.py build ${SETUPTOOLS_BUILD_ARGS}' execution failed."
38}
39setuptools3_legacy_do_compile[vardepsexclude] = "MACHINE"
40
41setuptools3_legacy_do_install() {
42        cd ${SETUPTOOLS_SETUP_PATH}
43        install -d ${D}${PYTHON_SITEPACKAGES_DIR}
44        STAGING_INCDIR=${STAGING_INCDIR} \
45        STAGING_LIBDIR=${STAGING_LIBDIR} \
46        PYTHONPATH=${D}${PYTHON_SITEPACKAGES_DIR} \
47        ${STAGING_BINDIR_NATIVE}/${PYTHON_PN}-native/${PYTHON_PN} setup.py \
48        build --build-base=${B} install --skip-build ${SETUPTOOLS_INSTALL_ARGS} || \
49        bbfatal_log "'${PYTHON_PN} setup.py install ${SETUPTOOLS_INSTALL_ARGS}' execution failed."
50
51        # support filenames with *spaces*
52        find ${D} -name "*.py" -exec grep -q ${D} {} \; \
53                               -exec sed -i -e s:${D}::g {} \;
54
55        for i in ${D}${bindir}/* ${D}${sbindir}/*; do
56            if [ -f "$i" ]; then
57                sed -i -e s:${PYTHON}:${USRBINPATH}/env\ ${SETUPTOOLS_PYTHON}:g $i
58                sed -i -e s:${STAGING_BINDIR_NATIVE}:${bindir}:g $i
59            fi
60        done
61
62        rm -f ${D}${PYTHON_SITEPACKAGES_DIR}/easy-install.pth
63
64        #
65        # FIXME: Bandaid against wrong datadir computation
66        #
67        if [ -e ${D}${datadir}/share ]; then
68            mv -f ${D}${datadir}/share/* ${D}${datadir}/
69            rmdir ${D}${datadir}/share
70        fi
71}
72setuptools3_legacy_do_install[vardepsexclude] = "MACHINE"
73
74EXPORT_FUNCTIONS do_configure do_compile do_install
75
76export LDSHARED="${CCLD} -shared"
77DEPENDS += "python3-setuptools-native"
78
79