[3/4] rootfs: Avoid unneeded commands inside chroot

Message ID f547f9c01860fe224a3531b74d10db1d946cbcf5.1757930833.git.jan.kiszka@siemens.com
State New
Headers show
Series Several micro-optimizations | expand

Commit Message

Jan Kiszka Sept. 15, 2025, 10:07 a.m. UTC
From: Jan Kiszka <jan.kiszka@siemens.com>

As the chroot implies emulation in case of cross-installation, any call
into it that can be avoided saves a few seconds.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 meta/classes/rootfs.bbclass | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Patch

diff --git a/meta/classes/rootfs.bbclass b/meta/classes/rootfs.bbclass
index de8077e6..f02397b8 100644
--- a/meta/classes/rootfs.bbclass
+++ b/meta/classes/rootfs.bbclass
@@ -245,8 +245,11 @@  rootfs_export_package_cache() {
 ROOTFS_INSTALL_COMMAND += "${@ 'rootfs_install_clean_files' if (d.getVar('ROOTFS_CLEAN_FILES') or '').strip() else ''}"
 rootfs_install_clean_files[weight] = "2"
 rootfs_install_clean_files() {
-    sudo -E chroot '${ROOTFSDIR}' \
-        /bin/rm -f ${ROOTFS_CLEAN_FILES}
+    sudo -s <<'EOSUDO'
+    for clean_file in ${ROOTFS_CLEAN_FILES}; do
+        rm -f "${ROOTFSDIR}/$clean_file"
+    done
+EOSUDO
 }
 
 ROOTFS_INSTALL_COMMAND += "rootfs_install_pkgs_install"
@@ -490,10 +493,10 @@  python do_generate_initramfs_setscene () {
 rootfs_generate_initramfs[progress] = "custom:rootfs_progress.InitrdProgressHandler"
 rootfs_generate_initramfs() {
     if [ -n "$(sudo find '${ROOTFSDIR}/boot' -type f -name 'vmlinu[xz]*')" ]; then
+        mods_total="$(sudo find '${ROOTFSDIR}/usr/lib/modules' -type f -name '*.ko*' | wc -l)"
+        echo "Total number of modules: $mods_total"
         sudo -E chroot "${ROOTFSDIR}" sh -c '\
-            mods_total="$(find /usr/lib/modules -type f -name '*.ko*' | wc -l)"; \
             export kernel_version=$(basename /boot/vmlinu[xz]-* | cut -d'-' -f2-); \
-            echo "Total number of modules: $mods_total"; \
             echo "Generating initrd for kernel version: $kernel_version"; \
             update-initramfs -u -v -k "$kernel_version";'
         if [ -n "${INITRD_DEPLOY_FILE}" ]; then