All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hongxu Jia <hongxu.jia@windriver.com>
To: <ross.burton@intel.com>, <richard.purdie@linuxfoundation.org>,
	<mark.hatle@windriver.com>
Cc: openembedded-core@lists.openembedded.org
Subject: [PATCH 03/17] conf/bitbake.conf package.bbclass: improve dbg package sources generation from work-shared
Date: Mon, 28 Mar 2016 04:18:47 -0400	[thread overview]
Message-ID: <ff32532a209902db6637c34b408e77abf7a1fda6.1459147231.git.hongxu.jia@windriver.com> (raw)
In-Reply-To: <cover.1459147231.git.hongxu.jia@windriver.com>

Previously, the dbg package could not generate sources if they
are in work-shared dir (toolchain, kernel).

The fix add a new fdebug-prefix-map to remap work-shared dir
and collect sources to dbg package.

[YOCTO #9305]

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
 meta/classes/package.bbclass | 100 +++++++++++++++++++++++++++++++------------
 meta/conf/bitbake.conf       |   1 +
 2 files changed, 73 insertions(+), 28 deletions(-)

diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass
index bdbe96d..f862d0b 100644
--- a/meta/classes/package.bbclass
+++ b/meta/classes/package.bbclass
@@ -300,6 +300,14 @@ def get_conffiles(pkg, d):
     os.chdir(cwd)
     return conf_list
 
+def checkworkshared(file, d):
+    with open(file) as f:
+        file_content = f.read()
+        if "work-shared" in file_content:
+            return True
+
+    return False
+
 def checkbuildpath(file, d):
     tmpdir = d.getVar('TMPDIR', True)
     with open(file) as f:
@@ -309,6 +317,50 @@ def checkbuildpath(file, d):
 
     return False
 
+def collectsources(sourcefile, prefix_new, prefix_old, dest, d):
+    bb.utils.mkdirhier(dest)
+
+    # List all available sources
+    cmd =  "LC_ALL=C ; sort -z -u '%s' | " % sourcefile
+
+    # Filter out <internal> and <built-in>
+    cmd +=  "egrep -v -z '(<internal>|<built-in>)$' | "
+
+    # We need to ignore files that are not actually ours
+    # we do this by only paying attention to items from this package
+    cmd += "fgrep -zw '%s' | " % prefix_new
+
+    # Remove prefix in the source paths
+    cmd += "sed 's#%s/##g' | " % prefix_new
+
+    # If sources in WORKDIR, it ignores work-shared;
+    # If sources in work-shared, it filters nothing;
+    cmd += " sed -z '/work-shared/d' | "
+
+    # Enter dir prefix_old to copy sources
+    cmd += "(cd '%s' ; cpio -pd0mlL --no-preserve-owner '%s' 2>/dev/null)" % (prefix_old, dest)
+
+    (retval, output) = oe.utils.getstatusoutput(cmd)
+    # Can "fail" if internal headers/transient sources are attempted
+    #if retval:
+    #    bb.fatal("debug source copy failed with exit code %s (cmd was %s)" % (retval, cmd))
+
+# cpio seems to have a bug with -lL together and symbolic links are just copied, not dereferenced.
+# Work around this by manually finding and copying any symbolic links that made it through.
+def dereferencesymlink(prefix_old, dest, d):
+    # Enter dir dest, list all available symlinks that were removed prefix dest
+    cmd = "find %s -type l -print0 -delete | sed 's#%s/##g' | " % (dest, dest)
+
+    # If sources in WORKDIR, it ignores work-shared;
+    # If sources in work-shared, it filters nothing;
+    cmd += " sed '/work-shared/d' | "
+
+    # Enter dir prefix_old to copy sources to dest
+    cmd += "(cd '%s'; cpio -pd0mL --no-preserve-owner '%s' 2>/dev/null)" % (prefix_old, dest)
+    (retval, output) = oe.utils.getstatusoutput(cmd)
+    if retval:
+        bb.fatal("debugsrc symlink fixup failed with exit code %s (cmd was %s)" % (retval, cmd))
+
 def splitdebuginfo(file, debugfile, debugsrcdir, sourcefile, d):
     # Function to split a single file into two components, one is the stripped
     # target system binary, the other contains any debugging information. The
@@ -370,15 +422,6 @@ def copydebugsources(debugsrcdir, d):
         objcopy = d.getVar("OBJCOPY", True)
         debugedit = d.expand("${STAGING_LIBDIR_NATIVE}/rpm/bin/debugedit")
         workdir = d.getVar("WORKDIR", True)
-        workparentdir = os.path.dirname(os.path.dirname(workdir))
-        workbasedir = os.path.basename(os.path.dirname(workdir)) + "/" + os.path.basename(workdir)
-
-        # If build path exists in sourcefile, it means toolchain did not use
-        # -fdebug-prefix-map to compile
-        if checkbuildpath(sourcefile, d):
-            localsrc_prefix = workparentdir + "/"
-        else:
-            localsrc_prefix = "/usr/src/debug/"
 
         nosuchdir = []
         basepath = dvar
@@ -389,26 +432,27 @@ def copydebugsources(debugsrcdir, d):
         bb.utils.mkdirhier(basepath)
         cpath.updatecache(basepath)
 
-        processdebugsrc =  "LC_ALL=C ; sort -z -u '%s' | egrep -v -z '(<internal>|<built-in>)$' | "
-        # We need to ignore files that are not actually ours
-        # we do this by only paying attention to items from this package
-        processdebugsrc += "fgrep -zw '%s' | "
-        # Remove prefix in the source paths
-        processdebugsrc += "sed 's#%s##g' | "
-        processdebugsrc += "(cd '%s' ; cpio -pd0mlL --no-preserve-owner '%s%s' 2>/dev/null)"
-
-        cmd = processdebugsrc % (sourcefile, workbasedir, localsrc_prefix, workparentdir, dvar, debugsrcdir)
-        (retval, output) = oe.utils.getstatusoutput(cmd)
-        # Can "fail" if internal headers/transient sources are attempted
-        #if retval:
-        #    bb.fatal("debug source copy failed with exit code %s (cmd was %s)" % (retval, cmd))
+        # Collect sources in work-shared
+        if checkworkshared(sourcefile, d):
+            if checkbuildpath(sourcefile, d):
+                prefix_new = prefix_old = d.expand("${TMPDIR}/work-shared")
+            else:
+                prefix_old = d.expand("${TMPDIR}/work-shared")
+                prefix_new = d.expand("/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}/work-shared")
+            dest = "%s%s" % (dvar, d.expand("/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}/work-shared"))
+            collectsources(sourcefile, prefix_new, prefix_old, dest, d)
+            dereferencesymlink(prefix_old, dest, d)
 
-        # cpio seems to have a bug with -lL together and symbolic links are just copied, not dereferenced.
-        # Work around this by manually finding and copying any symbolic links that made it through.
-        cmd = "find %s%s -type l -print0 -delete | sed s#%s%s/##g | (cd '%s' ; cpio -pd0mL --no-preserve-owner '%s%s' 2>/dev/null)" % (dvar, debugsrcdir, dvar, debugsrcdir, workparentdir, dvar, debugsrcdir)
-        (retval, output) = oe.utils.getstatusoutput(cmd)
-        if retval:
-            bb.fatal("debugsrc symlink fixup failed with exit code %s (cmd was %s)" % (retval, cmd))
+        # If build path exists in sourcefile, it means toolchain did not use
+        # -fdebug-prefix-map to compile
+        if checkbuildpath(sourcefile, d):
+            prefix_new = prefix_old = workdir
+        else:
+            prefix_old = workdir
+            prefix_new = d.expand("/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}")
+        dest = "%s%s" % (dvar, d.expand("/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}"))
+        collectsources(sourcefile, prefix_new, prefix_old, dest, d)
+        dereferencesymlink(prefix_old, dest, d)
 
         # The copy by cpio may have resulted in some empty directories!  Remove these
         cmd = "find %s%s -empty -type d -delete" % (dvar, debugsrcdir)
diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index 0eb288e..007ae0f 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -550,6 +550,7 @@ EXTRA_OEMAKE_prepend_task-install = "${PARALLEL_MAKEINST} "
 # Optimization flags.
 ##################################################################
 DEBUG_FLAGS ?= "-g -feliminate-unused-debug-types \
+                -fdebug-prefix-map=${TMPDIR}/work-shared=/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}/work-shared \
                 -fdebug-prefix-map=${WORKDIR}=/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR} \
                 -fdebug-prefix-map=${STAGING_DIR_NATIVE}= \
                 -fdebug-prefix-map=${STAGING_DIR_HOST}= \
-- 
1.9.1



  parent reply	other threads:[~2016-03-28  8:19 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-28  8:18 [PATCH V7 00/17] fix buildpaths QA issue && dbp package source generation Hongxu Jia
2016-03-28  8:18 ` [PATCH 01/17] conf/bitbake.conf package.bbclass: fix dbg package not contain sources while -fdebug-prefix-map used Hongxu Jia
2016-04-18  8:09   ` Andreas Müller
2016-04-18  8:11     ` Hongxu Jia
2016-04-18  8:23       ` Andreas Müller
2016-04-18  8:32         ` Hongxu Jia
2016-04-18  8:47           ` Andreas Müller
2016-04-18  9:04             ` Hongxu Jia
2016-04-18  9:15               ` Andreas Müller
2016-04-18  9:34                 ` Hongxu Jia
2016-04-18  9:52                   ` Andreas Müller
2016-04-18 13:08                     ` Hongxu Jia
2016-04-18 13:55                       ` Burton, Ross
2016-04-18 14:16                         ` Andreas Müller
2016-04-18 14:51                           ` Richard Purdie
2016-04-18 18:50                           ` Mark Hatle
2016-04-18 21:05                             ` Andreas Müller
2016-04-19  0:51                               ` Mark Hatle
2016-04-19  4:32                             ` Paul Eggleton
2016-04-19 12:29                               ` Mark Hatle
2016-04-19  7:33                           ` Hongxu Jia
2016-04-19 12:31                             ` Mark Hatle
2016-04-19 12:59                               ` Hongxu Jia
2016-04-19 14:11                             ` Andreas Müller
2016-04-19 14:47                               ` Mark Hatle
2016-04-19 14:49                                 ` Mark Hatle
2016-04-19 14:54                               ` Richard Purdie
2016-04-19 21:50                                 ` Andreas Müller
2016-04-28 21:41                                 ` Andreas Müller
2016-04-19  1:46                         ` Hongxu Jia
2016-03-28  8:18 ` [PATCH 02/17] gcc-5.3/gcc-4.9: -fdebug-prefix-map support to remap relative path Hongxu Jia
2016-03-28  8:18 ` Hongxu Jia [this message]
2016-03-29 22:38   ` [PATCH 03/17] conf/bitbake.conf package.bbclass: improve dbg package sources generation from work-shared Richard Purdie
2016-03-30  1:58     ` Hongxu Jia
2016-03-30  5:36       ` Hongxu Jia
2016-03-28  8:18 ` [PATCH 04/17] dtc.inc: fix buildpaths QA issue Hongxu Jia
2016-03-28  8:18 ` [PATCH 05/17] fix_buildpaths.bbclass: add bbclass to fix build path Hongxu Jia
2016-03-28  8:18 ` [PATCH 06/17] icu: fix buildpaths QA issue Hongxu Jia
2016-03-28  8:18 ` [PATCH 07/17] tcl: fix buildpath " Hongxu Jia
2016-03-28  8:18 ` [PATCH 08/17] python2/3: " Hongxu Jia
2016-03-28  8:18 ` [PATCH 09/17] bbclass distutils/distutils3: fix .pyc/.pyo buildpath Hongxu Jia
2016-03-28  8:18 ` [PATCH 10/17] bbclass distutils/distutils3/setuptools/setuptools3: clean up DISTUTILS_INSTALL_ARGS Hongxu Jia
2016-03-28  8:18 ` [PATCH 11/17] python-setuptools/python3-setuptools: use old-style install Hongxu Jia
2016-03-28  8:18 ` [PATCH 12/17] python3-pip: " Hongxu Jia
2016-03-28  8:18 ` [PATCH 13/17] waf.bbclass: support do patch on extracted files Hongxu Jia
2016-03-28  8:18 ` [PATCH 14/17] python-pycairo: fix buildpath QA issue Hongxu Jia
2016-03-28  8:18 ` [PATCH 15/17] openssl: " Hongxu Jia
2016-03-28  8:19 ` [PATCH 16/17] epiphany: fix buildpaths " Hongxu Jia
2016-03-28  8:19 ` [PATCH 17/17] ifupdown: fix do_compile failed while GCCVERSION = "4.9%" Hongxu Jia
2016-03-30  8:06 ` [PATCH V7 00/17] fix buildpaths QA issue && dbp package source generation Hongxu Jia

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ff32532a209902db6637c34b408e77abf7a1fda6.1459147231.git.hongxu.jia@windriver.com \
    --to=hongxu.jia@windriver.com \
    --cc=mark.hatle@windriver.com \
    --cc=openembedded-core@lists.openembedded.org \
    --cc=richard.purdie@linuxfoundation.org \
    --cc=ross.burton@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.