[v2,2/3] image: download deb-src packages after imager creation

Message ID 20250307122558.1882902-2-srinuvasan.a@siemens.com
State New
Headers show
Series [v2,1/3] mmdebstrap: add "skip=cleanup/reproducible" option to mmdebstrap | expand

Commit Message

srinuvasan.a March 7, 2025, 12:25 p.m. UTC
From: srinuvasan <srinuvasan.a@siemens.com>

With the present implementation, deb-src packages are missing for imager related
deb packages (packages listed in IMAGER_INSTALL).
Copy the /var/log/dpkg.log file from the sbuild environment to outside
With that, use the list to download deb-src packages for IMAGER_INSTALL
related deb packages.

Presently, cache_deb_src function running as part of ROOTFS_POSTPROCESS_COMMAND,
this will not be helpful to get the imager related deb-src packages, hence
make cache_deb_src as a separate task and running
always after do_image to get the imager deps related deb-src packages.

Signed-off-by: srinuvasan <srinuvasan.a@siemens.com>
---
 meta/classes/image-tools-extension.bbclass | 19 +++++++++++++++++--
 meta/classes/image.bbclass                 |  8 +++++++-
 meta/classes/rootfs.bbclass                |  3 ++-
 3 files changed, 26 insertions(+), 4 deletions(-)

Patch

diff --git a/meta/classes/image-tools-extension.bbclass b/meta/classes/image-tools-extension.bbclass
index e8ace8f5..0615229a 100644
--- a/meta/classes/image-tools-extension.bbclass
+++ b/meta/classes/image-tools-extension.bbclass
@@ -7,6 +7,9 @@ 
 
 inherit sbuild
 
+PP = "/home/builder/${PN}-${MACHINE}"
+ext_root="${PP}/rootfs"
+
 IMAGER_INSTALL ??= ""
 IMAGER_BUILD_DEPS ??= ""
 DEPENDS += "${IMAGER_BUILD_DEPS}"
@@ -58,10 +61,17 @@  imager_run() {
 EOAPT
 
         deb_dl_dir_export ${schroot_dir} ${distro}
-        schroot -r -c ${session_id} -d / -u root -- sh -c " \
+        export local_install=${local_install}
+        schroot -r -c ${session_id} -d / -u root -- /bin/bash <<"EOAPT"
+            rm -f /var/log/dpkg.log
+            pkg_status="$(dpkg-query --showformat='${binary:Package}\t' --show ${local_install} || echo "Not installed")"
             apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y \
                 --allow-unauthenticated --allow-downgrades install \
-                ${local_install}"
+                ${local_install}
+            if echo "${pkg_status}" | grep  "Not installed"; then
+                cp /var/log/dpkg.log ${ext_root}/dpkg_partial.log
+            fi
+EOAPT
     fi
 
     schroot -r -c ${session_id} "$@"
@@ -69,5 +79,10 @@  EOAPT
     schroot -e -c ${session_id}
 
     remove_mounts
+
     schroot_delete_configs
+
+    if [ -e ${WORKDIR}/rootfs/dpkg_partial.log ]; then
+        sbuild_dpkg_log_export "${WORKDIR}/rootfs/dpkg_partial.log"
+    fi
 }
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index 56eca202..66b4d313 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -72,7 +72,13 @@  ROOTFS_MANIFEST_DEPLOY_DIR ?= "${DEPLOY_DIR_IMAGE}"
 ROOTFS_DPKGSTATUS_DEPLOY_DIR ?= "${DEPLOY_DIR_IMAGE}"
 ROOTFS_PACKAGE_SUFFIX ?= "${PN}-${DISTRO}-${MACHINE}"
 
-ROOTFS_POSTPROCESS_COMMAND:prepend = "${@bb.utils.contains('BASE_REPO_FEATURES', 'cache-deb-src', 'cache_deb_src', '', d)} "
+CACHE_DEB_SRC = "${@bb.utils.contains('BASE_REPO_FEATURES', 'cache-deb-src', '1', '0', d)}"
+
+python () {
+    if bb.utils.to_boolean(d.getVar('CACHE_DEB_SRC')):
+        bb.build.addtask('do_cache_deb_src', 'do_deploy', 'do_image', d)
+}
+
 
 inherit rootfs
 inherit sdk
diff --git a/meta/classes/rootfs.bbclass b/meta/classes/rootfs.bbclass
index 2348e269..c9e832dc 100644
--- a/meta/classes/rootfs.bbclass
+++ b/meta/classes/rootfs.bbclass
@@ -272,7 +272,8 @@  python do_rootfs_install() {
 }
 addtask rootfs_install before do_rootfs_postprocess after do_unpack
 
-cache_deb_src() {
+do_cache_deb_src[network] = "${TASK_USE_SUDO}"
+do_cache_deb_src() {
     if [ -e "${ROOTFSDIR}"/etc/resolv.conf ] ||
        [ -h "${ROOTFSDIR}"/etc/resolv.conf ]; then
         sudo mv "${ROOTFSDIR}"/etc/resolv.conf "${ROOTFSDIR}"/etc/resolv.conf.isar