summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-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