blob: df15c80069c326a751d53af8ab36dd7b1bee9e7f [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
747
748class RecipetoolTests(RecipetoolBase):
749
750 @classmethod
751 def setUpClass(cls):
752 import sys
753
754 super(RecipetoolTests, cls).setUpClass()
755 bb_vars = get_bb_vars(['BBPATH'])
756 cls.bbpath = bb_vars['BBPATH']
757 libpath = os.path.join(get_bb_var('COREBASE'), 'scripts', 'lib', 'recipetool')
758 sys.path.insert(0, libpath)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500759
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600760 def test_recipetool_create_go(self):
761 # Basic test to check go recipe generation
762 def urifiy(url, version, modulepath = None, pathmajor = None, subdir = None):
763 modulepath = ",path='%s'" % modulepath if len(modulepath) else ''
764 pathmajor = ",pathmajor='%s'" % pathmajor if len(pathmajor) else ''
765 subdir = ",subdir='%s'" % subdir if len(subdir) else ''
766 return "${@go_src_uri('%s','%s'%s%s%s)}" % (url, version, modulepath, pathmajor, subdir)
767
768 temprecipe = os.path.join(self.tempdir, 'recipe')
769 os.makedirs(temprecipe)
770
771 recipefile = os.path.join(temprecipe, 'edgex-go_git.bb')
772 deps_require_file = os.path.join(temprecipe, 'edgex-go', 'edgex-go-modules.inc')
773 lics_require_file = os.path.join(temprecipe, 'edgex-go', 'edgex-go-licenses.inc')
774 modules_txt_file = os.path.join(temprecipe, 'edgex-go', 'modules.txt')
775
776 srcuri = 'https://github.com/edgexfoundry/edgex-go.git'
777 srcrev = "v3.0.0"
778 srcbranch = "main"
779
780 result = runCmd('recipetool create -o %s %s -S %s -B %s' % (temprecipe, srcuri, srcrev, srcbranch))
781
782 self.maxDiff = None
783 inherits = ['go-vendor']
784
785 checkvars = {}
786 checkvars['GO_IMPORT'] = "github.com/edgexfoundry/edgex-go"
787 checkvars['SRC_URI'] = {'git://${GO_IMPORT};destsuffix=git/src/${GO_IMPORT};nobranch=1;name=${BPN};protocol=https',
788 'file://modules.txt'}
789 checkvars['LIC_FILES_CHKSUM'] = {'file://src/${GO_IMPORT}/LICENSE;md5=8f8bc924cf73f6a32381e5fd4c58d603'}
790
791 self.assertTrue(os.path.isfile(recipefile))
792 self._test_recipe_contents(recipefile, checkvars, inherits)
793
794 checkvars = {}
795 checkvars['VENDORED_LIC_FILES_CHKSUM'] = set(
796 ['file://src/${GO_IMPORT}/vendor/github.com/Microsoft/go-winio/LICENSE;md5=69205ff73858f2c22b2ca135b557e8ef',
797 'file://src/${GO_IMPORT}/vendor/github.com/armon/go-metrics/LICENSE;md5=d2d77030c0183e3d1e66d26dc1f243be',
798 'file://src/${GO_IMPORT}/vendor/github.com/cenkalti/backoff/LICENSE;md5=1571d94433e3f3aa05267efd4dbea68b',
799 'file://src/${GO_IMPORT}/vendor/github.com/davecgh/go-spew/LICENSE;md5=c06795ed54b2a35ebeeb543cd3a73e56',
800 'file://src/${GO_IMPORT}/vendor/github.com/eclipse/paho.mqtt.golang/LICENSE;md5=dcdb33474b60c38efd27356d8f2edec7',
801 'file://src/${GO_IMPORT}/vendor/github.com/eclipse/paho.mqtt.golang/edl-v10;md5=3adfcc70f5aeb7a44f3f9b495aa1fbf3',
802 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-bootstrap/v3/LICENSE;md5=0d6dae39976133b2851fba4c1e1275ff',
803 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-configuration/v3/LICENSE;md5=0d6dae39976133b2851fba4c1e1275ff',
804 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-core-contracts/v3/LICENSE;md5=0d6dae39976133b2851fba4c1e1275ff',
805 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-messaging/v3/LICENSE;md5=0d6dae39976133b2851fba4c1e1275ff',
806 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-registry/v3/LICENSE;md5=0d6dae39976133b2851fba4c1e1275ff',
807 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-secrets/v3/LICENSE;md5=f9fa2f4f8e0ef8cc7b5dd150963eb457',
808 'file://src/${GO_IMPORT}/vendor/github.com/fatih/color/LICENSE.md;md5=316e6d590bdcde7993fb175662c0dd5a',
809 'file://src/${GO_IMPORT}/vendor/github.com/fxamacker/cbor/v2/LICENSE;md5=827f5a2fa861382d35a3943adf9ebb86',
810 'file://src/${GO_IMPORT}/vendor/github.com/go-jose/go-jose/v3/LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57',
811 'file://src/${GO_IMPORT}/vendor/github.com/go-jose/go-jose/v3/json/LICENSE;md5=591778525c869cdde0ab5a1bf283cd81',
812 'file://src/${GO_IMPORT}/vendor/github.com/go-kit/log/LICENSE;md5=5b7c15ad5fffe2ff6e9d58a6c161f082',
813 'file://src/${GO_IMPORT}/vendor/github.com/go-logfmt/logfmt/LICENSE;md5=98e39517c38127f969de33057067091e',
814 'file://src/${GO_IMPORT}/vendor/github.com/go-playground/locales/LICENSE;md5=3ccbda375ee345400ad1da85ba522301',
815 'file://src/${GO_IMPORT}/vendor/github.com/go-playground/universal-translator/LICENSE;md5=2e2b21ef8f61057977d27c727c84bef1',
816 'file://src/${GO_IMPORT}/vendor/github.com/go-playground/validator/v10/LICENSE;md5=a718a0f318d76f7c5d510cbae84f0b60',
817 'file://src/${GO_IMPORT}/vendor/github.com/go-redis/redis/v7/LICENSE;md5=58103aa5ea1ee9b7a369c9c4a95ef9b5',
818 'file://src/${GO_IMPORT}/vendor/github.com/golang/protobuf/LICENSE;md5=939cce1ec101726fa754e698ac871622',
819 'file://src/${GO_IMPORT}/vendor/github.com/gomodule/redigo/LICENSE;md5=2ee41112a44fe7014dce33e26468ba93',
820 'file://src/${GO_IMPORT}/vendor/github.com/google/uuid/LICENSE;md5=88073b6dd8ec00fe09da59e0b6dfded1',
821 'file://src/${GO_IMPORT}/vendor/github.com/gorilla/mux/LICENSE;md5=33fa1116c45f9e8de714033f99edde13',
822 'file://src/${GO_IMPORT}/vendor/github.com/gorilla/websocket/LICENSE;md5=c007b54a1743d596f46b2748d9f8c044',
823 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/consul/api/LICENSE;md5=b8a277a612171b7526e9be072f405ef4',
824 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/errwrap/LICENSE;md5=b278a92d2c1509760384428817710378',
825 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/go-cleanhttp/LICENSE;md5=65d26fcc2f35ea6a181ac777e42db1ea',
826 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/go-hclog/LICENSE;md5=ec7f605b74b9ad03347d0a93a5cc7eb8',
827 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/go-immutable-radix/LICENSE;md5=65d26fcc2f35ea6a181ac777e42db1ea',
828 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/go-multierror/LICENSE;md5=d44fdeb607e2d2614db9464dbedd4094',
829 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/go-rootcerts/LICENSE;md5=65d26fcc2f35ea6a181ac777e42db1ea',
830 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/golang-lru/LICENSE;md5=f27a50d2e878867827842f2c60e30bfc',
831 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/serf/LICENSE;md5=b278a92d2c1509760384428817710378',
832 'file://src/${GO_IMPORT}/vendor/github.com/leodido/go-urn/LICENSE;md5=8f50db5538ec1148a9b3d14ed96c3418',
833 'file://src/${GO_IMPORT}/vendor/github.com/mattn/go-colorable/LICENSE;md5=24ce168f90aec2456a73de1839037245',
834 'file://src/${GO_IMPORT}/vendor/github.com/mattn/go-isatty/LICENSE;md5=f509beadd5a11227c27b5d2ad6c9f2c6',
835 'file://src/${GO_IMPORT}/vendor/github.com/mitchellh/consulstructure/LICENSE;md5=96ada10a9e51c98c4656f2cede08c673',
836 'file://src/${GO_IMPORT}/vendor/github.com/mitchellh/copystructure/LICENSE;md5=56da355a12d4821cda57b8f23ec34bc4',
837 'file://src/${GO_IMPORT}/vendor/github.com/mitchellh/go-homedir/LICENSE;md5=3f7765c3d4f58e1f84c4313cecf0f5bd',
838 'file://src/${GO_IMPORT}/vendor/github.com/mitchellh/mapstructure/LICENSE;md5=3f7765c3d4f58e1f84c4313cecf0f5bd',
839 'file://src/${GO_IMPORT}/vendor/github.com/mitchellh/reflectwalk/LICENSE;md5=3f7765c3d4f58e1f84c4313cecf0f5bd',
840 'file://src/${GO_IMPORT}/vendor/github.com/nats-io/nats.go/LICENSE;md5=86d3f3a95c324c9479bd8986968f4327',
841 'file://src/${GO_IMPORT}/vendor/github.com/nats-io/nkeys/LICENSE;md5=86d3f3a95c324c9479bd8986968f4327',
842 'file://src/${GO_IMPORT}/vendor/github.com/nats-io/nuid/LICENSE;md5=86d3f3a95c324c9479bd8986968f4327',
843 'file://src/${GO_IMPORT}/vendor/github.com/pmezard/go-difflib/LICENSE;md5=e9a2ebb8de779a07500ddecca806145e',
844 'file://src/${GO_IMPORT}/vendor/github.com/rcrowley/go-metrics/LICENSE;md5=1bdf5d819f50f141366dabce3be1460f',
845 'file://src/${GO_IMPORT}/vendor/github.com/spiffe/go-spiffe/v2/LICENSE;md5=86d3f3a95c324c9479bd8986968f4327',
846 'file://src/${GO_IMPORT}/vendor/github.com/stretchr/objx/LICENSE;md5=d023fd31d3ca39ec61eec65a91732735',
847 'file://src/${GO_IMPORT}/vendor/github.com/stretchr/testify/LICENSE;md5=188f01994659f3c0d310612333d2a26f',
848 'file://src/${GO_IMPORT}/vendor/github.com/x448/float16/LICENSE;md5=de8f8e025d57fe7ee0b67f30d571323b',
849 'file://src/${GO_IMPORT}/vendor/github.com/zeebo/errs/LICENSE;md5=84914ab36fc0eb48edbaa53e66e8d326',
850 'file://src/${GO_IMPORT}/vendor/golang.org/x/crypto/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
851 'file://src/${GO_IMPORT}/vendor/golang.org/x/mod/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
852 'file://src/${GO_IMPORT}/vendor/golang.org/x/net/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
853 'file://src/${GO_IMPORT}/vendor/golang.org/x/sync/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
854 'file://src/${GO_IMPORT}/vendor/golang.org/x/sys/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
855 'file://src/${GO_IMPORT}/vendor/golang.org/x/text/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
856 'file://src/${GO_IMPORT}/vendor/golang.org/x/tools/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707',
857 'file://src/${GO_IMPORT}/vendor/google.golang.org/genproto/LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57',
858 'file://src/${GO_IMPORT}/vendor/google.golang.org/grpc/LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57',
859 'file://src/${GO_IMPORT}/vendor/google.golang.org/protobuf/LICENSE;md5=02d4002e9171d41a8fad93aa7faf3956',
860 'file://src/${GO_IMPORT}/vendor/gopkg.in/eapache/queue.v1/LICENSE;md5=1bfd4408d3de090ef6b908b0cc45a316',
861 'file://src/${GO_IMPORT}/vendor/gopkg.in/yaml.v3/LICENSE;md5=3c91c17266710e16afdbb2b6d15c761c'])
862
863 self.assertTrue(os.path.isfile(lics_require_file))
864 self._test_recipe_contents(lics_require_file, checkvars, [])
865
866 dependencies = \
867 [ ('github.com/eclipse/paho.mqtt.golang','v1.4.2', '', '', ''),
868 ('github.com/edgexfoundry/go-mod-bootstrap','v3.0.1','github.com/edgexfoundry/go-mod-bootstrap/v3','/v3', ''),
869 ('github.com/edgexfoundry/go-mod-configuration','v3.0.0','github.com/edgexfoundry/go-mod-configuration/v3','/v3', ''),
870 ('github.com/edgexfoundry/go-mod-core-contracts','v3.0.0','github.com/edgexfoundry/go-mod-core-contracts/v3','/v3', ''),
871 ('github.com/edgexfoundry/go-mod-messaging','v3.0.0','github.com/edgexfoundry/go-mod-messaging/v3','/v3', ''),
872 ('github.com/edgexfoundry/go-mod-secrets','v3.0.1','github.com/edgexfoundry/go-mod-secrets/v3','/v3', ''),
873 ('github.com/fxamacker/cbor','v2.4.0','github.com/fxamacker/cbor/v2','/v2', ''),
874 ('github.com/gomodule/redigo','v1.8.9', '', '', ''),
875 ('github.com/google/uuid','v1.3.0', '', '', ''),
876 ('github.com/gorilla/mux','v1.8.0', '', '', ''),
877 ('github.com/rcrowley/go-metrics','v0.0.0-20201227073835-cf1acfcdf475', '', '', ''),
878 ('github.com/spiffe/go-spiffe','v2.1.4','github.com/spiffe/go-spiffe/v2','/v2', ''),
879 ('github.com/stretchr/testify','v1.8.2', '', '', ''),
880 ('go.googlesource.com/crypto','v0.8.0','golang.org/x/crypto', '', ''),
881 ('gopkg.in/eapache/queue.v1','v1.1.0', '', '', ''),
882 ('gopkg.in/yaml.v3','v3.0.1', '', '', ''),
883 ('github.com/microsoft/go-winio','v0.6.0','github.com/Microsoft/go-winio', '', ''),
884 ('github.com/hashicorp/go-metrics','v0.3.10','github.com/armon/go-metrics', '', ''),
885 ('github.com/cenkalti/backoff','v2.2.1+incompatible', '', '', ''),
886 ('github.com/davecgh/go-spew','v1.1.1', '', '', ''),
887 ('github.com/edgexfoundry/go-mod-registry','v3.0.0','github.com/edgexfoundry/go-mod-registry/v3','/v3', ''),
888 ('github.com/fatih/color','v1.9.0', '', '', ''),
889 ('github.com/go-jose/go-jose','v3.0.0','github.com/go-jose/go-jose/v3','/v3', ''),
890 ('github.com/go-kit/log','v0.2.1', '', '', ''),
891 ('github.com/go-logfmt/logfmt','v0.5.1', '', '', ''),
892 ('github.com/go-playground/locales','v0.14.1', '', '', ''),
893 ('github.com/go-playground/universal-translator','v0.18.1', '', '', ''),
894 ('github.com/go-playground/validator','v10.13.0','github.com/go-playground/validator/v10','/v10', ''),
895 ('github.com/go-redis/redis','v7.3.0','github.com/go-redis/redis/v7','/v7', ''),
896 ('github.com/golang/protobuf','v1.5.2', '', '', ''),
897 ('github.com/gorilla/websocket','v1.4.2', '', '', ''),
898 ('github.com/hashicorp/consul','v1.20.0','github.com/hashicorp/consul/api', '', 'api'),
899 ('github.com/hashicorp/errwrap','v1.0.0', '', '', ''),
900 ('github.com/hashicorp/go-cleanhttp','v0.5.1', '', '', ''),
901 ('github.com/hashicorp/go-hclog','v0.14.1', '', '', ''),
902 ('github.com/hashicorp/go-immutable-radix','v1.3.0', '', '', ''),
903 ('github.com/hashicorp/go-multierror','v1.1.1', '', '', ''),
904 ('github.com/hashicorp/go-rootcerts','v1.0.2', '', '', ''),
905 ('github.com/hashicorp/golang-lru','v0.5.4', '', '', ''),
906 ('github.com/hashicorp/serf','v0.10.1', '', '', ''),
907 ('github.com/leodido/go-urn','v1.2.3', '', '', ''),
908 ('github.com/mattn/go-colorable','v0.1.12', '', '', ''),
909 ('github.com/mattn/go-isatty','v0.0.14', '', '', ''),
910 ('github.com/mitchellh/consulstructure','v0.0.0-20190329231841-56fdc4d2da54', '', '', ''),
911 ('github.com/mitchellh/copystructure','v1.2.0', '', '', ''),
912 ('github.com/mitchellh/go-homedir','v1.1.0', '', '', ''),
913 ('github.com/mitchellh/mapstructure','v1.5.0', '', '', ''),
914 ('github.com/mitchellh/reflectwalk','v1.0.2', '', '', ''),
915 ('github.com/nats-io/nats.go','v1.25.0', '', '', ''),
916 ('github.com/nats-io/nkeys','v0.4.4', '', '', ''),
917 ('github.com/nats-io/nuid','v1.0.1', '', '', ''),
918 ('github.com/pmezard/go-difflib','v1.0.0', '', '', ''),
919 ('github.com/stretchr/objx','v0.5.0', '', '', ''),
920 ('github.com/x448/float16','v0.8.4', '', '', ''),
921 ('github.com/zeebo/errs','v1.3.0', '', '', ''),
922 ('go.googlesource.com/mod','v0.8.0','golang.org/x/mod', '', ''),
923 ('go.googlesource.com/net','v0.9.0','golang.org/x/net', '', ''),
924 ('go.googlesource.com/sync','v0.1.0','golang.org/x/sync', '', ''),
925 ('go.googlesource.com/sys','v0.7.0','golang.org/x/sys', '', ''),
926 ('go.googlesource.com/text','v0.9.0','golang.org/x/text', '', ''),
927 ('go.googlesource.com/tools','v0.6.0','golang.org/x/tools', '', ''),
928 ('github.com/googleapis/go-genproto','v0.0.0-20230223222841-637eb2293923','google.golang.org/genproto', '', ''),
929 ('github.com/grpc/grpc-go','v1.53.0','google.golang.org/grpc', '', ''),
930 ('go.googlesource.com/protobuf','v1.28.1','google.golang.org/protobuf', '', ''),
931 ]
932
933 src_uri = set()
934 for d in dependencies:
935 src_uri.add(urifiy(*d))
936
937 checkvars = {}
938 checkvars['GO_DEPENDENCIES_SRC_URI'] = src_uri
939
940 self.assertTrue(os.path.isfile(deps_require_file))
941 self._test_recipe_contents(deps_require_file, checkvars, [])
942
943
Patrick Williams169d7bc2024-01-05 11:33:25 -0600944
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500945 def _copy_file_with_cleanup(self, srcfile, basedstdir, *paths):
946 dstdir = basedstdir
947 self.assertTrue(os.path.exists(dstdir))
948 for p in paths:
949 dstdir = os.path.join(dstdir, p)
950 if not os.path.exists(dstdir):
Patrick Williams169d7bc2024-01-05 11:33:25 -0600951 try:
952 os.makedirs(dstdir)
953 except PermissionError:
954 return False
955 except OSError as e:
956 if e.errno == errno.EROFS:
957 return False
958 else:
959 raise e
Andrew Geissler475cb722020-07-10 16:00:51 -0500960 if p == "lib":
961 # Can race with other tests
962 self.add_command_to_tearDown('rmdir --ignore-fail-on-non-empty %s' % dstdir)
963 else:
964 self.track_for_cleanup(dstdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500965 dstfile = os.path.join(dstdir, os.path.basename(srcfile))
966 if srcfile != dstfile:
Patrick Williams169d7bc2024-01-05 11:33:25 -0600967 try:
968 shutil.copy(srcfile, dstfile)
969 except PermissionError:
970 return False
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500971 self.track_for_cleanup(dstfile)
Patrick Williams169d7bc2024-01-05 11:33:25 -0600972 return True
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500973
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500974 def test_recipetool_load_plugin(self):
975 """Test that recipetool loads only the first found plugin in BBPATH."""
976
977 recipetool = runCmd("which recipetool")
978 fromname = runCmd("recipetool --quiet pluginfile")
979 srcfile = fromname.output
980 searchpath = self.bbpath.split(':') + [os.path.dirname(recipetool.output)]
981 plugincontent = []
982 with open(srcfile) as fh:
983 plugincontent = fh.readlines()
984 try:
985 self.assertIn('meta-selftest', srcfile, 'wrong bbpath plugin found')
Patrick Williams169d7bc2024-01-05 11:33:25 -0600986 searchpath = [
987 path for path in searchpath
988 if self._copy_file_with_cleanup(srcfile, path, 'lib', 'recipetool')
989 ]
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500990 result = runCmd("recipetool --quiet count")
991 self.assertEqual(result.output, '1')
992 result = runCmd("recipetool --quiet multiloaded")
993 self.assertEqual(result.output, "no")
994 for path in searchpath:
995 result = runCmd("recipetool --quiet bbdir")
Patrick Williams169d7bc2024-01-05 11:33:25 -0600996 self.assertEqual(os.path.realpath(result.output), os.path.realpath(path))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500997 os.unlink(os.path.join(result.output, 'lib', 'recipetool', 'bbpath.py'))
998 finally:
999 with open(srcfile, 'w') as fh:
1000 fh.writelines(plugincontent)
1001
Andrew Geissler595f6302022-01-24 19:11:47 +00001002 def test_recipetool_handle_license_vars(self):
1003 from create import handle_license_vars
1004 from unittest.mock import Mock
1005
1006 commonlicdir = get_bb_var('COMMON_LICENSE_DIR')
1007
Andrew Geisslerfc113ea2023-03-31 09:59:46 -05001008 class DataConnectorCopy(bb.tinfoil.TinfoilDataStoreConnector):
1009 pass
1010
1011 d = DataConnectorCopy
Andrew Geissler595f6302022-01-24 19:11:47 +00001012 d.getVar = Mock(return_value=commonlicdir)
1013
1014 srctree = tempfile.mkdtemp(prefix='recipetoolqa')
1015 self.track_for_cleanup(srctree)
1016
1017 # Multiple licenses
1018 licenses = ['MIT', 'ISC', 'BSD-3-Clause', 'Apache-2.0']
1019 for licence in licenses:
1020 shutil.copy(os.path.join(commonlicdir, licence), os.path.join(srctree, 'LICENSE.' + licence))
1021 # Duplicate license
1022 shutil.copy(os.path.join(commonlicdir, 'MIT'), os.path.join(srctree, 'LICENSE'))
1023
1024 extravalues = {
1025 # Duplicate and missing licenses
1026 'LICENSE': 'Zlib & BSD-2-Clause & Zlib',
1027 'LIC_FILES_CHKSUM': [
1028 'file://README.md;md5=0123456789abcdef0123456789abcd'
1029 ]
1030 }
1031 lines_before = []
1032 handled = []
1033 licvalues = handle_license_vars(srctree, lines_before, handled, extravalues, d)
1034 expected_lines_before = [
1035 '# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is',
1036 '# your responsibility to verify that the values are complete and correct.',
1037 '# NOTE: Original package / source metadata indicates license is: BSD-2-Clause & Zlib',
1038 '#',
1039 '# NOTE: multiple licenses have been detected; they have been separated with &',
1040 '# in the LICENSE value for now since it is a reasonable assumption that all',
1041 '# of the licenses apply. If instead there is a choice between the multiple',
1042 '# licenses then you should change the value to separate the licenses with |',
1043 '# instead of &. If there is any doubt, check the accompanying documentation',
1044 '# to determine which situation is applicable.',
1045 'LICENSE = "Apache-2.0 & BSD-2-Clause & BSD-3-Clause & ISC & MIT & Zlib"',
1046 'LIC_FILES_CHKSUM = "file://LICENSE;md5=0835ade698e0bcf8506ecda2f7b4f302 \\\n'
1047 ' file://LICENSE.Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10 \\\n'
1048 ' file://LICENSE.BSD-3-Clause;md5=550794465ba0ec5312d6919e203a55f9 \\\n'
1049 ' file://LICENSE.ISC;md5=f3b90e78ea0cffb20bf5cca7947a896d \\\n'
1050 ' file://LICENSE.MIT;md5=0835ade698e0bcf8506ecda2f7b4f302 \\\n'
1051 ' file://README.md;md5=0123456789abcdef0123456789abcd"',
1052 ''
1053 ]
1054 self.assertEqual(lines_before, expected_lines_before)
1055 expected_licvalues = [
1056 ('MIT', 'LICENSE', '0835ade698e0bcf8506ecda2f7b4f302'),
1057 ('Apache-2.0', 'LICENSE.Apache-2.0', '89aea4e17d99a7cacdbeed46a0096b10'),
1058 ('BSD-3-Clause', 'LICENSE.BSD-3-Clause', '550794465ba0ec5312d6919e203a55f9'),
1059 ('ISC', 'LICENSE.ISC', 'f3b90e78ea0cffb20bf5cca7947a896d'),
1060 ('MIT', 'LICENSE.MIT', '0835ade698e0bcf8506ecda2f7b4f302')
1061 ]
1062 self.assertEqual(handled, [('license', expected_licvalues)])
1063 self.assertEqual(extravalues, {})
1064 self.assertEqual(licvalues, expected_licvalues)
1065
1066
1067 def test_recipetool_split_pkg_licenses(self):
1068 from create import split_pkg_licenses
1069 licvalues = [
1070 # Duplicate licenses
1071 ('BSD-2-Clause', 'x/COPYING', None),
1072 ('BSD-2-Clause', 'x/LICENSE', None),
1073 # Multiple licenses
1074 ('MIT', 'x/a/LICENSE.MIT', None),
1075 ('ISC', 'x/a/LICENSE.ISC', None),
1076 # Alternative licenses
1077 ('(MIT | ISC)', 'x/b/LICENSE', None),
1078 # Alternative licenses without brackets
1079 ('MIT | BSD-2-Clause', 'x/c/LICENSE', None),
1080 # Multi licenses with alternatives
1081 ('MIT', 'x/d/COPYING', None),
1082 ('MIT | BSD-2-Clause', 'x/d/LICENSE', None),
1083 # Multi licenses with alternatives and brackets
1084 ('Apache-2.0 & ((MIT | ISC) & BSD-3-Clause)', 'x/e/LICENSE', None)
1085 ]
1086 packages = {
1087 '${PN}': '',
1088 'a': 'x/a',
1089 'b': 'x/b',
1090 'c': 'x/c',
1091 'd': 'x/d',
1092 'e': 'x/e',
1093 'f': 'x/f',
1094 'g': 'x/g',
1095 }
1096 fallback_licenses = {
1097 # Ignored
1098 'a': 'BSD-3-Clause',
1099 # Used
1100 'f': 'BSD-3-Clause'
1101 }
1102 outlines = []
1103 outlicenses = split_pkg_licenses(licvalues, packages, outlines, fallback_licenses)
1104 expected_outlicenses = {
1105 '${PN}': ['BSD-2-Clause'],
1106 'a': ['ISC', 'MIT'],
1107 'b': ['(ISC | MIT)'],
1108 'c': ['(BSD-2-Clause | MIT)'],
1109 'd': ['(BSD-2-Clause | MIT)', 'MIT'],
1110 'e': ['(ISC | MIT)', 'Apache-2.0', 'BSD-3-Clause'],
1111 'f': ['BSD-3-Clause'],
1112 'g': ['Unknown']
1113 }
1114 self.assertEqual(outlicenses, expected_outlicenses)
1115 expected_outlines = [
1116 'LICENSE:${PN} = "BSD-2-Clause"',
1117 'LICENSE:a = "ISC & MIT"',
1118 'LICENSE:b = "(ISC | MIT)"',
1119 'LICENSE:c = "(BSD-2-Clause | MIT)"',
1120 'LICENSE:d = "(BSD-2-Clause | MIT) & MIT"',
1121 'LICENSE:e = "(ISC | MIT) & Apache-2.0 & BSD-3-Clause"',
1122 'LICENSE:f = "BSD-3-Clause"',
1123 'LICENSE:g = "Unknown"'
1124 ]
1125 self.assertEqual(outlines, expected_outlines)
1126
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001127
1128class RecipetoolAppendsrcBase(RecipetoolBase):
1129 def _try_recipetool_appendsrcfile(self, testrecipe, newfile, destfile, options, expectedlines, expectedfiles):
1130 cmd = 'recipetool appendsrcfile %s %s %s %s %s' % (options, self.templayerdir, testrecipe, newfile, destfile)
1131 return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
1132
1133 def _try_recipetool_appendsrcfiles(self, testrecipe, newfiles, expectedlines=None, expectedfiles=None, destdir=None, options=''):
1134
1135 if destdir:
1136 options += ' -D %s' % destdir
1137
1138 if expectedfiles is None:
1139 expectedfiles = [os.path.basename(f) for f in newfiles]
1140
1141 cmd = 'recipetool appendsrcfiles %s %s %s %s' % (options, self.templayerdir, testrecipe, ' '.join(newfiles))
1142 return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
1143
1144 def _try_recipetool_appendsrcfile_fail(self, testrecipe, newfile, destfile, checkerror):
1145 cmd = 'recipetool appendsrcfile %s %s %s %s' % (self.templayerdir, testrecipe, newfile, destfile or '')
1146 result = runCmd(cmd, ignore_status=True)
1147 self.assertNotEqual(result.status, 0, 'Command "%s" should have failed but didn\'t' % cmd)
1148 self.assertNotIn('Traceback', result.output)
1149 for errorstr in checkerror:
1150 self.assertIn(errorstr, result.output)
1151
1152 @staticmethod
1153 def _get_first_file_uri(recipe):
1154 '''Return the first file:// in SRC_URI for the specified recipe.'''
1155 src_uri = get_bb_var('SRC_URI', recipe).split()
1156 for uri in src_uri:
1157 p = urllib.parse.urlparse(uri)
1158 if p.scheme == 'file':
Patrick Williams169d7bc2024-01-05 11:33:25 -06001159 return p.netloc + p.path, uri
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001160
Patrick Williams169d7bc2024-01-05 11:33:25 -06001161 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 -05001162 if newfile is None:
1163 newfile = self.testfile
1164
1165 if srcdir:
1166 if destdir:
1167 expected_subdir = os.path.join(srcdir, destdir)
1168 else:
1169 expected_subdir = srcdir
1170 else:
1171 options += " -W"
1172 expected_subdir = destdir
1173
1174 if filename:
1175 if destdir:
1176 destpath = os.path.join(destdir, filename)
1177 else:
1178 destpath = filename
1179 else:
1180 filename = os.path.basename(newfile)
1181 if destdir:
1182 destpath = destdir + os.sep
1183 else:
1184 destpath = '.' + os.sep
1185
Patrick Williams213cb262021-08-07 19:21:33 -05001186 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001187 '\n']
Patrick Williams169d7bc2024-01-05 11:33:25 -06001188
1189 override = ""
1190 if machine:
1191 options += ' -m %s' % machine
1192 override = ':append:%s' % machine
1193 expectedlines.extend(['PACKAGE_ARCH = "${MACHINE_ARCH}"\n',
1194 '\n'])
1195
1196 if remove:
1197 for entry in remove:
1198 if machine:
1199 entry_remove_line = 'SRC_URI:remove:%s = " %s"\n' % (machine, entry)
1200 else:
1201 entry_remove_line = 'SRC_URI:remove = "%s"\n' % entry
1202
1203 expectedlines.extend([entry_remove_line,
1204 '\n'])
1205
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001206 if has_src_uri:
1207 uri = 'file://%s' % filename
1208 if expected_subdir:
1209 uri += ';subdir=%s' % expected_subdir
Patrick Williams169d7bc2024-01-05 11:33:25 -06001210 if machine:
1211 src_uri_line = 'SRC_URI%s = " %s"\n' % (override, uri)
1212 else:
1213 src_uri_line = 'SRC_URI += "%s"\n' % uri
1214
1215 expectedlines.extend([src_uri_line, '\n'])
1216
1217 with open("/tmp/tmp.txt", "w") as file:
1218 print(expectedlines, file=file)
1219
1220 if machine:
1221 filename = '%s/%s' % (machine, filename)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001222
1223 return self._try_recipetool_appendsrcfile(testrecipe, newfile, destpath, options, expectedlines, [filename])
1224
1225 def _test_appendsrcfiles(self, testrecipe, newfiles, expectedfiles=None, destdir=None, options=''):
1226 if expectedfiles is None:
1227 expectedfiles = [os.path.basename(n) for n in newfiles]
1228
1229 self._try_recipetool_appendsrcfiles(testrecipe, newfiles, expectedfiles=expectedfiles, destdir=destdir, options=options)
1230
1231 bb_vars = get_bb_vars(['SRC_URI', 'FILE', 'FILESEXTRAPATHS'], testrecipe)
1232 src_uri = bb_vars['SRC_URI'].split()
1233 for f in expectedfiles:
1234 if destdir:
1235 self.assertIn('file://%s;subdir=%s' % (f, destdir), src_uri)
1236 else:
1237 self.assertIn('file://%s' % f, src_uri)
1238
1239 recipefile = bb_vars['FILE']
1240 bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir)
1241 filesdir = os.path.join(os.path.dirname(bbappendfile), testrecipe)
1242 filesextrapaths = bb_vars['FILESEXTRAPATHS'].split(':')
1243 self.assertIn(filesdir, filesextrapaths)
1244
1245
1246
1247
1248class RecipetoolAppendsrcTests(RecipetoolAppendsrcBase):
1249
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001250 def test_recipetool_appendsrcfile_basic(self):
1251 self._test_appendsrcfile('base-files', 'a-file')
1252
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001253 def test_recipetool_appendsrcfile_basic_wildcard(self):
1254 testrecipe = 'base-files'
1255 self._test_appendsrcfile(testrecipe, 'a-file', options='-w')
1256 recipefile = get_bb_var('FILE', testrecipe)
1257 bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir)
1258 self.assertEqual(os.path.basename(bbappendfile), '%s_%%.bbappend' % testrecipe)
1259
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001260 def test_recipetool_appendsrcfile_subdir_basic(self):
1261 self._test_appendsrcfile('base-files', 'a-file', 'tmp')
1262
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001263 def test_recipetool_appendsrcfile_subdir_basic_dirdest(self):
1264 self._test_appendsrcfile('base-files', destdir='tmp')
1265
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001266 def test_recipetool_appendsrcfile_srcdir_basic(self):
1267 testrecipe = 'bash'
1268 bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe)
1269 srcdir = bb_vars['S']
1270 workdir = bb_vars['WORKDIR']
1271 subdir = os.path.relpath(srcdir, workdir)
1272 self._test_appendsrcfile(testrecipe, 'a-file', srcdir=subdir)
1273
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001274 def test_recipetool_appendsrcfile_existing_in_src_uri(self):
1275 testrecipe = 'base-files'
Patrick Williams169d7bc2024-01-05 11:33:25 -06001276 filepath,_ = self._get_first_file_uri(testrecipe)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001277 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe)
1278 self._test_appendsrcfile(testrecipe, filepath, has_src_uri=False)
1279
Patrick Williams169d7bc2024-01-05 11:33:25 -06001280 def test_recipetool_appendsrcfile_existing_in_src_uri_diff_params(self, machine=None):
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001281 testrecipe = 'base-files'
1282 subdir = 'tmp'
Patrick Williams169d7bc2024-01-05 11:33:25 -06001283 filepath, srcuri_entry = self._get_first_file_uri(testrecipe)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001284 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe)
1285
Patrick Williams169d7bc2024-01-05 11:33:25 -06001286 self._test_appendsrcfile(testrecipe, filepath, subdir, machine=machine, remove=[srcuri_entry])
1287
1288 def test_recipetool_appendsrcfile_machine(self):
1289 # A very basic test
1290 self._test_appendsrcfile('base-files', 'a-file', machine='mymachine')
1291
1292 # Force cleaning the output of previous test
1293 self.tearDownLocal()
1294
1295 # A more complex test: existing entry in src_uri with different param
1296 self.test_recipetool_appendsrcfile_existing_in_src_uri_diff_params(machine='mymachine')
1297
1298 def test_recipetool_appendsrcfile_update_recipe_basic(self):
1299 testrecipe = "mtd-utils-selftest"
1300 recipefile = get_bb_var('FILE', testrecipe)
1301 self.assertIn('meta-selftest', recipefile, 'This test expect %s recipe to be in meta-selftest')
1302 cmd = 'recipetool appendsrcfile -W -u meta-selftest %s %s' % (testrecipe, self.testfile)
1303 result = runCmd(cmd)
1304 self.assertNotIn('Traceback', result.output)
1305 self.add_command_to_tearDown('cd %s; rm -f %s/%s; git checkout .' % (os.path.dirname(recipefile), testrecipe, os.path.basename(self.testfile)))
1306
1307 expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)),
1308 ('??', '.*/%s/%s$' % (testrecipe, os.path.basename(self.testfile)))]
1309 self._check_repo_status(os.path.dirname(recipefile), expected_status)
1310 result = runCmd('git diff %s' % os.path.basename(recipefile), cwd=os.path.dirname(recipefile))
1311 removelines = []
1312 addlines = [
1313 'file://%s \\\\' % os.path.basename(self.testfile),
1314 ]
1315 self._check_diff(result.output, addlines, removelines)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001316
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001317 def test_recipetool_appendsrcfile_replace_file_srcdir(self):
1318 testrecipe = 'bash'
1319 filepath = 'Makefile.in'
1320 bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe)
1321 srcdir = bb_vars['S']
1322 workdir = bb_vars['WORKDIR']
1323 subdir = os.path.relpath(srcdir, workdir)
1324
1325 self._test_appendsrcfile(testrecipe, filepath, srcdir=subdir)
1326 bitbake('%s:do_unpack' % testrecipe)
Brad Bishop64c979e2019-11-04 13:55:29 -05001327 with open(self.testfile, 'r') as testfile:
1328 with open(os.path.join(srcdir, filepath), 'r') as makefilein:
1329 self.assertEqual(testfile.read(), makefilein.read())
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001330
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001331 def test_recipetool_appendsrcfiles_basic(self, destdir=None):
1332 newfiles = [self.testfile]
1333 for i in range(1, 5):
1334 testfile = os.path.join(self.tempdir, 'testfile%d' % i)
1335 with open(testfile, 'w') as f:
1336 f.write('Test file %d\n' % i)
1337 newfiles.append(testfile)
1338 self._test_appendsrcfiles('gcc', newfiles, destdir=destdir, options='-W')
1339
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001340 def test_recipetool_appendsrcfiles_basic_subdir(self):
1341 self.test_recipetool_appendsrcfiles_basic(destdir='testdir')