summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorDaniel Turull <daniel.turull@ericsson.com>2025-06-19 10:47:35 +0200
committerSteve Sakoman <steve@sakoman.com>2025-07-07 07:42:58 -0700
commit5b7a6dec8542968b5062e4da407e322dda50326b (patch)
tree70c95761c72f786cf18fd70c6ac84122e2add3b6 /meta/lib
parent20d38517183f6bf183c1119fb363dd4bb302bc05 (diff)
downloadpoky-5b7a6dec8542968b5062e4da407e322dda50326b.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%) (From OE-Core rev: c507dcb8a8780a42bfe68b1ebaff0909b4236e6b) Adaptations to match spdx in scarthgap: change BP to PF CC: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> CC: Richard Purdie <richard.purdie@linuxfoundation.org> (From OE-Core rev: cba53212f5debf897752453364b9756a05c197de) Signed-off-by: Daniel Turull <daniel.turull@ericsson.com> Signed-off-by: Steve Sakoman <steve@sakoman.com>
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oe/package.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/meta/lib/oe/package.py b/meta/lib/oe/package.py
index af0923a63f..ba0d326781 100644
--- a/meta/lib/oe/package.py
+++ b/meta/lib/oe/package.py
@@ -1038,6 +1038,49 @@ def copydebugsources(debugsrcdir, sources, d):
1038 if os.path.exists(p) and not os.listdir(p): 1038 if os.path.exists(p) and not os.listdir(p):
1039 os.rmdir(p) 1039 os.rmdir(p)
1040 1040
1041def save_debugsources_info(debugsrcdir, sources_raw, d):
1042 import json
1043 import bb.compress.zstd
1044 if debugsrcdir and sources_raw:
1045 debugsources_file = d.expand("${PKGDESTWORK}/debugsources/${PN}-debugsources.json.zstd")
1046 debugsources_dir = os.path.dirname(debugsources_file)
1047 if not os.path.isdir(debugsources_dir):
1048 bb.utils.mkdirhier(debugsources_dir)
1049 bb.utils.remove(debugsources_file)
1050
1051 workdir = d.getVar("WORKDIR")
1052 pn = d.getVar('PN')
1053
1054 # Kernel sources are in a different directory and are special case
1055 # we format the sources as expected by spdx by replacing /usr/src/kernel/
1056 # into BP/
1057 kernel_src = d.getVar('KERNEL_SRC_PATH')
1058 pf = d.getVar('PF')
1059 sources_dict = {}
1060 for file, src_files in sources_raw:
1061 file_clean = file.replace(f"{workdir}/package/","")
1062 sources_clean = [
1063 src.replace(f"{debugsrcdir}/{pn}/", "")
1064 if not kernel_src else src.replace(f"{kernel_src}/", f"{pf}/")
1065 for src in src_files
1066 if not any(keyword in src for keyword in ("<internal>", "<built-in>")) and not src.endswith("/")
1067 ]
1068 sources_dict[file_clean] = sorted(sources_clean)
1069 num_threads = int(d.getVar("BB_NUMBER_THREADS"))
1070 with bb.compress.zstd.open(debugsources_file, "wt", encoding="utf-8", num_threads=num_threads) as f:
1071 json.dump(sources_dict, f, sort_keys=True)
1072
1073def read_debugsources_info(d):
1074 import json
1075 import bb.compress.zstd
1076 try:
1077 fn = d.expand("${PKGDESTWORK}/debugsources/${PN}-debugsources.json.zstd")
1078 num_threads = int(d.getVar("BB_NUMBER_THREADS"))
1079 with bb.compress.zstd.open(fn, "rt", encoding="utf-8", num_threads=num_threads) as f:
1080 return json.load(f)
1081 except FileNotFoundError:
1082 bb.debug(1, f"File not found: {fn}")
1083 return None
1041 1084
1042def process_split_and_strip_files(d): 1085def process_split_and_strip_files(d):
1043 cpath = oe.cachedpath.CachedPath() 1086 cpath = oe.cachedpath.CachedPath()
@@ -1269,6 +1312,9 @@ def process_split_and_strip_files(d):
1269 # Process the dv["srcdir"] if requested... 1312 # Process the dv["srcdir"] if requested...
1270 # This copies and places the referenced sources for later debugging... 1313 # This copies and places the referenced sources for later debugging...
1271 copydebugsources(dv["srcdir"], sources, d) 1314 copydebugsources(dv["srcdir"], sources, d)
1315
1316 # Save source info to be accessible to other tasks
1317 save_debugsources_info(dv["srcdir"], results, d)
1272 # 1318 #
1273 # End of debug splitting 1319 # End of debug splitting
1274 # 1320 #