blob: 0c296875b2398617db06fc6cae7a52e9a1ca0462 [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
Andrew Geissler595f6302022-01-24 19:11:47 +000031class RecipetoolBase(devtool.DevtoolTestCase):
Brad Bishopd7bf8c12018-02-25 22:55:05 -050032
33 def setUpLocal(self):
34 super(RecipetoolBase, self).setUpLocal()
35 self.templayerdir = templayerdir
36 self.tempdir = tempfile.mkdtemp(prefix='recipetoolqa')
37 self.track_for_cleanup(self.tempdir)
38 self.testfile = os.path.join(self.tempdir, 'testfile')
39 with open(self.testfile, 'w') as f:
40 f.write('Test file\n')
41
42 def tearDownLocal(self):
43 runCmd('rm -rf %s/recipes-*' % self.templayerdir)
44 super(RecipetoolBase, self).tearDownLocal()
45
46 def _try_recipetool_appendcmd(self, cmd, testrecipe, expectedfiles, expectedlines=None):
47 result = runCmd(cmd)
48 self.assertNotIn('Traceback', result.output)
49
50 # Check the bbappend was created and applies properly
51 recipefile = get_bb_var('FILE', testrecipe)
52 bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir)
53
54 # Check the bbappend contents
55 if expectedlines is not None:
56 with open(bbappendfile, 'r') as f:
57 self.assertEqual(expectedlines, f.readlines(), "Expected lines are not present in %s" % bbappendfile)
58
59 # Check file was copied
60 filesdir = os.path.join(os.path.dirname(bbappendfile), testrecipe)
61 for expectedfile in expectedfiles:
62 self.assertTrue(os.path.isfile(os.path.join(filesdir, expectedfile)), 'Expected file %s to be copied next to bbappend, but it wasn\'t' % expectedfile)
63
64 # Check no other files created
65 createdfiles = []
66 for root, _, files in os.walk(filesdir):
67 for f in files:
68 createdfiles.append(os.path.relpath(os.path.join(root, f), filesdir))
69 self.assertTrue(sorted(createdfiles), sorted(expectedfiles))
70
71 return bbappendfile, result.output
72
73
Andrew Geissler595f6302022-01-24 19:11:47 +000074class RecipetoolAppendTests(RecipetoolBase):
Brad Bishopd7bf8c12018-02-25 22:55:05 -050075
76 @classmethod
77 def setUpClass(cls):
Andrew Geissler595f6302022-01-24 19:11:47 +000078 super(RecipetoolAppendTests, cls).setUpClass()
Brad Bishopd7bf8c12018-02-25 22:55:05 -050079 # Ensure we have the right data in shlibs/pkgdata
80 cls.logger.info('Running bitbake to generate pkgdata')
81 bitbake('-c packagedata base-files coreutils busybox selftest-recipetool-appendfile')
Andrew Geissler595f6302022-01-24 19:11:47 +000082 bb_vars = get_bb_vars(['COREBASE'])
Brad Bishopd7bf8c12018-02-25 22:55:05 -050083 cls.corebase = bb_vars['COREBASE']
Brad Bishopd7bf8c12018-02-25 22:55:05 -050084
85 def _try_recipetool_appendfile(self, testrecipe, destfile, newfile, options, expectedlines, expectedfiles):
86 cmd = 'recipetool appendfile %s %s %s %s' % (self.templayerdir, destfile, newfile, options)
87 return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
88
89 def _try_recipetool_appendfile_fail(self, destfile, newfile, checkerror):
90 cmd = 'recipetool appendfile %s %s %s' % (self.templayerdir, destfile, newfile)
91 result = runCmd(cmd, ignore_status=True)
92 self.assertNotEqual(result.status, 0, 'Command "%s" should have failed but didn\'t' % cmd)
93 self.assertNotIn('Traceback', result.output)
94 for errorstr in checkerror:
95 self.assertIn(errorstr, result.output)
96
Brad Bishopd7bf8c12018-02-25 22:55:05 -050097 def test_recipetool_appendfile_basic(self):
98 # Basic test
Patrick Williams213cb262021-08-07 19:21:33 -050099 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500100 '\n']
101 _, output = self._try_recipetool_appendfile('base-files', '/etc/motd', self.testfile, '', expectedlines, ['motd'])
102 self.assertNotIn('WARNING: ', output)
103
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500104 def test_recipetool_appendfile_invalid(self):
105 # Test some commands that should error
106 self._try_recipetool_appendfile_fail('/etc/passwd', self.testfile, ['ERROR: /etc/passwd cannot be handled by this tool', 'useradd', 'extrausers'])
107 self._try_recipetool_appendfile_fail('/etc/timestamp', self.testfile, ['ERROR: /etc/timestamp cannot be handled by this tool'])
108 self._try_recipetool_appendfile_fail('/dev/console', self.testfile, ['ERROR: /dev/console cannot be handled by this tool'])
109
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500110 def test_recipetool_appendfile_alternatives(self):
111 # Now try with a file we know should be an alternative
112 # (this is very much a fake example, but one we know is reliably an alternative)
113 self._try_recipetool_appendfile_fail('/bin/ls', self.testfile, ['ERROR: File /bin/ls is an alternative possibly provided by the following recipes:', 'coreutils', 'busybox'])
114 # Need a test file - should be executable
115 testfile2 = os.path.join(self.corebase, 'oe-init-build-env')
116 testfile2name = os.path.basename(testfile2)
Patrick Williams213cb262021-08-07 19:21:33 -0500117 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500118 '\n',
119 'SRC_URI += "file://%s"\n' % testfile2name,
120 '\n',
Patrick Williams213cb262021-08-07 19:21:33 -0500121 'do_install:append() {\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500122 ' install -d ${D}${base_bindir}\n',
123 ' install -m 0755 ${WORKDIR}/%s ${D}${base_bindir}/ls\n' % testfile2name,
124 '}\n']
125 self._try_recipetool_appendfile('coreutils', '/bin/ls', testfile2, '-r coreutils', expectedlines, [testfile2name])
126 # Now try bbappending the same file again, contents should not change
127 bbappendfile, _ = self._try_recipetool_appendfile('coreutils', '/bin/ls', self.testfile, '-r coreutils', expectedlines, [testfile2name])
128 # But file should have
129 copiedfile = os.path.join(os.path.dirname(bbappendfile), 'coreutils', testfile2name)
130 result = runCmd('diff -q %s %s' % (testfile2, copiedfile), ignore_status=True)
131 self.assertNotEqual(result.status, 0, 'New file should have been copied but was not %s' % result.output)
132
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500133 def test_recipetool_appendfile_binary(self):
134 # Try appending a binary file
135 # /bin/ls can be a symlink to /usr/bin/ls
136 ls = os.path.realpath("/bin/ls")
137 result = runCmd('recipetool appendfile %s /bin/ls %s -r coreutils' % (self.templayerdir, ls))
138 self.assertIn('WARNING: ', result.output)
139 self.assertIn('is a binary', result.output)
140
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500141 def test_recipetool_appendfile_add(self):
142 # Try arbitrary file add to a recipe
Patrick Williams213cb262021-08-07 19:21:33 -0500143 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500144 '\n',
145 'SRC_URI += "file://testfile"\n',
146 '\n',
Patrick Williams213cb262021-08-07 19:21:33 -0500147 'do_install:append() {\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500148 ' install -d ${D}${datadir}\n',
149 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n',
150 '}\n']
151 self._try_recipetool_appendfile('netbase', '/usr/share/something', self.testfile, '-r netbase', expectedlines, ['testfile'])
152 # Try adding another file, this time where the source file is executable
153 # (so we're testing that, plus modifying an existing bbappend)
154 testfile2 = os.path.join(self.corebase, 'oe-init-build-env')
155 testfile2name = os.path.basename(testfile2)
Patrick Williams213cb262021-08-07 19:21:33 -0500156 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500157 '\n',
158 'SRC_URI += "file://testfile \\\n',
159 ' file://%s \\\n' % testfile2name,
160 ' "\n',
161 '\n',
Patrick Williams213cb262021-08-07 19:21:33 -0500162 'do_install:append() {\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500163 ' install -d ${D}${datadir}\n',
164 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n',
165 ' install -m 0755 ${WORKDIR}/%s ${D}${datadir}/scriptname\n' % testfile2name,
166 '}\n']
167 self._try_recipetool_appendfile('netbase', '/usr/share/scriptname', testfile2, '-r netbase', expectedlines, ['testfile', testfile2name])
168
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500169 def test_recipetool_appendfile_add_bindir(self):
170 # 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 -0500171 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500172 '\n',
173 'SRC_URI += "file://testfile"\n',
174 '\n',
Patrick Williams213cb262021-08-07 19:21:33 -0500175 'do_install:append() {\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500176 ' install -d ${D}${bindir}\n',
177 ' install -m 0755 ${WORKDIR}/testfile ${D}${bindir}/selftest-recipetool-testbin\n',
178 '}\n']
179 _, output = self._try_recipetool_appendfile('netbase', '/usr/bin/selftest-recipetool-testbin', self.testfile, '-r netbase', expectedlines, ['testfile'])
180 self.assertNotIn('WARNING: ', output)
181
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500182 def test_recipetool_appendfile_add_machine(self):
183 # 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 -0500184 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500185 '\n',
186 'PACKAGE_ARCH = "${MACHINE_ARCH}"\n',
187 '\n',
Patrick Williams213cb262021-08-07 19:21:33 -0500188 'SRC_URI:append:mymachine = " file://testfile"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500189 '\n',
Patrick Williams213cb262021-08-07 19:21:33 -0500190 'do_install:append:mymachine() {\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500191 ' install -d ${D}${datadir}\n',
192 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n',
193 '}\n']
194 _, output = self._try_recipetool_appendfile('netbase', '/usr/share/something', self.testfile, '-r netbase -m mymachine', expectedlines, ['mymachine/testfile'])
195 self.assertNotIn('WARNING: ', output)
196
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500197 def test_recipetool_appendfile_orig(self):
198 # A file that's in SRC_URI and in do_install with the same name
Patrick Williams213cb262021-08-07 19:21:33 -0500199 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500200 '\n']
201 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-orig', self.testfile, '', expectedlines, ['selftest-replaceme-orig'])
202 self.assertNotIn('WARNING: ', output)
203
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500204 def test_recipetool_appendfile_todir(self):
205 # A file that's in SRC_URI and in do_install with destination directory rather than file
Patrick Williams213cb262021-08-07 19:21:33 -0500206 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500207 '\n']
208 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-todir', self.testfile, '', expectedlines, ['selftest-replaceme-todir'])
209 self.assertNotIn('WARNING: ', output)
210
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500211 def test_recipetool_appendfile_renamed(self):
212 # A file that's in SRC_URI with a different name to the destination file
Patrick Williams213cb262021-08-07 19:21:33 -0500213 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500214 '\n']
215 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-renamed', self.testfile, '', expectedlines, ['file1'])
216 self.assertNotIn('WARNING: ', output)
217
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500218 def test_recipetool_appendfile_subdir(self):
219 # A file that's in SRC_URI in a subdir
Patrick Williams213cb262021-08-07 19:21:33 -0500220 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500221 '\n',
222 'SRC_URI += "file://testfile"\n',
223 '\n',
Patrick Williams213cb262021-08-07 19:21:33 -0500224 'do_install:append() {\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500225 ' install -d ${D}${datadir}\n',
226 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-subdir\n',
227 '}\n']
228 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-subdir', self.testfile, '', expectedlines, ['testfile'])
229 self.assertNotIn('WARNING: ', output)
230
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500231 def test_recipetool_appendfile_inst_glob(self):
232 # A file that's in do_install as a glob
Patrick Williams213cb262021-08-07 19:21:33 -0500233 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500234 '\n']
235 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-globfile', self.testfile, '', expectedlines, ['selftest-replaceme-inst-globfile'])
236 self.assertNotIn('WARNING: ', output)
237
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500238 def test_recipetool_appendfile_inst_todir_glob(self):
239 # A file that's in do_install as a glob with destination as a directory
Patrick Williams213cb262021-08-07 19:21:33 -0500240 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500241 '\n']
242 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-todir-globfile', self.testfile, '', expectedlines, ['selftest-replaceme-inst-todir-globfile'])
243 self.assertNotIn('WARNING: ', output)
244
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500245 def test_recipetool_appendfile_patch(self):
246 # A file that's added by a patch in SRC_URI
Patrick Williams213cb262021-08-07 19:21:33 -0500247 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500248 '\n',
249 'SRC_URI += "file://testfile"\n',
250 '\n',
Patrick Williams213cb262021-08-07 19:21:33 -0500251 'do_install:append() {\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500252 ' install -d ${D}${sysconfdir}\n',
253 ' install -m 0644 ${WORKDIR}/testfile ${D}${sysconfdir}/selftest-replaceme-patched\n',
254 '}\n']
255 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/etc/selftest-replaceme-patched', self.testfile, '', expectedlines, ['testfile'])
256 for line in output.splitlines():
257 if 'WARNING: ' in line:
258 self.assertIn('add-file.patch', line, 'Unexpected warning found in output:\n%s' % line)
259 break
260 else:
261 self.fail('Patch warning not found in output:\n%s' % output)
262
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500263 def test_recipetool_appendfile_script(self):
264 # 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 -0500265 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500266 '\n',
267 'SRC_URI += "file://testfile"\n',
268 '\n',
Patrick Williams213cb262021-08-07 19:21:33 -0500269 'do_install:append() {\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500270 ' install -d ${D}${datadir}\n',
271 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-scripted\n',
272 '}\n']
273 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-scripted', self.testfile, '', expectedlines, ['testfile'])
274 self.assertNotIn('WARNING: ', output)
275
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500276 def test_recipetool_appendfile_inst_func(self):
277 # A file that's installed from a function called by do_install
Patrick Williams213cb262021-08-07 19:21:33 -0500278 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500279 '\n']
280 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-func', self.testfile, '', expectedlines, ['selftest-replaceme-inst-func'])
281 self.assertNotIn('WARNING: ', output)
282
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500283 def test_recipetool_appendfile_postinstall(self):
284 # A file that's created by a postinstall script (and explicitly mentioned in it)
285 # First try without specifying recipe
286 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'])
287 # Now specify recipe
Patrick Williams213cb262021-08-07 19:21:33 -0500288 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500289 '\n',
290 'SRC_URI += "file://testfile"\n',
291 '\n',
Patrick Williams213cb262021-08-07 19:21:33 -0500292 'do_install:append() {\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500293 ' install -d ${D}${datadir}\n',
294 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-postinst\n',
295 '}\n']
296 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-postinst', self.testfile, '-r selftest-recipetool-appendfile', expectedlines, ['testfile'])
297
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500298 def test_recipetool_appendfile_extlayer(self):
299 # Try creating a bbappend in a layer that's not in bblayers.conf and has a different structure
300 exttemplayerdir = os.path.join(self.tempdir, 'extlayer')
301 self._create_temp_layer(exttemplayerdir, False, 'oeselftestextlayer', recipepathspec='metadata/recipes/recipes-*/*')
302 result = runCmd('recipetool appendfile %s /usr/share/selftest-replaceme-orig %s' % (exttemplayerdir, self.testfile))
303 self.assertNotIn('Traceback', result.output)
304 createdfiles = []
305 for root, _, files in os.walk(exttemplayerdir):
306 for f in files:
307 createdfiles.append(os.path.relpath(os.path.join(root, f), exttemplayerdir))
308 createdfiles.remove('conf/layer.conf')
309 expectedfiles = ['metadata/recipes/recipes-test/selftest-recipetool-appendfile/selftest-recipetool-appendfile.bbappend',
310 'metadata/recipes/recipes-test/selftest-recipetool-appendfile/selftest-recipetool-appendfile/selftest-replaceme-orig']
311 self.assertEqual(sorted(createdfiles), sorted(expectedfiles))
312
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500313 def test_recipetool_appendfile_wildcard(self):
314
315 def try_appendfile_wc(options):
316 result = runCmd('recipetool appendfile %s /etc/profile %s %s' % (self.templayerdir, self.testfile, options))
317 self.assertNotIn('Traceback', result.output)
318 bbappendfile = None
319 for root, _, files in os.walk(self.templayerdir):
320 for f in files:
321 if f.endswith('.bbappend'):
322 bbappendfile = f
323 break
324 if not bbappendfile:
325 self.fail('No bbappend file created')
326 runCmd('rm -rf %s/recipes-*' % self.templayerdir)
327 return bbappendfile
328
329 # Check without wildcard option
330 recipefn = os.path.basename(get_bb_var('FILE', 'base-files'))
331 filename = try_appendfile_wc('')
332 self.assertEqual(filename, recipefn.replace('.bb', '.bbappend'))
333 # Now check with wildcard option
334 filename = try_appendfile_wc('-w')
335 self.assertEqual(filename, recipefn.split('_')[0] + '_%.bbappend')
336
Andrew Geissler595f6302022-01-24 19:11:47 +0000337
338class RecipetoolCreateTests(RecipetoolBase):
339
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500340 def test_recipetool_create(self):
341 # Try adding a recipe
342 tempsrc = os.path.join(self.tempdir, 'srctree')
343 os.makedirs(tempsrc)
344 recipefile = os.path.join(self.tempdir, 'logrotate_3.12.3.bb')
345 srcuri = 'https://github.com/logrotate/logrotate/releases/download/3.12.3/logrotate-3.12.3.tar.xz'
346 result = runCmd('recipetool create -o %s %s -x %s' % (recipefile, srcuri, tempsrc))
347 self.assertTrue(os.path.isfile(recipefile))
348 checkvars = {}
Andrew Geissler9aee5002022-03-30 16:27:02 +0000349 checkvars['LICENSE'] = 'GPL-2.0-only'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500350 checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263'
351 checkvars['SRC_URI'] = 'https://github.com/logrotate/logrotate/releases/download/${PV}/logrotate-${PV}.tar.xz'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500352 checkvars['SRC_URI[sha256sum]'] = '2e6a401cac9024db2288297e3be1a8ab60e7401ba8e91225218aaf4a27e82a07'
353 self._test_recipe_contents(recipefile, checkvars, [])
354
Andrew Geissler595f6302022-01-24 19:11:47 +0000355 def test_recipetool_create_autotools(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500356 if 'x11' not in get_bb_var('DISTRO_FEATURES'):
357 self.skipTest('Test requires x11 as distro feature')
358 # Ensure we have the right data in shlibs/pkgdata
359 bitbake('libpng pango libx11 libxext jpeg libcheck')
360 # Try adding a recipe
361 tempsrc = os.path.join(self.tempdir, 'srctree')
362 os.makedirs(tempsrc)
363 recipefile = os.path.join(self.tempdir, 'libmatchbox.bb')
Andrew Geissler028142b2023-05-05 11:29:21 -0500364 srcuri = 'git://git.yoctoproject.org/libmatchbox;protocol=https'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500365 result = runCmd(['recipetool', 'create', '-o', recipefile, srcuri + ";rev=9f7cf8895ae2d39c465c04cc78e918c157420269", '-x', tempsrc])
366 self.assertTrue(os.path.isfile(recipefile), 'recipetool did not create recipe file; output:\n%s' % result.output)
367 checkvars = {}
Andrew Geissler9aee5002022-03-30 16:27:02 +0000368 checkvars['LICENSE'] = 'LGPL-2.1-only'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500369 checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=7fbc338309ac38fefcd64b04bb903e34'
370 checkvars['S'] = '${WORKDIR}/git'
Andrew Geissler5082cc72023-09-11 08:41:39 -0400371 checkvars['PV'] = '1.11+git'
Andrew Geissler595f6302022-01-24 19:11:47 +0000372 checkvars['SRC_URI'] = srcuri + ';branch=master'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500373 checkvars['DEPENDS'] = set(['libcheck', 'libjpeg-turbo', 'libpng', 'libx11', 'libxext', 'pango'])
374 inherits = ['autotools', 'pkgconfig']
375 self._test_recipe_contents(recipefile, checkvars, inherits)
376
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500377 def test_recipetool_create_simple(self):
378 # Try adding a recipe
379 temprecipe = os.path.join(self.tempdir, 'recipe')
380 os.makedirs(temprecipe)
Andrew Geissler5f350902021-07-23 13:09:54 -0400381 pv = '1.7.4.1'
Andrew Geissler9aee5002022-03-30 16:27:02 +0000382 srcuri = 'http://www.dest-unreach.org/socat/download/Archive/socat-%s.tar.bz2' % pv
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500383 result = runCmd('recipetool create %s -o %s' % (srcuri, temprecipe))
384 dirlist = os.listdir(temprecipe)
385 if len(dirlist) > 1:
386 self.fail('recipetool created more than just one file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist)))
387 if len(dirlist) < 1 or not os.path.isfile(os.path.join(temprecipe, dirlist[0])):
388 self.fail('recipetool did not create recipe file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist)))
389 self.assertEqual(dirlist[0], 'socat_%s.bb' % pv, 'Recipe file incorrectly named')
390 checkvars = {}
Andrew Geissler9aee5002022-03-30 16:27:02 +0000391 checkvars['LICENSE'] = set(['Unknown', 'GPL-2.0-only'])
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500392 checkvars['LIC_FILES_CHKSUM'] = set(['file://COPYING.OpenSSL;md5=5c9bccc77f67a8328ef4ebaf468116f4', 'file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263'])
393 # We don't check DEPENDS since they are variable for this recipe depending on what's in the sysroot
394 checkvars['S'] = None
395 checkvars['SRC_URI'] = srcuri.replace(pv, '${PV}')
396 inherits = ['autotools']
397 self._test_recipe_contents(os.path.join(temprecipe, dirlist[0]), checkvars, inherits)
398
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500399 def test_recipetool_create_cmake(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500400 temprecipe = os.path.join(self.tempdir, 'recipe')
401 os.makedirs(temprecipe)
Brad Bishop96ff1982019-08-19 13:50:42 -0400402 recipefile = os.path.join(temprecipe, 'taglib_1.11.1.bb')
403 srcuri = 'http://taglib.github.io/releases/taglib-1.11.1.tar.gz'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500404 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
405 self.assertTrue(os.path.isfile(recipefile))
406 checkvars = {}
Andrew Geissler9aee5002022-03-30 16:27:02 +0000407 checkvars['LICENSE'] = set(['LGPL-2.1-only', 'MPL-1.1-only'])
Brad Bishop96ff1982019-08-19 13:50:42 -0400408 checkvars['SRC_URI'] = 'http://taglib.github.io/releases/taglib-${PV}.tar.gz'
Brad Bishop96ff1982019-08-19 13:50:42 -0400409 checkvars['SRC_URI[sha256sum]'] = 'b6d1a5a610aae6ff39d93de5efd0fdc787aa9e9dc1e7026fa4c961b26563526b'
410 checkvars['DEPENDS'] = set(['boost', 'zlib'])
411 inherits = ['cmake']
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500412 self._test_recipe_contents(recipefile, checkvars, inherits)
413
Andrew Geissler82c905d2020-04-13 13:39:40 -0500414 def test_recipetool_create_npm(self):
Andrew Geisslerf0343792020-11-18 10:42:21 -0600415 collections = get_bb_var('BBFILE_COLLECTIONS').split()
416 if "openembedded-layer" not in collections:
417 self.skipTest("Test needs meta-oe for nodejs")
418
Andrew Geissler82c905d2020-04-13 13:39:40 -0500419 temprecipe = os.path.join(self.tempdir, 'recipe')
420 os.makedirs(temprecipe)
421 recipefile = os.path.join(temprecipe, 'savoirfairelinux-node-server-example_1.0.0.bb')
422 shrinkwrap = os.path.join(temprecipe, 'savoirfairelinux-node-server-example', 'npm-shrinkwrap.json')
423 srcuri = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
424 result = runCmd('recipetool create -o %s \'%s\'' % (temprecipe, srcuri))
425 self.assertTrue(os.path.isfile(recipefile))
426 self.assertTrue(os.path.isfile(shrinkwrap))
427 checkvars = {}
428 checkvars['SUMMARY'] = 'Node Server Example'
429 checkvars['HOMEPAGE'] = 'https://github.com/savoirfairelinux/node-server-example#readme'
Andrew Geissler595f6302022-01-24 19:11:47 +0000430 checkvars['LICENSE'] = 'BSD-3-Clause & ISC & MIT & Unknown'
Andrew Geissler82c905d2020-04-13 13:39:40 -0500431 urls = []
432 urls.append('npm://registry.npmjs.org/;package=@savoirfairelinux/node-server-example;version=${PV}')
433 urls.append('npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json')
434 checkvars['SRC_URI'] = set(urls)
435 checkvars['S'] = '${WORKDIR}/npm'
Patrick Williams213cb262021-08-07 19:21:33 -0500436 checkvars['LICENSE:${PN}'] = 'MIT'
437 checkvars['LICENSE:${PN}-base64'] = 'Unknown'
438 checkvars['LICENSE:${PN}-accepts'] = 'MIT'
439 checkvars['LICENSE:${PN}-inherits'] = 'ISC'
Andrew Geissler82c905d2020-04-13 13:39:40 -0500440 inherits = ['npm']
441 self._test_recipe_contents(recipefile, checkvars, inherits)
442
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500443 def test_recipetool_create_github(self):
444 # Basic test to see if github URL mangling works
445 temprecipe = os.path.join(self.tempdir, 'recipe')
446 os.makedirs(temprecipe)
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600447 recipefile = os.path.join(temprecipe, 'python3-meson_git.bb')
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500448 srcuri = 'https://github.com/mesonbuild/meson;rev=0.32.0'
449 result = runCmd(['recipetool', 'create', '-o', temprecipe, srcuri])
450 self.assertTrue(os.path.isfile(recipefile))
451 checkvars = {}
452 checkvars['LICENSE'] = set(['Apache-2.0'])
Andrew Geissler595f6302022-01-24 19:11:47 +0000453 checkvars['SRC_URI'] = 'git://github.com/mesonbuild/meson;protocol=https;branch=master'
Brad Bishop15ae2502019-06-18 21:44:24 -0400454 inherits = ['setuptools3']
455 self._test_recipe_contents(recipefile, checkvars, inherits)
456
457 def test_recipetool_create_python3_setuptools(self):
458 # Test creating python3 package from tarball (using setuptools3 class)
Patrick Williams169d7bc2024-01-05 11:33:25 -0600459 # Use the --no-pypi switch to avoid creating a pypi enabled recipe and
460 # and check the created recipe as if it was a more general tarball
461 temprecipe = os.path.join(self.tempdir, 'recipe')
462 os.makedirs(temprecipe)
463 pn = 'python-magic'
464 pv = '0.4.15'
465 recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, pv))
466 srcuri = 'https://files.pythonhosted.org/packages/84/30/80932401906eaf787f2e9bd86dc458f1d2e75b064b4c187341f29516945c/python-magic-%s.tar.gz' % pv
467 result = runCmd('recipetool create --no-pypi -o %s %s' % (temprecipe, srcuri))
468 self.assertTrue(os.path.isfile(recipefile))
469 checkvars = {}
470 checkvars['LICENSE'] = set(['MIT'])
471 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88'
472 checkvars['SRC_URI'] = 'https://files.pythonhosted.org/packages/84/30/80932401906eaf787f2e9bd86dc458f1d2e75b064b4c187341f29516945c/python-magic-${PV}.tar.gz'
473 checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5'
474 inherits = ['setuptools3']
475 self._test_recipe_contents(recipefile, checkvars, inherits)
476
477 def test_recipetool_create_python3_setuptools_pypi_tarball(self):
478 # Test creating python3 package from tarball (using setuptools3 and pypi classes)
Brad Bishop15ae2502019-06-18 21:44:24 -0400479 temprecipe = os.path.join(self.tempdir, 'recipe')
480 os.makedirs(temprecipe)
481 pn = 'python-magic'
482 pv = '0.4.15'
483 recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, pv))
484 srcuri = 'https://files.pythonhosted.org/packages/84/30/80932401906eaf787f2e9bd86dc458f1d2e75b064b4c187341f29516945c/python-magic-%s.tar.gz' % pv
485 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
486 self.assertTrue(os.path.isfile(recipefile))
487 checkvars = {}
488 checkvars['LICENSE'] = set(['MIT'])
489 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88'
Brad Bishop15ae2502019-06-18 21:44:24 -0400490 checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5'
Patrick Williams169d7bc2024-01-05 11:33:25 -0600491 checkvars['PYPI_PACKAGE'] = pn
492 inherits = ['setuptools3', 'pypi']
493 self._test_recipe_contents(recipefile, checkvars, inherits)
494
495 def test_recipetool_create_python3_setuptools_pypi(self):
496 # Test creating python3 package from pypi url (using setuptools3 and pypi classes)
497 # Intentionnaly using setuptools3 class here instead of any of the pep517 class
498 # to avoid the toml dependency and allows this test to run on host autobuilders
499 # with older version of python
500 temprecipe = os.path.join(self.tempdir, 'recipe')
501 os.makedirs(temprecipe)
502 pn = 'python-magic'
503 pv = '0.4.15'
504 recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, pv))
505 # First specify the required version in the url
506 srcuri = 'https://pypi.org/project/%s/%s' % (pn, pv)
507 runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
508 self.assertTrue(os.path.isfile(recipefile))
509 checkvars = {}
510 checkvars['LICENSE'] = set(['MIT'])
511 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88'
512 checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5'
513 checkvars['PYPI_PACKAGE'] = pn
514 inherits = ['setuptools3', "pypi"]
515 self._test_recipe_contents(recipefile, checkvars, inherits)
516
517 # Now specify the version as a recipetool parameter
518 runCmd('rm -rf %s' % recipefile)
519 self.assertFalse(os.path.isfile(recipefile))
520 srcuri = 'https://pypi.org/project/%s' % pn
521 runCmd('recipetool create -o %s %s --version %s' % (temprecipe, srcuri, pv))
522 self.assertTrue(os.path.isfile(recipefile))
523 checkvars = {}
524 checkvars['LICENSE'] = set(['MIT'])
525 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88'
526 checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5'
527 checkvars['PYPI_PACKAGE'] = pn
528 inherits = ['setuptools3', "pypi"]
529 self._test_recipe_contents(recipefile, checkvars, inherits)
530
531 # Now, try to grab latest version of the package, so we cannot guess the name of the recipe,
532 # unless hardcoding the latest version but it means we will need to update the test for each release,
533 # so use a regexp
534 runCmd('rm -rf %s' % recipefile)
535 self.assertFalse(os.path.isfile(recipefile))
536 recipefile_re = r'%s_(.*)\.bb' % pn
537 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
538 dirlist = os.listdir(temprecipe)
539 if len(dirlist) > 1:
540 self.fail('recipetool created more than just one file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist)))
541 if len(dirlist) < 1 or not os.path.isfile(os.path.join(temprecipe, dirlist[0])):
542 self.fail('recipetool did not create recipe file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist)))
543 import re
544 match = re.match(recipefile_re, dirlist[0])
545 self.assertTrue(match)
546 latest_pv = match.group(1)
547 self.assertTrue(latest_pv != pv)
548 recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, latest_pv))
549 # Do not check LIC_FILES_CHKSUM and SRC_URI checksum here to avoid having updating the test on each release
550 checkvars = {}
551 checkvars['LICENSE'] = set(['MIT'])
552 checkvars['PYPI_PACKAGE'] = pn
553 inherits = ['setuptools3', "pypi"]
Brad Bishop15ae2502019-06-18 21:44:24 -0400554 self._test_recipe_contents(recipefile, checkvars, inherits)
555
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600556 def test_recipetool_create_python3_pep517_setuptools_build_meta(self):
557 # This test require python 3.11 or above for the tomllib module
558 # or tomli module to be installed
559 try:
560 import tomllib
561 except ImportError:
562 try:
563 import tomli
564 except ImportError:
565 self.skipTest('Test requires python 3.11 or above for tomllib module or tomli module')
566
567 # Test creating python3 package from tarball (using setuptools.build_meta class)
568 temprecipe = os.path.join(self.tempdir, 'recipe')
569 os.makedirs(temprecipe)
570 pn = 'webcolors'
571 pv = '1.13'
572 recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
573 srcuri = 'https://files.pythonhosted.org/packages/a1/fb/f95560c6a5d4469d9c49e24cf1b5d4d21ffab5608251c6020a965fb7791c/%s-%s.tar.gz' % (pn, pv)
574 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
575 self.assertTrue(os.path.isfile(recipefile))
576 checkvars = {}
577 checkvars['SUMMARY'] = 'A library for working with the color formats defined by HTML and CSS.'
578 checkvars['LICENSE'] = set(['BSD-3-Clause'])
579 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=702b1ef12cf66832a88f24c8f2ee9c19'
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600580 checkvars['SRC_URI[sha256sum]'] = 'c225b674c83fa923be93d235330ce0300373d02885cef23238813b0d5668304a'
Patrick Williams169d7bc2024-01-05 11:33:25 -0600581 inherits = ['python_setuptools_build_meta', 'pypi']
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600582
583 self._test_recipe_contents(recipefile, checkvars, inherits)
584
585 def test_recipetool_create_python3_pep517_poetry_core_masonry_api(self):
586 # This test require python 3.11 or above for the tomllib module
587 # or tomli module to be installed
588 try:
589 import tomllib
590 except ImportError:
591 try:
592 import tomli
593 except ImportError:
594 self.skipTest('Test requires python 3.11 or above for tomllib module or tomli module')
595
596 # Test creating python3 package from tarball (using poetry.core.masonry.api class)
597 temprecipe = os.path.join(self.tempdir, 'recipe')
598 os.makedirs(temprecipe)
599 pn = 'iso8601'
600 pv = '2.1.0'
601 recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
602 srcuri = 'https://files.pythonhosted.org/packages/b9/f3/ef59cee614d5e0accf6fd0cbba025b93b272e626ca89fb70a3e9187c5d15/%s-%s.tar.gz' % (pn, pv)
603 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
604 self.assertTrue(os.path.isfile(recipefile))
605 checkvars = {}
606 checkvars['SUMMARY'] = 'Simple module to parse ISO 8601 dates'
607 checkvars['LICENSE'] = set(['MIT'])
608 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=aab31f2ef7ba214a5a341eaa47a7f367'
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600609 checkvars['SRC_URI[sha256sum]'] = '6b1d3829ee8921c4301998c909f7829fa9ed3cbdac0d3b16af2d743aed1ba8df'
Patrick Williams169d7bc2024-01-05 11:33:25 -0600610 inherits = ['python_poetry_core', 'pypi']
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600611
612 self._test_recipe_contents(recipefile, checkvars, inherits)
613
614 def test_recipetool_create_python3_pep517_flit_core_buildapi(self):
615 # This test require python 3.11 or above for the tomllib module
616 # or tomli module to be installed
617 try:
618 import tomllib
619 except ImportError:
620 try:
621 import tomli
622 except ImportError:
623 self.skipTest('Test requires python 3.11 or above for tomllib module or tomli module')
624
625 # Test creating python3 package from tarball (using flit_core.buildapi class)
626 temprecipe = os.path.join(self.tempdir, 'recipe')
627 os.makedirs(temprecipe)
628 pn = 'typing-extensions'
629 pv = '4.8.0'
630 recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
631 srcuri = 'https://files.pythonhosted.org/packages/1f/7a/8b94bb016069caa12fc9f587b28080ac33b4fbb8ca369b98bc0a4828543e/typing_extensions-%s.tar.gz' % pv
632 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
633 self.assertTrue(os.path.isfile(recipefile))
634 checkvars = {}
635 checkvars['SUMMARY'] = 'Backported and Experimental Type Hints for Python 3.8+'
636 checkvars['LICENSE'] = set(['PSF-2.0'])
637 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=fcf6b249c2641540219a727f35d8d2c2'
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600638 checkvars['SRC_URI[sha256sum]'] = 'df8e4339e9cb77357558cbdbceca33c303714cf861d1eef15e1070055ae8b7ef'
Patrick Williams169d7bc2024-01-05 11:33:25 -0600639 inherits = ['python_flit_core', 'pypi']
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600640
641 self._test_recipe_contents(recipefile, checkvars, inherits)
642
643 def test_recipetool_create_python3_pep517_hatchling(self):
644 # This test require python 3.11 or above for the tomllib module
645 # or tomli module to be installed
646 try:
647 import tomllib
648 except ImportError:
649 try:
650 import tomli
651 except ImportError:
652 self.skipTest('Test requires python 3.11 or above for tomllib module or tomli module')
653
654 # Test creating python3 package from tarball (using hatchling class)
655 temprecipe = os.path.join(self.tempdir, 'recipe')
656 os.makedirs(temprecipe)
657 pn = 'jsonschema'
658 pv = '4.19.1'
659 recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
660 srcuri = 'https://files.pythonhosted.org/packages/e4/43/087b24516db11722c8687e0caf0f66c7785c0b1c51b0ab951dfde924e3f5/jsonschema-%s.tar.gz' % pv
661 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
662 self.assertTrue(os.path.isfile(recipefile))
663 checkvars = {}
664 checkvars['SUMMARY'] = 'An implementation of JSON Schema validation for Python'
665 checkvars['HOMEPAGE'] = 'https://github.com/python-jsonschema/jsonschema'
666 checkvars['LICENSE'] = set(['MIT'])
667 checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=7a60a81c146ec25599a3e1dabb8610a8 file://json/LICENSE;md5=9d4de43111d33570c8fe49b4cb0e01af'
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600668 checkvars['SRC_URI[sha256sum]'] = 'ec84cc37cfa703ef7cd4928db24f9cb31428a5d0fa77747b8b51a847458e0bbf'
Patrick Williams169d7bc2024-01-05 11:33:25 -0600669 inherits = ['python_hatchling', 'pypi']
670
671 self._test_recipe_contents(recipefile, checkvars, inherits)
672
673 def test_recipetool_create_python3_pep517_maturin(self):
674 # This test require python 3.11 or above for the tomllib module
675 # or tomli module to be installed
676 try:
677 import tomllib
678 except ImportError:
679 try:
680 import tomli
681 except ImportError:
682 self.skipTest('Test requires python 3.11 or above for tomllib module or tomli module')
683
684 # Test creating python3 package from tarball (using maturin class)
685 temprecipe = os.path.join(self.tempdir, 'recipe')
686 os.makedirs(temprecipe)
687 pn = 'pydantic-core'
688 pv = '2.14.5'
689 recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
690 srcuri = 'https://files.pythonhosted.org/packages/64/26/cffb93fe9c6b5a91c497f37fae14a4b073ecbc47fc36a9979c7aa888b245/pydantic_core-%s.tar.gz' % pv
691 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
692 self.assertTrue(os.path.isfile(recipefile))
693 checkvars = {}
694 checkvars['HOMEPAGE'] = 'https://github.com/pydantic/pydantic-core'
695 checkvars['LICENSE'] = set(['MIT'])
696 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=ab599c188b4a314d2856b3a55030c75c'
697 checkvars['SRC_URI[sha256sum]'] = '6d30226dfc816dd0fdf120cae611dd2215117e4f9b124af8c60ab9093b6e8e71'
698 inherits = ['python_maturin', 'pypi']
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600699
700 self._test_recipe_contents(recipefile, checkvars, inherits)
701
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500702 def test_recipetool_create_github_tarball(self):
703 # Basic test to ensure github URL mangling doesn't apply to release tarballs
704 temprecipe = os.path.join(self.tempdir, 'recipe')
705 os.makedirs(temprecipe)
706 pv = '0.32.0'
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600707 recipefile = os.path.join(temprecipe, 'python3-meson_%s.bb' % pv)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500708 srcuri = 'https://github.com/mesonbuild/meson/releases/download/%s/meson-%s.tar.gz' % (pv, pv)
709 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
710 self.assertTrue(os.path.isfile(recipefile))
711 checkvars = {}
712 checkvars['LICENSE'] = set(['Apache-2.0'])
713 checkvars['SRC_URI'] = 'https://github.com/mesonbuild/meson/releases/download/${PV}/meson-${PV}.tar.gz'
Brad Bishop15ae2502019-06-18 21:44:24 -0400714 inherits = ['setuptools3']
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500715 self._test_recipe_contents(recipefile, checkvars, inherits)
716
Andrew Geissler595f6302022-01-24 19:11:47 +0000717 def _test_recipetool_create_git(self, srcuri, branch=None):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500718 # Basic test to check http git URL mangling works
719 temprecipe = os.path.join(self.tempdir, 'recipe')
720 os.makedirs(temprecipe)
Andrew Geissler595f6302022-01-24 19:11:47 +0000721 name = srcuri.split(';')[0].split('/')[-1]
722 recipefile = os.path.join(temprecipe, name + '_git.bb')
723 options = ' -B %s' % branch if branch else ''
724 result = runCmd('recipetool create -o %s%s "%s"' % (temprecipe, options, srcuri))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500725 self.assertTrue(os.path.isfile(recipefile))
726 checkvars = {}
Andrew Geissler595f6302022-01-24 19:11:47 +0000727 checkvars['SRC_URI'] = srcuri
728 for scheme in ['http', 'https']:
729 if srcuri.startswith(scheme + ":"):
730 checkvars['SRC_URI'] = 'git%s;protocol=%s' % (srcuri[len(scheme):], scheme)
731 if ';branch=' not in srcuri:
732 checkvars['SRC_URI'] += ';branch=' + (branch or 'master')
733 self._test_recipe_contents(recipefile, checkvars, [])
734
735 def test_recipetool_create_git_http(self):
736 self._test_recipetool_create_git('http://git.yoctoproject.org/git/matchbox-keyboard')
737
738 def test_recipetool_create_git_srcuri_master(self):
Andrew Geissler028142b2023-05-05 11:29:21 -0500739 self._test_recipetool_create_git('git://git.yoctoproject.org/matchbox-keyboard;branch=master;protocol=https')
Andrew Geissler595f6302022-01-24 19:11:47 +0000740
741 def test_recipetool_create_git_srcuri_branch(self):
Andrew Geissler028142b2023-05-05 11:29:21 -0500742 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 +0000743
744 def test_recipetool_create_git_srcbranch(self):
Andrew Geissler028142b2023-05-05 11:29:21 -0500745 self._test_recipetool_create_git('git://git.yoctoproject.org/matchbox-keyboard;protocol=https', 'matchbox-keyboard-0-1')
Andrew Geissler595f6302022-01-24 19:11:47 +0000746
Patrick Williams56b44a92024-01-19 08:49:29 -0600747 def _go_urifiy(self, url, version, modulepath = None, pathmajor = None, subdir = None):
748 modulepath = ",path='%s'" % modulepath if len(modulepath) else ''
749 pathmajor = ",pathmajor='%s'" % pathmajor if len(pathmajor) else ''
750 subdir = ",subdir='%s'" % subdir if len(subdir) else ''
751 return "${@go_src_uri('%s','%s'%s%s%s)}" % (url, version, modulepath, pathmajor, subdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500752
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600753 def test_recipetool_create_go(self):
754 # Basic test to check go recipe generation
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600755 temprecipe = os.path.join(self.tempdir, 'recipe')
756 os.makedirs(temprecipe)
757
758 recipefile = os.path.join(temprecipe, 'edgex-go_git.bb')
759 deps_require_file = os.path.join(temprecipe, 'edgex-go', 'edgex-go-modules.inc')
760 lics_require_file = os.path.join(temprecipe, 'edgex-go', 'edgex-go-licenses.inc')
761 modules_txt_file = os.path.join(temprecipe, 'edgex-go', 'modules.txt')
762
763 srcuri = 'https://github.com/edgexfoundry/edgex-go.git'
764 srcrev = "v3.0.0"
765 srcbranch = "main"
766
767 result = runCmd('recipetool create -o %s %s -S %s -B %s' % (temprecipe, srcuri, srcrev, srcbranch))
768
769 self.maxDiff = None
770 inherits = ['go-vendor']
771
772 checkvars = {}
773 checkvars['GO_IMPORT'] = "github.com/edgexfoundry/edgex-go"
774 checkvars['SRC_URI'] = {'git://${GO_IMPORT};destsuffix=git/src/${GO_IMPORT};nobranch=1;name=${BPN};protocol=https',
775 'file://modules.txt'}
776 checkvars['LIC_FILES_CHKSUM'] = {'file://src/${GO_IMPORT}/LICENSE;md5=8f8bc924cf73f6a32381e5fd4c58d603'}
777
778 self.assertTrue(os.path.isfile(recipefile))
779 self._test_recipe_contents(recipefile, checkvars, inherits)
780
781 checkvars = {}
782 checkvars['VENDORED_LIC_FILES_CHKSUM'] = set(
783 ['file://src/${GO_IMPORT}/vendor/github.com/Microsoft/go-winio/LICENSE;md5=69205ff73858f2c22b2ca135b557e8ef',
784 'file://src/${GO_IMPORT}/vendor/github.com/armon/go-metrics/LICENSE;md5=d2d77030c0183e3d1e66d26dc1f243be',
785 'file://src/${GO_IMPORT}/vendor/github.com/cenkalti/backoff/LICENSE;md5=1571d94433e3f3aa05267efd4dbea68b',
786 'file://src/${GO_IMPORT}/vendor/github.com/davecgh/go-spew/LICENSE;md5=c06795ed54b2a35ebeeb543cd3a73e56',
787 'file://src/${GO_IMPORT}/vendor/github.com/eclipse/paho.mqtt.golang/LICENSE;md5=dcdb33474b60c38efd27356d8f2edec7',
788 'file://src/${GO_IMPORT}/vendor/github.com/eclipse/paho.mqtt.golang/edl-v10;md5=3adfcc70f5aeb7a44f3f9b495aa1fbf3',
789 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-bootstrap/v3/LICENSE;md5=0d6dae39976133b2851fba4c1e1275ff',
790 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-configuration/v3/LICENSE;md5=0d6dae39976133b2851fba4c1e1275ff',
791 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-core-contracts/v3/LICENSE;md5=0d6dae39976133b2851fba4c1e1275ff',
792 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-messaging/v3/LICENSE;md5=0d6dae39976133b2851fba4c1e1275ff',
793 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-registry/v3/LICENSE;md5=0d6dae39976133b2851fba4c1e1275ff',
794 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-secrets/v3/LICENSE;md5=f9fa2f4f8e0ef8cc7b5dd150963eb457',
795 'file://src/${GO_IMPORT}/vendor/github.com/fatih/color/LICENSE.md;md5=316e6d590bdcde7993fb175662c0dd5a',
796 'file://src/${GO_IMPORT}/vendor/github.com/fxamacker/cbor/v2/LICENSE;md5=827f5a2fa861382d35a3943adf9ebb86',
797 'file://src/${GO_IMPORT}/vendor/github.com/go-jose/go-jose/v3/LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57',
798 'file://src/${GO_IMPORT}/vendor/github.com/go-jose/go-jose/v3/json/LICENSE;md5=591778525c869cdde0ab5a1bf283cd81',
799 'file://src/${GO_IMPORT}/vendor/github.com/go-kit/log/LICENSE;md5=5b7c15ad5fffe2ff6e9d58a6c161f082',
800 'file://src/${GO_IMPORT}/vendor/github.com/go-logfmt/logfmt/LICENSE;md5=98e39517c38127f969de33057067091e',
801 'file://src/${GO_IMPORT}/vendor/github.com/go-playground/locales/LICENSE;md5=3ccbda375ee345400ad1da85ba522301',
802 'file://src/${GO_IMPORT}/vendor/github.com/go-playground/universal-translator/LICENSE;md5=2e2b21ef8f61057977d27c727c84bef1',
803 'file://src/${GO_IMPORT}/vendor/github.com/go-playground/validator/v10/LICENSE;md5=a718a0f318d76f7c5d510cbae84f0b60',
804 'file://src/${GO_IMPORT}/vendor/github.com/go-redis/redis/v7/LICENSE;md5=58103aa5ea1ee9b7a369c9c4a95ef9b5',
805 'file://src/${GO_IMPORT}/vendor/github.com/golang/protobuf/LICENSE;md5=939cce1ec101726fa754e698ac871622',
806 'file://src/${GO_IMPORT}/vendor/github.com/gomodule/redigo/LICENSE;md5=2ee41112a44fe7014dce33e26468ba93',
807 'file://src/${GO_IMPORT}/vendor/github.com/google/uuid/LICENSE;md5=88073b6dd8ec00fe09da59e0b6dfded1',
808 'file://src/${GO_IMPORT}/vendor/github.com/gorilla/mux/LICENSE;md5=33fa1116c45f9e8de714033f99edde13',
809 'file://src/${GO_IMPORT}/vendor/github.com/gorilla/websocket/LICENSE;md5=c007b54a1743d596f46b2748d9f8c044',
810 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/consul/api/LICENSE;md5=b8a277a612171b7526e9be072f405ef4',
811 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/errwrap/LICENSE;md5=b278a92d2c1509760384428817710378',
812 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/go-cleanhttp/LICENSE;md5=65d26fcc2f35ea6a181ac777e42db1ea',
813 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/go-hclog/LICENSE;md5=ec7f605b74b9ad03347d0a93a5cc7eb8',
814 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/go-immutable-radix/LICENSE;md5=65d26fcc2f35ea6a181ac777e42db1ea',
815 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/go-multierror/LICENSE;md5=d44fdeb607e2d2614db9464dbedd4094',
816 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/go-rootcerts/LICENSE;md5=65d26fcc2f35ea6a181ac777e42db1ea',
817 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/golang-lru/LICENSE;md5=f27a50d2e878867827842f2c60e30bfc',
818 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/serf/LICENSE;md5=b278a92d2c1509760384428817710378',
819 'file://src/${GO_IMPORT}/vendor/github.com/leodido/go-urn/LICENSE;md5=8f50db5538ec1148a9b3d14ed96c3418',
820 'file://src/${GO_IMPORT}/vendor/github.com/mattn/go-colorable/LICENSE;md5=24ce168f90aec2456a73de1839037245',
821 'file://src/${GO_IMPORT}/vendor/github.com/mattn/go-isatty/LICENSE;md5=f509beadd5a11227c27b5d2ad6c9f2c6',
822 'file://src/${GO_IMPORT}/vendor/github.com/mitchellh/consulstructure/LICENSE;md5=96ada10a9e51c98c4656f2cede08c673',
823 'file://src/${GO_IMPORT}/vendor/github.com/mitchellh/copystructure/LICENSE;md5=56da355a12d4821cda57b8f23ec34bc4',
824 'file://src/${GO_IMPORT}/vendor/github.com/mitchellh/go-homedir/LICENSE;md5=3f7765c3d4f58e1f84c4313cecf0f5bd',
825 'file://src/${GO_IMPORT}/vendor/github.com/mitchellh/mapstructure/LICENSE;md5=3f7765c3d4f58e1f84c4313cecf0f5bd',
826 'file://src/${GO_IMPORT}/vendor/github.com/mitchellh/reflectwalk/LICENSE;md5=3f7765c3d4f58e1f84c4313cecf0f5bd',
827 'file://src/${GO_IMPORT}/vendor/github.com/nats-io/nats.go/LICENSE;md5=86d3f3a95c324c9479bd8986968f4327',
828 'file://src/${GO_IMPORT}/vendor/github.com/nats-io/nkeys/LICENSE;md5=86d3f3a95c324c9479bd8986968f4327',
829 'file://src/${GO_IMPORT}/vendor/github.com/nats-io/nuid/LICENSE;md5=86d3f3a95c324c9479bd8986968f4327',
830 'file://src/${GO_IMPORT}/vendor/github.com/pmezard/go-difflib/LICENSE;md5=e9a2ebb8de779a07500ddecca806145e',
831 'file://src/${GO_IMPORT}/vendor/github.com/rcrowley/go-metrics/LICENSE;md5=1bdf5d819f50f141366dabce3be1460f',
832 'file://src/${GO_IMPORT}/vendor/github.com/spiffe/go-spiffe/v2/LICENSE;md5=86d3f3a95c324c9479bd8986968f4327',
833 'file://src/${GO_IMPORT}/vendor/github.com/stretchr/objx/LICENSE;md5=d023fd31d3ca39ec61eec65a91732735',
834 'file://src/${GO_IMPORT}/vendor/github.com/stretchr/testify/LICENSE;md5=188f01994659f3c0d310612333d2a26f',
835 'file://src/${GO_IMPORT}/vendor/github.com/x448/float16/LICENSE;md5=de8f8e025d57fe7ee0b67f30d571323b',
836 'file://src/${GO_IMPORT}/vendor/github.com/zeebo/errs/LICENSE;md5=84914ab36fc0eb48edbaa53e66e8d326',
837 'file://src/${GO_IMPORT}/vendor/golang.org/x/crypto/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
838 'file://src/${GO_IMPORT}/vendor/golang.org/x/mod/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
839 'file://src/${GO_IMPORT}/vendor/golang.org/x/net/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
840 'file://src/${GO_IMPORT}/vendor/golang.org/x/sync/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
841 'file://src/${GO_IMPORT}/vendor/golang.org/x/sys/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
842 'file://src/${GO_IMPORT}/vendor/golang.org/x/text/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
843 'file://src/${GO_IMPORT}/vendor/golang.org/x/tools/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
844 'file://src/${GO_IMPORT}/vendor/google.golang.org/genproto/LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57',
845 'file://src/${GO_IMPORT}/vendor/google.golang.org/grpc/LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57',
846 'file://src/${GO_IMPORT}/vendor/google.golang.org/protobuf/LICENSE;md5=02d4002e9171d41a8fad93aa7faf3956',
847 'file://src/${GO_IMPORT}/vendor/gopkg.in/eapache/queue.v1/LICENSE;md5=1bfd4408d3de090ef6b908b0cc45a316',
848 'file://src/${GO_IMPORT}/vendor/gopkg.in/yaml.v3/LICENSE;md5=3c91c17266710e16afdbb2b6d15c761c'])
849
850 self.assertTrue(os.path.isfile(lics_require_file))
851 self._test_recipe_contents(lics_require_file, checkvars, [])
852
853 dependencies = \
854 [ ('github.com/eclipse/paho.mqtt.golang','v1.4.2', '', '', ''),
855 ('github.com/edgexfoundry/go-mod-bootstrap','v3.0.1','github.com/edgexfoundry/go-mod-bootstrap/v3','/v3', ''),
856 ('github.com/edgexfoundry/go-mod-configuration','v3.0.0','github.com/edgexfoundry/go-mod-configuration/v3','/v3', ''),
857 ('github.com/edgexfoundry/go-mod-core-contracts','v3.0.0','github.com/edgexfoundry/go-mod-core-contracts/v3','/v3', ''),
858 ('github.com/edgexfoundry/go-mod-messaging','v3.0.0','github.com/edgexfoundry/go-mod-messaging/v3','/v3', ''),
859 ('github.com/edgexfoundry/go-mod-secrets','v3.0.1','github.com/edgexfoundry/go-mod-secrets/v3','/v3', ''),
860 ('github.com/fxamacker/cbor','v2.4.0','github.com/fxamacker/cbor/v2','/v2', ''),
861 ('github.com/gomodule/redigo','v1.8.9', '', '', ''),
862 ('github.com/google/uuid','v1.3.0', '', '', ''),
863 ('github.com/gorilla/mux','v1.8.0', '', '', ''),
864 ('github.com/rcrowley/go-metrics','v0.0.0-20201227073835-cf1acfcdf475', '', '', ''),
865 ('github.com/spiffe/go-spiffe','v2.1.4','github.com/spiffe/go-spiffe/v2','/v2', ''),
866 ('github.com/stretchr/testify','v1.8.2', '', '', ''),
867 ('go.googlesource.com/crypto','v0.8.0','golang.org/x/crypto', '', ''),
868 ('gopkg.in/eapache/queue.v1','v1.1.0', '', '', ''),
869 ('gopkg.in/yaml.v3','v3.0.1', '', '', ''),
870 ('github.com/microsoft/go-winio','v0.6.0','github.com/Microsoft/go-winio', '', ''),
871 ('github.com/hashicorp/go-metrics','v0.3.10','github.com/armon/go-metrics', '', ''),
872 ('github.com/cenkalti/backoff','v2.2.1+incompatible', '', '', ''),
873 ('github.com/davecgh/go-spew','v1.1.1', '', '', ''),
874 ('github.com/edgexfoundry/go-mod-registry','v3.0.0','github.com/edgexfoundry/go-mod-registry/v3','/v3', ''),
875 ('github.com/fatih/color','v1.9.0', '', '', ''),
876 ('github.com/go-jose/go-jose','v3.0.0','github.com/go-jose/go-jose/v3','/v3', ''),
877 ('github.com/go-kit/log','v0.2.1', '', '', ''),
878 ('github.com/go-logfmt/logfmt','v0.5.1', '', '', ''),
879 ('github.com/go-playground/locales','v0.14.1', '', '', ''),
880 ('github.com/go-playground/universal-translator','v0.18.1', '', '', ''),
881 ('github.com/go-playground/validator','v10.13.0','github.com/go-playground/validator/v10','/v10', ''),
882 ('github.com/go-redis/redis','v7.3.0','github.com/go-redis/redis/v7','/v7', ''),
883 ('github.com/golang/protobuf','v1.5.2', '', '', ''),
884 ('github.com/gorilla/websocket','v1.4.2', '', '', ''),
885 ('github.com/hashicorp/consul','v1.20.0','github.com/hashicorp/consul/api', '', 'api'),
886 ('github.com/hashicorp/errwrap','v1.0.0', '', '', ''),
887 ('github.com/hashicorp/go-cleanhttp','v0.5.1', '', '', ''),
888 ('github.com/hashicorp/go-hclog','v0.14.1', '', '', ''),
889 ('github.com/hashicorp/go-immutable-radix','v1.3.0', '', '', ''),
890 ('github.com/hashicorp/go-multierror','v1.1.1', '', '', ''),
891 ('github.com/hashicorp/go-rootcerts','v1.0.2', '', '', ''),
892 ('github.com/hashicorp/golang-lru','v0.5.4', '', '', ''),
893 ('github.com/hashicorp/serf','v0.10.1', '', '', ''),
894 ('github.com/leodido/go-urn','v1.2.3', '', '', ''),
895 ('github.com/mattn/go-colorable','v0.1.12', '', '', ''),
896 ('github.com/mattn/go-isatty','v0.0.14', '', '', ''),
897 ('github.com/mitchellh/consulstructure','v0.0.0-20190329231841-56fdc4d2da54', '', '', ''),
898 ('github.com/mitchellh/copystructure','v1.2.0', '', '', ''),
899 ('github.com/mitchellh/go-homedir','v1.1.0', '', '', ''),
900 ('github.com/mitchellh/mapstructure','v1.5.0', '', '', ''),
901 ('github.com/mitchellh/reflectwalk','v1.0.2', '', '', ''),
902 ('github.com/nats-io/nats.go','v1.25.0', '', '', ''),
903 ('github.com/nats-io/nkeys','v0.4.4', '', '', ''),
904 ('github.com/nats-io/nuid','v1.0.1', '', '', ''),
905 ('github.com/pmezard/go-difflib','v1.0.0', '', '', ''),
906 ('github.com/stretchr/objx','v0.5.0', '', '', ''),
907 ('github.com/x448/float16','v0.8.4', '', '', ''),
908 ('github.com/zeebo/errs','v1.3.0', '', '', ''),
909 ('go.googlesource.com/mod','v0.8.0','golang.org/x/mod', '', ''),
910 ('go.googlesource.com/net','v0.9.0','golang.org/x/net', '', ''),
911 ('go.googlesource.com/sync','v0.1.0','golang.org/x/sync', '', ''),
912 ('go.googlesource.com/sys','v0.7.0','golang.org/x/sys', '', ''),
913 ('go.googlesource.com/text','v0.9.0','golang.org/x/text', '', ''),
914 ('go.googlesource.com/tools','v0.6.0','golang.org/x/tools', '', ''),
915 ('github.com/googleapis/go-genproto','v0.0.0-20230223222841-637eb2293923','google.golang.org/genproto', '', ''),
916 ('github.com/grpc/grpc-go','v1.53.0','google.golang.org/grpc', '', ''),
917 ('go.googlesource.com/protobuf','v1.28.1','google.golang.org/protobuf', '', ''),
918 ]
919
920 src_uri = set()
921 for d in dependencies:
Patrick Williams56b44a92024-01-19 08:49:29 -0600922 src_uri.add(self._go_urifiy(*d))
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600923
924 checkvars = {}
925 checkvars['GO_DEPENDENCIES_SRC_URI'] = src_uri
926
927 self.assertTrue(os.path.isfile(deps_require_file))
928 self._test_recipe_contents(deps_require_file, checkvars, [])
929
Patrick Williams56b44a92024-01-19 08:49:29 -0600930 def test_recipetool_create_go_replace_modules(self):
931 # Check handling of replaced modules
932 temprecipe = os.path.join(self.tempdir, 'recipe')
933 os.makedirs(temprecipe)
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600934
Patrick Williams56b44a92024-01-19 08:49:29 -0600935 recipefile = os.path.join(temprecipe, 'openapi-generator_git.bb')
936 deps_require_file = os.path.join(temprecipe, 'openapi-generator', 'go-modules.inc')
937 lics_require_file = os.path.join(temprecipe, 'openapi-generator', 'go-licenses.inc')
938 modules_txt_file = os.path.join(temprecipe, 'openapi-generator', 'modules.txt')
939
940 srcuri = 'https://github.com/OpenAPITools/openapi-generator.git'
941 srcrev = "v7.2.0"
942 srcbranch = "master"
943 srcsubdir = "samples/openapi3/client/petstore/go"
944
945 result = runCmd('recipetool create -o %s %s -S %s -B %s --src-subdir %s' % (temprecipe, srcuri, srcrev, srcbranch, srcsubdir))
946
947 self.maxDiff = None
948 inherits = ['go-vendor']
949
950 checkvars = {}
951 checkvars['GO_IMPORT'] = "github.com/OpenAPITools/openapi-generator/samples/openapi3/client/petstore/go"
952 checkvars['SRC_URI'] = {'git://${GO_IMPORT};destsuffix=git/src/${GO_IMPORT};nobranch=1;name=${BPN};protocol=https',
953 'file://modules.txt'}
954
955 self.assertNotIn('Traceback', result.output)
956 self.assertIn('No license file was detected for the main module', result.output)
957 self.assertTrue(os.path.isfile(recipefile))
958 self._test_recipe_contents(recipefile, checkvars, inherits)
959
960 # make sure that dependencies don't mention local directory ./go-petstore
961 dependencies = \
962 [ ('github.com/stretchr/testify','v1.8.4', '', '', ''),
963 ('go.googlesource.com/oauth2','v0.10.0','golang.org/x/oauth2', '', ''),
964 ('github.com/davecgh/go-spew','v1.1.1', '', '', ''),
965 ('github.com/golang/protobuf','v1.5.3', '', '', ''),
966 ('github.com/kr/pretty','v0.3.0', '', '', ''),
967 ('github.com/pmezard/go-difflib','v1.0.0', '', '', ''),
968 ('github.com/rogpeppe/go-internal','v1.9.0', '', '', ''),
969 ('go.googlesource.com/net','v0.12.0','golang.org/x/net', '', ''),
970 ('github.com/golang/appengine','v1.6.7','google.golang.org/appengine', '', ''),
971 ('go.googlesource.com/protobuf','v1.31.0','google.golang.org/protobuf', '', ''),
972 ('gopkg.in/check.v1','v1.0.0-20201130134442-10cb98267c6c', '', '', ''),
973 ('gopkg.in/yaml.v3','v3.0.1', '', '', ''),
974 ]
975
976 src_uri = set()
977 for d in dependencies:
978 src_uri.add(self._go_urifiy(*d))
979
980 checkvars = {}
981 checkvars['GO_DEPENDENCIES_SRC_URI'] = src_uri
982
983 self.assertTrue(os.path.isfile(deps_require_file))
984 self._test_recipe_contents(deps_require_file, checkvars, [])
985
986class RecipetoolTests(RecipetoolBase):
987
988 @classmethod
989 def setUpClass(cls):
990 import sys
991
992 super(RecipetoolTests, cls).setUpClass()
993 bb_vars = get_bb_vars(['BBPATH'])
994 cls.bbpath = bb_vars['BBPATH']
995 libpath = os.path.join(get_bb_var('COREBASE'), 'scripts', 'lib', 'recipetool')
996 sys.path.insert(0, libpath)
Patrick Williams169d7bc2024-01-05 11:33:25 -0600997
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500998 def _copy_file_with_cleanup(self, srcfile, basedstdir, *paths):
999 dstdir = basedstdir
1000 self.assertTrue(os.path.exists(dstdir))
1001 for p in paths:
1002 dstdir = os.path.join(dstdir, p)
1003 if not os.path.exists(dstdir):
Patrick Williams169d7bc2024-01-05 11:33:25 -06001004 try:
1005 os.makedirs(dstdir)
1006 except PermissionError:
1007 return False
1008 except OSError as e:
1009 if e.errno == errno.EROFS:
1010 return False
1011 else:
1012 raise e
Andrew Geissler475cb722020-07-10 16:00:51 -05001013 if p == "lib":
1014 # Can race with other tests
1015 self.add_command_to_tearDown('rmdir --ignore-fail-on-non-empty %s' % dstdir)
1016 else:
1017 self.track_for_cleanup(dstdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001018 dstfile = os.path.join(dstdir, os.path.basename(srcfile))
1019 if srcfile != dstfile:
Patrick Williams169d7bc2024-01-05 11:33:25 -06001020 try:
1021 shutil.copy(srcfile, dstfile)
1022 except PermissionError:
1023 return False
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001024 self.track_for_cleanup(dstfile)
Patrick Williams169d7bc2024-01-05 11:33:25 -06001025 return True
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001026
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001027 def test_recipetool_load_plugin(self):
1028 """Test that recipetool loads only the first found plugin in BBPATH."""
1029
1030 recipetool = runCmd("which recipetool")
1031 fromname = runCmd("recipetool --quiet pluginfile")
1032 srcfile = fromname.output
1033 searchpath = self.bbpath.split(':') + [os.path.dirname(recipetool.output)]
1034 plugincontent = []
1035 with open(srcfile) as fh:
1036 plugincontent = fh.readlines()
1037 try:
1038 self.assertIn('meta-selftest', srcfile, 'wrong bbpath plugin found')
Patrick Williams169d7bc2024-01-05 11:33:25 -06001039 searchpath = [
1040 path for path in searchpath
1041 if self._copy_file_with_cleanup(srcfile, path, 'lib', 'recipetool')
1042 ]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001043 result = runCmd("recipetool --quiet count")
1044 self.assertEqual(result.output, '1')
1045 result = runCmd("recipetool --quiet multiloaded")
1046 self.assertEqual(result.output, "no")
1047 for path in searchpath:
1048 result = runCmd("recipetool --quiet bbdir")
Patrick Williams169d7bc2024-01-05 11:33:25 -06001049 self.assertEqual(os.path.realpath(result.output), os.path.realpath(path))
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001050 os.unlink(os.path.join(result.output, 'lib', 'recipetool', 'bbpath.py'))
1051 finally:
1052 with open(srcfile, 'w') as fh:
1053 fh.writelines(plugincontent)
1054
Andrew Geissler595f6302022-01-24 19:11:47 +00001055 def test_recipetool_handle_license_vars(self):
1056 from create import handle_license_vars
1057 from unittest.mock import Mock
1058
1059 commonlicdir = get_bb_var('COMMON_LICENSE_DIR')
1060
Andrew Geisslerfc113ea2023-03-31 09:59:46 -05001061 class DataConnectorCopy(bb.tinfoil.TinfoilDataStoreConnector):
1062 pass
1063
1064 d = DataConnectorCopy
Andrew Geissler595f6302022-01-24 19:11:47 +00001065 d.getVar = Mock(return_value=commonlicdir)
1066
1067 srctree = tempfile.mkdtemp(prefix='recipetoolqa')
1068 self.track_for_cleanup(srctree)
1069
1070 # Multiple licenses
1071 licenses = ['MIT', 'ISC', 'BSD-3-Clause', 'Apache-2.0']
1072 for licence in licenses:
1073 shutil.copy(os.path.join(commonlicdir, licence), os.path.join(srctree, 'LICENSE.' + licence))
1074 # Duplicate license
1075 shutil.copy(os.path.join(commonlicdir, 'MIT'), os.path.join(srctree, 'LICENSE'))
1076
1077 extravalues = {
1078 # Duplicate and missing licenses
1079 'LICENSE': 'Zlib & BSD-2-Clause & Zlib',
1080 'LIC_FILES_CHKSUM': [
1081 'file://README.md;md5=0123456789abcdef0123456789abcd'
1082 ]
1083 }
1084 lines_before = []
1085 handled = []
1086 licvalues = handle_license_vars(srctree, lines_before, handled, extravalues, d)
1087 expected_lines_before = [
1088 '# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is',
1089 '# your responsibility to verify that the values are complete and correct.',
1090 '# NOTE: Original package / source metadata indicates license is: BSD-2-Clause & Zlib',
1091 '#',
1092 '# NOTE: multiple licenses have been detected; they have been separated with &',
1093 '# in the LICENSE value for now since it is a reasonable assumption that all',
1094 '# of the licenses apply. If instead there is a choice between the multiple',
1095 '# licenses then you should change the value to separate the licenses with |',
1096 '# instead of &. If there is any doubt, check the accompanying documentation',
1097 '# to determine which situation is applicable.',
1098 'LICENSE = "Apache-2.0 & BSD-2-Clause & BSD-3-Clause & ISC & MIT & Zlib"',
1099 'LIC_FILES_CHKSUM = "file://LICENSE;md5=0835ade698e0bcf8506ecda2f7b4f302 \\\n'
1100 ' file://LICENSE.Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10 \\\n'
1101 ' file://LICENSE.BSD-3-Clause;md5=550794465ba0ec5312d6919e203a55f9 \\\n'
1102 ' file://LICENSE.ISC;md5=f3b90e78ea0cffb20bf5cca7947a896d \\\n'
1103 ' file://LICENSE.MIT;md5=0835ade698e0bcf8506ecda2f7b4f302 \\\n'
1104 ' file://README.md;md5=0123456789abcdef0123456789abcd"',
1105 ''
1106 ]
1107 self.assertEqual(lines_before, expected_lines_before)
1108 expected_licvalues = [
1109 ('MIT', 'LICENSE', '0835ade698e0bcf8506ecda2f7b4f302'),
1110 ('Apache-2.0', 'LICENSE.Apache-2.0', '89aea4e17d99a7cacdbeed46a0096b10'),
1111 ('BSD-3-Clause', 'LICENSE.BSD-3-Clause', '550794465ba0ec5312d6919e203a55f9'),
1112 ('ISC', 'LICENSE.ISC', 'f3b90e78ea0cffb20bf5cca7947a896d'),
1113 ('MIT', 'LICENSE.MIT', '0835ade698e0bcf8506ecda2f7b4f302')
1114 ]
1115 self.assertEqual(handled, [('license', expected_licvalues)])
1116 self.assertEqual(extravalues, {})
1117 self.assertEqual(licvalues, expected_licvalues)
1118
1119
1120 def test_recipetool_split_pkg_licenses(self):
1121 from create import split_pkg_licenses
1122 licvalues = [
1123 # Duplicate licenses
1124 ('BSD-2-Clause', 'x/COPYING', None),
1125 ('BSD-2-Clause', 'x/LICENSE', None),
1126 # Multiple licenses
1127 ('MIT', 'x/a/LICENSE.MIT', None),
1128 ('ISC', 'x/a/LICENSE.ISC', None),
1129 # Alternative licenses
1130 ('(MIT | ISC)', 'x/b/LICENSE', None),
1131 # Alternative licenses without brackets
1132 ('MIT | BSD-2-Clause', 'x/c/LICENSE', None),
1133 # Multi licenses with alternatives
1134 ('MIT', 'x/d/COPYING', None),
1135 ('MIT | BSD-2-Clause', 'x/d/LICENSE', None),
1136 # Multi licenses with alternatives and brackets
1137 ('Apache-2.0 & ((MIT | ISC) & BSD-3-Clause)', 'x/e/LICENSE', None)
1138 ]
1139 packages = {
1140 '${PN}': '',
1141 'a': 'x/a',
1142 'b': 'x/b',
1143 'c': 'x/c',
1144 'd': 'x/d',
1145 'e': 'x/e',
1146 'f': 'x/f',
1147 'g': 'x/g',
1148 }
1149 fallback_licenses = {
1150 # Ignored
1151 'a': 'BSD-3-Clause',
1152 # Used
1153 'f': 'BSD-3-Clause'
1154 }
1155 outlines = []
1156 outlicenses = split_pkg_licenses(licvalues, packages, outlines, fallback_licenses)
1157 expected_outlicenses = {
1158 '${PN}': ['BSD-2-Clause'],
1159 'a': ['ISC', 'MIT'],
1160 'b': ['(ISC | MIT)'],
1161 'c': ['(BSD-2-Clause | MIT)'],
1162 'd': ['(BSD-2-Clause | MIT)', 'MIT'],
1163 'e': ['(ISC | MIT)', 'Apache-2.0', 'BSD-3-Clause'],
1164 'f': ['BSD-3-Clause'],
1165 'g': ['Unknown']
1166 }
1167 self.assertEqual(outlicenses, expected_outlicenses)
1168 expected_outlines = [
1169 'LICENSE:${PN} = "BSD-2-Clause"',
1170 'LICENSE:a = "ISC & MIT"',
1171 'LICENSE:b = "(ISC | MIT)"',
1172 'LICENSE:c = "(BSD-2-Clause | MIT)"',
1173 'LICENSE:d = "(BSD-2-Clause | MIT) & MIT"',
1174 'LICENSE:e = "(ISC | MIT) & Apache-2.0 & BSD-3-Clause"',
1175 'LICENSE:f = "BSD-3-Clause"',
1176 'LICENSE:g = "Unknown"'
1177 ]
1178 self.assertEqual(outlines, expected_outlines)
1179
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001180
1181class RecipetoolAppendsrcBase(RecipetoolBase):
1182 def _try_recipetool_appendsrcfile(self, testrecipe, newfile, destfile, options, expectedlines, expectedfiles):
1183 cmd = 'recipetool appendsrcfile %s %s %s %s %s' % (options, self.templayerdir, testrecipe, newfile, destfile)
1184 return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
1185
1186 def _try_recipetool_appendsrcfiles(self, testrecipe, newfiles, expectedlines=None, expectedfiles=None, destdir=None, options=''):
1187
1188 if destdir:
1189 options += ' -D %s' % destdir
1190
1191 if expectedfiles is None:
1192 expectedfiles = [os.path.basename(f) for f in newfiles]
1193
1194 cmd = 'recipetool appendsrcfiles %s %s %s %s' % (options, self.templayerdir, testrecipe, ' '.join(newfiles))
1195 return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
1196
1197 def _try_recipetool_appendsrcfile_fail(self, testrecipe, newfile, destfile, checkerror):
1198 cmd = 'recipetool appendsrcfile %s %s %s %s' % (self.templayerdir, testrecipe, newfile, destfile or '')
1199 result = runCmd(cmd, ignore_status=True)
1200 self.assertNotEqual(result.status, 0, 'Command "%s" should have failed but didn\'t' % cmd)
1201 self.assertNotIn('Traceback', result.output)
1202 for errorstr in checkerror:
1203 self.assertIn(errorstr, result.output)
1204
1205 @staticmethod
1206 def _get_first_file_uri(recipe):
1207 '''Return the first file:// in SRC_URI for the specified recipe.'''
1208 src_uri = get_bb_var('SRC_URI', recipe).split()
1209 for uri in src_uri:
1210 p = urllib.parse.urlparse(uri)
1211 if p.scheme == 'file':
Patrick Williams169d7bc2024-01-05 11:33:25 -06001212 return p.netloc + p.path, uri
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001213
Patrick Williams169d7bc2024-01-05 11:33:25 -06001214 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 -05001215 if newfile is None:
1216 newfile = self.testfile
1217
1218 if srcdir:
1219 if destdir:
1220 expected_subdir = os.path.join(srcdir, destdir)
1221 else:
1222 expected_subdir = srcdir
1223 else:
1224 options += " -W"
1225 expected_subdir = destdir
1226
1227 if filename:
1228 if destdir:
1229 destpath = os.path.join(destdir, filename)
1230 else:
1231 destpath = filename
1232 else:
1233 filename = os.path.basename(newfile)
1234 if destdir:
1235 destpath = destdir + os.sep
1236 else:
1237 destpath = '.' + os.sep
1238
Patrick Williams213cb262021-08-07 19:21:33 -05001239 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001240 '\n']
Patrick Williams169d7bc2024-01-05 11:33:25 -06001241
1242 override = ""
1243 if machine:
1244 options += ' -m %s' % machine
1245 override = ':append:%s' % machine
1246 expectedlines.extend(['PACKAGE_ARCH = "${MACHINE_ARCH}"\n',
1247 '\n'])
1248
1249 if remove:
1250 for entry in remove:
1251 if machine:
1252 entry_remove_line = 'SRC_URI:remove:%s = " %s"\n' % (machine, entry)
1253 else:
1254 entry_remove_line = 'SRC_URI:remove = "%s"\n' % entry
1255
1256 expectedlines.extend([entry_remove_line,
1257 '\n'])
1258
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001259 if has_src_uri:
1260 uri = 'file://%s' % filename
1261 if expected_subdir:
1262 uri += ';subdir=%s' % expected_subdir
Patrick Williams169d7bc2024-01-05 11:33:25 -06001263 if machine:
1264 src_uri_line = 'SRC_URI%s = " %s"\n' % (override, uri)
1265 else:
1266 src_uri_line = 'SRC_URI += "%s"\n' % uri
1267
1268 expectedlines.extend([src_uri_line, '\n'])
1269
1270 with open("/tmp/tmp.txt", "w") as file:
1271 print(expectedlines, file=file)
1272
1273 if machine:
1274 filename = '%s/%s' % (machine, filename)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001275
1276 return self._try_recipetool_appendsrcfile(testrecipe, newfile, destpath, options, expectedlines, [filename])
1277
1278 def _test_appendsrcfiles(self, testrecipe, newfiles, expectedfiles=None, destdir=None, options=''):
1279 if expectedfiles is None:
1280 expectedfiles = [os.path.basename(n) for n in newfiles]
1281
1282 self._try_recipetool_appendsrcfiles(testrecipe, newfiles, expectedfiles=expectedfiles, destdir=destdir, options=options)
1283
1284 bb_vars = get_bb_vars(['SRC_URI', 'FILE', 'FILESEXTRAPATHS'], testrecipe)
1285 src_uri = bb_vars['SRC_URI'].split()
1286 for f in expectedfiles:
1287 if destdir:
1288 self.assertIn('file://%s;subdir=%s' % (f, destdir), src_uri)
1289 else:
1290 self.assertIn('file://%s' % f, src_uri)
1291
1292 recipefile = bb_vars['FILE']
1293 bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir)
1294 filesdir = os.path.join(os.path.dirname(bbappendfile), testrecipe)
1295 filesextrapaths = bb_vars['FILESEXTRAPATHS'].split(':')
1296 self.assertIn(filesdir, filesextrapaths)
1297
1298
1299
1300
1301class RecipetoolAppendsrcTests(RecipetoolAppendsrcBase):
1302
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001303 def test_recipetool_appendsrcfile_basic(self):
1304 self._test_appendsrcfile('base-files', 'a-file')
1305
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001306 def test_recipetool_appendsrcfile_basic_wildcard(self):
1307 testrecipe = 'base-files'
1308 self._test_appendsrcfile(testrecipe, 'a-file', options='-w')
1309 recipefile = get_bb_var('FILE', testrecipe)
1310 bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir)
1311 self.assertEqual(os.path.basename(bbappendfile), '%s_%%.bbappend' % testrecipe)
1312
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001313 def test_recipetool_appendsrcfile_subdir_basic(self):
1314 self._test_appendsrcfile('base-files', 'a-file', 'tmp')
1315
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001316 def test_recipetool_appendsrcfile_subdir_basic_dirdest(self):
1317 self._test_appendsrcfile('base-files', destdir='tmp')
1318
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001319 def test_recipetool_appendsrcfile_srcdir_basic(self):
1320 testrecipe = 'bash'
1321 bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe)
1322 srcdir = bb_vars['S']
1323 workdir = bb_vars['WORKDIR']
1324 subdir = os.path.relpath(srcdir, workdir)
1325 self._test_appendsrcfile(testrecipe, 'a-file', srcdir=subdir)
1326
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001327 def test_recipetool_appendsrcfile_existing_in_src_uri(self):
1328 testrecipe = 'base-files'
Patrick Williams169d7bc2024-01-05 11:33:25 -06001329 filepath,_ = self._get_first_file_uri(testrecipe)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001330 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe)
1331 self._test_appendsrcfile(testrecipe, filepath, has_src_uri=False)
1332
Patrick Williams169d7bc2024-01-05 11:33:25 -06001333 def test_recipetool_appendsrcfile_existing_in_src_uri_diff_params(self, machine=None):
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001334 testrecipe = 'base-files'
1335 subdir = 'tmp'
Patrick Williams169d7bc2024-01-05 11:33:25 -06001336 filepath, srcuri_entry = self._get_first_file_uri(testrecipe)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001337 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe)
1338
Patrick Williams169d7bc2024-01-05 11:33:25 -06001339 self._test_appendsrcfile(testrecipe, filepath, subdir, machine=machine, remove=[srcuri_entry])
1340
1341 def test_recipetool_appendsrcfile_machine(self):
1342 # A very basic test
1343 self._test_appendsrcfile('base-files', 'a-file', machine='mymachine')
1344
1345 # Force cleaning the output of previous test
1346 self.tearDownLocal()
1347
1348 # A more complex test: existing entry in src_uri with different param
1349 self.test_recipetool_appendsrcfile_existing_in_src_uri_diff_params(machine='mymachine')
1350
1351 def test_recipetool_appendsrcfile_update_recipe_basic(self):
1352 testrecipe = "mtd-utils-selftest"
1353 recipefile = get_bb_var('FILE', testrecipe)
1354 self.assertIn('meta-selftest', recipefile, 'This test expect %s recipe to be in meta-selftest')
1355 cmd = 'recipetool appendsrcfile -W -u meta-selftest %s %s' % (testrecipe, self.testfile)
1356 result = runCmd(cmd)
1357 self.assertNotIn('Traceback', result.output)
1358 self.add_command_to_tearDown('cd %s; rm -f %s/%s; git checkout .' % (os.path.dirname(recipefile), testrecipe, os.path.basename(self.testfile)))
1359
1360 expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)),
1361 ('??', '.*/%s/%s$' % (testrecipe, os.path.basename(self.testfile)))]
1362 self._check_repo_status(os.path.dirname(recipefile), expected_status)
1363 result = runCmd('git diff %s' % os.path.basename(recipefile), cwd=os.path.dirname(recipefile))
1364 removelines = []
1365 addlines = [
1366 'file://%s \\\\' % os.path.basename(self.testfile),
1367 ]
1368 self._check_diff(result.output, addlines, removelines)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001369
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001370 def test_recipetool_appendsrcfile_replace_file_srcdir(self):
1371 testrecipe = 'bash'
1372 filepath = 'Makefile.in'
1373 bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe)
1374 srcdir = bb_vars['S']
1375 workdir = bb_vars['WORKDIR']
1376 subdir = os.path.relpath(srcdir, workdir)
1377
1378 self._test_appendsrcfile(testrecipe, filepath, srcdir=subdir)
1379 bitbake('%s:do_unpack' % testrecipe)
Brad Bishop64c979e2019-11-04 13:55:29 -05001380 with open(self.testfile, 'r') as testfile:
1381 with open(os.path.join(srcdir, filepath), 'r') as makefilein:
1382 self.assertEqual(testfile.read(), makefilein.read())
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001383
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001384 def test_recipetool_appendsrcfiles_basic(self, destdir=None):
1385 newfiles = [self.testfile]
1386 for i in range(1, 5):
1387 testfile = os.path.join(self.tempdir, 'testfile%d' % i)
1388 with open(testfile, 'w') as f:
1389 f.write('Test file %d\n' % i)
1390 newfiles.append(testfile)
1391 self._test_appendsrcfiles('gcc', newfiles, destdir=destdir, options='-W')
1392
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001393 def test_recipetool_appendsrcfiles_basic_subdir(self):
1394 self.test_recipetool_appendsrcfiles_basic(destdir='testdir')