devtool: account for sources in UNPACKDIR

There's a couple of assumptions in devtool that sources
are always in a directory under WORKDIR; this is no longer
the case since introduction of UNPACKDIR: some recipes
are starting to use

S = "${UNPACKDIR}/git"

or similar, and so the logic to determine source locations
needs to be tweaked accordingly.

The issue is that oe-core has no concept of 'top level source
path' (S points to where the build is started from, inside that
top level location), and yet devtool needs to know that in order
to move the complete source tree correctly to a workspace (and possibly
other uses).

And so devtool performs convoluted path calculations from WORKDIR and S;
now this has been extended to include UNPACKDIR and became more convoluted
but hopefully it won't get any worse.

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
This commit is contained in:
Alexander Kanavin 2025-04-11 13:11:15 +02:00
parent a79a4f5d84
commit 7895514228
4 changed files with 27 additions and 10 deletions

View File

@ -92,9 +92,13 @@ python devtool_post_unpack() {
for fname in local_files:
f.write('%s\n' % fname)
if os.path.dirname(srcsubdir) != workdir:
if srcsubdir.startswith(unpackdir) and srcsubdir != unpackdir:
srcparentdir = unpackdir
else:
srcparentdir = workdir
if os.path.dirname(srcsubdir) != srcparentdir:
# Handle if S is set to a subdirectory of the source
srcsubdir = os.path.join(workdir, os.path.relpath(srcsubdir, workdir).split(os.sep)[0])
srcsubdir = os.path.join(srcparentdir, os.path.relpath(srcsubdir, srcparentdir).split(os.sep)[0])
scriptutils.git_convert_standalone_clone(srcsubdir)

View File

@ -334,7 +334,7 @@ class RecipeModified:
self.srctree = workspace[workspacepn]['srctree']
# Need to grab this here in case the source is within a subdirectory
self.real_srctree = get_real_srctree(
self.srctree, recipe_d.getVar('S'), recipe_d.getVar('WORKDIR'))
self.srctree, recipe_d.getVar('S'), recipe_d.getVar('WORKDIR'), recipe_d.getVar('UNPACKDIR'))
self.bbappend = workspace[workspacepn]['bbappend']
self.ide_sdk_dir = os.path.join(

View File

@ -625,7 +625,12 @@ def _extract_source(srctree, keep_temp, devbranch, sync, config, basepath, works
srcsubdir = f.read()
except FileNotFoundError as e:
raise DevtoolError('Something went wrong with source extraction - the devtool-source class was not active or did not function correctly:\n%s' % str(e))
srcsubdir_rel = os.path.relpath(srcsubdir, os.path.join(tempdir, 'workdir'))
unpackdir = d.getVar('UNPACKDIR')
if d.getVar('S').startswith(d.getVar('UNPACKDIR')):
srcparentdir = os.path.relpath(d.getVar('UNPACKDIR'), d.getVar('WORKDIR'))
else:
srcparentdir = ''
srcsubdir_rel = os.path.relpath(srcsubdir, os.path.join(tempdir, 'workdir', srcparentdir))
# Check if work-shared is empty, if yes
# find source and copy to work-shared
@ -742,14 +747,22 @@ def get_staging_kbranch(srcdir):
staging_kbranch = "".join(branch.split('\n')[0])
return staging_kbranch
def get_real_srctree(srctree, s, workdir):
def get_real_srctree(srctree, s, workdir, unpackdir):
# Check that recipe isn't using a shared workdir
s = os.path.abspath(s)
workdir = os.path.abspath(workdir)
if s.startswith(workdir) and s != workdir and os.path.dirname(s) != workdir:
unpackdir = os.path.abspath(unpackdir)
if s.startswith(workdir) and s != workdir:
# Handle if S is set to a subdirectory of the source
srcsubdir = os.path.relpath(s, workdir).split(os.sep, 1)[1]
srctree = os.path.join(srctree, srcsubdir)
if s.startswith(unpackdir) and s != unpackdir:
srcparentdir = unpackdir
else:
srcparentdir = workdir
if os.path.dirname(s) != srcparentdir:
srcsubdir = os.path.relpath(s, srcparentdir).split(os.sep, 1)[1]
srctree = os.path.join(srctree, srcsubdir)
return srctree
def modify(args, config, basepath, workspace):
@ -907,7 +920,7 @@ def modify(args, config, basepath, workspace):
# Need to grab this here in case the source is within a subdirectory
srctreebase = srctree
srctree = get_real_srctree(srctree, rd.getVar('S'), rd.getVar('WORKDIR'))
srctree = get_real_srctree(srctree, rd.getVar('S'), rd.getVar('WORKDIR'), rd.getVar('UNPACKDIR'))
bb.utils.mkdirhier(os.path.dirname(appendfile))
with open(appendfile, 'w') as f:

View File

@ -571,7 +571,7 @@ def upgrade(args, config, basepath, workspace):
else:
srctree = standard.get_default_srctree(config, pn)
srctree_s = standard.get_real_srctree(srctree, rd.getVar('S'), rd.getVar('WORKDIR'))
srctree_s = standard.get_real_srctree(srctree, rd.getVar('S'), rd.getVar('WORKDIR'), rd.getVar('UNPACKDIR'))
# try to automatically discover latest version and revision if not provided on command line
if not args.version and not args.srcrev: