diff options
| author | Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com> | 2025-09-05 08:20:58 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-11-07 13:15:35 +0000 |
| commit | 8b123e2422b255b671176fe1c39672a0bcaae241 (patch) | |
| tree | b5f6e3480816bd1a8db57262c795385817ca7b6c /bitbake/lib | |
| parent | a823b0846362d1692aba48f4dee1bb5cd04849db (diff) | |
| download | poky-8b123e2422b255b671176fe1c39672a0bcaae241.tar.gz | |
bitbake: fetch2: gitsm: remove indirection and nesting
Use a single fetch object to reuse the fetch functionality. Remove
indirection, nesting and duplicate code.
(Bitbake rev: ed48050668189af43041f89e101140f3fe935e94)
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>
Diffstat (limited to 'bitbake/lib')
| -rw-r--r-- | bitbake/lib/bb/fetch2/gitsm.py | 98 |
1 files changed, 32 insertions, 66 deletions
diff --git a/bitbake/lib/bb/fetch2/gitsm.py b/bitbake/lib/bb/fetch2/gitsm.py index 4b6c88baa7..5ddc81f860 100644 --- a/bitbake/lib/bb/fetch2/gitsm.py +++ b/bitbake/lib/bb/fetch2/gitsm.py | |||
| @@ -33,10 +33,10 @@ class GitSM(Git): | |||
| 33 | """ | 33 | """ |
| 34 | return ud.type in ['gitsm'] | 34 | return ud.type in ['gitsm'] |
| 35 | 35 | ||
| 36 | def process_submodules(self, ud, workdir, function, d): | 36 | def process_submodules(self, ud, workdir, d): |
| 37 | """ | 37 | """ |
| 38 | Iterate over all of the submodules in this repository and execute | 38 | Iterate over all of the submodules in this repository and generate a |
| 39 | the 'function' for each of them. | 39 | fetch object for all of them. |
| 40 | """ | 40 | """ |
| 41 | 41 | ||
| 42 | submodules = [] | 42 | submodules = [] |
| @@ -91,6 +91,7 @@ class GitSM(Git): | |||
| 91 | newud.path = os.path.normpath(os.path.join(newud.path, uris[m])) | 91 | newud.path = os.path.normpath(os.path.join(newud.path, uris[m])) |
| 92 | uris[m] = Git._get_repo_url(self, newud) | 92 | uris[m] = Git._get_repo_url(self, newud) |
| 93 | 93 | ||
| 94 | urls = [] | ||
| 94 | for module in submodules: | 95 | for module in submodules: |
| 95 | # Translate the module url into a SRC_URI | 96 | # Translate the module url into a SRC_URI |
| 96 | 97 | ||
| @@ -138,21 +139,21 @@ class GitSM(Git): | |||
| 138 | # the user (See comment in git.py). | 139 | # the user (See comment in git.py). |
| 139 | # So, we will not take patches adding "user=" support here. | 140 | # So, we will not take patches adding "user=" support here. |
| 140 | 141 | ||
| 141 | function(ud, url, module, paths[module], workdir, d) | 142 | urls.append(url) |
| 142 | 143 | ||
| 143 | return submodules != [] | 144 | return Fetch(urls, d, cache=False) if urls else None |
| 144 | 145 | ||
| 145 | def call_process_submodules(self, ud, d, subfunc): | 146 | def call_process_submodules(self, ud, d): |
| 146 | # If we're using a shallow mirror tarball it needs to be | 147 | # If we're using a shallow mirror tarball it needs to be |
| 147 | # unpacked temporarily so that we can examine the .gitmodules file | 148 | # unpacked temporarily so that we can examine the .gitmodules file |
| 148 | # Unpack even when ud.clonedir is not available, | 149 | # Unpack even when ud.clonedir is not available, |
| 149 | # which may occur during a fast shallow clone | 150 | # which may occur during a fast shallow clone |
| 150 | if os.path.exists(ud.clonedir): | 151 | if os.path.exists(ud.clonedir): |
| 151 | self.process_submodules(ud, ud.clonedir, subfunc, d) | 152 | return self.process_submodules(ud, ud.clonedir, d) |
| 152 | elif ud.shallow and os.path.exists(ud.fullshallow): | 153 | elif ud.shallow and os.path.exists(ud.fullshallow): |
| 153 | with tempfile.TemporaryDirectory(dir=d.getVar("DL_DIR")) as tmpdir: | 154 | with tempfile.TemporaryDirectory(dir=d.getVar("DL_DIR")) as tmpdir: |
| 154 | runfetchcmd("tar -xzf %s" % ud.fullshallow, d, workdir=tmpdir) | 155 | runfetchcmd("tar -xzf %s" % ud.fullshallow, d, workdir=tmpdir) |
| 155 | self.process_submodules(ud, tmpdir, subfunc, d) | 156 | return self.process_submodules(ud, tmpdir, d) |
| 156 | else: | 157 | else: |
| 157 | raise bb.fetch2.FetchError("Submodule source not available.") | 158 | raise bb.fetch2.FetchError("Submodule source not available.") |
| 158 | 159 | ||
| @@ -160,51 +161,26 @@ class GitSM(Git): | |||
| 160 | if Git.need_update(self, ud, d): | 161 | if Git.need_update(self, ud, d): |
| 161 | return True | 162 | return True |
| 162 | 163 | ||
| 163 | need_update_list = [] | 164 | need_update = False |
| 164 | def need_update_submodule(ud, url, module, modpath, workdir, d): | 165 | fetch = self.call_process_submodules(ud, d) |
| 165 | try: | 166 | if fetch: |
| 166 | newfetch = Fetch([url], d, cache=False) | 167 | for url in fetch.urls: |
| 167 | new_ud = newfetch.ud[url] | 168 | urldata = fetch.ud[url] |
| 168 | if new_ud.method.need_update(new_ud, d): | 169 | if urldata.method.need_update(urldata, d): |
| 169 | need_update_list.append(modpath) | 170 | need_update = True |
| 170 | except Exception as e: | ||
| 171 | logger.error('gitsm: submodule update check failed: %s %s' % (type(e).__name__, str(e))) | ||
| 172 | need_update_result = True | ||
| 173 | |||
| 174 | self.call_process_submodules(ud, d, need_update_submodule) | ||
| 175 | |||
| 176 | if need_update_list: | ||
| 177 | logger.debug('gitsm: Submodules requiring update: %s' % (' '.join(need_update_list))) | ||
| 178 | return True | ||
| 179 | 171 | ||
| 180 | return False | 172 | return need_update |
| 181 | 173 | ||
| 182 | def download(self, ud, d): | 174 | def download(self, ud, d): |
| 183 | def download_submodule(ud, url, module, modpath, workdir, d): | ||
| 184 | # Is the following still needed? | ||
| 185 | #url += ";nocheckout=1" | ||
| 186 | |||
| 187 | try: | ||
| 188 | newfetch = Fetch([url], d, cache=False) | ||
| 189 | newfetch.download() | ||
| 190 | except Exception as e: | ||
| 191 | logger.error('gitsm: submodule download failed: %s %s' % (type(e).__name__, str(e))) | ||
| 192 | raise | ||
| 193 | |||
| 194 | Git.download(self, ud, d) | 175 | Git.download(self, ud, d) |
| 195 | self.call_process_submodules(ud, d, download_submodule) | 176 | |
| 177 | fetch = self.call_process_submodules(ud, d) | ||
| 178 | if fetch: | ||
| 179 | fetch.download() | ||
| 196 | 180 | ||
| 197 | def unpack(self, ud, destdir, d): | 181 | def unpack(self, ud, destdir, d): |
| 198 | fulldestdir = self.destdir(ud, destdir, d) | 182 | fulldestdir = self.destdir(ud, destdir, d) |
| 199 | 183 | ||
| 200 | def unpack_submodules(ud, url, module, modpath, workdir, d): | ||
| 201 | try: | ||
| 202 | newfetch = Fetch([url], d, cache=False) | ||
| 203 | newfetch.unpack(root=destdir) | ||
| 204 | except Exception as e: | ||
| 205 | logger.error('gitsm: submodule unpack failed: %s %s' % (type(e).__name__, str(e))) | ||
| 206 | raise | ||
| 207 | |||
| 208 | Git.unpack(self, ud, destdir, d) | 184 | Git.unpack(self, ud, destdir, d) |
| 209 | 185 | ||
| 210 | parentdir = ud.parm.get('parentdir') | 186 | parentdir = ud.parm.get('parentdir') |
| @@ -228,35 +204,25 @@ class GitSM(Git): | |||
| 228 | logger.error("Unable to set git config core.bare to false for %s" % fulldestdir) | 204 | logger.error("Unable to set git config core.bare to false for %s" % fulldestdir) |
| 229 | raise | 205 | raise |
| 230 | 206 | ||
| 231 | ret = self.process_submodules(ud, fulldestdir, unpack_submodules, d) | 207 | fetch = self.process_submodules(ud, fulldestdir, d) |
| 208 | if fetch: | ||
| 209 | fetch.unpack(destdir) | ||
| 232 | 210 | ||
| 233 | if not ud.bareclone and ret: | 211 | if not ud.bareclone and fetch: |
| 234 | cmdprefix = "" | 212 | cmdprefix = "" |
| 235 | # Avoid LFS smudging (replacing the LFS pointers with the actual content) when LFS shouldn't be used but git-lfs is installed. | 213 | # Avoid LFS smudging (replacing the LFS pointers with the actual content) when LFS shouldn't be used but git-lfs is installed. |
| 236 | if not self._need_lfs(ud): | 214 | if not self._need_lfs(ud): |
| 237 | cmdprefix = "GIT_LFS_SKIP_SMUDGE=1 " | 215 | cmdprefix = "GIT_LFS_SKIP_SMUDGE=1 " |
| 238 | runfetchcmd("%s%s submodule update --recursive --no-fetch" % (cmdprefix, ud.basecmd), d, quiet=True, workdir=fulldestdir) | 216 | runfetchcmd("%s%s submodule update --recursive --no-fetch" % (cmdprefix, ud.basecmd), d, quiet=True, workdir=fulldestdir) |
| 239 | def clean(self, ud, d): | 217 | def clean(self, ud, d): |
| 240 | def clean_submodule(ud, url, module, modpath, workdir, d): | 218 | fetch = self.call_process_submodules(ud, d) |
| 241 | try: | 219 | if fetch: |
| 242 | newfetch = Fetch([url], d, cache=False) | 220 | fetch.clean() |
| 243 | newfetch.clean() | ||
| 244 | except Exception as e: | ||
| 245 | logger.warning('gitsm: submodule clean failed: %s %s' % (type(e).__name__, str(e))) | ||
| 246 | |||
| 247 | self.call_process_submodules(ud, d, clean_submodule) | ||
| 248 | |||
| 249 | # Clean top git dir | ||
| 250 | Git.clean(self, ud, d) | 221 | Git.clean(self, ud, d) |
| 251 | 222 | ||
| 252 | def implicit_urldata(self, ud, d): | 223 | def implicit_urldata(self, ud, d): |
| 253 | import subprocess | 224 | fetch = self.call_process_submodules(ud, d) |
| 254 | 225 | if fetch: | |
| 255 | urldata = [] | 226 | return fetch.expanded_urldata() |
| 256 | def add_submodule(ud, url, module, modpath, workdir, d): | ||
| 257 | newfetch = Fetch([url], d, cache=False) | ||
| 258 | urldata.extend(newfetch.expanded_urldata()) | ||
| 259 | |||
| 260 | self.call_process_submodules(ud, d, add_submodule) | ||
| 261 | 227 | ||
| 262 | return urldata | 228 | return [] |
