[v2,3/5] dpkg: Add support for additional target and host builds

Message ID 20221220170921.1718503-4-stefan-koch@siemens.com
State Superseded, archived
Headers show
Series linux-custom: Split up binaries from kernel headers to kbuild packages | expand

Commit Message

Koch, Stefan Dec. 20, 2022, 5:09 p.m. UTC
By appending ISAR_BUILDS with "target" or "host" it's possible
to run additional target or host builds.
There are no "target" and "host" builds enabled by default.
When both build modes are enabled then for a cross build a kbuild package
for the target and a kbuild package for the host will be created.
When "host" build is not enabled instead of the kbuild
a kbuild-cross package for the host is generated.

Supported modes for ISAR_BUILDS:
default: default build (e.g. generic ISAR non-cross or cross build)
target: run target architecture build (non-cross, using QEMU)
host: run host architecture build

Signed-off-by: Stefan Koch <stefan-koch@siemens.com>
---
 meta/classes/dpkg-base.bbclass | 51 ++++++++++++++++++++++++++++++----
 meta/classes/dpkg.bbclass      |  2 +-
 2 files changed, 46 insertions(+), 7 deletions(-)

Patch

diff --git a/meta/classes/dpkg-base.bbclass b/meta/classes/dpkg-base.bbclass
index 260aa73..3108fee 100644
--- a/meta/classes/dpkg-base.bbclass
+++ b/meta/classes/dpkg-base.bbclass
@@ -228,7 +228,7 @@  dpkg_runbuild() {
 
 def isar_deb_build_profiles(d):
     deb_build_profiles = d.getVar('DEB_BUILD_PROFILES', True)
-    if d.getVar('ISAR_CROSS_COMPILE', True) == "1":
+    if d.getVar('ISAR_CROSS_COMPILE', True) == "1" and not "targetbuild" in d.getVar('DEB_BUILD_PROFILES', True):
         deb_build_profiles += ' cross'
     return deb_build_profiles.strip()
 
@@ -242,12 +242,51 @@  def isar_export_build_settings(d):
     os.environ['DEB_BUILD_OPTIONS']  = isar_deb_build_options(d)
     os.environ['DEB_BUILD_PROFILES'] = isar_deb_build_profiles(d)
 
+# By default only one dpkg build is executed
+# With enabled ISAR_CROSS_COMPILE and different HOST_ARCH from DISTRO_ARCH
+# it's possible to run additional target or host builds.
+# These can requested by appending the following strings (seperated by space):
+# target: run target architecture build (non-cross, using QEMU)
+# host: run host architecture build
+# Supported build modes for ISAR_BUILDS: default target host
+ISAR_BUILDS ?= "default"
+
 python do_dpkg_build() {
-    bb.build.exec_func('schroot_create_configs', d)
-    try:
-        bb.build.exec_func("dpkg_runbuild", d)
-    finally:
-        bb.build.exec_func('schroot_delete_configs', d)
+    # store default build values for restoring
+    deb_profiles = d.getVar('DEB_BUILD_PROFILES', True)
+    schroot_dir = d.getVar('SCHROOT_DIR', True)
+
+    for build in d.getVar('ISAR_BUILDS', True).split(" "):
+        runbuild = False
+
+        # set default build values
+        d.setVar('DEB_BUILD_PROFILES', deb_profiles)
+        d.setVar('SCHROOT_DIR', schroot_dir)
+        d.setVar('SBUILD_BUILD', d.getVar('SBUILD_HOST_ARCH', True))
+        d.setVar('SBUILD_HOST', d.getVar('PACKAGE_ARCH', True))
+
+        if build == "default":
+            runbuild = True
+        elif d.getVar('ISAR_CROSS_COMPILE', True) == "1" and d.getVar('HOST_ARCH', True) != d.getVar('DISTRO_ARCH', True):
+            if build == "target":
+                d.appendVar('DEB_BUILD_PROFILES', ' targetbuild')
+                d.setVar('SCHROOT_DIR', d.getVar('SCHROOT_TARGET_DIR', True))
+                d.setVar('SBUILD_BUILD', d.getVar('PACKAGE_ARCH', True))
+                runbuild = True
+            elif build == "host":
+                d.appendVar('DEB_BUILD_PROFILES', ' hostbuild')
+                d.setVar('SCHROOT_DIR', d.getVar('SCHROOT_HOST_DIR', True))
+                d.setVar('SBUILD_BUILD', d.getVar('HOST_ARCH', True))
+                d.setVar('SBUILD_HOST', d.getVar('HOST_ARCH', True))
+                runbuild = True
+
+        # execute build
+        if runbuild:
+            bb.build.exec_func('schroot_create_configs', d)
+            try:
+                bb.build.exec_func("dpkg_runbuild", d)
+            finally:
+                bb.build.exec_func('schroot_delete_configs', d)
 }
 
 addtask dpkg_build
diff --git a/meta/classes/dpkg.bbclass b/meta/classes/dpkg.bbclass
index 7822b14..70a1c6a 100644
--- a/meta/classes/dpkg.bbclass
+++ b/meta/classes/dpkg.bbclass
@@ -102,7 +102,7 @@  dpkg_runbuild() {
     DSC_FILE=$(find ${WORKDIR} -name "${DEB_SOURCE_NAME}*.dsc" -print)
 
     sbuild -A -n -c ${SBUILD_CHROOT} --extra-repository="${ISAR_APT_REPO}" \
-        --host=${PACKAGE_ARCH} --build=${SBUILD_HOST_ARCH} ${profiles} \
+        --host=${SBUILD_HOST} --build=${SBUILD_BUILD} ${profiles} \
         --no-run-lintian --no-run-piuparts --no-run-autopkgtest --resolve-alternatives \
         --no-apt-update \
         --chroot-setup-commands="echo \"Package: *\nPin: release n=${DEBDISTRONAME}\nPin-Priority: 1000\" > /etc/apt/preferences.d/isar-apt" \