oe-selftest: devtool: test modify git recipe building from a subdir

Add a test that verifies that devtool modify + devtool finish do the
right thing on a recipe that fetches from git and sets S to point to
a subdirectory of the source tree. We have a few examples among the core
recipes, dos2unix is a convenient one so let's use that. (The test first
verifies that that is still true in case the recipe is changed in
future.)

(From OE-Core rev: a994dbe517246cbc0bf359cd990efd6437e07a56)

Signed-off-by: Paul Eggleton <paul.eggleton@microsoft.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit a84d9ed14173b0bf467ea78dff4f0f7bae0bc082)
Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Paul Eggleton
2022-07-12 18:41:25 -07:00
committed by Richard Purdie
parent ee60960da3
commit eabdc02b76

View File

@@ -218,6 +218,34 @@ class DevtoolTestCase(OESelftestTestCase):
filelist.append(' '.join(splitline))
return filelist
def _check_diff(self, diffoutput, addlines, removelines):
"""Check output from 'git diff' matches expectation"""
remaining_addlines = addlines[:]
remaining_removelines = removelines[:]
for line in diffoutput.splitlines():
if line.startswith('+++') or line.startswith('---'):
continue
elif line.startswith('+'):
matched = False
for item in addlines:
if re.match(item, line[1:].strip()):
matched = True
remaining_addlines.remove(item)
break
self.assertTrue(matched, 'Unexpected diff add line: %s' % line)
elif line.startswith('-'):
matched = False
for item in removelines:
if re.match(item, line[1:].strip()):
matched = True
remaining_removelines.remove(item)
break
self.assertTrue(matched, 'Unexpected diff remove line: %s' % line)
if remaining_addlines:
self.fail('Expected added lines not found: %s' % remaining_addlines)
if remaining_removelines:
self.fail('Expected removed lines not found: %s' % remaining_removelines)
class DevtoolBase(DevtoolTestCase):
@@ -718,6 +746,7 @@ class DevtoolModifyTests(DevtoolBase):
self.assertTrue(bbclassextended, 'None of these recipes are BBCLASSEXTENDed to native - need to adjust testrecipes list: %s' % ', '.join(testrecipes))
self.assertTrue(inheritnative, 'None of these recipes do "inherit native" - need to adjust testrecipes list: %s' % ', '.join(testrecipes))
def test_devtool_modify_localfiles_only(self):
# Check preconditions
testrecipe = 'base-files'
@@ -930,23 +959,7 @@ class DevtoolUpdateTests(DevtoolBase):
srcurilines[0] = 'SRC_URI = "' + srcurilines[0]
srcurilines.append('"')
removelines = ['SRCREV = ".*"'] + srcurilines
for line in result.output.splitlines():
if line.startswith('+++') or line.startswith('---'):
continue
elif line.startswith('+'):
matched = False
for item in addlines:
if re.match(item, line[1:].strip()):
matched = True
break
self.assertTrue(matched, 'Unexpected diff add line: %s' % line)
elif line.startswith('-'):
matched = False
for item in removelines:
if re.match(item, line[1:].strip()):
matched = True
break
self.assertTrue(matched, 'Unexpected diff remove line: %s' % line)
self._check_diff(result.output, addlines, removelines)
# Now try with auto mode
runCmd('cd %s; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, os.path.basename(recipefile)))
result = runCmd('devtool update-recipe %s' % testrecipe)
@@ -1316,6 +1329,73 @@ class DevtoolUpdateTests(DevtoolBase):
expected_status = []
self._check_repo_status(os.path.dirname(recipefile), expected_status)
def test_devtool_finish_modify_git_subdir(self):
# Check preconditions
testrecipe = 'dos2unix'
bb_vars = get_bb_vars(['SRC_URI', 'S', 'WORKDIR', 'FILE'], testrecipe)
self.assertIn('git://', bb_vars['SRC_URI'], 'This test expects the %s recipe to be a git recipe' % testrecipe)
workdir_git = '%s/git/' % bb_vars['WORKDIR']
if not bb_vars['S'].startswith(workdir_git):
self.fail('This test expects the %s recipe to be building from a subdirectory of the git repo' % testrecipe)
subdir = bb_vars['S'].split(workdir_git, 1)[1]
# Clean up anything in the workdir/sysroot/sstate cache
bitbake('%s -c cleansstate' % testrecipe)
# Try modifying a recipe
tempdir = tempfile.mkdtemp(prefix='devtoolqa')
self.track_for_cleanup(tempdir)
self.track_for_cleanup(self.workspacedir)
self.add_command_to_tearDown('bitbake -c clean %s' % testrecipe)
self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
testsrcfile = os.path.join(tempdir, subdir, 'dos2unix.c')
self.assertExists(testsrcfile, 'Extracted source could not be found')
self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created. devtool output: %s' % result.output)
self.assertNotExists(os.path.join(tempdir, subdir, '.git'), 'Subdirectory has been initialised as a git repo')
# Check git repo
self._check_src_repo(tempdir)
# Modify file
runCmd("sed -i '1s:^:/* Add a comment */\\n:' %s" % testsrcfile)
result = runCmd('git commit -a -m "Add a comment"', cwd=tempdir)
# Now try updating original recipe
recipefile = bb_vars['FILE']
recipedir = os.path.dirname(recipefile)
self.add_command_to_tearDown('cd %s; rm -f %s/*.patch; git checkout .' % (recipedir, testrecipe))
result = runCmd('devtool update-recipe %s' % testrecipe)
expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)),
('??', '.*/%s/%s/$' % (testrecipe, testrecipe))]
self._check_repo_status(os.path.dirname(recipefile), expected_status)
result = runCmd('git diff %s' % os.path.basename(recipefile), cwd=os.path.dirname(recipefile))
removelines = ['SRC_URI = "git://.*"']
addlines = [
'SRC_URI = "git://.* \\\\',
'file://0001-Add-a-comment.patch;patchdir=.. \\\\',
'"'
]
self._check_diff(result.output, addlines, removelines)
# Put things back so we can run devtool finish on a different layer
runCmd('cd %s; rm -f %s/*.patch; git checkout .' % (recipedir, testrecipe))
# Run devtool finish
res = re.search('recipes-.*', recipedir)
self.assertTrue(res, 'Unable to find recipe subdirectory')
recipesubdir = res[0]
self.add_command_to_tearDown('rm -rf %s' % os.path.join(self.testlayer_path, recipesubdir))
result = runCmd('devtool finish %s meta-selftest' % testrecipe)
# Check bbappend file contents
appendfn = os.path.join(self.testlayer_path, recipesubdir, '%s_%%.bbappend' % testrecipe)
with open(appendfn, 'r') as f:
appendlines = f.readlines()
expected_appendlines = [
'FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
'\n',
'SRC_URI += "file://0001-Add-a-comment.patch;patchdir=.."\n',
'\n'
]
self.assertEqual(appendlines, expected_appendlines)
self.assertExists(os.path.join(os.path.dirname(appendfn), testrecipe, '0001-Add-a-comment.patch'))
# Try building
bitbake('%s -c patch' % testrecipe)
class DevtoolExtractTests(DevtoolBase):
def test_devtool_extract(self):