Fix cache-deb-src functionality for non-amd64 builds

Message ID 20250717105159.1989307-1-amikan@ilbers.de
State New
Headers show
Series Fix cache-deb-src functionality for non-amd64 builds | expand

Commit Message

Anton Mikanovich July 17, 2025, 10:51 a.m. UTC
Commit f0da749f introduced `apt-cache -o Dir=${rootfs} dumpavail`
method to get info about packages installed in rootfs, instead of
parsing dpkg.log previuosly used.

But it does not work in case of foreing architecture used. The list
comes empty and no source packages get downloaded.

Instead, chroot into the rootfs and run this inside. The difference:

Works for the same arch:
  apt-cache -o Dir=/build/tmp/work/debian-bookworm-amd64/isar-image-base-qemuamd64/1.0-r0/rootfs dumpavail | wc -l
  1190397

Doesn't work for the foreign arch:
  apt-cache -o Dir=/build/tmp/work/debian-bookworm-arm64/isar-image-base-qemuarm64/1.0-r0/rootfs/ dumpavail | wc -l
  0

After the patch:
  sudo chroot /build/tmp/work/debian-bookworm-arm64/isar-image-base-qemuarm64/1.0-r0/rootfs/ apt-cache dumpavail | wc -l
  1170789

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 meta/classes/deb-dl-dir.bbclass | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Patch

diff --git a/meta/classes/deb-dl-dir.bbclass b/meta/classes/deb-dl-dir.bbclass
index 3f560da4..1f3876db 100644
--- a/meta/classes/deb-dl-dir.bbclass
+++ b/meta/classes/deb-dl-dir.bbclass
@@ -68,7 +68,9 @@  debsrc_download() {
     trap "rm -f ${avail} ${wanted}" EXIT
 
     # List all packages known to apt
-    apt-cache -o Dir=${rootfs} dumpavail | debsrc_source_version_filter > ${avail}
+    sudo -E chroot --userspec=$( id -u ):$( id -g ) ${rootfs} \
+        apt-cache dumpavail \
+        | debsrc_source_version_filter > ${avail}
 
     # Use apt-ftparchive to scan all .deb files found in the download directory
     # and get the <source> <version> pairs that we wish to download