blob: 2eca1800de16defd5c1816e4835d0e72b4896ede [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright OpenEmbedded Contributors
3#
Brad Bishopc342db32019-05-15 21:57:59 -04004# SPDX-License-Identifier: MIT
5#
6
Patrick Williams169d7bc2024-01-05 11:33:25 -06007import errno
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008import os
9import shutil
10import tempfile
11import urllib.parse
12
13from oeqa.utils.commands import runCmd, bitbake, get_bb_var
14from oeqa.utils.commands import get_bb_vars, create_temp_layer
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015from oeqa.selftest.cases import devtool
16
17templayerdir = None
18
19def setUpModule():
20 global templayerdir
21 templayerdir = tempfile.mkdtemp(prefix='recipetoolqa')
22 create_temp_layer(templayerdir, 'selftestrecipetool')
23 runCmd('bitbake-layers add-layer %s' % templayerdir)
24
25
26def tearDownModule():
27 runCmd('bitbake-layers remove-layer %s' % templayerdir, ignore_status=True)
28 runCmd('rm -rf %s' % templayerdir)
29
30
Patrick Williams73bd93f2024-02-20 08:07:48 -060031def needTomllib(test):
32 # This test require python 3.11 or above for the tomllib module or tomli module to be installed
33 try:
34 import tomllib
35 except ImportError:
36 try:
37 import tomli
38 except ImportError:
39 test.skipTest('Test requires python 3.11 or above for tomllib module or tomli module')
40
Andrew Geissler595f6302022-01-24 19:11:47 +000041class RecipetoolBase(devtool.DevtoolTestCase):
Brad Bishopd7bf8c12018-02-25 22:55:05 -050042
43 def setUpLocal(self):
44 super(RecipetoolBase, self).setUpLocal()
45 self.templayerdir = templayerdir
46 self.tempdir = tempfile.mkdtemp(prefix='recipetoolqa')
47 self.track_for_cleanup(self.tempdir)
48 self.testfile = os.path.join(self.tempdir, 'testfile')
49 with open(self.testfile, 'w') as f:
50 f.write('Test file\n')
51
52 def tearDownLocal(self):
53 runCmd('rm -rf %s/recipes-*' % self.templayerdir)
54 super(RecipetoolBase, self).tearDownLocal()
55
56 def _try_recipetool_appendcmd(self, cmd, testrecipe, expectedfiles, expectedlines=None):
57 result = runCmd(cmd)
58 self.assertNotIn('Traceback', result.output)
59
60 # Check the bbappend was created and applies properly
61 recipefile = get_bb_var('FILE', testrecipe)
62 bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir)
63
64 # Check the bbappend contents
65 if expectedlines is not None:
66 with open(bbappendfile, 'r') as f:
67 self.assertEqual(expectedlines, f.readlines(), "Expected lines are not present in %s" % bbappendfile)
68
69 # Check file was copied
70 filesdir = os.path.join(os.path.dirname(bbappendfile), testrecipe)
71 for expectedfile in expectedfiles:
72 self.assertTrue(os.path.isfile(os.path.join(filesdir, expectedfile)), 'Expected file %s to be copied next to bbappend, but it wasn\'t' % expectedfile)
73
74 # Check no other files created
75 createdfiles = []
76 for root, _, files in os.walk(filesdir):
77 for f in files:
78 createdfiles.append(os.path.relpath(os.path.join(root, f), filesdir))
79 self.assertTrue(sorted(createdfiles), sorted(expectedfiles))
80
81 return bbappendfile, result.output
82
83
Andrew Geissler595f6302022-01-24 19:11:47 +000084class RecipetoolAppendTests(RecipetoolBase):
Brad Bishopd7bf8c12018-02-25 22:55:05 -050085
86 @classmethod
87 def setUpClass(cls):
Andrew Geissler595f6302022-01-24 19:11:47 +000088 super(RecipetoolAppendTests, cls).setUpClass()
Brad Bishopd7bf8c12018-02-25 22:55:05 -050089 # Ensure we have the right data in shlibs/pkgdata
90 cls.logger.info('Running bitbake to generate pkgdata')
91 bitbake('-c packagedata base-files coreutils busybox selftest-recipetool-appendfile')
Andrew Geissler595f6302022-01-24 19:11:47 +000092 bb_vars = get_bb_vars(['COREBASE'])
Brad Bishopd7bf8c12018-02-25 22:55:05 -050093 cls.corebase = bb_vars['COREBASE']
Brad Bishopd7bf8c12018-02-25 22:55:05 -050094
95 def _try_recipetool_appendfile(self, testrecipe, destfile, newfile, options, expectedlines, expectedfiles):
96 cmd = 'recipetool appendfile %s %s %s %s' % (self.templayerdir, destfile, newfile, options)
97 return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
98
99 def _try_recipetool_appendfile_fail(self, destfile, newfile, checkerror):
100 cmd = 'recipetool appendfile %s %s %s' % (self.templayerdir, destfile, newfile)
101 result = runCmd(cmd, ignore_status=True)
102 self.assertNotEqual(result.status, 0, 'Command "%s" should have failed but didn\'t' % cmd)
103 self.assertNotIn('Traceback', result.output)
104 for errorstr in checkerror:
105 self.assertIn(errorstr, result.output)
106
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500107 def test_recipetool_appendfile_basic(self):
108 # Basic test
Patrick Williams213cb262021-08-07 19:21:33 -0500109 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500110 '\n']
111 _, output = self._try_recipetool_appendfile('base-files', '/etc/motd', self.testfile, '', expectedlines, ['motd'])
112 self.assertNotIn('WARNING: ', output)
113
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500114 def test_recipetool_appendfile_invalid(self):
115 # Test some commands that should error
116 self._try_recipetool_appendfile_fail('/etc/passwd', self.testfile, ['ERROR: /etc/passwd cannot be handled by this tool', 'useradd', 'extrausers'])
117 self._try_recipetool_appendfile_fail('/etc/timestamp', self.testfile, ['ERROR: /etc/timestamp cannot be handled by this tool'])
118 self._try_recipetool_appendfile_fail('/dev/console', self.testfile, ['ERROR: /dev/console cannot be handled by this tool'])
119
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500120 def test_recipetool_appendfile_alternatives(self):
121 # Now try with a file we know should be an alternative
122 # (this is very much a fake example, but one we know is reliably an alternative)
123 self._try_recipetool_appendfile_fail('/bin/ls', self.testfile, ['ERROR: File /bin/ls is an alternative possibly provided by the following recipes:', 'coreutils', 'busybox'])
124 # Need a test file - should be executable
125 testfile2 = os.path.join(self.corebase, 'oe-init-build-env')
126 testfile2name = os.path.basename(testfile2)
Patrick Williams213cb262021-08-07 19:21:33 -0500127 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500128 '\n',
129 'SRC_URI += "file://%s"\n' % testfile2name,
130 '\n',
Patrick Williams213cb262021-08-07 19:21:33 -0500131 'do_install:append() {\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500132 ' install -d ${D}${base_bindir}\n',
133 ' install -m 0755 ${WORKDIR}/%s ${D}${base_bindir}/ls\n' % testfile2name,
134 '}\n']
135 self._try_recipetool_appendfile('coreutils', '/bin/ls', testfile2, '-r coreutils', expectedlines, [testfile2name])
136 # Now try bbappending the same file again, contents should not change
137 bbappendfile, _ = self._try_recipetool_appendfile('coreutils', '/bin/ls', self.testfile, '-r coreutils', expectedlines, [testfile2name])
138 # But file should have
139 copiedfile = os.path.join(os.path.dirname(bbappendfile), 'coreutils', testfile2name)
140 result = runCmd('diff -q %s %s' % (testfile2, copiedfile), ignore_status=True)
141 self.assertNotEqual(result.status, 0, 'New file should have been copied but was not %s' % result.output)
142
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500143 def test_recipetool_appendfile_binary(self):
144 # Try appending a binary file
145 # /bin/ls can be a symlink to /usr/bin/ls
146 ls = os.path.realpath("/bin/ls")
147 result = runCmd('recipetool appendfile %s /bin/ls %s -r coreutils' % (self.templayerdir, ls))
148 self.assertIn('WARNING: ', result.output)
149 self.assertIn('is a binary', result.output)
150
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500151 def test_recipetool_appendfile_add(self):
152 # Try arbitrary file add to a recipe
Patrick Williams213cb262021-08-07 19:21:33 -0500153 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500154 '\n',
155 'SRC_URI += "file://testfile"\n',
156 '\n',
Patrick Williams213cb262021-08-07 19:21:33 -0500157 'do_install:append() {\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500158 ' install -d ${D}${datadir}\n',
159 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n',
160 '}\n']
161 self._try_recipetool_appendfile('netbase', '/usr/share/something', self.testfile, '-r netbase', expectedlines, ['testfile'])
162 # Try adding another file, this time where the source file is executable
163 # (so we're testing that, plus modifying an existing bbappend)
164 testfile2 = os.path.join(self.corebase, 'oe-init-build-env')
165 testfile2name = os.path.basename(testfile2)
Patrick Williams213cb262021-08-07 19:21:33 -0500166 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500167 '\n',
168 'SRC_URI += "file://testfile \\\n',
169 ' file://%s \\\n' % testfile2name,
170 ' "\n',
171 '\n',
Patrick Williams213cb262021-08-07 19:21:33 -0500172 'do_install:append() {\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500173 ' install -d ${D}${datadir}\n',
174 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n',
175 ' install -m 0755 ${WORKDIR}/%s ${D}${datadir}/scriptname\n' % testfile2name,
176 '}\n']
177 self._try_recipetool_appendfile('netbase', '/usr/share/scriptname', testfile2, '-r netbase', expectedlines, ['testfile', testfile2name])
178
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500179 def test_recipetool_appendfile_add_bindir(self):
180 # Try arbitrary file add to a recipe, this time to a location such that should be installed as executable
Patrick Williams213cb262021-08-07 19:21:33 -0500181 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500182 '\n',
183 'SRC_URI += "file://testfile"\n',
184 '\n',
Patrick Williams213cb262021-08-07 19:21:33 -0500185 'do_install:append() {\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500186 ' install -d ${D}${bindir}\n',
187 ' install -m 0755 ${WORKDIR}/testfile ${D}${bindir}/selftest-recipetool-testbin\n',
188 '}\n']
189 _, output = self._try_recipetool_appendfile('netbase', '/usr/bin/selftest-recipetool-testbin', self.testfile, '-r netbase', expectedlines, ['testfile'])
190 self.assertNotIn('WARNING: ', output)
191
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500192 def test_recipetool_appendfile_add_machine(self):
193 # Try arbitrary file add to a recipe, this time to a location such that should be installed as executable
Patrick Williams213cb262021-08-07 19:21:33 -0500194 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500195 '\n',
196 'PACKAGE_ARCH = "${MACHINE_ARCH}"\n',
197 '\n',
Patrick Williams213cb262021-08-07 19:21:33 -0500198 'SRC_URI:append:mymachine = " file://testfile"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500199 '\n',
Patrick Williams213cb262021-08-07 19:21:33 -0500200 'do_install:append:mymachine() {\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500201 ' install -d ${D}${datadir}\n',
202 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n',
203 '}\n']
204 _, output = self._try_recipetool_appendfile('netbase', '/usr/share/something', self.testfile, '-r netbase -m mymachine', expectedlines, ['mymachine/testfile'])
205 self.assertNotIn('WARNING: ', output)
206
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500207 def test_recipetool_appendfile_orig(self):
208 # A file that's in SRC_URI and in do_install with the same name
Patrick Williams213cb262021-08-07 19:21:33 -0500209 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500210 '\n']
211 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-orig', self.testfile, '', expectedlines, ['selftest-replaceme-orig'])
212 self.assertNotIn('WARNING: ', output)
213
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500214 def test_recipetool_appendfile_todir(self):
215 # A file that's in SRC_URI and in do_install with destination directory rather than file
Patrick Williams213cb262021-08-07 19:21:33 -0500216 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500217 '\n']
218 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-todir', self.testfile, '', expectedlines, ['selftest-replaceme-todir'])
219 self.assertNotIn('WARNING: ', output)
220
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500221 def test_recipetool_appendfile_renamed(self):
222 # A file that's in SRC_URI with a different name to the destination file
Patrick Williams213cb262021-08-07 19:21:33 -0500223 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500224 '\n']
225 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-renamed', self.testfile, '', expectedlines, ['file1'])
226 self.assertNotIn('WARNING: ', output)
227
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500228 def test_recipetool_appendfile_subdir(self):
229 # A file that's in SRC_URI in a subdir
Patrick Williams213cb262021-08-07 19:21:33 -0500230 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500231 '\n',
232 'SRC_URI += "file://testfile"\n',
233 '\n',
Patrick Williams213cb262021-08-07 19:21:33 -0500234 'do_install:append() {\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500235 ' install -d ${D}${datadir}\n',
236 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-subdir\n',
237 '}\n']
238 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-subdir', self.testfile, '', expectedlines, ['testfile'])
239 self.assertNotIn('WARNING: ', output)
240
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500241 def test_recipetool_appendfile_inst_glob(self):
242 # A file that's in do_install as a glob
Patrick Williams213cb262021-08-07 19:21:33 -0500243 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500244 '\n']
245 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-globfile', self.testfile, '', expectedlines, ['selftest-replaceme-inst-globfile'])
246 self.assertNotIn('WARNING: ', output)
247
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500248 def test_recipetool_appendfile_inst_todir_glob(self):
249 # A file that's in do_install as a glob with destination as a directory
Patrick Williams213cb262021-08-07 19:21:33 -0500250 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500251 '\n']
252 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-todir-globfile', self.testfile, '', expectedlines, ['selftest-replaceme-inst-todir-globfile'])
253 self.assertNotIn('WARNING: ', output)
254
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500255 def test_recipetool_appendfile_patch(self):
256 # A file that's added by a patch in SRC_URI
Patrick Williams213cb262021-08-07 19:21:33 -0500257 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500258 '\n',
259 'SRC_URI += "file://testfile"\n',
260 '\n',
Patrick Williams213cb262021-08-07 19:21:33 -0500261 'do_install:append() {\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500262 ' install -d ${D}${sysconfdir}\n',
263 ' install -m 0644 ${WORKDIR}/testfile ${D}${sysconfdir}/selftest-replaceme-patched\n',
264 '}\n']
265 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/etc/selftest-replaceme-patched', self.testfile, '', expectedlines, ['testfile'])
266 for line in output.splitlines():
267 if 'WARNING: ' in line:
268 self.assertIn('add-file.patch', line, 'Unexpected warning found in output:\n%s' % line)
269 break
270 else:
271 self.fail('Patch warning not found in output:\n%s' % output)
272
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500273 def test_recipetool_appendfile_script(self):
274 # Now, a file that's in SRC_URI but installed by a script (so no mention in do_install)
Patrick Williams213cb262021-08-07 19:21:33 -0500275 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500276 '\n',
277 'SRC_URI += "file://testfile"\n',
278 '\n',
Patrick Williams213cb262021-08-07 19:21:33 -0500279 'do_install:append() {\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500280 ' install -d ${D}${datadir}\n',
281 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-scripted\n',
282 '}\n']
283 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-scripted', self.testfile, '', expectedlines, ['testfile'])
284 self.assertNotIn('WARNING: ', output)
285
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500286 def test_recipetool_appendfile_inst_func(self):
287 # A file that's installed from a function called by do_install
Patrick Williams213cb262021-08-07 19:21:33 -0500288 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500289 '\n']
290 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-func', self.testfile, '', expectedlines, ['selftest-replaceme-inst-func'])
291 self.assertNotIn('WARNING: ', output)
292
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500293 def test_recipetool_appendfile_postinstall(self):
294 # A file that's created by a postinstall script (and explicitly mentioned in it)
295 # First try without specifying recipe
296 self._try_recipetool_appendfile_fail('/usr/share/selftest-replaceme-postinst', self.testfile, ['File /usr/share/selftest-replaceme-postinst may be written out in a pre/postinstall script of the following recipes:', 'selftest-recipetool-appendfile'])
297 # Now specify recipe
Patrick Williams213cb262021-08-07 19:21:33 -0500298 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500299 '\n',
300 'SRC_URI += "file://testfile"\n',
301 '\n',
Patrick Williams213cb262021-08-07 19:21:33 -0500302 'do_install:append() {\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500303 ' install -d ${D}${datadir}\n',
304 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-postinst\n',
305 '}\n']
306 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-postinst', self.testfile, '-r selftest-recipetool-appendfile', expectedlines, ['testfile'])
307
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500308 def test_recipetool_appendfile_extlayer(self):
309 # Try creating a bbappend in a layer that's not in bblayers.conf and has a different structure
310 exttemplayerdir = os.path.join(self.tempdir, 'extlayer')
311 self._create_temp_layer(exttemplayerdir, False, 'oeselftestextlayer', recipepathspec='metadata/recipes/recipes-*/*')
312 result = runCmd('recipetool appendfile %s /usr/share/selftest-replaceme-orig %s' % (exttemplayerdir, self.testfile))
313 self.assertNotIn('Traceback', result.output)
314 createdfiles = []
315 for root, _, files in os.walk(exttemplayerdir):
316 for f in files:
317 createdfiles.append(os.path.relpath(os.path.join(root, f), exttemplayerdir))
318 createdfiles.remove('conf/layer.conf')
319 expectedfiles = ['metadata/recipes/recipes-test/selftest-recipetool-appendfile/selftest-recipetool-appendfile.bbappend',
320 'metadata/recipes/recipes-test/selftest-recipetool-appendfile/selftest-recipetool-appendfile/selftest-replaceme-orig']
321 self.assertEqual(sorted(createdfiles), sorted(expectedfiles))
322
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500323 def test_recipetool_appendfile_wildcard(self):
324
325 def try_appendfile_wc(options):
326 result = runCmd('recipetool appendfile %s /etc/profile %s %s' % (self.templayerdir, self.testfile, options))
327 self.assertNotIn('Traceback', result.output)
328 bbappendfile = None
329 for root, _, files in os.walk(self.templayerdir):
330 for f in files:
331 if f.endswith('.bbappend'):
332 bbappendfile = f
333 break
334 if not bbappendfile:
335 self.fail('No bbappend file created')
336 runCmd('rm -rf %s/recipes-*' % self.templayerdir)
337 return bbappendfile
338
339 # Check without wildcard option
340 recipefn = os.path.basename(get_bb_var('FILE', 'base-files'))
341 filename = try_appendfile_wc('')
342 self.assertEqual(filename, recipefn.replace('.bb', '.bbappend'))
343 # Now check with wildcard option
344 filename = try_appendfile_wc('-w')
345 self.assertEqual(filename, recipefn.split('_')[0] + '_%.bbappend')
346
Andrew Geissler595f6302022-01-24 19:11:47 +0000347
348class RecipetoolCreateTests(RecipetoolBase):
349
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500350 def test_recipetool_create(self):
351 # Try adding a recipe
352 tempsrc = os.path.join(self.tempdir, 'srctree')
353 os.makedirs(tempsrc)
354 recipefile = os.path.join(self.tempdir, 'logrotate_3.12.3.bb')
355 srcuri = 'https://github.com/logrotate/logrotate/releases/download/3.12.3/logrotate-3.12.3.tar.xz'
356 result = runCmd('recipetool create -o %s %s -x %s' % (recipefile, srcuri, tempsrc))
357 self.assertTrue(os.path.isfile(recipefile))
358 checkvars = {}
Andrew Geissler9aee5002022-03-30 16:27:02 +0000359 checkvars['LICENSE'] = 'GPL-2.0-only'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500360 checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263'
361 checkvars['SRC_URI'] = 'https://github.com/logrotate/logrotate/releases/download/${PV}/logrotate-${PV}.tar.xz'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500362 checkvars['SRC_URI[sha256sum]'] = '2e6a401cac9024db2288297e3be1a8ab60e7401ba8e91225218aaf4a27e82a07'
363 self._test_recipe_contents(recipefile, checkvars, [])
364
Andrew Geissler595f6302022-01-24 19:11:47 +0000365 def test_recipetool_create_autotools(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500366 if 'x11' not in get_bb_var('DISTRO_FEATURES'):
367 self.skipTest('Test requires x11 as distro feature')
368 # Ensure we have the right data in shlibs/pkgdata
369 bitbake('libpng pango libx11 libxext jpeg libcheck')
370 # Try adding a recipe
371 tempsrc = os.path.join(self.tempdir, 'srctree')
372 os.makedirs(tempsrc)
373 recipefile = os.path.join(self.tempdir, 'libmatchbox.bb')
Andrew Geissler028142b2023-05-05 11:29:21 -0500374 srcuri = 'git://git.yoctoproject.org/libmatchbox;protocol=https'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500375 result = runCmd(['recipetool', 'create', '-o', recipefile, srcuri + ";rev=9f7cf8895ae2d39c465c04cc78e918c157420269", '-x', tempsrc])
376 self.assertTrue(os.path.isfile(recipefile), 'recipetool did not create recipe file; output:\n%s' % result.output)
377 checkvars = {}
Andrew Geissler9aee5002022-03-30 16:27:02 +0000378 checkvars['LICENSE'] = 'LGPL-2.1-only'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500379 checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=7fbc338309ac38fefcd64b04bb903e34'
380 checkvars['S'] = '${WORKDIR}/git'
Andrew Geissler5082cc72023-09-11 08:41:39 -0400381 checkvars['PV'] = '1.11+git'
Andrew Geissler595f6302022-01-24 19:11:47 +0000382 checkvars['SRC_URI'] = srcuri + ';branch=master'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500383 checkvars['DEPENDS'] = set(['libcheck', 'libjpeg-turbo', 'libpng', 'libx11', 'libxext', 'pango'])
384 inherits = ['autotools', 'pkgconfig']
385 self._test_recipe_contents(recipefile, checkvars, inherits)
386
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500387 def test_recipetool_create_simple(self):
388 # Try adding a recipe
389 temprecipe = os.path.join(self.tempdir, 'recipe')
390 os.makedirs(temprecipe)
Andrew Geissler5f350902021-07-23 13:09:54 -0400391 pv = '1.7.4.1'
Andrew Geissler9aee5002022-03-30 16:27:02 +0000392 srcuri = 'http://www.dest-unreach.org/socat/download/Archive/socat-%s.tar.bz2' % pv
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500393 result = runCmd('recipetool create %s -o %s' % (srcuri, temprecipe))
394 dirlist = os.listdir(temprecipe)
395 if len(dirlist) > 1:
396 self.fail('recipetool created more than just one file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist)))
397 if len(dirlist) < 1 or not os.path.isfile(os.path.join(temprecipe, dirlist[0])):
398 self.fail('recipetool did not create recipe file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist)))
399 self.assertEqual(dirlist[0], 'socat_%s.bb' % pv, 'Recipe file incorrectly named')
400 checkvars = {}
Andrew Geissler9aee5002022-03-30 16:27:02 +0000401 checkvars['LICENSE'] = set(['Unknown', 'GPL-2.0-only'])
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500402 checkvars['LIC_FILES_CHKSUM'] = set(['file://COPYING.OpenSSL;md5=5c9bccc77f67a8328ef4ebaf468116f4', 'file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263'])
403 # We don't check DEPENDS since they are variable for this recipe depending on what's in the sysroot
404 checkvars['S'] = None
405 checkvars['SRC_URI'] = srcuri.replace(pv, '${PV}')
406 inherits = ['autotools']
407 self._test_recipe_contents(os.path.join(temprecipe, dirlist[0]), checkvars, inherits)
408
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500409 def test_recipetool_create_cmake(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500410 temprecipe = os.path.join(self.tempdir, 'recipe')
411 os.makedirs(temprecipe)
Brad Bishop96ff1982019-08-19 13:50:42 -0400412 recipefile = os.path.join(temprecipe, 'taglib_1.11.1.bb')
413 srcuri = 'http://taglib.github.io/releases/taglib-1.11.1.tar.gz'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500414 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
415 self.assertTrue(os.path.isfile(recipefile))
416 checkvars = {}
Andrew Geissler9aee5002022-03-30 16:27:02 +0000417 checkvars['LICENSE'] = set(['LGPL-2.1-only', 'MPL-1.1-only'])
Brad Bishop96ff1982019-08-19 13:50:42 -0400418 checkvars['SRC_URI'] = 'http://taglib.github.io/releases/taglib-${PV}.tar.gz'
Brad Bishop96ff1982019-08-19 13:50:42 -0400419 checkvars['SRC_URI[sha256sum]'] = 'b6d1a5a610aae6ff39d93de5efd0fdc787aa9e9dc1e7026fa4c961b26563526b'
420 checkvars['DEPENDS'] = set(['boost', 'zlib'])
421 inherits = ['cmake']
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500422 self._test_recipe_contents(recipefile, checkvars, inherits)
423
Andrew Geissler82c905d2020-04-13 13:39:40 -0500424 def test_recipetool_create_npm(self):
Andrew Geisslerf0343792020-11-18 10:42:21 -0600425 collections = get_bb_var('BBFILE_COLLECTIONS').split()
426 if "openembedded-layer" not in collections:
427 self.skipTest("Test needs meta-oe for nodejs")
428
Andrew Geissler82c905d2020-04-13 13:39:40 -0500429 temprecipe = os.path.join(self.tempdir, 'recipe')
430 os.makedirs(temprecipe)
431 recipefile = os.path.join(temprecipe, 'savoirfairelinux-node-server-example_1.0.0.bb')
432 shrinkwrap = os.path.join(temprecipe, 'savoirfairelinux-node-server-example', 'npm-shrinkwrap.json')
433 srcuri = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
434 result = runCmd('recipetool create -o %s \'%s\'' % (temprecipe, srcuri))
435 self.assertTrue(os.path.isfile(recipefile))
436 self.assertTrue(os.path.isfile(shrinkwrap))
437 checkvars = {}
438 checkvars['SUMMARY'] = 'Node Server Example'
439 checkvars['HOMEPAGE'] = 'https://github.com/savoirfairelinux/node-server-example#readme'
Andrew Geissler595f6302022-01-24 19:11:47 +0000440 checkvars['LICENSE'] = 'BSD-3-Clause & ISC & MIT & Unknown'
Andrew Geissler82c905d2020-04-13 13:39:40 -0500441 urls = []
442 urls.append('npm://registry.npmjs.org/;package=@savoirfairelinux/node-server-example;version=${PV}')
443 urls.append('npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json')
444 checkvars['SRC_URI'] = set(urls)
445 checkvars['S'] = '${WORKDIR}/npm'
Patrick Williams213cb262021-08-07 19:21:33 -0500446 checkvars['LICENSE:${PN}'] = 'MIT'
447 checkvars['LICENSE:${PN}-base64'] = 'Unknown'
448 checkvars['LICENSE:${PN}-accepts'] = 'MIT'
449 checkvars['LICENSE:${PN}-inherits'] = 'ISC'
Andrew Geissler82c905d2020-04-13 13:39:40 -0500450 inherits = ['npm']
451 self._test_recipe_contents(recipefile, checkvars, inherits)
452
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500453 def test_recipetool_create_github(self):
Patrick Williams73bd93f2024-02-20 08:07:48 -0600454 # Basic test to see if github URL mangling works. Deliberately use an
455 # older release of Meson at present so we don't need a toml parser.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500456 temprecipe = os.path.join(self.tempdir, 'recipe')
457 os.makedirs(temprecipe)
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600458 recipefile = os.path.join(temprecipe, 'python3-meson_git.bb')
Patrick Williams73bd93f2024-02-20 08:07:48 -0600459 srcuri = 'https://github.com/mesonbuild/meson;rev=0.52.1'
460 cmd = ['recipetool', 'create', '-o', temprecipe, srcuri]
461 result = runCmd(cmd)
462 self.assertTrue(os.path.isfile(recipefile), msg="recipe %s not created for command %s, output %s" % (recipefile, " ".join(cmd), result.output))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500463 checkvars = {}
Patrick Williams73bd93f2024-02-20 08:07:48 -0600464 checkvars['LICENSE'] = set(['Apache-2.0', "Unknown"])
465 checkvars['SRC_URI'] = 'git://github.com/mesonbuild/meson;protocol=https;branch=0.52'
Brad Bishop15ae2502019-06-18 21:44:24 -0400466 inherits = ['setuptools3']
467 self._test_recipe_contents(recipefile, checkvars, inherits)
468
469 def test_recipetool_create_python3_setuptools(self):
470 # Test creating python3 package from tarball (using setuptools3 class)
Patrick Williams169d7bc2024-01-05 11:33:25 -0600471 # Use the --no-pypi switch to avoid creating a pypi enabled recipe and
472 # and check the created recipe as if it was a more general tarball
473 temprecipe = os.path.join(self.tempdir, 'recipe')
474 os.makedirs(temprecipe)
475 pn = 'python-magic'
476 pv = '0.4.15'
477 recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, pv))
478 srcuri = 'https://files.pythonhosted.org/packages/84/30/80932401906eaf787f2e9bd86dc458f1d2e75b064b4c187341f29516945c/python-magic-%s.tar.gz' % pv
479 result = runCmd('recipetool create --no-pypi -o %s %s' % (temprecipe, srcuri))
480 self.assertTrue(os.path.isfile(recipefile))
481 checkvars = {}
482 checkvars['LICENSE'] = set(['MIT'])
483 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88'
484 checkvars['SRC_URI'] = 'https://files.pythonhosted.org/packages/84/30/80932401906eaf787f2e9bd86dc458f1d2e75b064b4c187341f29516945c/python-magic-${PV}.tar.gz'
485 checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5'
486 inherits = ['setuptools3']
487 self._test_recipe_contents(recipefile, checkvars, inherits)
488
489 def test_recipetool_create_python3_setuptools_pypi_tarball(self):
490 # Test creating python3 package from tarball (using setuptools3 and pypi classes)
Brad Bishop15ae2502019-06-18 21:44:24 -0400491 temprecipe = os.path.join(self.tempdir, 'recipe')
492 os.makedirs(temprecipe)
493 pn = 'python-magic'
494 pv = '0.4.15'
495 recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, pv))
496 srcuri = 'https://files.pythonhosted.org/packages/84/30/80932401906eaf787f2e9bd86dc458f1d2e75b064b4c187341f29516945c/python-magic-%s.tar.gz' % pv
497 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
498 self.assertTrue(os.path.isfile(recipefile))
499 checkvars = {}
500 checkvars['LICENSE'] = set(['MIT'])
501 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88'
Brad Bishop15ae2502019-06-18 21:44:24 -0400502 checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5'
Patrick Williams169d7bc2024-01-05 11:33:25 -0600503 checkvars['PYPI_PACKAGE'] = pn
504 inherits = ['setuptools3', 'pypi']
505 self._test_recipe_contents(recipefile, checkvars, inherits)
506
507 def test_recipetool_create_python3_setuptools_pypi(self):
508 # Test creating python3 package from pypi url (using setuptools3 and pypi classes)
509 # Intentionnaly using setuptools3 class here instead of any of the pep517 class
510 # to avoid the toml dependency and allows this test to run on host autobuilders
511 # with older version of python
512 temprecipe = os.path.join(self.tempdir, 'recipe')
513 os.makedirs(temprecipe)
514 pn = 'python-magic'
515 pv = '0.4.15'
516 recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, pv))
517 # First specify the required version in the url
518 srcuri = 'https://pypi.org/project/%s/%s' % (pn, pv)
519 runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
520 self.assertTrue(os.path.isfile(recipefile))
521 checkvars = {}
522 checkvars['LICENSE'] = set(['MIT'])
523 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88'
524 checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5'
525 checkvars['PYPI_PACKAGE'] = pn
526 inherits = ['setuptools3', "pypi"]
527 self._test_recipe_contents(recipefile, checkvars, inherits)
528
529 # Now specify the version as a recipetool parameter
530 runCmd('rm -rf %s' % recipefile)
531 self.assertFalse(os.path.isfile(recipefile))
532 srcuri = 'https://pypi.org/project/%s' % pn
533 runCmd('recipetool create -o %s %s --version %s' % (temprecipe, srcuri, pv))
534 self.assertTrue(os.path.isfile(recipefile))
535 checkvars = {}
536 checkvars['LICENSE'] = set(['MIT'])
537 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88'
538 checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5'
539 checkvars['PYPI_PACKAGE'] = pn
540 inherits = ['setuptools3', "pypi"]
541 self._test_recipe_contents(recipefile, checkvars, inherits)
542
543 # Now, try to grab latest version of the package, so we cannot guess the name of the recipe,
544 # unless hardcoding the latest version but it means we will need to update the test for each release,
545 # so use a regexp
546 runCmd('rm -rf %s' % recipefile)
547 self.assertFalse(os.path.isfile(recipefile))
548 recipefile_re = r'%s_(.*)\.bb' % pn
549 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
550 dirlist = os.listdir(temprecipe)
551 if len(dirlist) > 1:
552 self.fail('recipetool created more than just one file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist)))
553 if len(dirlist) < 1 or not os.path.isfile(os.path.join(temprecipe, dirlist[0])):
554 self.fail('recipetool did not create recipe file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist)))
555 import re
556 match = re.match(recipefile_re, dirlist[0])
557 self.assertTrue(match)
558 latest_pv = match.group(1)
559 self.assertTrue(latest_pv != pv)
560 recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, latest_pv))
561 # Do not check LIC_FILES_CHKSUM and SRC_URI checksum here to avoid having updating the test on each release
562 checkvars = {}
563 checkvars['LICENSE'] = set(['MIT'])
564 checkvars['PYPI_PACKAGE'] = pn
565 inherits = ['setuptools3', "pypi"]
Brad Bishop15ae2502019-06-18 21:44:24 -0400566 self._test_recipe_contents(recipefile, checkvars, inherits)
567
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600568 def test_recipetool_create_python3_pep517_setuptools_build_meta(self):
Patrick Williams73bd93f2024-02-20 08:07:48 -0600569 # This test require python 3.11 or above for the tomllib module or tomli module to be installed
570 needTomllib(self)
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600571
572 # Test creating python3 package from tarball (using setuptools.build_meta class)
573 temprecipe = os.path.join(self.tempdir, 'recipe')
574 os.makedirs(temprecipe)
575 pn = 'webcolors'
576 pv = '1.13'
577 recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
578 srcuri = 'https://files.pythonhosted.org/packages/a1/fb/f95560c6a5d4469d9c49e24cf1b5d4d21ffab5608251c6020a965fb7791c/%s-%s.tar.gz' % (pn, pv)
579 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
580 self.assertTrue(os.path.isfile(recipefile))
581 checkvars = {}
582 checkvars['SUMMARY'] = 'A library for working with the color formats defined by HTML and CSS.'
583 checkvars['LICENSE'] = set(['BSD-3-Clause'])
584 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=702b1ef12cf66832a88f24c8f2ee9c19'
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600585 checkvars['SRC_URI[sha256sum]'] = 'c225b674c83fa923be93d235330ce0300373d02885cef23238813b0d5668304a'
Patrick Williams169d7bc2024-01-05 11:33:25 -0600586 inherits = ['python_setuptools_build_meta', 'pypi']
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600587
588 self._test_recipe_contents(recipefile, checkvars, inherits)
589
590 def test_recipetool_create_python3_pep517_poetry_core_masonry_api(self):
Patrick Williams73bd93f2024-02-20 08:07:48 -0600591 # This test require python 3.11 or above for the tomllib module or tomli module to be installed
592 needTomllib(self)
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600593
594 # Test creating python3 package from tarball (using poetry.core.masonry.api class)
595 temprecipe = os.path.join(self.tempdir, 'recipe')
596 os.makedirs(temprecipe)
597 pn = 'iso8601'
598 pv = '2.1.0'
599 recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
600 srcuri = 'https://files.pythonhosted.org/packages/b9/f3/ef59cee614d5e0accf6fd0cbba025b93b272e626ca89fb70a3e9187c5d15/%s-%s.tar.gz' % (pn, pv)
601 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
602 self.assertTrue(os.path.isfile(recipefile))
603 checkvars = {}
604 checkvars['SUMMARY'] = 'Simple module to parse ISO 8601 dates'
605 checkvars['LICENSE'] = set(['MIT'])
606 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=aab31f2ef7ba214a5a341eaa47a7f367'
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600607 checkvars['SRC_URI[sha256sum]'] = '6b1d3829ee8921c4301998c909f7829fa9ed3cbdac0d3b16af2d743aed1ba8df'
Patrick Williams169d7bc2024-01-05 11:33:25 -0600608 inherits = ['python_poetry_core', 'pypi']
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600609
610 self._test_recipe_contents(recipefile, checkvars, inherits)
611
612 def test_recipetool_create_python3_pep517_flit_core_buildapi(self):
Patrick Williams73bd93f2024-02-20 08:07:48 -0600613 # This test require python 3.11 or above for the tomllib module or tomli module to be installed
614 needTomllib(self)
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600615
616 # Test creating python3 package from tarball (using flit_core.buildapi class)
617 temprecipe = os.path.join(self.tempdir, 'recipe')
618 os.makedirs(temprecipe)
619 pn = 'typing-extensions'
620 pv = '4.8.0'
621 recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
622 srcuri = 'https://files.pythonhosted.org/packages/1f/7a/8b94bb016069caa12fc9f587b28080ac33b4fbb8ca369b98bc0a4828543e/typing_extensions-%s.tar.gz' % pv
623 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
624 self.assertTrue(os.path.isfile(recipefile))
625 checkvars = {}
626 checkvars['SUMMARY'] = 'Backported and Experimental Type Hints for Python 3.8+'
627 checkvars['LICENSE'] = set(['PSF-2.0'])
628 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=fcf6b249c2641540219a727f35d8d2c2'
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600629 checkvars['SRC_URI[sha256sum]'] = 'df8e4339e9cb77357558cbdbceca33c303714cf861d1eef15e1070055ae8b7ef'
Patrick Williams169d7bc2024-01-05 11:33:25 -0600630 inherits = ['python_flit_core', 'pypi']
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600631
632 self._test_recipe_contents(recipefile, checkvars, inherits)
633
634 def test_recipetool_create_python3_pep517_hatchling(self):
Patrick Williams73bd93f2024-02-20 08:07:48 -0600635 # This test require python 3.11 or above for the tomllib module or tomli module to be installed
636 needTomllib(self)
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600637
638 # Test creating python3 package from tarball (using hatchling class)
639 temprecipe = os.path.join(self.tempdir, 'recipe')
640 os.makedirs(temprecipe)
641 pn = 'jsonschema'
642 pv = '4.19.1'
643 recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
644 srcuri = 'https://files.pythonhosted.org/packages/e4/43/087b24516db11722c8687e0caf0f66c7785c0b1c51b0ab951dfde924e3f5/jsonschema-%s.tar.gz' % pv
645 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
646 self.assertTrue(os.path.isfile(recipefile))
647 checkvars = {}
648 checkvars['SUMMARY'] = 'An implementation of JSON Schema validation for Python'
649 checkvars['HOMEPAGE'] = 'https://github.com/python-jsonschema/jsonschema'
650 checkvars['LICENSE'] = set(['MIT'])
651 checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=7a60a81c146ec25599a3e1dabb8610a8 file://json/LICENSE;md5=9d4de43111d33570c8fe49b4cb0e01af'
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600652 checkvars['SRC_URI[sha256sum]'] = 'ec84cc37cfa703ef7cd4928db24f9cb31428a5d0fa77747b8b51a847458e0bbf'
Patrick Williams169d7bc2024-01-05 11:33:25 -0600653 inherits = ['python_hatchling', 'pypi']
654
655 self._test_recipe_contents(recipefile, checkvars, inherits)
656
657 def test_recipetool_create_python3_pep517_maturin(self):
Patrick Williams73bd93f2024-02-20 08:07:48 -0600658 # This test require python 3.11 or above for the tomllib module or tomli module to be installed
659 needTomllib(self)
Patrick Williams169d7bc2024-01-05 11:33:25 -0600660
661 # Test creating python3 package from tarball (using maturin class)
662 temprecipe = os.path.join(self.tempdir, 'recipe')
663 os.makedirs(temprecipe)
664 pn = 'pydantic-core'
665 pv = '2.14.5'
666 recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
667 srcuri = 'https://files.pythonhosted.org/packages/64/26/cffb93fe9c6b5a91c497f37fae14a4b073ecbc47fc36a9979c7aa888b245/pydantic_core-%s.tar.gz' % pv
668 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
669 self.assertTrue(os.path.isfile(recipefile))
670 checkvars = {}
671 checkvars['HOMEPAGE'] = 'https://github.com/pydantic/pydantic-core'
672 checkvars['LICENSE'] = set(['MIT'])
673 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=ab599c188b4a314d2856b3a55030c75c'
674 checkvars['SRC_URI[sha256sum]'] = '6d30226dfc816dd0fdf120cae611dd2215117e4f9b124af8c60ab9093b6e8e71'
675 inherits = ['python_maturin', 'pypi']
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600676
677 self._test_recipe_contents(recipefile, checkvars, inherits)
678
Patrick Williams73bd93f2024-02-20 08:07:48 -0600679 def test_recipetool_create_python3_pep517_mesonpy(self):
680 # This test require python 3.11 or above for the tomllib module or tomli module to be installed
681 needTomllib(self)
682
683 # Test creating python3 package from tarball (using mesonpy class)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500684 temprecipe = os.path.join(self.tempdir, 'recipe')
685 os.makedirs(temprecipe)
Patrick Williams73bd93f2024-02-20 08:07:48 -0600686 pn = 'siphash24'
687 pv = '1.4'
688 recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
689 srcuri = 'https://files.pythonhosted.org/packages/c2/32/b934a70592f314afcfa86c7f7e388804a8061be65b822e2aa07e573b6477/%s-%s.tar.gz' % (pn, pv)
690 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
691 self.assertTrue(os.path.isfile(recipefile))
692 checkvars = {}
693 checkvars['SRC_URI[sha256sum]'] = '7fd65e39b2a7c8c4ddc3a168a687f4610751b0ac2ebb518783c0cdfc30bec4a0'
694 inherits = ['python_mesonpy', 'pypi']
695
696 self._test_recipe_contents(recipefile, checkvars, inherits)
697
698 def test_recipetool_create_github_tarball(self):
699 # Basic test to ensure github URL mangling doesn't apply to release tarballs.
700 # Deliberately use an older release of Meson at present so we don't need a toml parser.
701 temprecipe = os.path.join(self.tempdir, 'recipe')
702 os.makedirs(temprecipe)
703 pv = '0.52.1'
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600704 recipefile = os.path.join(temprecipe, 'python3-meson_%s.bb' % pv)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500705 srcuri = 'https://github.com/mesonbuild/meson/releases/download/%s/meson-%s.tar.gz' % (pv, pv)
706 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
707 self.assertTrue(os.path.isfile(recipefile))
708 checkvars = {}
709 checkvars['LICENSE'] = set(['Apache-2.0'])
710 checkvars['SRC_URI'] = 'https://github.com/mesonbuild/meson/releases/download/${PV}/meson-${PV}.tar.gz'
Brad Bishop15ae2502019-06-18 21:44:24 -0400711 inherits = ['setuptools3']
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500712 self._test_recipe_contents(recipefile, checkvars, inherits)
713
Andrew Geissler595f6302022-01-24 19:11:47 +0000714 def _test_recipetool_create_git(self, srcuri, branch=None):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500715 # Basic test to check http git URL mangling works
716 temprecipe = os.path.join(self.tempdir, 'recipe')
717 os.makedirs(temprecipe)
Andrew Geissler595f6302022-01-24 19:11:47 +0000718 name = srcuri.split(';')[0].split('/')[-1]
719 recipefile = os.path.join(temprecipe, name + '_git.bb')
720 options = ' -B %s' % branch if branch else ''
721 result = runCmd('recipetool create -o %s%s "%s"' % (temprecipe, options, srcuri))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500722 self.assertTrue(os.path.isfile(recipefile))
723 checkvars = {}
Andrew Geissler595f6302022-01-24 19:11:47 +0000724 checkvars['SRC_URI'] = srcuri
725 for scheme in ['http', 'https']:
726 if srcuri.startswith(scheme + ":"):
727 checkvars['SRC_URI'] = 'git%s;protocol=%s' % (srcuri[len(scheme):], scheme)
728 if ';branch=' not in srcuri:
729 checkvars['SRC_URI'] += ';branch=' + (branch or 'master')
730 self._test_recipe_contents(recipefile, checkvars, [])
731
732 def test_recipetool_create_git_http(self):
733 self._test_recipetool_create_git('http://git.yoctoproject.org/git/matchbox-keyboard')
734
735 def test_recipetool_create_git_srcuri_master(self):
Andrew Geissler028142b2023-05-05 11:29:21 -0500736 self._test_recipetool_create_git('git://git.yoctoproject.org/matchbox-keyboard;branch=master;protocol=https')
Andrew Geissler595f6302022-01-24 19:11:47 +0000737
738 def test_recipetool_create_git_srcuri_branch(self):
Andrew Geissler028142b2023-05-05 11:29:21 -0500739 self._test_recipetool_create_git('git://git.yoctoproject.org/matchbox-keyboard;branch=matchbox-keyboard-0-1;protocol=https')
Andrew Geissler595f6302022-01-24 19:11:47 +0000740
741 def test_recipetool_create_git_srcbranch(self):
Andrew Geissler028142b2023-05-05 11:29:21 -0500742 self._test_recipetool_create_git('git://git.yoctoproject.org/matchbox-keyboard;protocol=https', 'matchbox-keyboard-0-1')
Andrew Geissler595f6302022-01-24 19:11:47 +0000743
Patrick Williams56b44a92024-01-19 08:49:29 -0600744 def _go_urifiy(self, url, version, modulepath = None, pathmajor = None, subdir = None):
745 modulepath = ",path='%s'" % modulepath if len(modulepath) else ''
746 pathmajor = ",pathmajor='%s'" % pathmajor if len(pathmajor) else ''
747 subdir = ",subdir='%s'" % subdir if len(subdir) else ''
748 return "${@go_src_uri('%s','%s'%s%s%s)}" % (url, version, modulepath, pathmajor, subdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500749
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600750 def test_recipetool_create_go(self):
751 # Basic test to check go recipe generation
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600752 temprecipe = os.path.join(self.tempdir, 'recipe')
753 os.makedirs(temprecipe)
754
755 recipefile = os.path.join(temprecipe, 'edgex-go_git.bb')
756 deps_require_file = os.path.join(temprecipe, 'edgex-go', 'edgex-go-modules.inc')
757 lics_require_file = os.path.join(temprecipe, 'edgex-go', 'edgex-go-licenses.inc')
758 modules_txt_file = os.path.join(temprecipe, 'edgex-go', 'modules.txt')
759
760 srcuri = 'https://github.com/edgexfoundry/edgex-go.git'
761 srcrev = "v3.0.0"
762 srcbranch = "main"
763
764 result = runCmd('recipetool create -o %s %s -S %s -B %s' % (temprecipe, srcuri, srcrev, srcbranch))
765
766 self.maxDiff = None
767 inherits = ['go-vendor']
768
769 checkvars = {}
770 checkvars['GO_IMPORT'] = "github.com/edgexfoundry/edgex-go"
771 checkvars['SRC_URI'] = {'git://${GO_IMPORT};destsuffix=git/src/${GO_IMPORT};nobranch=1;name=${BPN};protocol=https',
772 'file://modules.txt'}
773 checkvars['LIC_FILES_CHKSUM'] = {'file://src/${GO_IMPORT}/LICENSE;md5=8f8bc924cf73f6a32381e5fd4c58d603'}
774
775 self.assertTrue(os.path.isfile(recipefile))
776 self._test_recipe_contents(recipefile, checkvars, inherits)
777
778 checkvars = {}
779 checkvars['VENDORED_LIC_FILES_CHKSUM'] = set(
780 ['file://src/${GO_IMPORT}/vendor/github.com/Microsoft/go-winio/LICENSE;md5=69205ff73858f2c22b2ca135b557e8ef',
781 'file://src/${GO_IMPORT}/vendor/github.com/armon/go-metrics/LICENSE;md5=d2d77030c0183e3d1e66d26dc1f243be',
782 'file://src/${GO_IMPORT}/vendor/github.com/cenkalti/backoff/LICENSE;md5=1571d94433e3f3aa05267efd4dbea68b',
783 'file://src/${GO_IMPORT}/vendor/github.com/davecgh/go-spew/LICENSE;md5=c06795ed54b2a35ebeeb543cd3a73e56',
784 'file://src/${GO_IMPORT}/vendor/github.com/eclipse/paho.mqtt.golang/LICENSE;md5=dcdb33474b60c38efd27356d8f2edec7',
785 'file://src/${GO_IMPORT}/vendor/github.com/eclipse/paho.mqtt.golang/edl-v10;md5=3adfcc70f5aeb7a44f3f9b495aa1fbf3',
786 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-bootstrap/v3/LICENSE;md5=0d6dae39976133b2851fba4c1e1275ff',
787 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-configuration/v3/LICENSE;md5=0d6dae39976133b2851fba4c1e1275ff',
788 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-core-contracts/v3/LICENSE;md5=0d6dae39976133b2851fba4c1e1275ff',
789 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-messaging/v3/LICENSE;md5=0d6dae39976133b2851fba4c1e1275ff',
790 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-registry/v3/LICENSE;md5=0d6dae39976133b2851fba4c1e1275ff',
791 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-secrets/v3/LICENSE;md5=f9fa2f4f8e0ef8cc7b5dd150963eb457',
792 'file://src/${GO_IMPORT}/vendor/github.com/fatih/color/LICENSE.md;md5=316e6d590bdcde7993fb175662c0dd5a',
793 'file://src/${GO_IMPORT}/vendor/github.com/fxamacker/cbor/v2/LICENSE;md5=827f5a2fa861382d35a3943adf9ebb86',
794 'file://src/${GO_IMPORT}/vendor/github.com/go-jose/go-jose/v3/LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57',
795 'file://src/${GO_IMPORT}/vendor/github.com/go-jose/go-jose/v3/json/LICENSE;md5=591778525c869cdde0ab5a1bf283cd81',
796 'file://src/${GO_IMPORT}/vendor/github.com/go-kit/log/LICENSE;md5=5b7c15ad5fffe2ff6e9d58a6c161f082',
797 'file://src/${GO_IMPORT}/vendor/github.com/go-logfmt/logfmt/LICENSE;md5=98e39517c38127f969de33057067091e',
798 'file://src/${GO_IMPORT}/vendor/github.com/go-playground/locales/LICENSE;md5=3ccbda375ee345400ad1da85ba522301',
799 'file://src/${GO_IMPORT}/vendor/github.com/go-playground/universal-translator/LICENSE;md5=2e2b21ef8f61057977d27c727c84bef1',
800 'file://src/${GO_IMPORT}/vendor/github.com/go-playground/validator/v10/LICENSE;md5=a718a0f318d76f7c5d510cbae84f0b60',
801 'file://src/${GO_IMPORT}/vendor/github.com/go-redis/redis/v7/LICENSE;md5=58103aa5ea1ee9b7a369c9c4a95ef9b5',
802 'file://src/${GO_IMPORT}/vendor/github.com/golang/protobuf/LICENSE;md5=939cce1ec101726fa754e698ac871622',
803 'file://src/${GO_IMPORT}/vendor/github.com/gomodule/redigo/LICENSE;md5=2ee41112a44fe7014dce33e26468ba93',
804 'file://src/${GO_IMPORT}/vendor/github.com/google/uuid/LICENSE;md5=88073b6dd8ec00fe09da59e0b6dfded1',
805 'file://src/${GO_IMPORT}/vendor/github.com/gorilla/mux/LICENSE;md5=33fa1116c45f9e8de714033f99edde13',
806 'file://src/${GO_IMPORT}/vendor/github.com/gorilla/websocket/LICENSE;md5=c007b54a1743d596f46b2748d9f8c044',
807 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/consul/api/LICENSE;md5=b8a277a612171b7526e9be072f405ef4',
808 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/errwrap/LICENSE;md5=b278a92d2c1509760384428817710378',
809 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/go-cleanhttp/LICENSE;md5=65d26fcc2f35ea6a181ac777e42db1ea',
810 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/go-hclog/LICENSE;md5=ec7f605b74b9ad03347d0a93a5cc7eb8',
811 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/go-immutable-radix/LICENSE;md5=65d26fcc2f35ea6a181ac777e42db1ea',
812 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/go-multierror/LICENSE;md5=d44fdeb607e2d2614db9464dbedd4094',
813 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/go-rootcerts/LICENSE;md5=65d26fcc2f35ea6a181ac777e42db1ea',
814 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/golang-lru/LICENSE;md5=f27a50d2e878867827842f2c60e30bfc',
815 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/serf/LICENSE;md5=b278a92d2c1509760384428817710378',
816 'file://src/${GO_IMPORT}/vendor/github.com/leodido/go-urn/LICENSE;md5=8f50db5538ec1148a9b3d14ed96c3418',
817 'file://src/${GO_IMPORT}/vendor/github.com/mattn/go-colorable/LICENSE;md5=24ce168f90aec2456a73de1839037245',
818 'file://src/${GO_IMPORT}/vendor/github.com/mattn/go-isatty/LICENSE;md5=f509beadd5a11227c27b5d2ad6c9f2c6',
819 'file://src/${GO_IMPORT}/vendor/github.com/mitchellh/consulstructure/LICENSE;md5=96ada10a9e51c98c4656f2cede08c673',
820 'file://src/${GO_IMPORT}/vendor/github.com/mitchellh/copystructure/LICENSE;md5=56da355a12d4821cda57b8f23ec34bc4',
821 'file://src/${GO_IMPORT}/vendor/github.com/mitchellh/go-homedir/LICENSE;md5=3f7765c3d4f58e1f84c4313cecf0f5bd',
822 'file://src/${GO_IMPORT}/vendor/github.com/mitchellh/mapstructure/LICENSE;md5=3f7765c3d4f58e1f84c4313cecf0f5bd',
823 'file://src/${GO_IMPORT}/vendor/github.com/mitchellh/reflectwalk/LICENSE;md5=3f7765c3d4f58e1f84c4313cecf0f5bd',
824 'file://src/${GO_IMPORT}/vendor/github.com/nats-io/nats.go/LICENSE;md5=86d3f3a95c324c9479bd8986968f4327',
825 'file://src/${GO_IMPORT}/vendor/github.com/nats-io/nkeys/LICENSE;md5=86d3f3a95c324c9479bd8986968f4327',
826 'file://src/${GO_IMPORT}/vendor/github.com/nats-io/nuid/LICENSE;md5=86d3f3a95c324c9479bd8986968f4327',
827 'file://src/${GO_IMPORT}/vendor/github.com/pmezard/go-difflib/LICENSE;md5=e9a2ebb8de779a07500ddecca806145e',
828 'file://src/${GO_IMPORT}/vendor/github.com/rcrowley/go-metrics/LICENSE;md5=1bdf5d819f50f141366dabce3be1460f',
829 'file://src/${GO_IMPORT}/vendor/github.com/spiffe/go-spiffe/v2/LICENSE;md5=86d3f3a95c324c9479bd8986968f4327',
830 'file://src/${GO_IMPORT}/vendor/github.com/stretchr/objx/LICENSE;md5=d023fd31d3ca39ec61eec65a91732735',
831 'file://src/${GO_IMPORT}/vendor/github.com/stretchr/testify/LICENSE;md5=188f01994659f3c0d310612333d2a26f',
832 'file://src/${GO_IMPORT}/vendor/github.com/x448/float16/LICENSE;md5=de8f8e025d57fe7ee0b67f30d571323b',
833 'file://src/${GO_IMPORT}/vendor/github.com/zeebo/errs/LICENSE;md5=84914ab36fc0eb48edbaa53e66e8d326',
834 'file://src/${GO_IMPORT}/vendor/golang.org/x/crypto/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
835 'file://src/${GO_IMPORT}/vendor/golang.org/x/mod/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
836 'file://src/${GO_IMPORT}/vendor/golang.org/x/net/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
837 'file://src/${GO_IMPORT}/vendor/golang.org/x/sync/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
838 'file://src/${GO_IMPORT}/vendor/golang.org/x/sys/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
839 'file://src/${GO_IMPORT}/vendor/golang.org/x/text/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
840 'file://src/${GO_IMPORT}/vendor/golang.org/x/tools/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
841 'file://src/${GO_IMPORT}/vendor/google.golang.org/genproto/LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57',
842 'file://src/${GO_IMPORT}/vendor/google.golang.org/grpc/LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57',
843 'file://src/${GO_IMPORT}/vendor/google.golang.org/protobuf/LICENSE;md5=02d4002e9171d41a8fad93aa7faf3956',
844 'file://src/${GO_IMPORT}/vendor/gopkg.in/eapache/queue.v1/LICENSE;md5=1bfd4408d3de090ef6b908b0cc45a316',
845 'file://src/${GO_IMPORT}/vendor/gopkg.in/yaml.v3/LICENSE;md5=3c91c17266710e16afdbb2b6d15c761c'])
846
847 self.assertTrue(os.path.isfile(lics_require_file))
848 self._test_recipe_contents(lics_require_file, checkvars, [])
849
850 dependencies = \
851 [ ('github.com/eclipse/paho.mqtt.golang','v1.4.2', '', '', ''),
852 ('github.com/edgexfoundry/go-mod-bootstrap','v3.0.1','github.com/edgexfoundry/go-mod-bootstrap/v3','/v3', ''),
853 ('github.com/edgexfoundry/go-mod-configuration','v3.0.0','github.com/edgexfoundry/go-mod-configuration/v3','/v3', ''),
854 ('github.com/edgexfoundry/go-mod-core-contracts','v3.0.0','github.com/edgexfoundry/go-mod-core-contracts/v3','/v3', ''),
855 ('github.com/edgexfoundry/go-mod-messaging','v3.0.0','github.com/edgexfoundry/go-mod-messaging/v3','/v3', ''),
856 ('github.com/edgexfoundry/go-mod-secrets','v3.0.1','github.com/edgexfoundry/go-mod-secrets/v3','/v3', ''),
857 ('github.com/fxamacker/cbor','v2.4.0','github.com/fxamacker/cbor/v2','/v2', ''),
858 ('github.com/gomodule/redigo','v1.8.9', '', '', ''),
859 ('github.com/google/uuid','v1.3.0', '', '', ''),
860 ('github.com/gorilla/mux','v1.8.0', '', '', ''),
861 ('github.com/rcrowley/go-metrics','v0.0.0-20201227073835-cf1acfcdf475', '', '', ''),
862 ('github.com/spiffe/go-spiffe','v2.1.4','github.com/spiffe/go-spiffe/v2','/v2', ''),
863 ('github.com/stretchr/testify','v1.8.2', '', '', ''),
864 ('go.googlesource.com/crypto','v0.8.0','golang.org/x/crypto', '', ''),
865 ('gopkg.in/eapache/queue.v1','v1.1.0', '', '', ''),
866 ('gopkg.in/yaml.v3','v3.0.1', '', '', ''),
867 ('github.com/microsoft/go-winio','v0.6.0','github.com/Microsoft/go-winio', '', ''),
868 ('github.com/hashicorp/go-metrics','v0.3.10','github.com/armon/go-metrics', '', ''),
869 ('github.com/cenkalti/backoff','v2.2.1+incompatible', '', '', ''),
870 ('github.com/davecgh/go-spew','v1.1.1', '', '', ''),
871 ('github.com/edgexfoundry/go-mod-registry','v3.0.0','github.com/edgexfoundry/go-mod-registry/v3','/v3', ''),
872 ('github.com/fatih/color','v1.9.0', '', '', ''),
873 ('github.com/go-jose/go-jose','v3.0.0','github.com/go-jose/go-jose/v3','/v3', ''),
874 ('github.com/go-kit/log','v0.2.1', '', '', ''),
875 ('github.com/go-logfmt/logfmt','v0.5.1', '', '', ''),
876 ('github.com/go-playground/locales','v0.14.1', '', '', ''),
877 ('github.com/go-playground/universal-translator','v0.18.1', '', '', ''),
878 ('github.com/go-playground/validator','v10.13.0','github.com/go-playground/validator/v10','/v10', ''),
879 ('github.com/go-redis/redis','v7.3.0','github.com/go-redis/redis/v7','/v7', ''),
880 ('github.com/golang/protobuf','v1.5.2', '', '', ''),
881 ('github.com/gorilla/websocket','v1.4.2', '', '', ''),
882 ('github.com/hashicorp/consul','v1.20.0','github.com/hashicorp/consul/api', '', 'api'),
883 ('github.com/hashicorp/errwrap','v1.0.0', '', '', ''),
884 ('github.com/hashicorp/go-cleanhttp','v0.5.1', '', '', ''),
885 ('github.com/hashicorp/go-hclog','v0.14.1', '', '', ''),
886 ('github.com/hashicorp/go-immutable-radix','v1.3.0', '', '', ''),
887 ('github.com/hashicorp/go-multierror','v1.1.1', '', '', ''),
888 ('github.com/hashicorp/go-rootcerts','v1.0.2', '', '', ''),
889 ('github.com/hashicorp/golang-lru','v0.5.4', '', '', ''),
890 ('github.com/hashicorp/serf','v0.10.1', '', '', ''),
891 ('github.com/leodido/go-urn','v1.2.3', '', '', ''),
892 ('github.com/mattn/go-colorable','v0.1.12', '', '', ''),
893 ('github.com/mattn/go-isatty','v0.0.14', '', '', ''),
894 ('github.com/mitchellh/consulstructure','v0.0.0-20190329231841-56fdc4d2da54', '', '', ''),
895 ('github.com/mitchellh/copystructure','v1.2.0', '', '', ''),
896 ('github.com/mitchellh/go-homedir','v1.1.0', '', '', ''),
897 ('github.com/mitchellh/mapstructure','v1.5.0', '', '', ''),
898 ('github.com/mitchellh/reflectwalk','v1.0.2', '', '', ''),
899 ('github.com/nats-io/nats.go','v1.25.0', '', '', ''),
900 ('github.com/nats-io/nkeys','v0.4.4', '', '', ''),
901 ('github.com/nats-io/nuid','v1.0.1', '', '', ''),
902 ('github.com/pmezard/go-difflib','v1.0.0', '', '', ''),
903 ('github.com/stretchr/objx','v0.5.0', '', '', ''),
904 ('github.com/x448/float16','v0.8.4', '', '', ''),
905 ('github.com/zeebo/errs','v1.3.0', '', '', ''),
906 ('go.googlesource.com/mod','v0.8.0','golang.org/x/mod', '', ''),
907 ('go.googlesource.com/net','v0.9.0','golang.org/x/net', '', ''),
908 ('go.googlesource.com/sync','v0.1.0','golang.org/x/sync', '', ''),
909 ('go.googlesource.com/sys','v0.7.0','golang.org/x/sys', '', ''),
910 ('go.googlesource.com/text','v0.9.0','golang.org/x/text', '', ''),
911 ('go.googlesource.com/tools','v0.6.0','golang.org/x/tools', '', ''),
912 ('github.com/googleapis/go-genproto','v0.0.0-20230223222841-637eb2293923','google.golang.org/genproto', '', ''),
913 ('github.com/grpc/grpc-go','v1.53.0','google.golang.org/grpc', '', ''),
914 ('go.googlesource.com/protobuf','v1.28.1','google.golang.org/protobuf', '', ''),
915 ]
916
917 src_uri = set()
918 for d in dependencies:
Patrick Williams56b44a92024-01-19 08:49:29 -0600919 src_uri.add(self._go_urifiy(*d))
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600920
921 checkvars = {}
922 checkvars['GO_DEPENDENCIES_SRC_URI'] = src_uri
923
924 self.assertTrue(os.path.isfile(deps_require_file))
925 self._test_recipe_contents(deps_require_file, checkvars, [])
926
Patrick Williams56b44a92024-01-19 08:49:29 -0600927 def test_recipetool_create_go_replace_modules(self):
928 # Check handling of replaced modules
929 temprecipe = os.path.join(self.tempdir, 'recipe')
930 os.makedirs(temprecipe)
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600931
Patrick Williams56b44a92024-01-19 08:49:29 -0600932 recipefile = os.path.join(temprecipe, 'openapi-generator_git.bb')
933 deps_require_file = os.path.join(temprecipe, 'openapi-generator', 'go-modules.inc')
934 lics_require_file = os.path.join(temprecipe, 'openapi-generator', 'go-licenses.inc')
935 modules_txt_file = os.path.join(temprecipe, 'openapi-generator', 'modules.txt')
936
937 srcuri = 'https://github.com/OpenAPITools/openapi-generator.git'
938 srcrev = "v7.2.0"
939 srcbranch = "master"
940 srcsubdir = "samples/openapi3/client/petstore/go"
941
942 result = runCmd('recipetool create -o %s %s -S %s -B %s --src-subdir %s' % (temprecipe, srcuri, srcrev, srcbranch, srcsubdir))
943
944 self.maxDiff = None
945 inherits = ['go-vendor']
946
947 checkvars = {}
948 checkvars['GO_IMPORT'] = "github.com/OpenAPITools/openapi-generator/samples/openapi3/client/petstore/go"
949 checkvars['SRC_URI'] = {'git://${GO_IMPORT};destsuffix=git/src/${GO_IMPORT};nobranch=1;name=${BPN};protocol=https',
950 'file://modules.txt'}
951
952 self.assertNotIn('Traceback', result.output)
953 self.assertIn('No license file was detected for the main module', result.output)
954 self.assertTrue(os.path.isfile(recipefile))
955 self._test_recipe_contents(recipefile, checkvars, inherits)
956
957 # make sure that dependencies don't mention local directory ./go-petstore
958 dependencies = \
959 [ ('github.com/stretchr/testify','v1.8.4', '', '', ''),
960 ('go.googlesource.com/oauth2','v0.10.0','golang.org/x/oauth2', '', ''),
961 ('github.com/davecgh/go-spew','v1.1.1', '', '', ''),
962 ('github.com/golang/protobuf','v1.5.3', '', '', ''),
963 ('github.com/kr/pretty','v0.3.0', '', '', ''),
964 ('github.com/pmezard/go-difflib','v1.0.0', '', '', ''),
965 ('github.com/rogpeppe/go-internal','v1.9.0', '', '', ''),
966 ('go.googlesource.com/net','v0.12.0','golang.org/x/net', '', ''),
967 ('github.com/golang/appengine','v1.6.7','google.golang.org/appengine', '', ''),
968 ('go.googlesource.com/protobuf','v1.31.0','google.golang.org/protobuf', '', ''),
969 ('gopkg.in/check.v1','v1.0.0-20201130134442-10cb98267c6c', '', '', ''),
970 ('gopkg.in/yaml.v3','v3.0.1', '', '', ''),
971 ]
972
973 src_uri = set()
974 for d in dependencies:
975 src_uri.add(self._go_urifiy(*d))
976
977 checkvars = {}
978 checkvars['GO_DEPENDENCIES_SRC_URI'] = src_uri
979
980 self.assertTrue(os.path.isfile(deps_require_file))
981 self._test_recipe_contents(deps_require_file, checkvars, [])
982
983class RecipetoolTests(RecipetoolBase):
984
985 @classmethod
986 def setUpClass(cls):
987 import sys
988
989 super(RecipetoolTests, cls).setUpClass()
990 bb_vars = get_bb_vars(['BBPATH'])
991 cls.bbpath = bb_vars['BBPATH']
992 libpath = os.path.join(get_bb_var('COREBASE'), 'scripts', 'lib', 'recipetool')
993 sys.path.insert(0, libpath)
Patrick Williams169d7bc2024-01-05 11:33:25 -0600994
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500995 def _copy_file_with_cleanup(self, srcfile, basedstdir, *paths):
996 dstdir = basedstdir
997 self.assertTrue(os.path.exists(dstdir))
998 for p in paths:
999 dstdir = os.path.join(dstdir, p)
1000 if not os.path.exists(dstdir):
Patrick Williams169d7bc2024-01-05 11:33:25 -06001001 try:
1002 os.makedirs(dstdir)
1003 except PermissionError:
1004 return False
1005 except OSError as e:
1006 if e.errno == errno.EROFS:
1007 return False
1008 else:
1009 raise e
Andrew Geissler475cb722020-07-10 16:00:51 -05001010 if p == "lib":
1011 # Can race with other tests
1012 self.add_command_to_tearDown('rmdir --ignore-fail-on-non-empty %s' % dstdir)
1013 else:
1014 self.track_for_cleanup(dstdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001015 dstfile = os.path.join(dstdir, os.path.basename(srcfile))
1016 if srcfile != dstfile:
Patrick Williams169d7bc2024-01-05 11:33:25 -06001017 try:
1018 shutil.copy(srcfile, dstfile)
1019 except PermissionError:
1020 return False
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001021 self.track_for_cleanup(dstfile)
Patrick Williams169d7bc2024-01-05 11:33:25 -06001022 return True
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001023
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001024 def test_recipetool_load_plugin(self):
1025 """Test that recipetool loads only the first found plugin in BBPATH."""
1026
1027 recipetool = runCmd("which recipetool")
1028 fromname = runCmd("recipetool --quiet pluginfile")
1029 srcfile = fromname.output
1030 searchpath = self.bbpath.split(':') + [os.path.dirname(recipetool.output)]
1031 plugincontent = []
1032 with open(srcfile) as fh:
1033 plugincontent = fh.readlines()
1034 try:
1035 self.assertIn('meta-selftest', srcfile, 'wrong bbpath plugin found')
Patrick Williams169d7bc2024-01-05 11:33:25 -06001036 searchpath = [
1037 path for path in searchpath
1038 if self._copy_file_with_cleanup(srcfile, path, 'lib', 'recipetool')
1039 ]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001040 result = runCmd("recipetool --quiet count")
1041 self.assertEqual(result.output, '1')
1042 result = runCmd("recipetool --quiet multiloaded")
1043 self.assertEqual(result.output, "no")
1044 for path in searchpath:
1045 result = runCmd("recipetool --quiet bbdir")
Patrick Williams169d7bc2024-01-05 11:33:25 -06001046 self.assertEqual(os.path.realpath(result.output), os.path.realpath(path))
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001047 os.unlink(os.path.join(result.output, 'lib', 'recipetool', 'bbpath.py'))
1048 finally:
1049 with open(srcfile, 'w') as fh:
1050 fh.writelines(plugincontent)
1051
Andrew Geissler595f6302022-01-24 19:11:47 +00001052 def test_recipetool_handle_license_vars(self):
1053 from create import handle_license_vars
1054 from unittest.mock import Mock
1055
1056 commonlicdir = get_bb_var('COMMON_LICENSE_DIR')
1057
Andrew Geisslerfc113ea2023-03-31 09:59:46 -05001058 class DataConnectorCopy(bb.tinfoil.TinfoilDataStoreConnector):
1059 pass
1060
1061 d = DataConnectorCopy
Andrew Geissler595f6302022-01-24 19:11:47 +00001062 d.getVar = Mock(return_value=commonlicdir)
1063
1064 srctree = tempfile.mkdtemp(prefix='recipetoolqa')
1065 self.track_for_cleanup(srctree)
1066
1067 # Multiple licenses
1068 licenses = ['MIT', 'ISC', 'BSD-3-Clause', 'Apache-2.0']
1069 for licence in licenses:
1070 shutil.copy(os.path.join(commonlicdir, licence), os.path.join(srctree, 'LICENSE.' + licence))
1071 # Duplicate license
1072 shutil.copy(os.path.join(commonlicdir, 'MIT'), os.path.join(srctree, 'LICENSE'))
1073
1074 extravalues = {
1075 # Duplicate and missing licenses
1076 'LICENSE': 'Zlib & BSD-2-Clause & Zlib',
1077 'LIC_FILES_CHKSUM': [
1078 'file://README.md;md5=0123456789abcdef0123456789abcd'
1079 ]
1080 }
1081 lines_before = []
1082 handled = []
1083 licvalues = handle_license_vars(srctree, lines_before, handled, extravalues, d)
1084 expected_lines_before = [
1085 '# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is',
1086 '# your responsibility to verify that the values are complete and correct.',
1087 '# NOTE: Original package / source metadata indicates license is: BSD-2-Clause & Zlib',
1088 '#',
1089 '# NOTE: multiple licenses have been detected; they have been separated with &',
1090 '# in the LICENSE value for now since it is a reasonable assumption that all',
1091 '# of the licenses apply. If instead there is a choice between the multiple',
1092 '# licenses then you should change the value to separate the licenses with |',
1093 '# instead of &. If there is any doubt, check the accompanying documentation',
1094 '# to determine which situation is applicable.',
1095 'LICENSE = "Apache-2.0 & BSD-2-Clause & BSD-3-Clause & ISC & MIT & Zlib"',
1096 'LIC_FILES_CHKSUM = "file://LICENSE;md5=0835ade698e0bcf8506ecda2f7b4f302 \\\n'
1097 ' file://LICENSE.Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10 \\\n'
1098 ' file://LICENSE.BSD-3-Clause;md5=550794465ba0ec5312d6919e203a55f9 \\\n'
1099 ' file://LICENSE.ISC;md5=f3b90e78ea0cffb20bf5cca7947a896d \\\n'
1100 ' file://LICENSE.MIT;md5=0835ade698e0bcf8506ecda2f7b4f302 \\\n'
1101 ' file://README.md;md5=0123456789abcdef0123456789abcd"',
1102 ''
1103 ]
1104 self.assertEqual(lines_before, expected_lines_before)
1105 expected_licvalues = [
1106 ('MIT', 'LICENSE', '0835ade698e0bcf8506ecda2f7b4f302'),
1107 ('Apache-2.0', 'LICENSE.Apache-2.0', '89aea4e17d99a7cacdbeed46a0096b10'),
1108 ('BSD-3-Clause', 'LICENSE.BSD-3-Clause', '550794465ba0ec5312d6919e203a55f9'),
1109 ('ISC', 'LICENSE.ISC', 'f3b90e78ea0cffb20bf5cca7947a896d'),
1110 ('MIT', 'LICENSE.MIT', '0835ade698e0bcf8506ecda2f7b4f302')
1111 ]
1112 self.assertEqual(handled, [('license', expected_licvalues)])
1113 self.assertEqual(extravalues, {})
1114 self.assertEqual(licvalues, expected_licvalues)
1115
1116
1117 def test_recipetool_split_pkg_licenses(self):
1118 from create import split_pkg_licenses
1119 licvalues = [
1120 # Duplicate licenses
1121 ('BSD-2-Clause', 'x/COPYING', None),
1122 ('BSD-2-Clause', 'x/LICENSE', None),
1123 # Multiple licenses
1124 ('MIT', 'x/a/LICENSE.MIT', None),
1125 ('ISC', 'x/a/LICENSE.ISC', None),
1126 # Alternative licenses
1127 ('(MIT | ISC)', 'x/b/LICENSE', None),
1128 # Alternative licenses without brackets
1129 ('MIT | BSD-2-Clause', 'x/c/LICENSE', None),
1130 # Multi licenses with alternatives
1131 ('MIT', 'x/d/COPYING', None),
1132 ('MIT | BSD-2-Clause', 'x/d/LICENSE', None),
1133 # Multi licenses with alternatives and brackets
1134 ('Apache-2.0 & ((MIT | ISC) & BSD-3-Clause)', 'x/e/LICENSE', None)
1135 ]
1136 packages = {
1137 '${PN}': '',
1138 'a': 'x/a',
1139 'b': 'x/b',
1140 'c': 'x/c',
1141 'd': 'x/d',
1142 'e': 'x/e',
1143 'f': 'x/f',
1144 'g': 'x/g',
1145 }
1146 fallback_licenses = {
1147 # Ignored
1148 'a': 'BSD-3-Clause',
1149 # Used
1150 'f': 'BSD-3-Clause'
1151 }
1152 outlines = []
1153 outlicenses = split_pkg_licenses(licvalues, packages, outlines, fallback_licenses)
1154 expected_outlicenses = {
1155 '${PN}': ['BSD-2-Clause'],
1156 'a': ['ISC', 'MIT'],
1157 'b': ['(ISC | MIT)'],
1158 'c': ['(BSD-2-Clause | MIT)'],
1159 'd': ['(BSD-2-Clause | MIT)', 'MIT'],
1160 'e': ['(ISC | MIT)', 'Apache-2.0', 'BSD-3-Clause'],
1161 'f': ['BSD-3-Clause'],
1162 'g': ['Unknown']
1163 }
1164 self.assertEqual(outlicenses, expected_outlicenses)
1165 expected_outlines = [
1166 'LICENSE:${PN} = "BSD-2-Clause"',
1167 'LICENSE:a = "ISC & MIT"',
1168 'LICENSE:b = "(ISC | MIT)"',
1169 'LICENSE:c = "(BSD-2-Clause | MIT)"',
1170 'LICENSE:d = "(BSD-2-Clause | MIT) & MIT"',
1171 'LICENSE:e = "(ISC | MIT) & Apache-2.0 & BSD-3-Clause"',
1172 'LICENSE:f = "BSD-3-Clause"',
1173 'LICENSE:g = "Unknown"'
1174 ]
1175 self.assertEqual(outlines, expected_outlines)
1176
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001177
1178class RecipetoolAppendsrcBase(RecipetoolBase):
1179 def _try_recipetool_appendsrcfile(self, testrecipe, newfile, destfile, options, expectedlines, expectedfiles):
1180 cmd = 'recipetool appendsrcfile %s %s %s %s %s' % (options, self.templayerdir, testrecipe, newfile, destfile)
1181 return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
1182
1183 def _try_recipetool_appendsrcfiles(self, testrecipe, newfiles, expectedlines=None, expectedfiles=None, destdir=None, options=''):
1184
1185 if destdir:
1186 options += ' -D %s' % destdir
1187
1188 if expectedfiles is None:
1189 expectedfiles = [os.path.basename(f) for f in newfiles]
1190
1191 cmd = 'recipetool appendsrcfiles %s %s %s %s' % (options, self.templayerdir, testrecipe, ' '.join(newfiles))
1192 return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
1193
1194 def _try_recipetool_appendsrcfile_fail(self, testrecipe, newfile, destfile, checkerror):
1195 cmd = 'recipetool appendsrcfile %s %s %s %s' % (self.templayerdir, testrecipe, newfile, destfile or '')
1196 result = runCmd(cmd, ignore_status=True)
1197 self.assertNotEqual(result.status, 0, 'Command "%s" should have failed but didn\'t' % cmd)
1198 self.assertNotIn('Traceback', result.output)
1199 for errorstr in checkerror:
1200 self.assertIn(errorstr, result.output)
1201
1202 @staticmethod
1203 def _get_first_file_uri(recipe):
1204 '''Return the first file:// in SRC_URI for the specified recipe.'''
1205 src_uri = get_bb_var('SRC_URI', recipe).split()
1206 for uri in src_uri:
1207 p = urllib.parse.urlparse(uri)
1208 if p.scheme == 'file':
Patrick Williams169d7bc2024-01-05 11:33:25 -06001209 return p.netloc + p.path, uri
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001210
Patrick Williams169d7bc2024-01-05 11:33:25 -06001211 def _test_appendsrcfile(self, testrecipe, filename=None, destdir=None, has_src_uri=True, srcdir=None, newfile=None, remove=None, machine=None , options=''):
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001212 if newfile is None:
1213 newfile = self.testfile
1214
1215 if srcdir:
1216 if destdir:
1217 expected_subdir = os.path.join(srcdir, destdir)
1218 else:
1219 expected_subdir = srcdir
1220 else:
1221 options += " -W"
1222 expected_subdir = destdir
1223
1224 if filename:
1225 if destdir:
1226 destpath = os.path.join(destdir, filename)
1227 else:
1228 destpath = filename
1229 else:
1230 filename = os.path.basename(newfile)
1231 if destdir:
1232 destpath = destdir + os.sep
1233 else:
1234 destpath = '.' + os.sep
1235
Patrick Williams213cb262021-08-07 19:21:33 -05001236 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001237 '\n']
Patrick Williams169d7bc2024-01-05 11:33:25 -06001238
1239 override = ""
1240 if machine:
1241 options += ' -m %s' % machine
1242 override = ':append:%s' % machine
1243 expectedlines.extend(['PACKAGE_ARCH = "${MACHINE_ARCH}"\n',
1244 '\n'])
1245
1246 if remove:
1247 for entry in remove:
1248 if machine:
1249 entry_remove_line = 'SRC_URI:remove:%s = " %s"\n' % (machine, entry)
1250 else:
1251 entry_remove_line = 'SRC_URI:remove = "%s"\n' % entry
1252
1253 expectedlines.extend([entry_remove_line,
1254 '\n'])
1255
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001256 if has_src_uri:
1257 uri = 'file://%s' % filename
1258 if expected_subdir:
1259 uri += ';subdir=%s' % expected_subdir
Patrick Williams169d7bc2024-01-05 11:33:25 -06001260 if machine:
1261 src_uri_line = 'SRC_URI%s = " %s"\n' % (override, uri)
1262 else:
1263 src_uri_line = 'SRC_URI += "%s"\n' % uri
1264
1265 expectedlines.extend([src_uri_line, '\n'])
1266
1267 with open("/tmp/tmp.txt", "w") as file:
1268 print(expectedlines, file=file)
1269
1270 if machine:
1271 filename = '%s/%s' % (machine, filename)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001272
1273 return self._try_recipetool_appendsrcfile(testrecipe, newfile, destpath, options, expectedlines, [filename])
1274
1275 def _test_appendsrcfiles(self, testrecipe, newfiles, expectedfiles=None, destdir=None, options=''):
1276 if expectedfiles is None:
1277 expectedfiles = [os.path.basename(n) for n in newfiles]
1278
1279 self._try_recipetool_appendsrcfiles(testrecipe, newfiles, expectedfiles=expectedfiles, destdir=destdir, options=options)
1280
1281 bb_vars = get_bb_vars(['SRC_URI', 'FILE', 'FILESEXTRAPATHS'], testrecipe)
1282 src_uri = bb_vars['SRC_URI'].split()
1283 for f in expectedfiles:
1284 if destdir:
1285 self.assertIn('file://%s;subdir=%s' % (f, destdir), src_uri)
1286 else:
1287 self.assertIn('file://%s' % f, src_uri)
1288
1289 recipefile = bb_vars['FILE']
1290 bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir)
1291 filesdir = os.path.join(os.path.dirname(bbappendfile), testrecipe)
1292 filesextrapaths = bb_vars['FILESEXTRAPATHS'].split(':')
1293 self.assertIn(filesdir, filesextrapaths)
1294
1295
1296
1297
1298class RecipetoolAppendsrcTests(RecipetoolAppendsrcBase):
1299
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001300 def test_recipetool_appendsrcfile_basic(self):
1301 self._test_appendsrcfile('base-files', 'a-file')
1302
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001303 def test_recipetool_appendsrcfile_basic_wildcard(self):
1304 testrecipe = 'base-files'
1305 self._test_appendsrcfile(testrecipe, 'a-file', options='-w')
1306 recipefile = get_bb_var('FILE', testrecipe)
1307 bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir)
1308 self.assertEqual(os.path.basename(bbappendfile), '%s_%%.bbappend' % testrecipe)
1309
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001310 def test_recipetool_appendsrcfile_subdir_basic(self):
1311 self._test_appendsrcfile('base-files', 'a-file', 'tmp')
1312
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001313 def test_recipetool_appendsrcfile_subdir_basic_dirdest(self):
1314 self._test_appendsrcfile('base-files', destdir='tmp')
1315
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001316 def test_recipetool_appendsrcfile_srcdir_basic(self):
1317 testrecipe = 'bash'
1318 bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe)
1319 srcdir = bb_vars['S']
1320 workdir = bb_vars['WORKDIR']
1321 subdir = os.path.relpath(srcdir, workdir)
1322 self._test_appendsrcfile(testrecipe, 'a-file', srcdir=subdir)
1323
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001324 def test_recipetool_appendsrcfile_existing_in_src_uri(self):
1325 testrecipe = 'base-files'
Patrick Williams169d7bc2024-01-05 11:33:25 -06001326 filepath,_ = self._get_first_file_uri(testrecipe)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001327 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe)
1328 self._test_appendsrcfile(testrecipe, filepath, has_src_uri=False)
1329
Patrick Williams169d7bc2024-01-05 11:33:25 -06001330 def test_recipetool_appendsrcfile_existing_in_src_uri_diff_params(self, machine=None):
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001331 testrecipe = 'base-files'
1332 subdir = 'tmp'
Patrick Williams169d7bc2024-01-05 11:33:25 -06001333 filepath, srcuri_entry = self._get_first_file_uri(testrecipe)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001334 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe)
1335
Patrick Williams169d7bc2024-01-05 11:33:25 -06001336 self._test_appendsrcfile(testrecipe, filepath, subdir, machine=machine, remove=[srcuri_entry])
1337
1338 def test_recipetool_appendsrcfile_machine(self):
1339 # A very basic test
1340 self._test_appendsrcfile('base-files', 'a-file', machine='mymachine')
1341
1342 # Force cleaning the output of previous test
1343 self.tearDownLocal()
1344
1345 # A more complex test: existing entry in src_uri with different param
1346 self.test_recipetool_appendsrcfile_existing_in_src_uri_diff_params(machine='mymachine')
1347
1348 def test_recipetool_appendsrcfile_update_recipe_basic(self):
1349 testrecipe = "mtd-utils-selftest"
1350 recipefile = get_bb_var('FILE', testrecipe)
1351 self.assertIn('meta-selftest', recipefile, 'This test expect %s recipe to be in meta-selftest')
1352 cmd = 'recipetool appendsrcfile -W -u meta-selftest %s %s' % (testrecipe, self.testfile)
1353 result = runCmd(cmd)
1354 self.assertNotIn('Traceback', result.output)
1355 self.add_command_to_tearDown('cd %s; rm -f %s/%s; git checkout .' % (os.path.dirname(recipefile), testrecipe, os.path.basename(self.testfile)))
1356
1357 expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)),
1358 ('??', '.*/%s/%s$' % (testrecipe, os.path.basename(self.testfile)))]
1359 self._check_repo_status(os.path.dirname(recipefile), expected_status)
1360 result = runCmd('git diff %s' % os.path.basename(recipefile), cwd=os.path.dirname(recipefile))
1361 removelines = []
1362 addlines = [
1363 'file://%s \\\\' % os.path.basename(self.testfile),
1364 ]
1365 self._check_diff(result.output, addlines, removelines)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001366
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001367 def test_recipetool_appendsrcfile_replace_file_srcdir(self):
1368 testrecipe = 'bash'
1369 filepath = 'Makefile.in'
1370 bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe)
1371 srcdir = bb_vars['S']
1372 workdir = bb_vars['WORKDIR']
1373 subdir = os.path.relpath(srcdir, workdir)
1374
1375 self._test_appendsrcfile(testrecipe, filepath, srcdir=subdir)
1376 bitbake('%s:do_unpack' % testrecipe)
Brad Bishop64c979e2019-11-04 13:55:29 -05001377 with open(self.testfile, 'r') as testfile:
1378 with open(os.path.join(srcdir, filepath), 'r') as makefilein:
1379 self.assertEqual(testfile.read(), makefilein.read())
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001380
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001381 def test_recipetool_appendsrcfiles_basic(self, destdir=None):
1382 newfiles = [self.testfile]
1383 for i in range(1, 5):
1384 testfile = os.path.join(self.tempdir, 'testfile%d' % i)
1385 with open(testfile, 'w') as f:
1386 f.write('Test file %d\n' % i)
1387 newfiles.append(testfile)
1388 self._test_appendsrcfiles('gcc', newfiles, destdir=destdir, options='-W')
1389
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001390 def test_recipetool_appendsrcfiles_basic_subdir(self):
1391 self.test_recipetool_appendsrcfiles_basic(destdir='testdir')