summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2019-07-02 16:24:00 +1200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-07-03 17:00:57 +0100
commitb52d58b8bb81f5053b9fa8b79a137c37d6ef6fb3 (patch)
tree3b956afac235b4a0054e313f9c7ab96382ca6482
parent1dffd9c2ec5d7b69b95b46230d12cead88a47977 (diff)
downloadpoky-b52d58b8bb81f5053b9fa8b79a137c37d6ef6fb3.tar.gz
devtool: upgrade: fix handling of errors parsing upgraded recipe
As part of upgrading a recipe we create the upgraded recipe file in the workspace and then try to parse it so we can then make further modifications. If for some reason that parsing fails then the failure was not being handled very well - the broken recipe was being left in place, breaking parsing until it was removed by hand. Fix that by adding a call to the cleanup function, and fix the following issues: * Fix the cleanup function which doesn't look like it has ever worked due to a typo in the function call * Fix double-printing the error message * Remove usage of DevtoolError in this case (DevtoolError is for simple usage errors, not this kind of issue which may be the result of a bug). We're still printing a traceback in this scenario but at least it doesn't break the build system requiring manual cleanup. I also introduced a command-line option to preserve the broken upgraded recipe file(s) for debugging purposes. (The reproducer for this is "devtool upgrade libnewt-python", however you need to check out revision b82ea144e144671d3f64c0785ba4beafe905cd4f or earlier since that recipe has now been absorbed into the libnewt recipe. The libnewt-python recipe was causing an issue with the upgrade because it actually included the libnewt recipe using ${PV} in the include statement, and of course PV was changing in the upgrade.) Fixes [YOCTO #13404]. (From OE-Core rev: c519ac360796675d7fc09a5250d21f0f5b6236fc) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--scripts/lib/devtool/upgrade.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/scripts/lib/devtool/upgrade.py b/scripts/lib/devtool/upgrade.py
index 62ec2f94cb..706f91c935 100644
--- a/scripts/lib/devtool/upgrade.py
+++ b/scripts/lib/devtool/upgrade.py
@@ -122,18 +122,22 @@ def _cleanup_on_error(rf, srctree):
122 rfp = os.path.split(rf)[0] # recipe folder 122 rfp = os.path.split(rf)[0] # recipe folder
123 rfpp = os.path.split(rfp)[0] # recipes folder 123 rfpp = os.path.split(rfp)[0] # recipes folder
124 if os.path.exists(rfp): 124 if os.path.exists(rfp):
125 shutil.rmtree(b) 125 shutil.rmtree(rfp)
126 if not len(os.listdir(rfpp)): 126 if not len(os.listdir(rfpp)):
127 os.rmdir(rfpp) 127 os.rmdir(rfpp)
128 srctree = os.path.abspath(srctree) 128 srctree = os.path.abspath(srctree)
129 if os.path.exists(srctree): 129 if os.path.exists(srctree):
130 shutil.rmtree(srctree) 130 shutil.rmtree(srctree)
131 131
132def _upgrade_error(e, rf, srctree): 132def _upgrade_error(e, rf, srctree, keep_failure=False, extramsg=None):
133 if rf: 133 if rf and not keep_failure:
134 cleanup_on_error(rf, srctree) 134 _cleanup_on_error(rf, srctree)
135 logger.error(e) 135 logger.error(e)
136 raise DevtoolError(e) 136 if extramsg:
137 logger.error(extramsg)
138 if keep_failure:
139 logger.info('Preserving failed upgrade files (--keep-failure)')
140 sys.exit(1)
137 141
138def _get_uri(rd): 142def _get_uri(rd):
139 srcuris = rd.getVar('SRC_URI').split() 143 srcuris = rd.getVar('SRC_URI').split()
@@ -299,7 +303,7 @@ def _add_license_diff_to_recipe(path, diff):
299 f.write("\n#\n\n".encode()) 303 f.write("\n#\n\n".encode())
300 f.write(orig_content) 304 f.write(orig_content)
301 305
302def _create_new_recipe(newpv, md5, sha256, srcrev, srcbranch, srcsubdir_old, srcsubdir_new, workspace, tinfoil, rd, license_diff, new_licenses): 306def _create_new_recipe(newpv, md5, sha256, srcrev, srcbranch, srcsubdir_old, srcsubdir_new, workspace, tinfoil, rd, license_diff, new_licenses, srctree, keep_failure):
303 """Creates the new recipe under workspace""" 307 """Creates the new recipe under workspace"""
304 308
305 bpn = rd.getVar('BPN') 309 bpn = rd.getVar('BPN')
@@ -416,7 +420,10 @@ def _create_new_recipe(newpv, md5, sha256, srcrev, srcbranch, srcsubdir_old, src
416 newvalues["LIC_FILES_CHKSUM"] = newlicchksum 420 newvalues["LIC_FILES_CHKSUM"] = newlicchksum
417 _add_license_diff_to_recipe(fullpath, license_diff) 421 _add_license_diff_to_recipe(fullpath, license_diff)
418 422
419 rd = tinfoil.parse_recipe_file(fullpath, False) 423 try:
424 rd = tinfoil.parse_recipe_file(fullpath, False)
425 except bb.tinfoil.TinfoilCommandFailed as e:
426 _upgrade_error(e, fullpath, srctree, keep_failure, 'Parsing of upgraded recipe failed')
420 oe.recipeutils.patch_recipe(rd, fullpath, newvalues) 427 oe.recipeutils.patch_recipe(rd, fullpath, newvalues)
421 428
422 return fullpath, copied 429 return fullpath, copied
@@ -548,11 +555,11 @@ def upgrade(args, config, basepath, workspace):
548 tinfoil, rd) 555 tinfoil, rd)
549 new_licenses = _extract_licenses(srctree, rd.getVar('LIC_FILES_CHKSUM')) 556 new_licenses = _extract_licenses(srctree, rd.getVar('LIC_FILES_CHKSUM'))
550 license_diff = _generate_license_diff(old_licenses, new_licenses) 557 license_diff = _generate_license_diff(old_licenses, new_licenses)
551 rf, copied = _create_new_recipe(args.version, md5, sha256, args.srcrev, srcbranch, srcsubdir1, srcsubdir2, config.workspace_path, tinfoil, rd, license_diff, new_licenses) 558 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)
552 except bb.process.CmdError as e: 559 except bb.process.CmdError as e:
553 _upgrade_error(e, rf, srctree) 560 _upgrade_error(e, rf, srctree, args.keep_failure)
554 except DevtoolError as e: 561 except DevtoolError as e:
555 _upgrade_error(e, rf, srctree) 562 _upgrade_error(e, rf, srctree, args.keep_failure)
556 standard._add_md5(config, pn, os.path.dirname(rf)) 563 standard._add_md5(config, pn, os.path.dirname(rf))
557 564
558 af = _write_append(rf, srctree, args.same_dir, args.no_same_dir, rev2, 565 af = _write_append(rf, srctree, args.same_dir, args.no_same_dir, rev2,
@@ -623,6 +630,7 @@ def register_commands(subparsers, context):
623 group.add_argument('--same-dir', '-s', help='Build in same directory as source', action="store_true") 630 group.add_argument('--same-dir', '-s', help='Build in same directory as source', action="store_true")
624 group.add_argument('--no-same-dir', help='Force build in a separate build directory', action="store_true") 631 group.add_argument('--no-same-dir', help='Force build in a separate build directory', action="store_true")
625 parser_upgrade.add_argument('--keep-temp', action="store_true", help='Keep temporary directory (for debugging)') 632 parser_upgrade.add_argument('--keep-temp', action="store_true", help='Keep temporary directory (for debugging)')
633 parser_upgrade.add_argument('--keep-failure', action="store_true", help='Keep failed upgrade recipe and associated files (for debugging)')
626 parser_upgrade.set_defaults(func=upgrade, fixed_setup=context.fixed_setup) 634 parser_upgrade.set_defaults(func=upgrade, fixed_setup=context.fixed_setup)
627 635
628 parser_latest_version = subparsers.add_parser('latest-version', help='Report the latest version of an existing recipe', 636 parser_latest_version = subparsers.add_parser('latest-version', help='Report the latest version of an existing recipe',