All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Purdie <richard.purdie@linuxfoundation.org>
To: Alejandro Hernandez Samaniego <alhe@linux.microsoft.com>,
	openembedded-core@lists.openembedded.org,
	Bruce Ashfield <bruce.ashfield@gmail.com>
Subject: Re: [OE-core] [PATCH] package.bbclass: Fix base directory for debugsource files when using externalsrc
Date: Mon, 11 Jul 2022 13:12:12 +0100	[thread overview]
Message-ID: <72eca448989f313fa322e19a59751d46ef7babc7.camel@linuxfoundation.org> (raw)
In-Reply-To: <20220701020939.62295-1-alhe@linux.microsoft.com>

On Thu, 2022-06-30 at 20:09 -0600, Alejandro Hernandez Samaniego wrote:
> While executing do_package, bitbake checks for a list of
> debug source files and uses a pattern to match the ones
> to be included in copydebugsources.
> 
> Previously when externalsrc was in use either directly or by
> using devtool, the source location changed and this pattern
> no longer matched, hence debug source files failed to be
> included in the corresponding package.
> 
> Check when the source directory isnt the default (based on
> WORKDIR), and change the pattern used to match debug source
> files if that is the case, allowing us to perform do_package
> properly.
> 
> Workaround debugsource.list containing paths from the host by
> moving debug source files away from the host directory
> structure  to avoid host contamination (this seems to happen
> when packages use $TMPDIR/work-shared and externalsrc is
> in use).
> 
> Test matrix included using:
> - devtool to use externalsrc automatically
> - externalsrc with a non-devtool based source directory
> - No externalsrc at all
> Tested the following packages to be working:
> - glibc ($TMPDIR/work-shared based)
> - libxcrypt ($TMPDIR/work based)
> 
> [YOCTO 8015]
> 
> Signed-off-by: Alejandro Enedino Hernandez Samaniego <alhe@linux.microsoft.com>
> ---
>  meta/classes/package.bbclass | 31 ++++++++++++++++++++++++++++---
>  1 file changed, 28 insertions(+), 3 deletions(-)
> 
> diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass
> index 62050a18b8..4850134022 100644
> --- a/meta/classes/package.bbclass
> +++ b/meta/classes/package.bbclass
> @@ -553,13 +553,25 @@ def copydebugsources(debugsrcdir, sources, d):
>          strip = d.getVar("STRIP")
>          objcopy = d.getVar("OBJCOPY")
>          workdir = d.getVar("WORKDIR")
> +        sdir = d.getVar("S")
> +        sparentdir = os.path.dirname(os.path.dirname(sdir))
> +        sbasedir = os.path.basename(os.path.dirname(sdir)) + "/" + os.path.basename(sdir)
>          workparentdir = os.path.dirname(os.path.dirname(workdir))
>          workbasedir = os.path.basename(os.path.dirname(workdir)) + "/" + os.path.basename(workdir)
>  
> +        # If S isnt based on WORKDIR we can infer our sources are located elsewhere,
> +        # e.g. using externalsrc; use S as base for our dirs
> +        if workdir in sdir:
> +            basedir = workbasedir
> +            parentdir = workparentdir
> +        else:
> +            basedir = sbasedir
> +            parentdir = sparentdir
> +
>          # If build path exists in sourcefile, it means toolchain did not use
>          # -fdebug-prefix-map to compile
>          if checkbuildpath(sourcefile, d):
> -            localsrc_prefix = workparentdir + "/"
> +            localsrc_prefix = parentdir + "/"
>          else:
>              localsrc_prefix = "/usr/src/debug/"
>  
> @@ -581,7 +593,7 @@ def copydebugsources(debugsrcdir, sources, d):
>          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)
> +        cmd = processdebugsrc % (sourcefile, basedir, localsrc_prefix, parentdir, dvar, debugsrcdir)
>          try:
>              subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
>          except subprocess.CalledProcessError:
> @@ -591,9 +603,22 @@ def copydebugsources(debugsrcdir, sources, 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')" % \
> -                (dvar, debugsrcdir, dvar, debugsrcdir, workparentdir, dvar, debugsrcdir)
> +                (dvar, debugsrcdir, dvar, debugsrcdir, parentdir, dvar, debugsrcdir)
>          subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
>  
> +
> +        # debugsources.list may be polluted from the host if we used externalsrc,
> +        # cpio uses copy-pass and may have just created a directory structure
> +        # matching the one from the host, if thats the case move those files to
> +        # debugsrcdir to avoid host contamination.
> +        # Empty dir structure will be deleted in the next step.
> +
> +        # Same check as above for externalsrc
> +        if workdir not in sdir:
> +            if os.path.exists(dvar + debugsrcdir + sdir):
> +                cmd = "mv %s%s%s/* %s%s" % (dvar, debugsrcdir, sdir, dvar,debugsrcdir)
> +                subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
> +
>          # The copy by cpio may have resulted in some empty directories!  Remove these
>          cmd = "find %s%s -empty -type d -delete" % (dvar, debugsrcdir)
>          subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)

This has merged but unfortunately it introduces some kind of
regression. If you build a kernel after this is applied, the kernel
source in /usr/src/ for debug information is no longer present.

This is why I was seeing build failures for the buildpaths QA test
addition whilst Bruce was not since I didn't have this applied in that
particular build.

We need to find out what broke here and how to fix it.

Clearly we need some better QA tests as well to detect this.

Cheers,

Richard



      parent reply	other threads:[~2022-07-11 12:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-01  2:09 [PATCH] package.bbclass: Fix base directory for debugsource files when using externalsrc Alejandro Enedino Hernandez Samaniego
2022-07-01 11:05 ` [OE-core] " Jose Quaresma
2022-07-01 11:19   ` Richard Purdie
2022-07-01 16:36     ` Jose Quaresma
2022-07-11 12:12 ` Richard Purdie [this message]

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=72eca448989f313fa322e19a59751d46ef7babc7.camel@linuxfoundation.org \
    --to=richard.purdie@linuxfoundation.org \
    --cc=alhe@linux.microsoft.com \
    --cc=bruce.ashfield@gmail.com \
    --cc=openembedded-core@lists.openembedded.org \
    /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.