[RFC,v2,17/19] dpkg-source: implement multiarch support for unshare backend

Message ID 20260220171601.3845113-18-felix.moessbauer@siemens.com
State New
Headers show
Series add support to build isar unprivileged | expand

Commit Message

Felix Moessbauer Feb. 20, 2026, 5:15 p.m. UTC
The fetching of a common source package needs to happen in the
chroot. Previously we only had an implementation for the schroot
backend, but we also need one for unshare, which is added here.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 meta/classes-recipe/dpkg-source.bbclass | 40 ++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 4 deletions(-)

Patch

diff --git a/meta/classes-recipe/dpkg-source.bbclass b/meta/classes-recipe/dpkg-source.bbclass
index d0809477..5272fc39 100644
--- a/meta/classes-recipe/dpkg-source.bbclass
+++ b/meta/classes-recipe/dpkg-source.bbclass
@@ -52,10 +52,7 @@  do_dpkg_build[depends] += "${BPN}:do_deploy_source"
 
 SCHROOT_MOUNTS = "${WORKDIR}:/work ${REPO_ISAR_DIR}/${DISTRO}:/isar-apt"
 
-do_fetch_common_source[depends] += "${SCHROOT_DEP} ${BPN}:do_deploy_source"
-do_fetch_common_source[lockfiles] = "${REPO_ISAR_DIR}/isar.lock"
-do_fetch_common_source[network] = "${TASK_USE_SUDO}"
-do_fetch_common_source() {
+fetch_common_source_schroot() {
     schroot_create_configs
     insert_mounts
 
@@ -83,6 +80,41 @@  do_fetch_common_source() {
     remove_mounts
     schroot_delete_configs
 }
+
+UNSHARE_DPKG_SOURCE_CHROOT = "${WORKDIR}/dpkg-source-chroot"
+fetch_common_source_unshare() {
+    create_chroot_parent_dir $(realpath -m "${UNSHARE_DPKG_SOURCE_CHROOT}/..")
+
+    run_privileged_heredoc <<'EOF'
+        set -e
+        mkdir -p ${UNSHARE_DPKG_SOURCE_CHROOT}
+        tar -xf "${SBUILD_CHROOT}" -C ${UNSHARE_DPKG_SOURCE_CHROOT}
+
+        ${@insert_isar_mounts(d, d.getVar('UNSHARE_DPKG_SOURCE_CHROOT'), d.getVar('SCHROOT_MOUNTS'))}
+        chroot ${UNSHARE_DPKG_SOURCE_CHROOT} /bin/bash -s <<'EOAPT'
+            set -e
+            apt-get update \
+                -o Dir::Etc::SourceList="sources.list.d/isar-apt.list" \
+                -o Dir::Etc::SourceParts="-" \
+                -o APT::Get::List-Cleanup="0"
+
+            cd /work
+            apt-get -y --download-only --only-source \
+                -o Debug::NoLocking=1 -o Acquire::Source-Symlinks="false"  \
+                source ${DEBIAN_SOURCE}
+EOAPT
+EOF
+
+    # run cleanup in separate session to ensure nothing is mounted
+    run_privileged rm -rf ${UNSHARE_DPKG_SOURCE_CHROOT}
+}
+
+do_fetch_common_source[depends] += "${SCHROOT_DEP} ${BPN}:do_deploy_source"
+do_fetch_common_source[lockfiles] = "${REPO_ISAR_DIR}/isar.lock"
+do_fetch_common_source[network] = "${TASK_USE_SUDO}"
+do_fetch_common_source() {
+    fetch_common_source_${ISAR_CHROOT_MODE}
+}
 addtask fetch_common_source
 
 do_dpkg_build[depends] += "${@'${PN}:do_dpkg_source' if '${PN}' == '${BPN}' else '${PN}:do_fetch_common_source'}"