[1/3] crossvars: provide the base distro of the selected sbuild chroot

Message ID 20261021102544.3614772-2-felix.moessbauer@siemens.com
State New
Headers show
Series Fixes for BASE_DISTRO | expand

Commit Message

Felix Moessbauer Oct. 21, 2026, 10:25 a.m. UTC
Several places need to know which base distro the chroot of a recipe was
bootstrapped from, mostly to name the DEBDIR/DEBSRCDIR sub-directory that
base-apt later imports. They all answer that question differently:

  dpkg.bbclass          keys off ISAR_CROSS_COMPILE
  aptsrc_fetcher.py     uses BASE_DISTRO
  sbuild-chroot-*.bb    set ROOTFS_BASE_DISTRO explicitly

Only the last one is correct in general. BASE_DISTRO is resolved against
OVERRIDES, which start with PACKAGE_ARCH, so it does not describe the
chroot at all: for native recipes PACKAGE_ARCH is HOST_ARCH, which means
"BASE_DISTRO:arm64 = raspios64" is not applied and BASE_DISTRO silently
expands to something else than it does for a target recipe of the same
multiconfig. The ISAR_CROSS_COMPILE heuristic disagrees with the actual
chroot selection whenever DISTRO_ARCH equals HOST_ARCH.

crossvars.bbclass already performs the host/target chroot dispatch, so
let it export the matching base distro as SCHROOT_BASE_DISTRO next to
SCHROOT_DIR and SCHROOT_DEP, and consume it in dpkg.bbclass. This keeps
one single source of truth and mirrors the ROOTFS_BASE_DISTRO naming of
the sbuild-chroot recipes.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 meta/classes-recipe/crossvars.bbclass | 8 ++++++++
 meta/classes-recipe/dpkg.bbclass      | 5 +----
 2 files changed, 9 insertions(+), 4 deletions(-)

Patch

diff --git a/meta/classes-recipe/crossvars.bbclass b/meta/classes-recipe/crossvars.bbclass
index 7cf2d660..fbfcda93 100644
--- a/meta/classes-recipe/crossvars.bbclass
+++ b/meta/classes-recipe/crossvars.bbclass
@@ -30,13 +30,21 @@  python __anonymous() {
         schroot_dir = d.getVar('SCHROOT_HOST_DIR', False)
         sbuild_dep = "sbuild-chroot-host" + flavor_suffix + ":do_build"
         sdk_toolchain = "crossbuild-essential-" + distro_arch
+        schroot_base_distro = d.getVar('HOST_BASE_DISTRO', False)
     else:
         d.setVar('BUILD_ARCH', distro_arch)
         schroot_dir = d.getVar('SCHROOT_TARGET_DIR', False)
         sbuild_dep = "sbuild-chroot-target" + flavor_suffix + ":do_build"
         sdk_toolchain = "build-essential"
+        schroot_base_distro = d.getVar('BASE_DISTRO', False)
     d.setVar('SCHROOT_DIR', schroot_dir + flavor_suffix)
     d.setVar('SCHROOT_DEP', sbuild_dep)
+    # BASE_DISTRO is resolved against OVERRIDES, which start with PACKAGE_ARCH,
+    # so it does not describe the chroot a recipe is built in (PACKAGE_ARCH is
+    # HOST_ARCH for native recipes). Mirror ROOTFS_BASE_DISTRO of the
+    # sbuild-chroot recipes to give the DEBDIR/DEBSRCDIR layout a single,
+    # chroot-correct name.
+    d.setVar('SCHROOT_BASE_DISTRO', schroot_base_distro)
     if isar_can_build_compat(d):
         sdk_toolchain += " crossbuild-essential-" + compat_arch
     d.setVar('SDK_TOOLCHAIN', sdk_toolchain)
diff --git a/meta/classes-recipe/dpkg.bbclass b/meta/classes-recipe/dpkg.bbclass
index 35408495..0ae00b75 100644
--- a/meta/classes-recipe/dpkg.bbclass
+++ b/meta/classes-recipe/dpkg.bbclass
@@ -82,10 +82,7 @@  dpkg_runbuild() {
         bbwarn "Export of '${line}' detected, please migrate to templates"
     done
 
-    distro="${BASE_DISTRO}-${BASE_DISTRO_CODENAME}"
-    if [ ${ISAR_CROSS_COMPILE} -eq 1 ]; then
-        distro="${HOST_BASE_DISTRO}-${BASE_DISTRO_CODENAME}"
-    fi
+    distro="${SCHROOT_BASE_DISTRO}-${BASE_DISTRO_CODENAME}"
 
     deb_dl_dir_import "${WORKDIR}/rootfs" "${distro}"