summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2021-10-25 16:04:50 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-11-03 10:12:42 +0000
commit5acc6975063b82e34aa99366fedb1ce5c4238f70 (patch)
treee16ab57f4fc59132185b6756f3691fa59710ee17
parente17d4895ca069d3d5b268f8be561c3651c132b5c (diff)
downloadpoky-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>
-rw-r--r--bitbake/lib/bb/fetch2/git.py27
-rw-r--r--bitbake/lib/bb/tests/fetch.py4
2 files changed, 21 insertions, 10 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)
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index a008e7cc5b..e1638bc478 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -2157,7 +2157,7 @@ class GitLfsTest(FetcherTest):
2157 def test_lfs_enabled(self): 2157 def test_lfs_enabled(self):
2158 import shutil 2158 import shutil
2159 2159
2160 uri = 'git://%s;protocol=file;subdir=${S};lfs=1' % self.srcdir 2160 uri = 'git://%s;protocol=file;lfs=1' % self.srcdir
2161 self.d.setVar('SRC_URI', uri) 2161 self.d.setVar('SRC_URI', uri)
2162 2162
2163 # Careful: suppress initial attempt at downloading until 2163 # Careful: suppress initial attempt at downloading until
@@ -2182,7 +2182,7 @@ class GitLfsTest(FetcherTest):
2182 def test_lfs_disabled(self): 2182 def test_lfs_disabled(self):
2183 import shutil 2183 import shutil
2184 2184
2185 uri = 'git://%s;protocol=file;subdir=${S};lfs=0' % self.srcdir 2185 uri = 'git://%s;protocol=file;lfs=0' % self.srcdir
2186 self.d.setVar('SRC_URI', uri) 2186 self.d.setVar('SRC_URI', uri)
2187 2187
2188 # In contrast to test_lfs_enabled(), allow the implicit download 2188 # In contrast to test_lfs_enabled(), allow the implicit download