diff options
| author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2015-05-22 16:41:27 +0300 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-06-18 09:14:05 +0100 |
| commit | 18efa996c6c3afe4e4d71688ee43a45c398b2282 (patch) | |
| tree | 44947c8d1546b4c56724415bd48db77447da4795 /scripts/lib | |
| parent | f5ea48cb126119ec09dee4c252db4f9b1cbbf3de (diff) | |
| download | poky-18efa996c6c3afe4e4d71688ee43a45c398b2282.tar.gz | |
devtool: split out 'srcrev' update mode into a separate function
Refactor update_recipe() (i.e. the implementation of the update-recipe
command) by splitting out the 'srcrev' into a distinct function.
(From OE-Core rev: 5da26bfd8b34af9075b9b900d353df555d8f2ef0)
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib')
| -rw-r--r-- | scripts/lib/devtool/standard.py | 188 |
1 files changed, 111 insertions, 77 deletions
diff --git a/scripts/lib/devtool/standard.py b/scripts/lib/devtool/standard.py index c92c9aed31..af73009ca2 100644 --- a/scripts/lib/devtool/standard.py +++ b/scripts/lib/devtool/standard.py | |||
| @@ -29,6 +29,12 @@ from devtool import exec_build_env_command, setup_tinfoil | |||
| 29 | 29 | ||
| 30 | logger = logging.getLogger('devtool') | 30 | logger = logging.getLogger('devtool') |
| 31 | 31 | ||
| 32 | |||
| 33 | class DevtoolError(Exception): | ||
| 34 | """Exception for handling devtool errors""" | ||
| 35 | pass | ||
| 36 | |||
| 37 | |||
| 32 | def plugin_init(pluginlist): | 38 | def plugin_init(pluginlist): |
| 33 | """Plugin initialization""" | 39 | """Plugin initialization""" |
| 34 | pass | 40 | pass |
| @@ -542,6 +548,103 @@ def _get_patchset_revs(args, srctree, recipe_path): | |||
| 542 | 548 | ||
| 543 | return initial_rev, update_rev | 549 | return initial_rev, update_rev |
| 544 | 550 | ||
| 551 | def _remove_patch_entries(srcuri, patchlist): | ||
| 552 | """Remove patch entries from SRC_URI""" | ||
| 553 | remaining = patchlist[:] | ||
| 554 | entries = [] | ||
| 555 | for patch in patchlist: | ||
| 556 | patchfile = os.path.basename(patch) | ||
| 557 | for i in xrange(len(srcuri)): | ||
| 558 | if srcuri[i].startswith('file://') and os.path.basename(srcuri[i].split(';')[0]) == patchfile: | ||
| 559 | entries.append(srcuri[i]) | ||
| 560 | remaining.remove(patch) | ||
| 561 | srcuri.pop(i) | ||
| 562 | break | ||
| 563 | return entries, remaining | ||
| 564 | |||
| 565 | def _remove_patch_files(args, patches, destpath): | ||
| 566 | """Unlink existing patch files""" | ||
| 567 | for patchfile in patches: | ||
| 568 | if args.append: | ||
| 569 | if not destpath: | ||
| 570 | raise Exception('destpath should be set here') | ||
| 571 | patchfile = os.path.join(destpath, os.path.basename(patchfile)) | ||
| 572 | |||
| 573 | if os.path.exists(patchfile): | ||
| 574 | logger.info('Removing patch %s' % patchfile) | ||
| 575 | # FIXME "git rm" here would be nice if the file in question is | ||
| 576 | # tracked | ||
| 577 | # FIXME there's a chance that this file is referred to by | ||
| 578 | # another recipe, in which case deleting wouldn't be the | ||
| 579 | # right thing to do | ||
| 580 | os.remove(patchfile) | ||
| 581 | # Remove directory if empty | ||
| 582 | try: | ||
| 583 | os.rmdir(os.path.dirname(patchfile)) | ||
| 584 | except OSError as ose: | ||
| 585 | if ose.errno != errno.ENOTEMPTY: | ||
| 586 | raise | ||
| 587 | |||
| 588 | def _update_recipe_srcrev(args, srctree, rd, config_data): | ||
| 589 | """Implement the 'srcrev' mode of update-recipe""" | ||
| 590 | import bb | ||
| 591 | import oe.recipeutils | ||
| 592 | from oe.patch import GitApplyTree | ||
| 593 | |||
| 594 | recipefile = rd.getVar('FILE', True) | ||
| 595 | logger.info('Updating SRCREV in recipe %s' % os.path.basename(recipefile)) | ||
| 596 | |||
| 597 | # Get HEAD revision | ||
| 598 | try: | ||
| 599 | stdout, _ = bb.process.run('git rev-parse HEAD', cwd=srctree) | ||
| 600 | except bb.process.ExecutionError as err: | ||
| 601 | raise DevtoolError('Failed to get HEAD revision in %s: %s' % | ||
| 602 | (srctree, err)) | ||
| 603 | srcrev = stdout.strip() | ||
| 604 | if len(srcrev) != 40: | ||
| 605 | raise DevtoolError('Invalid hash returned by git: %s' % stdout) | ||
| 606 | |||
| 607 | destpath = None | ||
| 608 | removepatches = [] | ||
| 609 | patchfields = {} | ||
| 610 | patchfields['SRCREV'] = srcrev | ||
| 611 | orig_src_uri = rd.getVar('SRC_URI', False) or '' | ||
| 612 | if not args.no_remove: | ||
| 613 | # Find list of existing patches in recipe file | ||
| 614 | existing_patches = oe.recipeutils.get_recipe_patches(rd) | ||
| 615 | |||
| 616 | old_srcrev = (rd.getVar('SRCREV', False) or '') | ||
| 617 | tempdir = tempfile.mkdtemp(prefix='devtool') | ||
| 618 | try: | ||
| 619 | GitApplyTree.extractPatches(srctree, old_srcrev, tempdir) | ||
| 620 | newpatches = os.listdir(tempdir) | ||
| 621 | for patch in existing_patches: | ||
| 622 | patchfile = os.path.basename(patch) | ||
| 623 | if patchfile in newpatches: | ||
| 624 | removepatches.append(patch) | ||
| 625 | finally: | ||
| 626 | shutil.rmtree(tempdir) | ||
| 627 | |||
| 628 | if removepatches: | ||
| 629 | srcuri = orig_src_uri.split() | ||
| 630 | removedentries, _ = _remove_patch_entries(srcuri, removepatches) | ||
| 631 | if removedentries: | ||
| 632 | patchfields['SRC_URI'] = ' '.join(srcuri) | ||
| 633 | |||
| 634 | if args.append: | ||
| 635 | _, destpath = oe.recipeutils.bbappend_recipe( | ||
| 636 | rd, args.append, None, wildcardver=args.wildcard_version, | ||
| 637 | extralines=patchfields) | ||
| 638 | else: | ||
| 639 | oe.recipeutils.patch_recipe(config_data, recipefile, patchfields) | ||
| 640 | |||
| 641 | if not 'git://' in orig_src_uri: | ||
| 642 | logger.info('You will need to update SRC_URI within the recipe to ' | ||
| 643 | 'point to a git repository where you have pushed your ' | ||
| 644 | 'changes') | ||
| 645 | |||
| 646 | _remove_patch_files(args, removepatches, destpath) | ||
| 647 | |||
| 545 | def update_recipe(args, config, basepath, workspace): | 648 | def update_recipe(args, config, basepath, workspace): |
| 546 | """Entry point for the devtool 'update-recipe' subcommand""" | 649 | """Entry point for the devtool 'update-recipe' subcommand""" |
| 547 | if not args.recipename in workspace: | 650 | if not args.recipename in workspace: |
| @@ -581,69 +684,16 @@ def update_recipe(args, config, basepath, workspace): | |||
| 581 | else: | 684 | else: |
| 582 | mode = args.mode | 685 | mode = args.mode |
| 583 | 686 | ||
| 584 | def remove_patch_entries(srcuri, patchlist): | ||
| 585 | """Remove patch entries from SRC_URI""" | ||
| 586 | remaining = patchlist[:] | ||
| 587 | entries = [] | ||
| 588 | for patch in patchlist: | ||
| 589 | patchfile = os.path.basename(patch) | ||
| 590 | for i in xrange(len(srcuri)): | ||
| 591 | if srcuri[i].startswith('file://') and os.path.basename(srcuri[i].split(';')[0]) == patchfile: | ||
| 592 | entries.append(srcuri[i]) | ||
| 593 | remaining.remove(patch) | ||
| 594 | srcuri.pop(i) | ||
| 595 | break | ||
| 596 | return entries, remaining | ||
| 597 | |||
| 598 | srctree = workspace[args.recipename] | 687 | srctree = workspace[args.recipename] |
| 599 | 688 | ||
| 600 | # Get HEAD revision | ||
| 601 | try: | ||
| 602 | (stdout, _) = bb.process.run('git rev-parse HEAD', cwd=srctree) | ||
| 603 | except bb.process.ExecutionError as err: | ||
| 604 | print('Failed to get HEAD revision in %s: %s' % (srctree, err)) | ||
| 605 | return 1 | ||
| 606 | srcrev = stdout.strip() | ||
| 607 | if len(srcrev) != 40: | ||
| 608 | logger.error('Invalid hash returned by git: %s' % stdout) | ||
| 609 | return 1 | ||
| 610 | |||
| 611 | removepatches = [] | 689 | removepatches = [] |
| 612 | destpath = None | 690 | destpath = None |
| 613 | if mode == 'srcrev': | 691 | if mode == 'srcrev': |
| 614 | logger.info('Updating SRCREV in recipe %s' % os.path.basename(recipefile)) | 692 | try: |
| 615 | removevalues = None | 693 | _update_recipe_srcrev(args, srctree, rd, tinfoil.config_data) |
| 616 | patchfields = {} | 694 | except DevtoolError as err: |
| 617 | patchfields['SRCREV'] = srcrev | 695 | logger.error(err) |
| 618 | if not args.no_remove: | 696 | return 1 |
| 619 | # Find list of existing patches in recipe file | ||
| 620 | existing_patches = oe.recipeutils.get_recipe_patches(rd) | ||
| 621 | |||
| 622 | old_srcrev = (rd.getVar('SRCREV', False) or '') | ||
| 623 | tempdir = tempfile.mkdtemp(prefix='devtool') | ||
| 624 | try: | ||
| 625 | GitApplyTree.extractPatches(srctree, old_srcrev, tempdir) | ||
| 626 | newpatches = os.listdir(tempdir) | ||
| 627 | for patch in existing_patches: | ||
| 628 | patchfile = os.path.basename(patch) | ||
| 629 | if patchfile in newpatches: | ||
| 630 | removepatches.append(patch) | ||
| 631 | finally: | ||
| 632 | shutil.rmtree(tempdir) | ||
| 633 | if removepatches: | ||
| 634 | srcuri = (rd.getVar('SRC_URI', False) or '').split() | ||
| 635 | removedentries, _ = remove_patch_entries(srcuri, removepatches) | ||
| 636 | if removedentries: | ||
| 637 | patchfields['SRC_URI'] = ' '.join(srcuri) | ||
| 638 | |||
| 639 | if args.append: | ||
| 640 | (appendfile, destpath) = oe.recipeutils.bbappend_recipe(rd, args.append, None, wildcardver=args.wildcard_version, extralines=patchfields) | ||
| 641 | else: | ||
| 642 | oe.recipeutils.patch_recipe(tinfoil.config_data, recipefile, patchfields) | ||
| 643 | |||
| 644 | if not 'git://' in orig_src_uri: | ||
| 645 | logger.info('You will need to update SRC_URI within the recipe to point to a git repository where you have pushed your changes') | ||
| 646 | |||
| 647 | elif mode == 'patch': | 697 | elif mode == 'patch': |
| 648 | initial_rev, update_rev = _get_patchset_revs(args, srctree, append) | 698 | initial_rev, update_rev = _get_patchset_revs(args, srctree, append) |
| 649 | if not initial_rev: | 699 | if not initial_rev: |
| @@ -698,7 +748,7 @@ def update_recipe(args, config, basepath, workspace): | |||
| 698 | removevalues = None | 748 | removevalues = None |
| 699 | if removepatches: | 749 | if removepatches: |
| 700 | srcuri = (rd.getVar('SRC_URI', False) or '').split() | 750 | srcuri = (rd.getVar('SRC_URI', False) or '').split() |
| 701 | removedentries, remaining = remove_patch_entries(srcuri, removepatches) | 751 | removedentries, remaining = _remove_patch_entries(srcuri, removepatches) |
| 702 | if removedentries or remaining: | 752 | if removedentries or remaining: |
| 703 | removevalues = {'SRC_URI': removedentries + ['file://' + os.path.basename(item) for item in remaining]} | 753 | removevalues = {'SRC_URI': removedentries + ['file://' + os.path.basename(item) for item in remaining]} |
| 704 | (appendfile, destpath) = oe.recipeutils.bbappend_recipe(rd, args.append, patchfiles, removevalues=removevalues) | 754 | (appendfile, destpath) = oe.recipeutils.bbappend_recipe(rd, args.append, patchfiles, removevalues=removevalues) |
| @@ -737,28 +787,12 @@ def update_recipe(args, config, basepath, workspace): | |||
| 737 | finally: | 787 | finally: |
| 738 | shutil.rmtree(tempdir) | 788 | shutil.rmtree(tempdir) |
| 739 | 789 | ||
| 790 | _remove_patch_files(args, removepatches, destpath) | ||
| 791 | |||
| 740 | else: | 792 | else: |
| 741 | logger.error('update_recipe: invalid mode %s' % mode) | 793 | logger.error('update_recipe: invalid mode %s' % mode) |
| 742 | return 1 | 794 | return 1 |
| 743 | 795 | ||
| 744 | if removepatches: | ||
| 745 | for patchfile in removepatches: | ||
| 746 | if args.append: | ||
| 747 | if not destpath: | ||
| 748 | raise Exception('destpath should be set here') | ||
| 749 | patchfile = os.path.join(destpath, os.path.basename(patchfile)) | ||
| 750 | |||
| 751 | if os.path.exists(patchfile): | ||
| 752 | logger.info('Removing patch %s' % patchfile) | ||
| 753 | # FIXME "git rm" here would be nice if the file in question is tracked | ||
| 754 | # FIXME there's a chance that this file is referred to by another recipe, in which case deleting wouldn't be the right thing to do | ||
| 755 | os.remove(patchfile) | ||
| 756 | # Remove directory if empty | ||
| 757 | try: | ||
| 758 | os.rmdir(os.path.dirname(patchfile)) | ||
| 759 | except OSError as ose: | ||
| 760 | if ose.errno != errno.ENOTEMPTY: | ||
| 761 | raise | ||
| 762 | return 0 | 796 | return 0 |
| 763 | 797 | ||
| 764 | 798 | ||
