criu: build and install wheels

Mimic what we do with python_pep517.bbclass in do_compile (python3 -m build) and
do_install (python3 -m install) to build and install wheels and avoid the heavy
handed pip install usage.

FIXME: even though lib/pycriu/version.py is properly being dynamically generated,
       setuptools/config/expand.py is failing to detect the __version__ attr.

Signed-off-by: Tim Orling <tim.orling@konsulko.com>
This commit is contained in:
Tim Orling 2024-03-01 10:19:30 -08:00 committed by Bruce Ashfield
parent 6509f2f6e1
commit 9b4acf5185
2 changed files with 107 additions and 10 deletions

View File

@ -19,11 +19,12 @@ PV = "3.19.0+git"
SRC_URI = "git://github.com/checkpoint-restore/criu.git;branch=master;protocol=https \
file://0001-criu-Skip-documentation-install.patch \
file://0002-criu-Change-libraries-install-directory.patch \
file://0003-crit-pycriu-build-and-install-wheels.patch \
"
COMPATIBLE_HOST = "(x86_64|arm|aarch64).*-linux"
DEPENDS += "libnl libcap protobuf-c-native protobuf-c util-linux-native libbsd libnet python3-pip-native"
DEPENDS += "libnl libcap protobuf-c-native protobuf-c util-linux-native libbsd libnet"
RDEPENDS:${PN} = "bash cgroup-lite"
S = "${WORKDIR}/git"
@ -40,7 +41,7 @@ EXTRA_OEMAKE:aarch64 += "ARCH=aarch64 WERROR=0"
EXTRA_OEMAKE:append = " SBINDIR=${sbindir} LIBDIR=${libdir} INCLUDEDIR=${includedir} PIEGEN=no"
EXTRA_OEMAKE:append = " LOGROTATEDIR=${sysconfdir} SYSTEMDUNITDIR=${systemd_unitdir}"
CFLAGS += "-D__USE_GNU -D_GNU_SOURCE "
CFLAGS += "-D__USE_GNU -D_GNU_SOURCE "
CFLAGS += " -I${STAGING_INCDIR} -I${STAGING_INCDIR}/libnl3"
CFLAGS:arm += "-D__WORDSIZE"
@ -53,7 +54,8 @@ export BUILD_SYS
export HOST_SYS
export HOSTCFLAGS = "${BUILD_CFLAGS}"
inherit setuptools3
inherit python_setuptools_build_meta
#inherit setuptools3
inherit pkgconfig
B = "${S}"
@ -71,27 +73,47 @@ do_compile:prepend() {
ln -s ${PKG_CONFIG_SYSROOT_DIR}/usr/include/google/protobuf/descriptor.proto ${S}/images/google/protobuf/descriptor.proto
}
#PEP517_SOURCE_PATH ="${S}/lib"
#do_compile[network] = "1"
do_compile () {
oe_runmake FULL_PYTHON=${PYTHON} PYTHON=python3
#python_pep517_do_compile
#export PEP517_SOURCE_PATH="${S}/crit"
#python_pep517_do_compile
#oe_runmake
#oe_runmake #PIP_BREAK_SYSTEM_PACKAGES=1
export PEP517_WHEEL_PATH="${PEP517_WHEEL_PATH}"
oe_runmake FULL_PYTHON=${PYTHON} PYTHON=nativepython3
}
#do_install[network] = "1"
do_install () {
export INSTALL_LIB="${libdir}/${PYTHON_DIR}/site-packages"
oe_runmake PREFIX=${exec_prefix} LIBDIR=${libdir} DESTDIR="${D}" PLUGINDIR="${localstatedir}/lib" FULL_PYTHON=${PYTHON} PYTHON=python3 install
export PEP517_WHEEL_PATH="${PEP517_WHEEL_PATH}"
#oe_runmake PREFIX=${exec_prefix} LIBDIR=${libdir} DESTDIR="${D}" PLUGINDIR="${localstatedir}/lib" PIP_BREAK_SYSTEM_PACKAGES=1 install
oe_runmake PREFIX=${exec_prefix} LIBDIR=${libdir} DESTDIR="${D}" PLUGINDIR="${localstatedir}/lib" FULL_PYTHON=${PYTHON} PYTHON=nativepython3 install
# python3's distutils has a feature of rewriting the interpeter on setup installed
# scripts. 'crit' is one of those scripts. The "executable" or "e" option to the
# setup call should fix it, but it is being ignored. So to avoid getting our native
# intepreter replaced in the script, we'll do an explicit update ourselves.
sed -i 's%^\#\!.*%\#\!/usr/bin/env python3%' ${D}/usr/bin/crit ${D}${libdir}/python3*/site-packages/crit-*-py3*.egg/EGG-INFO/scripts/crit
#
# we're building wheels now, so EGG-INFO need not apply
#sed -i 's%^\#\!.*%\#\!/usr/bin/env python3%' ${D}/usr/bin/crit ${D}${libdir}/python3*/site-packages/crit-*-py3*.egg/EGG-INFO/scripts/crit
rm -rf ${D}/__pycache__
# all the __pycache__ contains references to TMPDIR and these will be built the first time
# it runs on the target anyway
for pycachedir in $(find ${D} -name __pycache__); do
rm -rf $pycachedir
done
}
FILES:${PN} += "${systemd_unitdir}/ \
${libdir}/python3*/site-packages/ \
${libdir}/pycriu/ \
${libdir}/crit-0.0.1-py3*.egg-info \
#${libdir}/python3*/site-packages/ \
#${libdir}/pycriu/ \
#${libdir}/crit-0.0.1-py3*.egg-info \
"
FILES:${PN}-staticdev += " \

