Skip to content

Commit c507dcb

Browse files
danielturullrpurdie
authored andcommitted
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> 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>
1 parent 602d1ca commit c507dcb

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

meta/conf/bitbake.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,5 +991,7 @@ oe.sstatesig.find_sstate_manifest[vardepsexclude] = "BBEXTENDCURR BBEXTENDVARIAN
991991
oe.utils.get_multilib_datastore[vardepsexclude] = "DEFAULTTUNE_MULTILIB_ORIGINAL OVERRIDES"
992992
oe.path.format_display[vardepsexclude] = "TOPDIR"
993993
oe.utils.get_bb_number_threads[vardepsexclude] = "BB_NUMBER_THREADS"
994+
oe.package.save_debugsources_info[vardepsexclude] = "BB_NUMBER_THREADS"
995+
oe.package.read_debugsources_info[vardepsexclude] = "BB_NUMBER_THREADS"
994996
oe.packagedata.emit_pkgdata[vardepsexclude] = "BB_NUMBER_THREADS"
995997
oe.packagedata.read_subpkgdata_extended[vardepsexclude] = "BB_NUMBER_THREADS"

meta/lib/oe/package.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,49 @@ def copydebugsources(debugsrcdir, sources, d):
10491049
if os.path.exists(p) and not os.listdir(p):
10501050
os.rmdir(p)
10511051

1052+
def 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+
1084+
def 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
10521095

10531096
def process_split_and_strip_files(d):
10541097
cpath = oe.cachedpath.CachedPath()
@@ -1280,6 +1323,9 @@ def strip_pkgd_prefix(f):
12801323
# Process the dv["srcdir"] if requested...
12811324
# This copies and places the referenced sources for later debugging...
12821325
copydebugsources(dv["srcdir"], sources, d)
1326+
1327+
# Save source info to be accessible to other tasks
1328+
save_debugsources_info(dv["srcdir"], results, d)
12831329
#
12841330
# End of debug splitting
12851331
#

0 commit comments

Comments
 (0)