summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Yang <liezhi.yang@windriver.com>2024-10-26 02:39:51 -0700
committerSteve Sakoman <steve@sakoman.com>2024-11-02 06:06:09 -0700
commite66f081f5197cd6b5c956b3a8fa5e563a1b41fd5 (patch)
treecb3b9fc5425563d2a547cbc501ba8912b829bcd5
parentd38f77a200d7152d12f3fce1451b5d1b99d0b163 (diff)
downloadpoky-e66f081f5197cd6b5c956b3a8fa5e563a1b41fd5.tar.gz
bitbake: gitsm: Add call_process_submodules() to remove duplicated code
There are 14 lines can be removed, and can make it easy to maintain. (Bitbake rev: ff2dfda55258d8034ea748d87222e51124a03f02) Signed-off-by: Robert Yang <liezhi.yang@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit 0ea2c1ac079d63349407a69172ff80cd9acc7252) Signed-off-by: Steve Sakoman <steve@sakoman.com>
-rw-r--r--bitbake/lib/bb/fetch2/gitsm.py42
1 files changed, 14 insertions, 28 deletions
diff --git a/bitbake/lib/bb/fetch2/gitsm.py b/bitbake/lib/bb/fetch2/gitsm.py
index c5f7c03c4c..0699645fbf 100644
--- a/bitbake/lib/bb/fetch2/gitsm.py
+++ b/bitbake/lib/bb/fetch2/gitsm.py
@@ -139,6 +139,17 @@ class GitSM(Git):
139 139
140 return submodules != [] 140 return submodules != []
141 141
142 def call_process_submodules(self, ud, d, extra_check, subfunc):
143 # If we're using a shallow mirror tarball it needs to be
144 # unpacked temporarily so that we can examine the .gitmodules file
145 if ud.shallow and os.path.exists(ud.fullshallow) and extra_check:
146 tmpdir = tempfile.mkdtemp(dir=d.getVar("DL_DIR"))
147 runfetchcmd("tar -xzf %s" % ud.fullshallow, d, workdir=tmpdir)
148 self.process_submodules(ud, tmpdir, subfunc, d)
149 shutil.rmtree(tmpdir)
150 else:
151 self.process_submodules(ud, ud.clonedir, subfunc, d)
152
142 def need_update(self, ud, d): 153 def need_update(self, ud, d):
143 if Git.need_update(self, ud, d): 154 if Git.need_update(self, ud, d):
144 return True 155 return True
@@ -156,15 +167,7 @@ class GitSM(Git):
156 logger.error('gitsm: submodule update check failed: %s %s' % (type(e).__name__, str(e))) 167 logger.error('gitsm: submodule update check failed: %s %s' % (type(e).__name__, str(e)))
157 need_update_result = True 168 need_update_result = True
158 169
159 # If we're using a shallow mirror tarball it needs to be unpacked 170 self.call_process_submodules(ud, d, not os.path.exists(ud.clonedir), need_update_submodule)
160 # temporarily so that we can examine the .gitmodules file
161 if ud.shallow and os.path.exists(ud.fullshallow) and not os.path.exists(ud.clonedir):
162 tmpdir = tempfile.mkdtemp(dir=d.getVar("DL_DIR"))
163 runfetchcmd("tar -xzf %s" % ud.fullshallow, d, workdir=tmpdir)
164 self.process_submodules(ud, tmpdir, need_update_submodule, d)
165 shutil.rmtree(tmpdir)
166 else:
167 self.process_submodules(ud, ud.clonedir, need_update_submodule, d)
168 171
169 if need_update_list: 172 if need_update_list:
170 logger.debug('gitsm: Submodules requiring update: %s' % (' '.join(need_update_list))) 173 logger.debug('gitsm: Submodules requiring update: %s' % (' '.join(need_update_list)))
@@ -187,16 +190,7 @@ class GitSM(Git):
187 raise 190 raise
188 191
189 Git.download(self, ud, d) 192 Git.download(self, ud, d)
190 193 self.call_process_submodules(ud, d, self.need_update(ud, d), download_submodule)
191 # If we're using a shallow mirror tarball it needs to be unpacked
192 # temporarily so that we can examine the .gitmodules file
193 if ud.shallow and os.path.exists(ud.fullshallow) and self.need_update(ud, d):
194 tmpdir = tempfile.mkdtemp(dir=d.getVar("DL_DIR"))
195 runfetchcmd("tar -xzf %s" % ud.fullshallow, d, workdir=tmpdir)
196 self.process_submodules(ud, tmpdir, download_submodule, d)
197 shutil.rmtree(tmpdir)
198 else:
199 self.process_submodules(ud, ud.clonedir, download_submodule, d)
200 194
201 def unpack(self, ud, destdir, d): 195 def unpack(self, ud, destdir, d):
202 def unpack_submodules(ud, url, module, modpath, workdir, d): 196 def unpack_submodules(ud, url, module, modpath, workdir, d):
@@ -249,14 +243,6 @@ class GitSM(Git):
249 newfetch = Fetch([url], d, cache=False) 243 newfetch = Fetch([url], d, cache=False)
250 urldata.extend(newfetch.expanded_urldata()) 244 urldata.extend(newfetch.expanded_urldata())
251 245
252 # If we're using a shallow mirror tarball it needs to be unpacked 246 self.call_process_submodules(ud, d, ud.method.need_update(ud, d), add_submodule)
253 # temporarily so that we can examine the .gitmodules file
254 if ud.shallow and os.path.exists(ud.fullshallow) and ud.method.need_update(ud, d):
255 tmpdir = tempfile.mkdtemp(dir=d.getVar("DL_DIR"))
256 subprocess.check_call("tar -xzf %s" % ud.fullshallow, cwd=tmpdir, shell=True)
257 self.process_submodules(ud, tmpdir, add_submodule, d)
258 shutil.rmtree(tmpdir)
259 else:
260 self.process_submodules(ud, ud.clonedir, add_submodule, d)
261 247
262 return urldata 248 return urldata