View File

@ -0,0 +1,75 @@
From 40d2f0735d668dca893a5f0e787f1f11af74cf25 Mon Sep 17 00:00:00 2001
From: Tim Orling <tim.orling@konsulko.com>
Date: Fri, 1 Mar 2024 22:22:37 -0800
Subject: [PATCH] crit/pycriu: build and install wheels
Rather than using heavy handed pip (which requires network access to
fetch the index), mimic what we do in python_pep517.bbclass do_compile
and do_install for both crit/ and lib/pycriu
Signed-off-by: Tim Orling <tim.orling@konsulko.com>
---
crit/Makefile | 8 ++++++--
lib/Makefile | 11 +++++++++--
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/crit/Makefile b/crit/Makefile
index 9a856db6d..9b36f4be1 100644
--- a/crit/Makefile
+++ b/crit/Makefile
@@ -1,5 +1,7 @@
PYTHON_EXTERNALLY_MANAGED := $(shell $(PYTHON) -c 'import os, sysconfig; print(int(os.path.isfile(os.path.join(sysconfig.get_path("stdlib"), "EXTERNALLY-MANAGED"))))')
PIP_BREAK_SYSTEM_PACKAGES := 0
+PEP517_SOURCE_PATH := ./crit
+PEP517_BUILD_OPTS :=
VERSION_FILE := $(if $(obj),$(addprefix $(obj)/,crit/version.py),crit/version.py)
@@ -16,11 +18,13 @@ ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make install"
else
$(E) " INSTALL " crit
- $(Q) $(PYTHON) -m pip install --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./crit
+ $(Q) $(PYTHON) -m build --no-isolation --wheel --outdir $(PEP517_WHEEL_PATH) $(PEP517_SOURCE_PATH) $(PEP517_BUILD_OPTS)
endif
else
+ $(E) " BUILD " crit
+ $(Q) $(PYTHON) -m build --no-isolation --wheel --outdir $(PEP517_WHEEL_PATH) $(PEP517_SOURCE_PATH) $(PEP517_BUILD_OPTS)
$(E) " INSTALL " crit
- $(Q) $(PYTHON) -m pip install --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./crit
+ $(Q) $(PYTHON) -m installer $(INSTALL_WHEEL_COMPILE_BYTECODE) --interpreter "$(USRBINPATH)/env $(PEP517_INSTALL_PYTHON)" --destdir=$(DESTDIR) $(PEP517_WHEEL_PATH)/crit-*.whl
endif
.PHONY: install
diff --git a/lib/Makefile b/lib/Makefile
index ae371e78e..b5f147482 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -1,6 +1,9 @@
CRIU_SO := libcriu.so
CRIU_A := libcriu.a
UAPI_HEADERS := lib/c/criu.h images/rpc.proto images/rpc.pb-c.h criu/include/version.h
+PEP517_SOURCE_PATH := ./lib
+PEP517_BUILD_OPTS :=
+INSTALL_WHEEL_COMPILE_BYTECODE ?= "--compile-bytecode=0"
all-y += lib-c lib-a lib-py
@@ -63,11 +66,15 @@ ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make install"
else
$(E) " INSTALL " pycriu
- $(Q) $(PYTHON) -m pip install --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./lib
+ $(Q) $(PYTHON) -m build --no-isolation --wheel --outdir $(PEP517_WHEEL_PATH) $(PEP517_SOURCE_PATH) $(PEP517_BUILD_OPTS)
endif
else
+ $(E) " BUILD " pycriu
+ $(Q) $(PYTHON) -m build --no-isolation --wheel --outdir $(PEP517_WHEEL_PATH) $(PEP517_SOURCE_PATH) $(PEP517_BUILD_OPTS)
$(E) " INSTALL " pycriu
- $(Q) $(PYTHON) -m pip install --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./lib
+ #nativepython3 -m installer ${INSTALL_WHEEL_COMPILE_BYTECODE} --interpreter "${USRBINPATH}/env ${PEP517_INSTALL_PYTHON}" --destdir=${D} ${PEP517_WHEEL_PATH}/*.whl
+
+ $(Q) $(PYTHON) -m installer $(INSTALL_WHEEL_COMPILE_BYTECODE) --interpreter "$(USRBINPATH)/env $(PEP517_INSTALL_PYTHON)" --destdir=$(DESTDIR) $(PEP517_WHEEL_PATH)/pycriu-*.whl
endif
.PHONY: install