summaryrefslogtreecommitdiffstats
path: root/scripts/lib/devtool/upgrade.py
diff options
context:
space:
mode:
authorJulien Stephan <jstephan@baylibre.com>2023-11-22 12:08:16 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-12-01 11:48:25 +0000
commit89f16624842a91e063dc9e6b98787d44c55e4900 (patch)
treec22ebb7b7f5ff89d3ed8431e8dcace59678b9ed3 /scripts/lib/devtool/upgrade.py
parent17427db136491f13b0c9f187906ce9e3f6c85b29 (diff)
downloadpoky-89f16624842a91e063dc9e6b98787d44c55e4900.tar.gz
devtool: add support for git submodules
Adding the support of submodules required a lot of changes on the internal data structures: * initial_rev/startcommit used as a starting point for looking at new / updated commits was replaced by a dictionary where the keys are the submodule name ("." for main repo) and the values are the initial_rev/startcommit * the extractPatches function now extracts patch for the main repo and for all submodules and stores them in a hierarchical way describing the submodule path * store initial_rev/commit also for all submodules inside the recipe bbappend file * _export_patches now returns dictionaries that contains the 'patchdir' parameter (if any). This parameter is used to add the correct 'patchdir=' parameter on the recipe Also, recipe can extract a secondary git tree inside the workdir. By default, at the end of the do_patch function, there is a hook in devtool that commits everything that was modified to have a clean repository. It uses the command: "git add .; git commit ..." The issue here is that, it adds the secondary git tree as a submodule but in a wrong way. Doing "git add <git dir>" declares a submodule but do not adds a url associated to it, and all following "git submodule foreach" commands will fail. So detect that a git tree was extracted inside S and correctly add it using "git submodule add <url> <path>", so that it will be considered as a regular git submodule (From OE-Core rev: 900129cbdf25297a42ab5dbd02d1adbea405c935) Signed-off-by: Julien Stephan <jstephan@baylibre.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/devtool/upgrade.py')
-rw-r--r--scripts/lib/devtool/upgrade.py51
1 files changed, 30 insertions, 21 deletions
diff --git a/scripts/lib/devtool/upgrade.py b/scripts/lib/devtool/upgrade.py
index 9cd50be3a2..10827a762b 100644
--- a/scripts/lib/devtool/upgrade.py
+++ b/scripts/lib/devtool/upgrade.py
@@ -90,7 +90,7 @@ def _rename_recipe_files(oldrecipe, bpn, oldpv, newpv, path):
90 _rename_recipe_dirs(oldpv, newpv, path) 90 _rename_recipe_dirs(oldpv, newpv, path)
91 return _rename_recipe_file(oldrecipe, bpn, oldpv, newpv, path) 91 return _rename_recipe_file(oldrecipe, bpn, oldpv, newpv, path)
92 92
93def _write_append(rc, srctreebase, srctree, same_dir, no_same_dir, rev, copied, workspace, d): 93def _write_append(rc, srctreebase, srctree, same_dir, no_same_dir, revs, copied, workspace, d):
94 """Writes an append file""" 94 """Writes an append file"""
95 if not os.path.exists(rc): 95 if not os.path.exists(rc):
96 raise DevtoolError("bbappend not created because %s does not exist" % rc) 96 raise DevtoolError("bbappend not created because %s does not exist" % rc)
@@ -119,8 +119,9 @@ def _write_append(rc, srctreebase, srctree, same_dir, no_same_dir, rev, copied,
119 if b_is_s: 119 if b_is_s:
120 f.write('EXTERNALSRC_BUILD:pn-%s = "%s"\n' % (pn, srctree)) 120 f.write('EXTERNALSRC_BUILD:pn-%s = "%s"\n' % (pn, srctree))
121 f.write('\n') 121 f.write('\n')
122 if rev: 122 if revs:
123 f.write('# initial_rev: %s\n' % rev) 123 for name, rev in revs.items():
124 f.write('# initial_rev %s: %s\n' % (name, rev))
124 if copied: 125 if copied:
125 f.write('# original_path: %s\n' % os.path.dirname(d.getVar('FILE'))) 126 f.write('# original_path: %s\n' % os.path.dirname(d.getVar('FILE')))
126 f.write('# original_files: %s\n' % ' '.join(copied)) 127 f.write('# original_files: %s\n' % ' '.join(copied))
@@ -182,10 +183,15 @@ def _extract_new_source(newpv, srctree, no_patch, srcrev, srcbranch, branch, kee
182 uri, rev = _get_uri(crd) 183 uri, rev = _get_uri(crd)
183 if srcrev: 184 if srcrev:
184 rev = srcrev 185 rev = srcrev
186 paths = [srctree]
185 if uri.startswith('git://') or uri.startswith('gitsm://'): 187 if uri.startswith('git://') or uri.startswith('gitsm://'):
186 __run('git fetch') 188 __run('git fetch')
187 __run('git checkout %s' % rev) 189 __run('git checkout %s' % rev)
188 __run('git tag -f devtool-base-new') 190 __run('git tag -f devtool-base-new')
191 __run('git submodule update --recursive')
192 __run('git submodule foreach \'git tag -f devtool-base-new\'')
193 (stdout, _) = __run('git submodule --quiet foreach \'echo $sm_path\'')
194 paths += [os.path.join(srctree, p) for p in stdout.splitlines()]
189 md5 = None 195 md5 = None
190 sha256 = None 196 sha256 = None
191 _, _, _, _, _, params = bb.fetch2.decodeurl(uri) 197 _, _, _, _, _, params = bb.fetch2.decodeurl(uri)
@@ -256,29 +262,32 @@ def _extract_new_source(newpv, srctree, no_patch, srcrev, srcbranch, branch, kee
256 __run('git %s commit -q -m "Commit of upstream changes at version %s" --allow-empty' % (' '.join(useroptions), newpv)) 262 __run('git %s commit -q -m "Commit of upstream changes at version %s" --allow-empty' % (' '.join(useroptions), newpv))
257 __run('git tag -f devtool-base-%s' % newpv) 263 __run('git tag -f devtool-base-%s' % newpv)
258 264
259 (stdout, _) = __run('git rev-parse HEAD') 265 revs = {}
260 rev = stdout.rstrip() 266 for path in paths:
267 (stdout, _) = _run('git rev-parse HEAD', cwd=path)
268 revs[os.path.relpath(path,srctree)] = stdout.rstrip()
261 269
262 if no_patch: 270 if no_patch:
263 patches = oe.recipeutils.get_recipe_patches(crd) 271 patches = oe.recipeutils.get_recipe_patches(crd)
264 if patches: 272 if patches:
265 logger.warning('By user choice, the following patches will NOT be applied to the new source tree:\n %s' % '\n '.join([os.path.basename(patch) for patch in patches])) 273 logger.warning('By user choice, the following patches will NOT be applied to the new source tree:\n %s' % '\n '.join([os.path.basename(patch) for patch in patches]))
266 else: 274 else:
267 __run('git checkout devtool-patched -b %s' % branch) 275 for path in paths:
268 (stdout, _) = __run('git branch --list devtool-override-*') 276 _run('git checkout devtool-patched -b %s' % branch, cwd=path)
269 branches_to_rebase = [branch] + stdout.split() 277 (stdout, _) = _run('git branch --list devtool-override-*', cwd=path)
270 for b in branches_to_rebase: 278 branches_to_rebase = [branch] + stdout.split()
271 logger.info("Rebasing {} onto {}".format(b, rev)) 279 for b in branches_to_rebase:
272 __run('git checkout %s' % b) 280 logger.info("Rebasing {} onto {}".format(b, revs[os.path.relpath(path,srctree)]))
273 try: 281 _run('git checkout %s' % b, cwd=path)
274 __run('git rebase %s' % rev) 282 try:
275 except bb.process.ExecutionError as e: 283 _run('git rebase %s' % revs[os.path.relpath(path, srctree)], cwd=path)
276 if 'conflict' in e.stdout: 284 except bb.process.ExecutionError as e:
277 logger.warning('Command \'%s\' failed:\n%s\n\nYou will need to resolve conflicts in order to complete the upgrade.' % (e.command, e.stdout.rstrip())) 285 if 'conflict' in e.stdout:
278 __run('git rebase --abort') 286 logger.warning('Command \'%s\' failed:\n%s\n\nYou will need to resolve conflicts in order to complete the upgrade.' % (e.command, e.stdout.rstrip()))
279 else: 287 _run('git rebase --abort', cwd=path)
280 logger.warning('Command \'%s\' failed:\n%s' % (e.command, e.stdout)) 288 else:
281 __run('git checkout %s' % branch) 289 logger.warning('Command \'%s\' failed:\n%s' % (e.command, e.stdout))
290 _run('git checkout %s' % branch, cwd=path)
282 291
283 if tmpsrctree: 292 if tmpsrctree:
284 if keep_temp: 293 if keep_temp:
@@ -288,7 +297,7 @@ def _extract_new_source(newpv, srctree, no_patch, srcrev, srcbranch, branch, kee
288 if tmpdir != tmpsrctree: 297 if tmpdir != tmpsrctree:
289 shutil.rmtree(tmpdir) 298 shutil.rmtree(tmpdir)
290 299
291 return (rev, md5, sha256, srcbranch, srcsubdir_rel) 300 return (revs, md5, sha256, srcbranch, srcsubdir_rel)
292 301
293def _add_license_diff_to_recipe(path, diff): 302def _add_license_diff_to_recipe(path, diff):
294 notice_text = """# FIXME: the LIC_FILES_CHKSUM values have been updated by 'devtool upgrade'. 303 notice_text = """# FIXME: the LIC_FILES_CHKSUM values have been updated by 'devtool upgrade'.