diff options
| author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2015-05-25 15:12:43 +0300 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-06-18 09:14:05 +0100 |
| commit | 60278094cc2c917b2ae1ee45b932ec6ba35d246b (patch) | |
| tree | a85c4a14cece754162796a16512ac4732fd12ab0 /scripts/lib/devtool | |
| parent | 18efa996c6c3afe4e4d71688ee43a45c398b2282 (diff) | |
| download | poky-60278094cc2c917b2ae1ee45b932ec6ba35d246b.tar.gz | |
devtool: split out 'patch' update mode into a separate function
Continue refactoring of update_recipe() by splitting out the 'patch'
mode into a separate function.
(From OE-Core rev: cdcfedec5489a5d8d0df56bbe100e5fc2cca03af)
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/devtool')
| -rw-r--r-- | scripts/lib/devtool/standard.py | 236 |
1 files changed, 122 insertions, 114 deletions
diff --git a/scripts/lib/devtool/standard.py b/scripts/lib/devtool/standard.py index af73009ca2..fb3cc78de0 100644 --- a/scripts/lib/devtool/standard.py +++ b/scripts/lib/devtool/standard.py | |||
| @@ -645,6 +645,119 @@ def _update_recipe_srcrev(args, srctree, rd, config_data): | |||
| 645 | 645 | ||
| 646 | _remove_patch_files(args, removepatches, destpath) | 646 | _remove_patch_files(args, removepatches, destpath) |
| 647 | 647 | ||
| 648 | def _update_recipe_patch(args, config, srctree, rd, config_data): | ||
| 649 | """Implement the 'patch' mode of update-recipe""" | ||
| 650 | import bb | ||
| 651 | import oe.recipeutils | ||
| 652 | from oe.patch import GitApplyTree | ||
| 653 | |||
| 654 | recipefile = rd.getVar('FILE', True) | ||
| 655 | append = os.path.join(config.workspace_path, 'appends', '%s.bbappend' % | ||
| 656 | os.path.splitext(os.path.basename(recipefile))[0]) | ||
| 657 | if not os.path.exists(append): | ||
| 658 | raise DevtoolError('unable to find workspace bbappend for recipe %s' % | ||
| 659 | args.recipename) | ||
| 660 | |||
| 661 | initial_rev, update_rev = _get_patchset_revs(args, srctree, append) | ||
| 662 | if not initial_rev: | ||
| 663 | raise DevtoolError('Unable to find initial revision - please specify ' | ||
| 664 | 'it with --initial-rev') | ||
| 665 | |||
| 666 | # Find list of existing patches in recipe file | ||
| 667 | existing_patches = oe.recipeutils.get_recipe_patches(rd) | ||
| 668 | |||
| 669 | removepatches = [] | ||
| 670 | seqpatch_re = re.compile('^([0-9]{4}-)?(.+)') | ||
| 671 | if not args.no_remove: | ||
| 672 | # Get all patches from source tree and check if any should be removed | ||
| 673 | tempdir = tempfile.mkdtemp(prefix='devtool') | ||
| 674 | try: | ||
| 675 | GitApplyTree.extractPatches(srctree, initial_rev, tempdir) | ||
| 676 | # Strip numbering from patch names. If it's a git sequence named | ||
| 677 | # patch, the numbers might not match up since we are starting from | ||
| 678 | # a different revision This does assume that people are using | ||
| 679 | # unique shortlog values, but they ought to be anyway... | ||
| 680 | newpatches = [seqpatch_re.match(fname).group(2) for fname in | ||
| 681 | os.listdir(tempdir)] | ||
| 682 | for patch in existing_patches: | ||
| 683 | basename = seqpatch_re.match( | ||
| 684 | os.path.basename(patch)).group(2) | ||
| 685 | if basename not in newpatches: | ||
| 686 | removepatches.append(patch) | ||
| 687 | finally: | ||
| 688 | shutil.rmtree(tempdir) | ||
| 689 | |||
| 690 | # Get updated patches from source tree | ||
| 691 | tempdir = tempfile.mkdtemp(prefix='devtool') | ||
| 692 | try: | ||
| 693 | GitApplyTree.extractPatches(srctree, update_rev, tempdir) | ||
| 694 | |||
| 695 | # Match up and replace existing patches with corresponding new patches | ||
| 696 | updatepatches = False | ||
| 697 | updaterecipe = False | ||
| 698 | destpath = None | ||
| 699 | newpatches = os.listdir(tempdir) | ||
| 700 | if args.append: | ||
| 701 | patchfiles = {} | ||
| 702 | for patch in existing_patches: | ||
| 703 | patchfile = os.path.basename(patch) | ||
| 704 | if patchfile in newpatches: | ||
| 705 | patchfiles[os.path.join(tempdir, patchfile)] = patchfile | ||
| 706 | newpatches.remove(patchfile) | ||
| 707 | for patchfile in newpatches: | ||
| 708 | patchfiles[os.path.join(tempdir, patchfile)] = None | ||
| 709 | |||
| 710 | if patchfiles or removepatches: | ||
| 711 | removevalues = None | ||
| 712 | if removepatches: | ||
| 713 | srcuri = (rd.getVar('SRC_URI', False) or '').split() | ||
| 714 | removedentries, remaining = _remove_patch_entries( | ||
| 715 | srcuri, removepatches) | ||
| 716 | if removedentries or remaining: | ||
| 717 | remaining = ['file://' + os.path.basename(item) for | ||
| 718 | item in remaining] | ||
| 719 | removevalues = {'SRC_URI': removedentries + remaining} | ||
| 720 | _, destpath = oe.recipeutils.bbappend_recipe( | ||
| 721 | rd, args.append, patchfiles, | ||
| 722 | removevalues=removevalues) | ||
| 723 | else: | ||
| 724 | logger.info('No patches needed updating') | ||
| 725 | else: | ||
| 726 | for patch in existing_patches: | ||
| 727 | patchfile = os.path.basename(patch) | ||
| 728 | if patchfile in newpatches: | ||
| 729 | logger.info('Updating patch %s' % patchfile) | ||
| 730 | shutil.move(os.path.join(tempdir, patchfile), patch) | ||
| 731 | newpatches.remove(patchfile) | ||
| 732 | updatepatches = True | ||
| 733 | srcuri = (rd.getVar('SRC_URI', False) or '').split() | ||
| 734 | if newpatches: | ||
| 735 | # Add any patches left over | ||
| 736 | patchdir = os.path.join(os.path.dirname(recipefile), | ||
| 737 | rd.getVar('BPN', True)) | ||
| 738 | bb.utils.mkdirhier(patchdir) | ||
| 739 | for patchfile in newpatches: | ||
| 740 | logger.info('Adding new patch %s' % patchfile) | ||
| 741 | shutil.move(os.path.join(tempdir, patchfile), | ||
| 742 | os.path.join(patchdir, patchfile)) | ||
| 743 | srcuri.append('file://%s' % patchfile) | ||
| 744 | updaterecipe = True | ||
| 745 | if removepatches: | ||
| 746 | removedentries, _ = _remove_patch_entries(srcuri, removepatches) | ||
| 747 | if removedentries: | ||
| 748 | updaterecipe = True | ||
| 749 | if updaterecipe: | ||
| 750 | logger.info('Updating recipe %s' % os.path.basename(recipefile)) | ||
| 751 | oe.recipeutils.patch_recipe(config_data, recipefile, | ||
| 752 | {'SRC_URI': ' '.join(srcuri)}) | ||
| 753 | elif not updatepatches: | ||
| 754 | # Neither patches nor recipe were updated | ||
| 755 | logger.info('No patches need updating') | ||
| 756 | finally: | ||
| 757 | shutil.rmtree(tempdir) | ||
| 758 | |||
| 759 | _remove_patch_files(args, removepatches, destpath) | ||
| 760 | |||
| 648 | def update_recipe(args, config, basepath, workspace): | 761 | def update_recipe(args, config, basepath, workspace): |
| 649 | """Entry point for the devtool 'update-recipe' subcommand""" | 762 | """Entry point for the devtool 'update-recipe' subcommand""" |
| 650 | if not args.recipename in workspace: | 763 | if not args.recipename in workspace: |
| @@ -660,20 +773,10 @@ def update_recipe(args, config, basepath, workspace): | |||
| 660 | return 2 | 773 | return 2 |
| 661 | 774 | ||
| 662 | tinfoil = setup_tinfoil() | 775 | tinfoil = setup_tinfoil() |
| 663 | import bb | ||
| 664 | from oe.patch import GitApplyTree | ||
| 665 | import oe.recipeutils | ||
| 666 | 776 | ||
| 667 | rd = _parse_recipe(config, tinfoil, args.recipename, True) | 777 | rd = _parse_recipe(config, tinfoil, args.recipename, True) |
| 668 | if not rd: | 778 | if not rd: |
| 669 | return -1 | 779 | return -1 |
| 670 | recipefile = rd.getVar('FILE', True) | ||
| 671 | |||
| 672 | # Get initial revision from bbappend | ||
| 673 | append = os.path.join(config.workspace_path, 'appends', '%s.bbappend' % os.path.splitext(os.path.basename(recipefile))[0]) | ||
| 674 | if not os.path.exists(append): | ||
| 675 | logger.error('unable to find workspace bbappend for recipe %s' % args.recipename) | ||
| 676 | return -1 | ||
| 677 | 780 | ||
| 678 | orig_src_uri = rd.getVar('SRC_URI', False) or '' | 781 | orig_src_uri = rd.getVar('SRC_URI', False) or '' |
| 679 | if args.mode == 'auto': | 782 | if args.mode == 'auto': |
| @@ -686,111 +789,16 @@ def update_recipe(args, config, basepath, workspace): | |||
| 686 | 789 | ||
| 687 | srctree = workspace[args.recipename] | 790 | srctree = workspace[args.recipename] |
| 688 | 791 | ||
| 689 | removepatches = [] | 792 | try: |
| 690 | destpath = None | 793 | if mode == 'srcrev': |
| 691 | if mode == 'srcrev': | ||
| 692 | try: | ||
| 693 | _update_recipe_srcrev(args, srctree, rd, tinfoil.config_data) | 794 | _update_recipe_srcrev(args, srctree, rd, tinfoil.config_data) |
| 694 | except DevtoolError as err: | 795 | elif mode == 'patch': |
| 695 | logger.error(err) | 796 | _update_recipe_patch(args, config, srctree, rd, |
| 696 | return 1 | 797 | tinfoil.config_data) |
| 697 | elif mode == 'patch': | 798 | else: |
| 698 | initial_rev, update_rev = _get_patchset_revs(args, srctree, append) | 799 | raise DevtoolError('update_recipe: invalid mode %s' % mode) |
| 699 | if not initial_rev: | 800 | except DevtoolError as err: |
| 700 | logger.error('Unable to find initial revision - please specify it with --initial-rev') | 801 | logger.error(err) |
| 701 | return -1 | ||
| 702 | |||
| 703 | # Find list of existing patches in recipe file | ||
| 704 | existing_patches = oe.recipeutils.get_recipe_patches(rd) | ||
| 705 | |||
| 706 | removepatches = [] | ||
| 707 | seqpatch_re = re.compile('^([0-9]{4}-)?(.+)') | ||
| 708 | if not args.no_remove: | ||
| 709 | # Get all patches from source tree and check if any should be removed | ||
| 710 | tempdir = tempfile.mkdtemp(prefix='devtool') | ||
| 711 | try: | ||
| 712 | GitApplyTree.extractPatches(srctree, initial_rev, tempdir) | ||
| 713 | # Strip numbering from patch names. If it's a git sequence | ||
| 714 | # named patch, the numbers might not match up since we are | ||
| 715 | # starting from a different revision This does assume that | ||
| 716 | # people are using unique shortlog values, but they ought to be | ||
| 717 | # anyway... | ||
| 718 | newpatches = [seqpatch_re.match(fname).group(2) for fname in | ||
| 719 | os.listdir(tempdir)] | ||
| 720 | for patch in existing_patches: | ||
| 721 | basename = seqpatch_re.match( | ||
| 722 | os.path.basename(patch)).group(2) | ||
| 723 | if basename not in newpatches: | ||
| 724 | removepatches.append(patch) | ||
| 725 | finally: | ||
| 726 | shutil.rmtree(tempdir) | ||
| 727 | |||
| 728 | # Get updated patches from source tree | ||
| 729 | tempdir = tempfile.mkdtemp(prefix='devtool') | ||
| 730 | try: | ||
| 731 | GitApplyTree.extractPatches(srctree, update_rev, tempdir) | ||
| 732 | |||
| 733 | # Match up and replace existing patches with corresponding new patches | ||
| 734 | updatepatches = False | ||
| 735 | updaterecipe = False | ||
| 736 | newpatches = os.listdir(tempdir) | ||
| 737 | if args.append: | ||
| 738 | patchfiles = {} | ||
| 739 | for patch in existing_patches: | ||
| 740 | patchfile = os.path.basename(patch) | ||
| 741 | if patchfile in newpatches: | ||
| 742 | patchfiles[os.path.join(tempdir, patchfile)] = patchfile | ||
| 743 | newpatches.remove(patchfile) | ||
| 744 | for patchfile in newpatches: | ||
| 745 | patchfiles[os.path.join(tempdir, patchfile)] = None | ||
| 746 | |||
| 747 | if patchfiles or removepatches: | ||
| 748 | removevalues = None | ||
| 749 | if removepatches: | ||
| 750 | srcuri = (rd.getVar('SRC_URI', False) or '').split() | ||
| 751 | removedentries, remaining = _remove_patch_entries(srcuri, removepatches) | ||
| 752 | if removedentries or remaining: | ||
| 753 | removevalues = {'SRC_URI': removedentries + ['file://' + os.path.basename(item) for item in remaining]} | ||
| 754 | (appendfile, destpath) = oe.recipeutils.bbappend_recipe(rd, args.append, patchfiles, removevalues=removevalues) | ||
| 755 | else: | ||
| 756 | logger.info('No patches needed updating') | ||
| 757 | else: | ||
| 758 | for patch in existing_patches: | ||
| 759 | patchfile = os.path.basename(patch) | ||
| 760 | if patchfile in newpatches: | ||
| 761 | logger.info('Updating patch %s' % patchfile) | ||
| 762 | shutil.move(os.path.join(tempdir, patchfile), patch) | ||
| 763 | newpatches.remove(patchfile) | ||
| 764 | updatepatches = True | ||
| 765 | srcuri = (rd.getVar('SRC_URI', False) or '').split() | ||
| 766 | if newpatches: | ||
| 767 | # Add any patches left over | ||
| 768 | patchdir = os.path.join(os.path.dirname(recipefile), rd.getVar('BPN', True)) | ||
| 769 | bb.utils.mkdirhier(patchdir) | ||
| 770 | for patchfile in newpatches: | ||
| 771 | logger.info('Adding new patch %s' % patchfile) | ||
| 772 | shutil.move(os.path.join(tempdir, patchfile), os.path.join(patchdir, patchfile)) | ||
| 773 | srcuri.append('file://%s' % patchfile) | ||
| 774 | updaterecipe = True | ||
| 775 | if removepatches: | ||
| 776 | removedentries, _ = remove_patch_entries(srcuri, removepatches) | ||
| 777 | if removedentries: | ||
| 778 | updaterecipe = True | ||
| 779 | if updaterecipe: | ||
| 780 | logger.info('Updating recipe %s' % os.path.basename(recipefile)) | ||
| 781 | oe.recipeutils.patch_recipe(tinfoil.config_data, | ||
| 782 | recipefile, {'SRC_URI': ' '.join(srcuri)}) | ||
| 783 | elif not updatepatches: | ||
| 784 | # Neither patches nor recipe were updated | ||
| 785 | logger.info('No patches need updating') | ||
| 786 | |||
| 787 | finally: | ||
| 788 | shutil.rmtree(tempdir) | ||
| 789 | |||
| 790 | _remove_patch_files(args, removepatches, destpath) | ||
| 791 | |||
| 792 | else: | ||
| 793 | logger.error('update_recipe: invalid mode %s' % mode) | ||
| 794 | return 1 | 802 | return 1 |
| 795 | 803 | ||
| 796 | return 0 | 804 | return 0 |
