The rootfs-footprint class can be inherited by image recipes to generate
a .json footprint file. This file contains a list of all installed packages,
with the following format:

{
    "package_name": "busybox-udhcpc",
    "version": "1.37.0",
    "total_size": 2701,
    "installed_files": {
        "/etc/udhcpc.d/50default": 2652,
        "/usr/share/udhcpc/default.script": 49
    }
}

The data can be used with other tools/scripts to generate detailed
rootfs reports or perform relevant comparisons.

Signed-off-by: Beniamin Sandu <[email protected]>
---
 meta/classes/rootfs-footprint.bbclass | 54 +++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 meta/classes/rootfs-footprint.bbclass

diff --git a/meta/classes/rootfs-footprint.bbclass 
b/meta/classes/rootfs-footprint.bbclass
new file mode 100644
index 0000000000..247db0b709
--- /dev/null
+++ b/meta/classes/rootfs-footprint.bbclass
@@ -0,0 +1,54 @@
+# Generates a json footprint file with the list of packages installed in the 
rootfs image,
+# with the following format:
+# 
+# {
+#     "package_name": "busybox-syslog",
+#     "version": "1.37.0",
+#     "total_size": 2824,
+#     "installed_files": {
+#         "/etc/init.d/syslog": 2104,
+#         "/etc/syslog-startup.conf": 651,
+#         "/etc/syslog.conf": 69
+#     }
+# }
+#
+# Copyright (C) 2024 Wind River Systems, Inc.
+# Author: Beniamin Sandu <[email protected]>
+#
+# SPDX-License-Identifier: GPL-2.0-only
+
+ROOTFS_POSTPROCESS_COMMAND:append = " create_rootfs_footprint; "
+ROOTFS_FOOTPRINT_FILE ?= "${IMGDEPLOYDIR}/${IMAGE_NAME}.footprint.json"
+
+python create_rootfs_footprint() {
+    from oe.rootfs import image_list_installed_packages
+    import oe.packagedata
+    import json
+
+    footprint_file = d.getVar('ROOTFS_FOOTPRINT_FILE')
+    pkg_info_dic = {}
+    pkg_dic = dict(package_name="", version="", total_size=0, 
installed_files="")
+    pkg_list = sorted(image_list_installed_packages(d))
+
+    pkg_data_list = []
+
+    for pkg in pkg_list:
+        pkg_info = os.path.join(d.getVar('PKGDATA_DIR'), 'runtime-reverse', 
pkg)
+        pkg_name = os.path.basename(os.readlink(pkg_info))
+        pkg_info_dic[pkg_name] = oe.packagedata.read_pkgdatafile(pkg_info)
+
+        pkg_dic["package_name"] = pkg_name
+        pkg_dic["version"] = pkg_info_dic[pkg_name]["PV"]
+        pkg_dic["total_size"] = int(pkg_info_dic[pkg_name]["PKGSIZE:" + 
pkg_name])
+        pkg_dic["installed_files"] = 
json.loads(pkg_info_dic[pkg_name]["FILES_INFO:" + pkg_name])
+
+        pkg_data_list.append(pkg_dic.copy())
+
+    with open(footprint_file, 'w') as f:
+        json.dump(pkg_data_list, f, indent=4)
+
+    footprint_link = os.path.join(d.getVar('IMGDEPLOYDIR'), 
"%s.footprint.json" % d.getVar('IMAGE_LINK_NAME'))
+    if os.path.lexists(footprint_link):
+        os.remove(footprint_link)
+    os.symlink(os.path.basename(footprint_file), footprint_link)
+}
-- 
2.39.5

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#210224): 
https://lists.openembedded.org/g/openembedded-core/message/210224
Mute This Topic: https://lists.openembedded.org/mt/110791960/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to