summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2015-09-08 11:39:12 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-09-09 14:27:52 +0100
commit3dd9fc39abdbccdbc313b577e7750974e3d6454e (patch)
treefb5458798559fa4c3def01120a1ae0c6b43c113e
parent0d0e50810a793f517b253e329339ba40d4bedd36 (diff)
downloadpoky-3dd9fc39abdbccdbc313b577e7750974e3d6454e.tar.gz
devtool: update-recipe: better 'auto' mode
Enhance the logic behind the 'auto' mode a bit by only updating the SRCREV if the changes are already found upstream. The logic is simple: update SRCREV only if the current local HEAD commit is found in the remote branch (i.e. 'origin/<branch_name>'). Otherwise resort to patching. This affects a couple of the oe-selftest tests so update those as well. [YOCTO #7907] (From OE-Core rev: 9b9733b7d74032aef4979bec553019421e77da14) Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com> Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oeqa/selftest/devtool.py32
-rw-r--r--scripts/lib/devtool/standard.py34
2 files changed, 53 insertions, 13 deletions
diff --git a/meta/lib/oeqa/selftest/devtool.py b/meta/lib/oeqa/selftest/devtool.py
index 255f2c3820..6e731d6777 100644
--- a/meta/lib/oeqa/selftest/devtool.py
+++ b/meta/lib/oeqa/selftest/devtool.py
@@ -547,8 +547,8 @@ class DevtoolTests(DevtoolBase):
547 result = runCmd('echo "A new file" > devtool-new-file', cwd=tempdir) 547 result = runCmd('echo "A new file" > devtool-new-file', cwd=tempdir)
548 result = runCmd('git add devtool-new-file', cwd=tempdir) 548 result = runCmd('git add devtool-new-file', cwd=tempdir)
549 result = runCmd('git commit -m "Add a new file"', cwd=tempdir) 549 result = runCmd('git commit -m "Add a new file"', cwd=tempdir)
550 self.add_command_to_tearDown('cd %s; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, os.path.basename(recipefile))) 550 self.add_command_to_tearDown('cd %s; rm -rf %s; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
551 result = runCmd('devtool update-recipe %s' % testrecipe) 551 result = runCmd('devtool update-recipe -m srcrev %s' % testrecipe)
552 result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) 552 result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile))
553 self.assertNotEqual(result.output.strip(), "", '%s recipe should be modified' % testrecipe) 553 self.assertNotEqual(result.output.strip(), "", '%s recipe should be modified' % testrecipe)
554 status = result.output.splitlines() 554 status = result.output.splitlines()
@@ -585,6 +585,26 @@ class DevtoolTests(DevtoolBase):
585 matched = True 585 matched = True
586 break 586 break
587 self.assertTrue(matched, 'Unexpected diff remove line: %s' % line) 587 self.assertTrue(matched, 'Unexpected diff remove line: %s' % line)
588 # Now try with auto mode
589 runCmd('cd %s; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, os.path.basename(recipefile)))
590 result = runCmd('devtool update-recipe %s' % testrecipe)
591 result = runCmd('git rev-parse --show-toplevel')
592 topleveldir = result.output.strip()
593 result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile))
594 status = result.output.splitlines()
595 relpatchpath = os.path.join(os.path.relpath(os.path.dirname(recipefile), topleveldir), testrecipe)
596 expectedstatus = [('M', os.path.relpath(recipefile, topleveldir)),
597 ('??', '%s/0001-Change-the-Makefile.patch' % relpatchpath),
598 ('??', '%s/0002-Add-a-new-file.patch' % relpatchpath)]
599 for line in status:
600 statusline = line.split(None, 1)
601 for fstatus, fn in expectedstatus:
602 if fn == statusline[1]:
603 if fstatus != statusline[0]:
604 self.fail('Unexpected status in line: %s' % line)
605 break
606 else:
607 self.fail('Unexpected modified file in line: %s' % line)
588 608
589 @testcase(1170) 609 @testcase(1170)
590 def test_devtool_update_recipe_append(self): 610 def test_devtool_update_recipe_append(self):
@@ -708,7 +728,7 @@ class DevtoolTests(DevtoolBase):
708 self.add_command_to_tearDown('bitbake-layers remove-layer %s || true' % templayerdir) 728 self.add_command_to_tearDown('bitbake-layers remove-layer %s || true' % templayerdir)
709 result = runCmd('bitbake-layers add-layer %s' % templayerdir, cwd=self.builddir) 729 result = runCmd('bitbake-layers add-layer %s' % templayerdir, cwd=self.builddir)
710 # Create the bbappend 730 # Create the bbappend
711 result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir)) 731 result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir))
712 self.assertNotIn('WARNING:', result.output) 732 self.assertNotIn('WARNING:', result.output)
713 # Check recipe is still clean 733 # Check recipe is still clean
714 result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) 734 result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile))
@@ -729,12 +749,12 @@ class DevtoolTests(DevtoolBase):
729 self.assertEqual(expectedlines, f.readlines()) 749 self.assertEqual(expectedlines, f.readlines())
730 750
731 # Check we can run it again and bbappend isn't modified 751 # Check we can run it again and bbappend isn't modified
732 result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir)) 752 result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir))
733 with open(bbappendfile, 'r') as f: 753 with open(bbappendfile, 'r') as f:
734 self.assertEqual(expectedlines, f.readlines()) 754 self.assertEqual(expectedlines, f.readlines())
735 # Drop new commit and check SRCREV changes 755 # Drop new commit and check SRCREV changes
736 result = runCmd('git reset HEAD^', cwd=tempsrcdir) 756 result = runCmd('git reset HEAD^', cwd=tempsrcdir)
737 result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir)) 757 result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir))
738 self.assertFalse(os.path.exists(os.path.join(appenddir, testrecipe)), 'Patch directory should not be created') 758 self.assertFalse(os.path.exists(os.path.join(appenddir, testrecipe)), 'Patch directory should not be created')
739 result = runCmd('git rev-parse HEAD', cwd=tempsrcdir) 759 result = runCmd('git rev-parse HEAD', cwd=tempsrcdir)
740 expectedlines = ['SRCREV = "%s"\n' % result.output, 760 expectedlines = ['SRCREV = "%s"\n' % result.output,
@@ -747,7 +767,7 @@ class DevtoolTests(DevtoolBase):
747 os.remove(bbappendfile) 767 os.remove(bbappendfile)
748 result = runCmd('git commit -a -m "Change the Makefile"', cwd=tempsrcdir) 768 result = runCmd('git commit -a -m "Change the Makefile"', cwd=tempsrcdir)
749 result = runCmd('bitbake-layers remove-layer %s' % templayerdir, cwd=self.builddir) 769 result = runCmd('bitbake-layers remove-layer %s' % templayerdir, cwd=self.builddir)
750 result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir)) 770 result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir))
751 self.assertIn('WARNING: Specified layer is not currently enabled in bblayers.conf', result.output) 771 self.assertIn('WARNING: Specified layer is not currently enabled in bblayers.conf', result.output)
752 self.assertFalse(os.path.exists(os.path.join(appenddir, testrecipe)), 'Patch directory should not be created') 772 self.assertFalse(os.path.exists(os.path.join(appenddir, testrecipe)), 'Patch directory should not be created')
753 result = runCmd('git rev-parse HEAD', cwd=tempsrcdir) 773 result = runCmd('git rev-parse HEAD', cwd=tempsrcdir)
diff --git a/scripts/lib/devtool/standard.py b/scripts/lib/devtool/standard.py
index cbc023247e..f76c632e78 100644
--- a/scripts/lib/devtool/standard.py
+++ b/scripts/lib/devtool/standard.py
@@ -757,6 +757,31 @@ def _update_recipe_patch(args, config, srctree, rd, config_data):
757 757
758 _remove_patch_files(args, removepatches, destpath) 758 _remove_patch_files(args, removepatches, destpath)
759 759
760def _guess_recipe_update_mode(srctree, rdata):
761 """Guess the recipe update mode to use"""
762 src_uri = (rdata.getVar('SRC_URI', False) or '').split()
763 git_uris = [uri for uri in src_uri if uri.startswith('git://')]
764 if not git_uris:
765 return 'patch'
766 # Just use the first URI for now
767 uri = git_uris[0]
768 # Check remote branch
769 upstr_branch = 'master'
770 for paramdef in uri.split(';')[1:]:
771 name, value = paramdef.split('=', 1)
772 if name == 'branch':
773 upstr_branch = value
774 # Check if current branch HEAD is found in upstream branch
775 stdout, _ = bb.process.run('git rev-parse HEAD', cwd=srctree)
776 head_rev = stdout.rstrip()
777 stdout, _ = bb.process.run('git branch -r --contains %s' % head_rev,
778 cwd=srctree)
779 remote_brs = [branch.strip() for branch in stdout.splitlines()]
780 if 'origin/' + upstr_branch in remote_brs:
781 return 'srcrev'
782
783 return 'patch'
784
760def update_recipe(args, config, basepath, workspace): 785def update_recipe(args, config, basepath, workspace):
761 """Entry point for the devtool 'update-recipe' subcommand""" 786 """Entry point for the devtool 'update-recipe' subcommand"""
762 if not args.recipename in workspace: 787 if not args.recipename in workspace:
@@ -777,17 +802,12 @@ def update_recipe(args, config, basepath, workspace):
777 if not rd: 802 if not rd:
778 return 1 803 return 1
779 804
780 orig_src_uri = rd.getVar('SRC_URI', False) or '' 805 srctree = workspace[args.recipename]['srctree']
781 if args.mode == 'auto': 806 if args.mode == 'auto':
782 if 'git://' in orig_src_uri: 807 mode = _guess_recipe_update_mode(srctree, rd)
783 mode = 'srcrev'
784 else:
785 mode = 'patch'
786 else: 808 else:
787 mode = args.mode 809 mode = args.mode
788 810
789 srctree = workspace[args.recipename]['srctree']
790
791 if mode == 'srcrev': 811 if mode == 'srcrev':
792 _update_recipe_srcrev(args, srctree, rd, tinfoil.config_data) 812 _update_recipe_srcrev(args, srctree, rd, tinfoil.config_data)
793 elif mode == 'patch': 813 elif mode == 'patch':