Files
meta-external-toolchain/classes/external-debugsrc.bbclass
Christopher Larson 7e0d273131 external-debugsrc.bbclass: add class
This class copies debug sources out of the external toolchain, obeying the paths
in DEBUG_PREFIX_MAP, the same way do_package does to copy those sources into the
src binary package. Between the two, this redistributes the debug sources in the
appropriate -src packages as it would for non-external recipes.

JIRA: SB-21854

Signed-off-by: Christopher Larson <chris_larson@mentor.com>
2023-04-21 02:42:25 +05:00

63 lines
2.6 KiB
Plaintext

# Copy debug sources into ${S} where package.bbclass can find them
EXTERNAL_DEBUGSOURCES ?= "0"
EXTERNAL_DEBUGSOURCES:external ?= "1"
# Sane default for external recipes
DEBUG_PREFIX_MAP:append:external = "\
-fdebug-prefix-map=${S}=/usr/src/debug/${EXTERNAL_PN}/${EXTENDPE}${PV}-${PR} \
"
# Fallback
DEBUG_PREFIX_MAP:prepend:external = "\
-fdebug-prefix-map=${S}=/usr/src/debug/${EXTERNAL_PN} \
"
inherit package copydebugsources_extra
python external_debugsrc () {
enabled = d.getVar('EXTERNAL_DEBUGSOURCES')
prefix_map = d.getVar('DEBUG_PREFIX_MAP')
if prefix_map and str(enabled) != '0':
# Handle any source paths owned by us which are not in the assumed path relative to WORKDIR, such as
# sources generated and written in ${B}
import shlex
import subprocess
prefix_maps = []
for arg in shlex.split(prefix_map):
if arg.startswith('-fdebug-prefix-map=') or arg.startswith('-ffile-prefix-map='):
_, from_path, to_path = arg.split('=', 2)
if to_path and 'recipe-sysroot' not in from_path:
# Entries like recipe-sysroot are excluded here
prefix_maps.append((from_path, to_path))
if prefix_maps:
seen = set()
workdir = d.getVar('WORKDIR')
pn, external_pn = d.getVar('PN'), d.getVar('EXTERNAL_PN')
for from_path, to_path in reversed(prefix_maps):
if to_path in seen or (from_path != workdir and not from_path.startswith(workdir + '/')):
continue
to_path = os.path.normpath(to_path)
sysroot_files = oe.external.find_sysroot_files([to_path], d)
if sysroot_files and sysroot_files[0]:
seen.add(to_path)
for entry in sysroot_files:
if not entry:
continue
for sysroot_path in entry:
bb.utils.mkdirhier(from_path)
bb.debug(1, "external_debugsrc: '%s' -> '%s'" % (sysroot_path, from_path))
subprocess.check_call(['cp', '-PR', '--preserve=mode,timestamps',
'--no-preserve=ownership',
sysroot_path + '/.', from_path + '/'])
else:
bb.debug(1, "external_debugsrc: '%s' not found" % to_path)
if not seen:
bb.note('external_debugsrc: no debug sources found')
}
do_unpack[postfuncs] += "external_debugsrc"