summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Turull <daniel.turull@ericsson.com>2025-06-10 17:24:41 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-06-12 11:03:43 +0100
commitd0d9f1e88d9b36e3ee6fd4ea335e4d8ad336fa0a (patch)
tree0efbf8198ef9ebb8e612698816e7e48997a455a4
parent436bde4c5f24e2571c9635b7c6a5b1424cfd296e (diff)
downloadpoky-d0d9f1e88d9b36e3ee6fd4ea335e4d8ad336fa0a.tar.gz
package: export debugsources in PKGDESTWORK as json
The source information used during packaging can be use from other tasks to have more detailed information on the files used during the compilation and improve SPDX accuracy. Source files used during compilation are store as compressed zstd json in pkgdata/debugsources/$PN-debugsources.json.zstd Format: { binary1: [src1, src2, ...], binary2: [src1, src2, ...] } I checked the sstate size, and it slightly increases using core-image-full-cmdline: without patch: 2456792 KB sstate-cache/ with patch: 2460028 KB sstate-cache/ (4236 KB or 0.17%) CC: Richard Purdie <richard.purdie@linuxfoundation.org> (From OE-Core rev: c507dcb8a8780a42bfe68b1ebaff0909b4236e6b) Signed-off-by: Daniel Turull <daniel.turull@ericsson.com> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/conf/bitbake.conf2
-rw-r--r--meta/lib/oe/package.py46
2 files changed, 48 insertions, 0 deletions
diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index c515a07b6f..e600d9d774 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -991,5 +991,7 @@ oe.sstatesig.find_sstate_manifest[vardepsexclude] = "BBEXTENDCURR BBEXTENDVARIAN
991oe.utils.get_multilib_datastore[vardepsexclude] = "DEFAULTTUNE_MULTILIB_ORIGINAL OVERRIDES" 991oe.utils.get_multilib_datastore[vardepsexclude] = "DEFAULTTUNE_MULTILIB_ORIGINAL OVERRIDES"
992oe.path.format_display[vardepsexclude] = "TOPDIR" 992oe.path.format_display[vardepsexclude] = "TOPDIR"
993oe.utils.get_bb_number_threads[vardepsexclude] = "BB_NUMBER_THREADS" 993oe.utils.get_bb_number_threads[vardepsexclude] = "BB_NUMBER_THREADS"
994oe.package.save_debugsources_info[vardepsexclude] = "BB_NUMBER_THREADS"
995oe.package.read_debugsources_info[vardepsexclude] = "BB_NUMBER_THREADS"
994oe.packagedata.emit_pkgdata[vardepsexclude] = "BB_NUMBER_THREADS" 996oe.packagedata.emit_pkgdata[vardepsexclude] = "BB_NUMBER_THREADS"
995oe.packagedata.read_subpkgdata_extended[vardepsexclude] = "BB_NUMBER_THREADS" 997oe.packagedata.read_subpkgdata_extended[vardepsexclude] = "BB_NUMBER_THREADS"
diff --git a/meta/lib/oe/package.py b/meta/lib/oe/package.py
index 0bcc04ea54..60392cbced 100644
--- a/meta/lib/oe/package.py
+++ b/meta/lib/oe/package.py
@@ -1049,6 +1049,49 @@ def copydebugsources(debugsrcdir, sources, d):
1049 if os.path.exists(p) and not os.listdir(p): 1049 if os.path.exists(p) and not os.listdir(p):
1050 os.rmdir(p) 1050 os.rmdir(p)
1051 1051
1052def save_debugsources_info(debugsrcdir, sources_raw, d):
1053 import json
1054 import bb.compress.zstd
1055 if debugsrcdir and sources_raw:
1056 debugsources_file = d.expand("${PKGDESTWORK}/debugsources/${PN}-debugsources.json.zstd")
1057 debugsources_dir = os.path.dirname(debugsources_file)
1058 if not os.path.isdir(debugsources_dir):
1059 bb.utils.mkdirhier(debugsources_dir)
1060 bb.utils.remove(debugsources_file)
1061
1062 workdir = d.getVar("WORKDIR")
1063 pn = d.getVar('PN')
1064
1065 # Kernel sources are in a different directory and are special case
1066 # we format the sources as expected by spdx by replacing /usr/src/kernel/
1067 # into BP/
1068 kernel_src = d.getVar('KERNEL_SRC_PATH')
1069 bp = d.getVar('BP')
1070 sources_dict = {}
1071 for file, src_files in sources_raw:
1072 file_clean = file.replace(f"{workdir}/package/","")
1073 sources_clean = [
1074 src.replace(f"{debugsrcdir}/{pn}/", "")
1075 if not kernel_src else src.replace(f"{kernel_src}/", f"{bp}/")
1076 for src in src_files
1077 if not any(keyword in src for keyword in ("<internal>", "<built-in>")) and not src.endswith("/")
1078 ]
1079 sources_dict[file_clean] = sorted(sources_clean)
1080 num_threads = int(d.getVar("BB_NUMBER_THREADS"))
1081 with bb.compress.zstd.open(debugsources_file, "wt", encoding="utf-8", num_threads=num_threads) as f:
1082 json.dump(sources_dict, f, sort_keys=True)
1083
1084def read_debugsources_info(d):
1085 import json
1086 import bb.compress.zstd
1087 try:
1088 fn = d.expand("${PKGDESTWORK}/debugsources/${PN}-debugsources.json.zstd")
1089 num_threads = int(d.getVar("BB_NUMBER_THREADS"))
1090 with bb.compress.zstd.open(fn, "rt", encoding="utf-8", num_threads=num_threads) as f:
1091 return json.load(f)
1092 except FileNotFoundError:
1093 bb.debug(1, f"File not found: {fn}")
1094 return None
1052 1095
1053def process_split_and_strip_files(d): 1096def process_split_and_strip_files(d):
1054 cpath = oe.cachedpath.CachedPath() 1097 cpath = oe.cachedpath.CachedPath()
@@ -1280,6 +1323,9 @@ def process_split_and_strip_files(d):
1280 # Process the dv["srcdir"] if requested... 1323 # Process the dv["srcdir"] if requested...
1281 # This copies and places the referenced sources for later debugging... 1324 # This copies and places the referenced sources for later debugging...
1282 copydebugsources(dv["srcdir"], sources, d) 1325 copydebugsources(dv["srcdir"], sources, d)
1326
1327 # Save source info to be accessible to other tasks
1328 save_debugsources_info(dv["srcdir"], results, d)
1283 # 1329 #
1284 # End of debug splitting 1330 # End of debug splitting
1285 # 1331 #