summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>2025-09-05 08:20:46 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-11-07 13:15:34 +0000
commitc1d084184a1e825144def4e1fe707dd67b3cf700 (patch)
treec87e1ffdbe48bc329830129f3844c33ddb19a436
parentbf99008b061e560b7cb56991bac2865ac7f80d52 (diff)
downloadpoky-c1d084184a1e825144def4e1fe707dd67b3cf700.tar.gz
bitbake: fetch2: git: replace destdir variable with function
The destdir variable of FetchData contains the volatile value of the destdir parameter of the unpack function and is only valid after the first call of unpack. Replace the variable with a function to make it independent of the unpack function. (Bitbake rev: 3d10ee897eb5851e901a3dde8d952e3b0e44de39) Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/bb/fetch2/git.py25
-rw-r--r--bitbake/lib/bb/fetch2/gitannex.py10
-rw-r--r--bitbake/lib/bb/fetch2/gitsm.py20
3 files changed, 33 insertions, 22 deletions
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
index 0fcdb19df1..0c8c63ecc4 100644
--- a/bitbake/lib/bb/fetch2/git.py
+++ b/bitbake/lib/bb/fetch2/git.py
@@ -656,30 +656,37 @@ class Git(FetchMethod):
656 # The url is local ud.clonedir, set it to upstream one 656 # The url is local ud.clonedir, set it to upstream one
657 runfetchcmd("%s remote set-url origin %s" % (ud.basecmd, shlex.quote(repourl)), d, workdir=dest) 657 runfetchcmd("%s remote set-url origin %s" % (ud.basecmd, shlex.quote(repourl)), d, workdir=dest)
658 658
659 def unpack(self, ud, destdir, d): 659 def destdir(self, ud, destdir, d):
660 """ unpack the downloaded src to destdir"""
661
662 subdir = ud.parm.get("subdir") 660 subdir = ud.parm.get("subdir")
663 subpath = ud.parm.get("subpath") 661 subpath = ud.parm.get("subpath")
664 readpathspec = ""
665 def_destsuffix = (d.getVar("BB_GIT_DEFAULT_DESTSUFFIX") or "git") + "/" 662 def_destsuffix = (d.getVar("BB_GIT_DEFAULT_DESTSUFFIX") or "git") + "/"
666 663
667 if subpath: 664 if subpath:
668 readpathspec = ":%s" % subpath
669 def_destsuffix = "%s/" % os.path.basename(subpath.rstrip('/')) 665 def_destsuffix = "%s/" % os.path.basename(subpath.rstrip('/'))
670 666
671 if subdir: 667 if subdir:
672 # If 'subdir' param exists, create a dir and use it as destination for unpack cmd
673 if os.path.isabs(subdir): 668 if os.path.isabs(subdir):
674 if not os.path.realpath(subdir).startswith(os.path.realpath(destdir)):
675 raise bb.fetch2.UnpackError("subdir argument isn't a subdirectory of unpack root %s" % destdir, ud.url)
676 destdir = subdir 669 destdir = subdir
677 else: 670 else:
678 destdir = os.path.join(destdir, subdir) 671 destdir = os.path.join(destdir, subdir)
679 def_destsuffix = "" 672 def_destsuffix = ""
680 673
681 destsuffix = ud.parm.get("destsuffix", def_destsuffix) 674 destsuffix = ud.parm.get("destsuffix", def_destsuffix)
682 destdir = ud.destdir = os.path.join(destdir, destsuffix) 675 return os.path.join(destdir, destsuffix)
676
677 def unpack(self, ud, destdir, d):
678 """ unpack the downloaded src to destdir"""
679
680 subpath = ud.parm.get("subpath")
681 readpathspec = ""
682 if subpath:
683 readpathspec = ":%s" % subpath
684
685 root = destdir
686 destdir = self.destdir(ud, root, d)
687 if not os.path.realpath(destdir).startswith(os.path.realpath(root)):
688 raise bb.fetch2.UnpackError("subdir argument isn't a subdirectory of unpack root %s" % root, ud.url)
689
683 if os.path.exists(destdir): 690 if os.path.exists(destdir):
684 bb.utils.prunedir(destdir) 691 bb.utils.prunedir(destdir)
685 if not ud.bareclone: 692 if not ud.bareclone:
diff --git a/bitbake/lib/bb/fetch2/gitannex.py b/bitbake/lib/bb/fetch2/gitannex.py
index 80a808d88f..dbb74e35dd 100644
--- a/bitbake/lib/bb/fetch2/gitannex.py
+++ b/bitbake/lib/bb/fetch2/gitannex.py
@@ -65,13 +65,15 @@ class GitANNEX(Git):
65 def unpack(self, ud, destdir, d): 65 def unpack(self, ud, destdir, d):
66 Git.unpack(self, ud, destdir, d) 66 Git.unpack(self, ud, destdir, d)
67 67
68 destdir = self.destdir(ud, destdir, d)
69
68 try: 70 try:
69 runfetchcmd("%s annex init" % (ud.basecmd), d, workdir=ud.destdir) 71 runfetchcmd("%s annex init" % (ud.basecmd), d, workdir=destdir)
70 except bb.fetch.FetchError: 72 except bb.fetch.FetchError:
71 pass 73 pass
72 74
73 annex = self.uses_annex(ud, d, ud.destdir) 75 annex = self.uses_annex(ud, d, destdir)
74 if annex: 76 if annex:
75 runfetchcmd("%s annex get" % (ud.basecmd), d, workdir=ud.destdir) 77 runfetchcmd("%s annex get" % (ud.basecmd), d, workdir=destdir)
76 runfetchcmd("chmod u+w -R %s/.git/annex" % (ud.destdir), d, quiet=True, workdir=ud.destdir) 78 runfetchcmd("chmod u+w -R %s/.git/annex" % (destdir), d, quiet=True, workdir=destdir)
77 79
diff --git a/bitbake/lib/bb/fetch2/gitsm.py b/bitbake/lib/bb/fetch2/gitsm.py
index 5869e1b99b..d9ebe8d186 100644
--- a/bitbake/lib/bb/fetch2/gitsm.py
+++ b/bitbake/lib/bb/fetch2/gitsm.py
@@ -205,14 +205,16 @@ class GitSM(Git):
205 self.call_process_submodules(ud, d, self.need_update(ud, d), download_submodule) 205 self.call_process_submodules(ud, d, self.need_update(ud, d), download_submodule)
206 206
207 def unpack(self, ud, destdir, d): 207 def unpack(self, ud, destdir, d):
208 subdestdir = self.destdir(ud, destdir, d)
209
208 def unpack_submodules(ud, url, module, modpath, workdir, d): 210 def unpack_submodules(ud, url, module, modpath, workdir, d):
209 url += ";bareclone=1;nobranch=1" 211 url += ";bareclone=1;nobranch=1"
210 212
211 # Figure out where we clone over the bare submodules... 213 # Figure out where we clone over the bare submodules...
212 if ud.bareclone: 214 if ud.bareclone:
213 repo_conf = ud.destdir 215 repo_conf = ''
214 else: 216 else:
215 repo_conf = os.path.join(ud.destdir, '.git') 217 repo_conf = '.git'
216 218
217 try: 219 try:
218 newfetch = Fetch([url], d, cache=False) 220 newfetch = Fetch([url], d, cache=False)
@@ -220,7 +222,7 @@ class GitSM(Git):
220 # checkout dir 222 # checkout dir
221 new_ud = newfetch.ud[url] 223 new_ud = newfetch.ud[url]
222 new_ud.modpath = modpath 224 new_ud.modpath = modpath
223 newfetch.unpack(root=os.path.dirname(os.path.join(repo_conf, 'modules', module))) 225 newfetch.unpack(root=os.path.dirname(os.path.join(subdestdir, repo_conf, 'modules', module)))
224 except Exception as e: 226 except Exception as e:
225 logger.error('gitsm: submodule unpack failed: %s %s' % (type(e).__name__, str(e))) 227 logger.error('gitsm: submodule unpack failed: %s %s' % (type(e).__name__, str(e)))
226 raise 228 raise
@@ -228,28 +230,28 @@ class GitSM(Git):
228 local_path = newfetch.localpath(url) 230 local_path = newfetch.localpath(url)
229 231
230 # Correct the submodule references to the local download version... 232 # Correct the submodule references to the local download version...
231 runfetchcmd("%(basecmd)s config submodule.%(module)s.url %(url)s" % {'basecmd': ud.basecmd, 'module': module, 'url' : local_path}, d, workdir=ud.destdir) 233 runfetchcmd("%(basecmd)s config submodule.%(module)s.url %(url)s" % {'basecmd': ud.basecmd, 'module': module, 'url' : local_path}, d, workdir=subdestdir)
232 234
233 if ud.shallow: 235 if ud.shallow:
234 runfetchcmd("%(basecmd)s config submodule.%(module)s.shallow true" % {'basecmd': ud.basecmd, 'module': module}, d, workdir=ud.destdir) 236 runfetchcmd("%(basecmd)s config submodule.%(module)s.shallow true" % {'basecmd': ud.basecmd, 'module': module}, d, workdir=subdestdir)
235 237
236 # Ensure the submodule repository is NOT set to bare, since we're checking it out... 238 # Ensure the submodule repository is NOT set to bare, since we're checking it out...
237 try: 239 try:
238 runfetchcmd("%s config core.bare false" % (ud.basecmd), d, quiet=True, workdir=os.path.join(repo_conf, 'modules', module)) 240 runfetchcmd("%s config core.bare false" % (ud.basecmd), d, quiet=True, workdir=os.path.join(subdestdir, repo_conf, 'modules', module))
239 except: 241 except:
240 logger.error("Unable to set git config core.bare to false for %s" % os.path.join(repo_conf, 'modules', module)) 242 logger.error("Unable to set git config core.bare to false for %s" % os.path.join(subdestdir, repo_conf, 'modules', module))
241 raise 243 raise
242 244
243 Git.unpack(self, ud, destdir, d) 245 Git.unpack(self, ud, destdir, d)
244 246
245 ret = self.process_submodules(ud, ud.destdir, unpack_submodules, d) 247 ret = self.process_submodules(ud, subdestdir, unpack_submodules, d)
246 248
247 if not ud.bareclone and ret: 249 if not ud.bareclone and ret:
248 cmdprefix = "" 250 cmdprefix = ""
249 # Avoid LFS smudging (replacing the LFS pointers with the actual content) when LFS shouldn't be used but git-lfs is installed. 251 # Avoid LFS smudging (replacing the LFS pointers with the actual content) when LFS shouldn't be used but git-lfs is installed.
250 if not self._need_lfs(ud): 252 if not self._need_lfs(ud):
251 cmdprefix = "GIT_LFS_SKIP_SMUDGE=1 " 253 cmdprefix = "GIT_LFS_SKIP_SMUDGE=1 "
252 runfetchcmd("%s%s submodule update --recursive --no-fetch" % (cmdprefix, ud.basecmd), d, quiet=True, workdir=ud.destdir) 254 runfetchcmd("%s%s submodule update --recursive --no-fetch" % (cmdprefix, ud.basecmd), d, quiet=True, workdir=subdestdir)
253 def clean(self, ud, d): 255 def clean(self, ud, d):
254 def clean_submodule(ud, url, module, modpath, workdir, d): 256 def clean_submodule(ud, url, module, modpath, workdir, d):
255 url += ";bareclone=1;nobranch=1" 257 url += ";bareclone=1;nobranch=1"