diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-10-25 16:04:50 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-11-03 10:12:42 +0000 |
commit | 5acc6975063b82e34aa99366fedb1ce5c4238f70 (patch) | |
tree | e16ab57f4fc59132185b6756f3691fa59710ee17 /bitbake/lib/bb/fetch2/git.py | |
parent | e17d4895ca069d3d5b268f8be561c3651c132b5c (diff) | |
download | poky-5acc6975063b82e34aa99366fedb1ce5c4238f70.tar.gz |
bitbake: fetch2/git: Allow git fetcher to support subdir param
The git fetcher is odd in that it supports destsuffix as a parameter but not
the default documented subdir parameter. destsuffix is more limited as it can't
take absolute paths. Rework the code to correctly support subdir.
Also cleanup to use the None default .get() values and be a bit more pythonic
and use subpath as the variable name for subpath for code clarity.
We could consider dropping destsuffix as a parameter as some future point.
Also fix the tests not to pass in a subdir parameter which was never used
but now causes errors.
(Bitbake rev: 66953f06fe822e4001efabd9fc1c985ea2b03f96)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/fetch2/git.py')
-rw-r--r-- | bitbake/lib/bb/fetch2/git.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py index e8ddf2c761..51b616bad7 100644 --- a/bitbake/lib/bb/fetch2/git.py +++ b/bitbake/lib/bb/fetch2/git.py | |||
@@ -516,13 +516,24 @@ class Git(FetchMethod): | |||
516 | def unpack(self, ud, destdir, d): | 516 | def unpack(self, ud, destdir, d): |
517 | """ unpack the downloaded src to destdir""" | 517 | """ unpack the downloaded src to destdir""" |
518 | 518 | ||
519 | subdir = ud.parm.get("subpath", "") | 519 | subdir = ud.parm.get("subdir") |
520 | if subdir != "": | 520 | subpath = ud.parm.get("subpath") |
521 | readpathspec = ":%s" % subdir | 521 | readpathspec = "" |
522 | def_destsuffix = "%s/" % os.path.basename(subdir.rstrip('/')) | 522 | def_destsuffix = "git/" |
523 | else: | 523 | |
524 | readpathspec = "" | 524 | if subpath: |
525 | def_destsuffix = "git/" | 525 | readpathspec = ":%s" % subpath |
526 | def_destsuffix = "%s/" % os.path.basename(subpath.rstrip('/')) | ||
527 | |||
528 | if subdir: | ||
529 | # If 'subdir' param exists, create a dir and use it as destination for unpack cmd | ||
530 | if os.path.isabs(subdir): | ||
531 | if not os.path.realpath(subdir).startswith(os.path.realpath(destdir)): | ||
532 | raise bb.fetch2.UnpackError("subdir argument isn't a subdirectory of unpack root %s" % destdir, ud.url) | ||
533 | destdir = subdir | ||
534 | else: | ||
535 | destdir = os.path.join(destdir, subdir) | ||
536 | def_destsuffix = "" | ||
526 | 537 | ||
527 | destsuffix = ud.parm.get("destsuffix", def_destsuffix) | 538 | destsuffix = ud.parm.get("destsuffix", def_destsuffix) |
528 | destdir = ud.destdir = os.path.join(destdir, destsuffix) | 539 | destdir = ud.destdir = os.path.join(destdir, destsuffix) |
@@ -569,7 +580,7 @@ class Git(FetchMethod): | |||
569 | bb.note("Repository %s has LFS content but it is not being fetched" % (repourl)) | 580 | bb.note("Repository %s has LFS content but it is not being fetched" % (repourl)) |
570 | 581 | ||
571 | if not ud.nocheckout: | 582 | if not ud.nocheckout: |
572 | if subdir != "": | 583 | if subpath: |
573 | runfetchcmd("%s read-tree %s%s" % (ud.basecmd, ud.revisions[ud.names[0]], readpathspec), d, | 584 | runfetchcmd("%s read-tree %s%s" % (ud.basecmd, ud.revisions[ud.names[0]], readpathspec), d, |
574 | workdir=destdir) | 585 | workdir=destdir) |
575 | runfetchcmd("%s checkout-index -q -f -a" % ud.basecmd, d, workdir=destdir) | 586 | runfetchcmd("%s checkout-index -q -f -a" % ud.basecmd, d, workdir=destdir) |