diff options
author | Alexander Kanavin <alex.kanavin@gmail.com> | 2022-08-01 17:44:33 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-08-04 16:27:25 +0100 |
commit | b8c5b2bfd530735a0fab8ce4f0d0e9f76496f3cb (patch) | |
tree | a3c2047fb08c4c0ec710e5d91a28c8509d5af119 /scripts/lib/devtool/upgrade.py | |
parent | 9f99474fa313cc42768fe1ffeed387e6d649fc62 (diff) | |
download | poky-b8c5b2bfd530735a0fab8ce4f0d0e9f76496f3cb.tar.gz |
devtool/upgrade: correctly clean up when recipe filename isn't yet known
There is a coding error in the second invocation of _upgrade_error:
rf is passed into it before it is initialized in the try: block. And so
bogus recipes are left behind in the workspace, causing breakage.
Instead, rewrite the functions to take the recipe directory name in the
workspace layer, which can be calculated in advance.
(From OE-Core rev: e653996369c1d2b5ac8367ad85f4816d679b6c98)
Signed-off-by: Alexander Kanavin <alex@linutronix.de>
Signed-off-by: Luca Ceresoli <luca.ceresoli@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.py | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/scripts/lib/devtool/upgrade.py b/scripts/lib/devtool/upgrade.py index 0357ec07bf..c57015eb40 100644 --- a/scripts/lib/devtool/upgrade.py +++ b/scripts/lib/devtool/upgrade.py | |||
@@ -119,20 +119,19 @@ def _write_append(rc, srctree, same_dir, no_same_dir, rev, copied, workspace, d) | |||
119 | f.write('# original_files: %s\n' % ' '.join(copied)) | 119 | f.write('# original_files: %s\n' % ' '.join(copied)) |
120 | return af | 120 | return af |
121 | 121 | ||
122 | def _cleanup_on_error(rf, srctree): | 122 | def _cleanup_on_error(rd, srctree): |
123 | rfp = os.path.split(rf)[0] # recipe folder | 123 | rdp = os.path.split(rd)[0] # recipes folder |
124 | rfpp = os.path.split(rfp)[0] # recipes folder | 124 | if os.path.exists(rd): |
125 | if os.path.exists(rfp): | 125 | shutil.rmtree(rd) |
126 | shutil.rmtree(rfp) | 126 | if not len(os.listdir(rdp)): |
127 | if not len(os.listdir(rfpp)): | 127 | os.rmdir(rdp) |
128 | os.rmdir(rfpp) | ||
129 | srctree = os.path.abspath(srctree) | 128 | srctree = os.path.abspath(srctree) |
130 | if os.path.exists(srctree): | 129 | if os.path.exists(srctree): |
131 | shutil.rmtree(srctree) | 130 | shutil.rmtree(srctree) |
132 | 131 | ||
133 | def _upgrade_error(e, rf, srctree, keep_failure=False, extramsg=None): | 132 | def _upgrade_error(e, rd, srctree, keep_failure=False, extramsg=None): |
134 | if rf and not keep_failure: | 133 | if not keep_failure: |
135 | _cleanup_on_error(rf, srctree) | 134 | _cleanup_on_error(rd, srctree) |
136 | logger.error(e) | 135 | logger.error(e) |
137 | if extramsg: | 136 | if extramsg: |
138 | logger.error(extramsg) | 137 | logger.error(extramsg) |
@@ -426,7 +425,7 @@ def _create_new_recipe(newpv, md5, sha256, srcrev, srcbranch, srcsubdir_old, src | |||
426 | try: | 425 | try: |
427 | rd = tinfoil.parse_recipe_file(fullpath, False) | 426 | rd = tinfoil.parse_recipe_file(fullpath, False) |
428 | except bb.tinfoil.TinfoilCommandFailed as e: | 427 | except bb.tinfoil.TinfoilCommandFailed as e: |
429 | _upgrade_error(e, fullpath, srctree, keep_failure, 'Parsing of upgraded recipe failed') | 428 | _upgrade_error(e, os.path.dirname(fullpath), srctree, keep_failure, 'Parsing of upgraded recipe failed') |
430 | oe.recipeutils.patch_recipe(rd, fullpath, newvalues) | 429 | oe.recipeutils.patch_recipe(rd, fullpath, newvalues) |
431 | 430 | ||
432 | return fullpath, copied | 431 | return fullpath, copied |
@@ -568,10 +567,9 @@ def upgrade(args, config, basepath, workspace): | |||
568 | new_licenses = _extract_licenses(srctree_s, (rd.getVar('LIC_FILES_CHKSUM') or "")) | 567 | new_licenses = _extract_licenses(srctree_s, (rd.getVar('LIC_FILES_CHKSUM') or "")) |
569 | license_diff = _generate_license_diff(old_licenses, new_licenses) | 568 | license_diff = _generate_license_diff(old_licenses, new_licenses) |
570 | rf, copied = _create_new_recipe(args.version, md5, sha256, args.srcrev, srcbranch, srcsubdir1, srcsubdir2, config.workspace_path, tinfoil, rd, license_diff, new_licenses, srctree, args.keep_failure) | 569 | rf, copied = _create_new_recipe(args.version, md5, sha256, args.srcrev, srcbranch, srcsubdir1, srcsubdir2, config.workspace_path, tinfoil, rd, license_diff, new_licenses, srctree, args.keep_failure) |
571 | except bb.process.CmdError as e: | 570 | except (bb.process.CmdError, DevtoolError) as e: |
572 | _upgrade_error(e, rf, srctree, args.keep_failure) | 571 | recipedir = os.path.join(config.workspace_path, 'recipes', rd.getVar('BPN')) |
573 | except DevtoolError as e: | 572 | _upgrade_error(e, recipedir, srctree, args.keep_failure) |
574 | _upgrade_error(e, rf, srctree, args.keep_failure) | ||
575 | standard._add_md5(config, pn, os.path.dirname(rf)) | 573 | standard._add_md5(config, pn, os.path.dirname(rf)) |
576 | 574 | ||
577 | af = _write_append(rf, srctree_s, args.same_dir, args.no_same_dir, rev2, | 575 | af = _write_append(rf, srctree_s, args.same_dir, args.no_same_dir, rev2, |