summaryrefslogtreecommitdiffstats
path: root/scripts/lib/devtool/upgrade.py
diff options
context:
space:
mode:
authorAlexander Kanavin <alexander.kanavin@linux.intel.com>2017-11-27 16:47:22 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-12-18 18:03:58 +0000
commit2de2a19a007516cb5685209658a5e89e022e00ae (patch)
treee285a54b8803f1ceeb4b09aafc1fa3e7e6e0096f /scripts/lib/devtool/upgrade.py
parentb52a9cf310aacca042760adc6cc581951886715f (diff)
downloadpoky-2de2a19a007516cb5685209658a5e89e022e00ae.tar.gz
devtool: add license checksum change handling to 'devtool upgrade'
Specifically, 'devtool upgrade' will now do these things: 1) determine if any of the license checksums need updating; if so, write the new checksums into the LIC_FILES_CHKSUM value in the recipe that is written to the workspace; 2) print a notice to the standard output: NOTE: New recipe is /home/ak/development/poky/build/workspace/recipes/puzzles/puzzles_git.bb NOTE: License checksums have been updated in the new recipe; please refer to it for the difference between the old and the new license texts. 3) and the cool part: devtool will create a diff of the old and new licenses, and write the diff into the workspace recipe as a comment, like this: ====== FIXME: the LIC_FILES_CHKSUM values have been updated by 'devtool upgrade'. The following is the difference between the old and the new license text. Please update the LICENSE value if needed, and summarize the changes in the commit message via 'License-checksum-change:' tag. (example: 'License-checksum-change: copyright years updated.') The changes: --- LICENCE +++ LICENCE @@ -1,8 +1,9 @@ This software is copyright (c) 2004-2014 Simon Tatham. Portions copyright Richard Boulton, James Harvey, Mike Pinna, Jonas -Klker, Dariusz Olszewski, Michael Schierl, Lambros Lambrou, Bernd -Schmidt, Steffen Bauer, Lennard Sprong and Rogier Goossens. +Kölker, Dariusz Olszewski, Michael Schierl, Lambros Lambrou, Bernd +Schmidt, Steffen Bauer, Lennard Sprong, Rogier Goossens and Michael +Quevillon. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files ====== (From OE-Core rev: ccb37f9e81eb78ed0eb2a238d7c3e196db9b2f72) Signed-off-by: Alexander Kanavin <alexander.kanavin@linux.intel.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.py75
1 files changed, 73 insertions, 2 deletions
diff --git a/scripts/lib/devtool/upgrade.py b/scripts/lib/devtool/upgrade.py
index 28fbdaee35..7de9ab5c2d 100644
--- a/scripts/lib/devtool/upgrade.py
+++ b/scripts/lib/devtool/upgrade.py
@@ -291,7 +291,26 @@ def _extract_new_source(newpv, srctree, no_patch, srcrev, srcbranch, branch, kee
291 291
292 return (rev, md5, sha256, srcbranch, srcsubdir_rel) 292 return (rev, md5, sha256, srcbranch, srcsubdir_rel)
293 293
294def _create_new_recipe(newpv, md5, sha256, srcrev, srcbranch, srcsubdir_old, srcsubdir_new, workspace, tinfoil, rd): 294def _add_license_diff_to_recipe(path, diff):
295 notice_text = """# FIXME: the LIC_FILES_CHKSUM values have been updated by 'devtool upgrade'.
296# The following is the difference between the old and the new license text.
297# Please update the LICENSE value if needed, and summarize the changes in
298# the commit message via 'License-checksum-change:' tag.
299# (example: 'License-checksum-change: copyright years updated.')
300#
301# The changes:
302#
303"""
304 commented_diff = "\n".join(["# {}".format(l) for l in diff.split('\n')])
305 with open(path, 'rb') as f:
306 orig_content = f.read()
307 with open(path, 'wb') as f:
308 f.write(notice_text.encode())
309 f.write(commented_diff.encode())
310 f.write("\n#\n\n".encode())
311 f.write(orig_content)
312
313def _create_new_recipe(newpv, md5, sha256, srcrev, srcbranch, srcsubdir_old, srcsubdir_new, workspace, tinfoil, rd, license_diff, new_licenses):
295 """Creates the new recipe under workspace""" 314 """Creates the new recipe under workspace"""
296 315
297 bpn = rd.getVar('BPN') 316 bpn = rd.getVar('BPN')
@@ -400,6 +419,11 @@ def _create_new_recipe(newpv, md5, sha256, srcrev, srcbranch, srcsubdir_old, src
400 else: 419 else:
401 logger.info('Source subdirectory has changed, updating S value') 420 logger.info('Source subdirectory has changed, updating S value')
402 421
422 if license_diff:
423 newlicchksum = " ".join(["file://{};md5={}".format(l["path"], l["actual_md5"]) + (";beginline={}".format(l["beginline"]) if l["beginline"] else "") + (";endline={}".format(l["endline"]) if l["endline"] else "") for l in new_licenses])
424 newvalues["LIC_FILES_CHKSUM"] = newlicchksum
425 _add_license_diff_to_recipe(fullpath, license_diff)
426
403 rd = tinfoil.parse_recipe_file(fullpath, False) 427 rd = tinfoil.parse_recipe_file(fullpath, False)
404 oe.recipeutils.patch_recipe(rd, fullpath, newvalues) 428 oe.recipeutils.patch_recipe(rd, fullpath, newvalues)
405 429
@@ -427,6 +451,47 @@ def _check_git_config():
427 if configerr: 451 if configerr:
428 raise DevtoolError('Your git configuration is incomplete which will prevent rebases from working:\n' + '\n'.join(configerr)) 452 raise DevtoolError('Your git configuration is incomplete which will prevent rebases from working:\n' + '\n'.join(configerr))
429 453
454def _extract_licenses(srcpath, recipe_licenses):
455 licenses = []
456 for url in recipe_licenses.split():
457 license = {}
458 (type, host, path, user, pswd, parm) = bb.fetch.decodeurl(url)
459 license['path'] = path
460 license['md5'] = parm.get('md5', '')
461 license['beginline'], license['endline'] = 0, 0
462 if 'beginline' in parm:
463 license['beginline'] = int(parm['beginline'])
464 if 'endline' in parm:
465 license['endline'] = int(parm['endline'])
466 license['text'] = []
467 with open(os.path.join(srcpath, path), 'rb') as f:
468 import hashlib
469 actual_md5 = hashlib.md5()
470 lineno = 0
471 for line in f:
472 lineno += 1
473 if (lineno >= license['beginline']) and ((lineno <= license['endline']) or not license['endline']):
474 license['text'].append(line.decode(errors='ignore'))
475 actual_md5.update(line)
476 license['actual_md5'] = actual_md5.hexdigest()
477 licenses.append(license)
478 return licenses
479
480def _generate_license_diff(old_licenses, new_licenses):
481 need_diff = False
482 for l in new_licenses:
483 if l['md5'] != l['actual_md5']:
484 need_diff = True
485 break
486 if need_diff == False:
487 return None
488
489 import difflib
490 diff = ''
491 for old, new in zip(old_licenses, new_licenses):
492 for line in difflib.unified_diff(old['text'], new['text'], old['path'], new['path']):
493 diff = diff + line
494 return diff
430 495
431def upgrade(args, config, basepath, workspace): 496def upgrade(args, config, basepath, workspace):
432 """Entry point for the devtool 'upgrade' subcommand""" 497 """Entry point for the devtool 'upgrade' subcommand"""
@@ -480,14 +545,18 @@ def upgrade(args, config, basepath, workspace):
480 check_prerelease_version(args.version, 'devtool upgrade') 545 check_prerelease_version(args.version, 'devtool upgrade')
481 546
482 rf = None 547 rf = None
548 license_diff = None
483 try: 549 try:
484 logger.info('Extracting current version source...') 550 logger.info('Extracting current version source...')
485 rev1, srcsubdir1 = standard._extract_source(srctree, False, 'devtool-orig', False, config, basepath, workspace, args.fixed_setup, rd, tinfoil, no_overrides=args.no_overrides) 551 rev1, srcsubdir1 = standard._extract_source(srctree, False, 'devtool-orig', False, config, basepath, workspace, args.fixed_setup, rd, tinfoil, no_overrides=args.no_overrides)
552 old_licenses = _extract_licenses(srctree, rd.getVar('LIC_FILES_CHKSUM'))
486 logger.info('Extracting upgraded version source...') 553 logger.info('Extracting upgraded version source...')
487 rev2, md5, sha256, srcbranch, srcsubdir2 = _extract_new_source(args.version, srctree, args.no_patch, 554 rev2, md5, sha256, srcbranch, srcsubdir2 = _extract_new_source(args.version, srctree, args.no_patch,
488 args.srcrev, args.srcbranch, args.branch, args.keep_temp, 555 args.srcrev, args.srcbranch, args.branch, args.keep_temp,
489 tinfoil, rd) 556 tinfoil, rd)
490 rf, copied = _create_new_recipe(args.version, md5, sha256, args.srcrev, srcbranch, srcsubdir1, srcsubdir2, config.workspace_path, tinfoil, rd) 557 new_licenses = _extract_licenses(srctree, rd.getVar('LIC_FILES_CHKSUM'))
558 license_diff = _generate_license_diff(old_licenses, new_licenses)
559 rf, copied = _create_new_recipe(args.version, md5, sha256, args.srcrev, srcbranch, srcsubdir1, srcsubdir2, config.workspace_path, tinfoil, rd, license_diff, new_licenses)
491 except bb.process.CmdError as e: 560 except bb.process.CmdError as e:
492 _upgrade_error(e, rf, srctree) 561 _upgrade_error(e, rf, srctree)
493 except DevtoolError as e: 562 except DevtoolError as e:
@@ -502,6 +571,8 @@ def upgrade(args, config, basepath, workspace):
502 571
503 logger.info('Upgraded source extracted to %s' % srctree) 572 logger.info('Upgraded source extracted to %s' % srctree)
504 logger.info('New recipe is %s' % rf) 573 logger.info('New recipe is %s' % rf)
574 if license_diff:
575 logger.info('License checksums have been updated in the new recipe; please refer to it for the difference between the old and the new license texts.')
505 finally: 576 finally:
506 tinfoil.shutdown() 577 tinfoil.shutdown()
507 return 0 578 return 0