summaryrefslogtreecommitdiffstats
path: root/meta/classes-global
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2022-07-19 17:32:32 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-08-17 19:57:32 +0100
commit1d6c7af0e35811e66a0b3cd3dcc7e3d15b54f99a (patch)
tree8e5c84e354e6e995c8895e08ed5f22fbe62a228b /meta/classes-global
parentb33cf2d113d0b247042d3c1491c40e0c57bdffa6 (diff)
downloadpoky-1d6c7af0e35811e66a0b3cd3dcc7e3d15b54f99a.tar.gz
package: Switch debug source handling to use prefix map
Reproducible builds are no longer a configuration option but are required. We also rely on the prefix mapping capability of the compilers now. As such, rewrite the source locating code to use the prefix maps instead of taking a guess about WORKDIR which isn't correct for kernels, gcc, externalsrc and probably more. Instead, iterate the maps to locate any matching source code, keeping in mind that multiple maps may map to one target location. (From OE-Core rev: cbd6144a9769d21371ae0fe04db2adc05f6eed02) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes-global')
-rw-r--r--meta/classes-global/package.bbclass68
1 files changed, 28 insertions, 40 deletions
diff --git a/meta/classes-global/package.bbclass b/meta/classes-global/package.bbclass
index 418400da8c..2d985d8aff 100644
--- a/meta/classes-global/package.bbclass
+++ b/meta/classes-global/package.bbclass
@@ -565,26 +565,16 @@ def copydebugsources(debugsrcdir, sources, d):
565 objcopy = d.getVar("OBJCOPY") 565 objcopy = d.getVar("OBJCOPY")
566 workdir = d.getVar("WORKDIR") 566 workdir = d.getVar("WORKDIR")
567 sdir = d.getVar("S") 567 sdir = d.getVar("S")
568 sparentdir = os.path.dirname(os.path.dirname(sdir)) 568 cflags = d.expand("${CFLAGS}")
569 sbasedir = os.path.basename(os.path.dirname(sdir)) + "/" + os.path.basename(sdir)
570 workparentdir = os.path.dirname(os.path.dirname(workdir))
571 workbasedir = os.path.basename(os.path.dirname(workdir)) + "/" + os.path.basename(workdir)
572
573 # If S isnt based on WORKDIR we can infer our sources are located elsewhere,
574 # e.g. using externalsrc; use S as base for our dirs
575 if workdir in sdir or 'work-shared' in sdir:
576 basedir = workbasedir
577 parentdir = workparentdir
578 else:
579 basedir = sbasedir
580 parentdir = sparentdir
581 569
582 # If build path exists in sourcefile, it means toolchain did not use 570 prefixmap = {}
583 # -fdebug-prefix-map to compile 571 for flag in cflags.split():
584 if checkbuildpath(sourcefile, d): 572 if not flag.startswith("-fdebug-prefix-map"):
585 localsrc_prefix = parentdir + "/" 573 continue
586 else: 574 if "recipe-sysroot" in flag:
587 localsrc_prefix = "/usr/src/debug/" 575 continue
576 flag = flag.split("=")
577 prefixmap[flag[1]] = flag[2]
588 578
589 nosuchdir = [] 579 nosuchdir = []
590 basepath = dvar 580 basepath = dvar
@@ -595,28 +585,26 @@ def copydebugsources(debugsrcdir, sources, d):
595 bb.utils.mkdirhier(basepath) 585 bb.utils.mkdirhier(basepath)
596 cpath.updatecache(basepath) 586 cpath.updatecache(basepath)
597 587
598 # Ignore files from the recipe sysroots (target and native) 588 for pmap in prefixmap:
599 processdebugsrc = "LC_ALL=C ; sort -z -u '%s' | egrep -v -z '((<internal>|<built-in>)$|/.*recipe-sysroot.*/)' | " 589 # Ignore files from the recipe sysroots (target and native)
600 # We need to ignore files that are not actually ours 590 cmd = "LC_ALL=C ; sort -z -u '%s' | egrep -v -z '((<internal>|<built-in>)$|/.*recipe-sysroot.*/)' | " % sourcefile
601 # we do this by only paying attention to items from this package 591 # We need to ignore files that are not actually ours
602 processdebugsrc += "fgrep -zw '%s' | " 592 # we do this by only paying attention to items from this package
603 # Remove prefix in the source paths 593 cmd += "fgrep -zw '%s' | " % prefixmap[pmap]
604 processdebugsrc += "sed 's#%s##g' | " 594 # Remove prefix in the source paths
605 processdebugsrc += "(cd '%s' ; cpio -pd0mlL --no-preserve-owner '%s%s' 2>/dev/null)" 595 cmd += "sed 's#%s/##g' | " % (prefixmap[pmap])
606 596 cmd += "(cd '%s' ; cpio -pd0mlL --no-preserve-owner '%s%s' 2>/dev/null)" % (pmap, dvar, prefixmap[pmap])
607 cmd = processdebugsrc % (sourcefile, basedir, localsrc_prefix, parentdir, dvar, debugsrcdir)
608 try:
609 subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
610 except subprocess.CalledProcessError:
611 # Can "fail" if internal headers/transient sources are attempted
612 pass
613
614 # cpio seems to have a bug with -lL together and symbolic links are just copied, not dereferenced.
615 # Work around this by manually finding and copying any symbolic links that made it through.
616 cmd = "find %s%s -type l -print0 -delete | sed s#%s%s/##g | (cd '%s' ; cpio -pd0mL --no-preserve-owner '%s%s')" % \
617 (dvar, debugsrcdir, dvar, debugsrcdir, parentdir, dvar, debugsrcdir)
618 subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
619 597
598 try:
599 subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
600 except subprocess.CalledProcessError:
601 # Can "fail" if internal headers/transient sources are attempted
602 pass
603 # cpio seems to have a bug with -lL together and symbolic links are just copied, not dereferenced.
604 # Work around this by manually finding and copying any symbolic links that made it through.
605 cmd = "find %s%s -type l -print0 -delete | sed s#%s%s/##g | (cd '%s' ; cpio -pd0mL --no-preserve-owner '%s%s')" % \
606 (dvar, prefixmap[pmap], dvar, prefixmap[pmap], pmap, dvar, prefixmap[pmap])
607 subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
620 608
621 # debugsources.list may be polluted from the host if we used externalsrc, 609 # debugsources.list may be polluted from the host if we used externalsrc,
622 # cpio uses copy-pass and may have just created a directory structure 610 # cpio uses copy-pass and may have just created a directory structure