[v3,13/16] dpkg-source: implement multiarch support for unshare backend

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

Commit Message

Felix Moessbauer April 7, 2026, 2:23 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 | 38 ++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 4 deletions(-)

Patch

diff --git a/meta/classes-recipe/dpkg-source.bbclass b/meta/classes-recipe/dpkg-source.bbclass
index 629796d6..a1848473 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,39 @@  do_fetch_common_source() {
     remove_mounts
     schroot_delete_configs
 }
+
+UNSHARE_DPKG_SOURCE_CHROOT = "${WORKDIR}/dpkg-source-chroot"
+fetch_common_source_unshare() {
+    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'}"