blob: 06f980e1b0eff6a5bf3ec03db12274c520cbba10 [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001import os
2import shutil
3import tempfile
4import urllib.parse
5
6from oeqa.utils.commands import runCmd, bitbake, get_bb_var
7from oeqa.utils.commands import get_bb_vars, create_temp_layer
8from oeqa.core.decorator.oeid import OETestID
9from oeqa.selftest.cases import devtool
10
11templayerdir = None
12
13def setUpModule():
14 global templayerdir
15 templayerdir = tempfile.mkdtemp(prefix='recipetoolqa')
16 create_temp_layer(templayerdir, 'selftestrecipetool')
17 runCmd('bitbake-layers add-layer %s' % templayerdir)
18
19
20def tearDownModule():
21 runCmd('bitbake-layers remove-layer %s' % templayerdir, ignore_status=True)
22 runCmd('rm -rf %s' % templayerdir)
23
24
25class RecipetoolBase(devtool.DevtoolBase):
26
27 def setUpLocal(self):
28 super(RecipetoolBase, self).setUpLocal()
29 self.templayerdir = templayerdir
30 self.tempdir = tempfile.mkdtemp(prefix='recipetoolqa')
31 self.track_for_cleanup(self.tempdir)
32 self.testfile = os.path.join(self.tempdir, 'testfile')
33 with open(self.testfile, 'w') as f:
34 f.write('Test file\n')
35
36 def tearDownLocal(self):
37 runCmd('rm -rf %s/recipes-*' % self.templayerdir)
38 super(RecipetoolBase, self).tearDownLocal()
39
40 def _try_recipetool_appendcmd(self, cmd, testrecipe, expectedfiles, expectedlines=None):
41 result = runCmd(cmd)
42 self.assertNotIn('Traceback', result.output)
43
44 # Check the bbappend was created and applies properly
45 recipefile = get_bb_var('FILE', testrecipe)
46 bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir)
47
48 # Check the bbappend contents
49 if expectedlines is not None:
50 with open(bbappendfile, 'r') as f:
51 self.assertEqual(expectedlines, f.readlines(), "Expected lines are not present in %s" % bbappendfile)
52
53 # Check file was copied
54 filesdir = os.path.join(os.path.dirname(bbappendfile), testrecipe)
55 for expectedfile in expectedfiles:
56 self.assertTrue(os.path.isfile(os.path.join(filesdir, expectedfile)), 'Expected file %s to be copied next to bbappend, but it wasn\'t' % expectedfile)
57
58 # Check no other files created
59 createdfiles = []
60 for root, _, files in os.walk(filesdir):
61 for f in files:
62 createdfiles.append(os.path.relpath(os.path.join(root, f), filesdir))
63 self.assertTrue(sorted(createdfiles), sorted(expectedfiles))
64
65 return bbappendfile, result.output
66
67
68class RecipetoolTests(RecipetoolBase):
69
70 @classmethod
71 def setUpClass(cls):
72 super(RecipetoolTests, cls).setUpClass()
73 # Ensure we have the right data in shlibs/pkgdata
74 cls.logger.info('Running bitbake to generate pkgdata')
75 bitbake('-c packagedata base-files coreutils busybox selftest-recipetool-appendfile')
76 bb_vars = get_bb_vars(['COREBASE', 'BBPATH'])
77 cls.corebase = bb_vars['COREBASE']
78 cls.bbpath = bb_vars['BBPATH']
79
80 def _try_recipetool_appendfile(self, testrecipe, destfile, newfile, options, expectedlines, expectedfiles):
81 cmd = 'recipetool appendfile %s %s %s %s' % (self.templayerdir, destfile, newfile, options)
82 return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
83
84 def _try_recipetool_appendfile_fail(self, destfile, newfile, checkerror):
85 cmd = 'recipetool appendfile %s %s %s' % (self.templayerdir, destfile, newfile)
86 result = runCmd(cmd, ignore_status=True)
87 self.assertNotEqual(result.status, 0, 'Command "%s" should have failed but didn\'t' % cmd)
88 self.assertNotIn('Traceback', result.output)
89 for errorstr in checkerror:
90 self.assertIn(errorstr, result.output)
91
92 @OETestID(1177)
93 def test_recipetool_appendfile_basic(self):
94 # Basic test
95 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
96 '\n']
97 _, output = self._try_recipetool_appendfile('base-files', '/etc/motd', self.testfile, '', expectedlines, ['motd'])
98 self.assertNotIn('WARNING: ', output)
99
100 @OETestID(1183)
101 def test_recipetool_appendfile_invalid(self):
102 # Test some commands that should error
103 self._try_recipetool_appendfile_fail('/etc/passwd', self.testfile, ['ERROR: /etc/passwd cannot be handled by this tool', 'useradd', 'extrausers'])
104 self._try_recipetool_appendfile_fail('/etc/timestamp', self.testfile, ['ERROR: /etc/timestamp cannot be handled by this tool'])
105 self._try_recipetool_appendfile_fail('/dev/console', self.testfile, ['ERROR: /dev/console cannot be handled by this tool'])
106
107 @OETestID(1176)
108 def test_recipetool_appendfile_alternatives(self):
109 # Now try with a file we know should be an alternative
110 # (this is very much a fake example, but one we know is reliably an alternative)
111 self._try_recipetool_appendfile_fail('/bin/ls', self.testfile, ['ERROR: File /bin/ls is an alternative possibly provided by the following recipes:', 'coreutils', 'busybox'])
112 # Need a test file - should be executable
113 testfile2 = os.path.join(self.corebase, 'oe-init-build-env')
114 testfile2name = os.path.basename(testfile2)
115 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
116 '\n',
117 'SRC_URI += "file://%s"\n' % testfile2name,
118 '\n',
119 'do_install_append() {\n',
120 ' install -d ${D}${base_bindir}\n',
121 ' install -m 0755 ${WORKDIR}/%s ${D}${base_bindir}/ls\n' % testfile2name,
122 '}\n']
123 self._try_recipetool_appendfile('coreutils', '/bin/ls', testfile2, '-r coreutils', expectedlines, [testfile2name])
124 # Now try bbappending the same file again, contents should not change
125 bbappendfile, _ = self._try_recipetool_appendfile('coreutils', '/bin/ls', self.testfile, '-r coreutils', expectedlines, [testfile2name])
126 # But file should have
127 copiedfile = os.path.join(os.path.dirname(bbappendfile), 'coreutils', testfile2name)
128 result = runCmd('diff -q %s %s' % (testfile2, copiedfile), ignore_status=True)
129 self.assertNotEqual(result.status, 0, 'New file should have been copied but was not %s' % result.output)
130
131 @OETestID(1178)
132 def test_recipetool_appendfile_binary(self):
133 # Try appending a binary file
134 # /bin/ls can be a symlink to /usr/bin/ls
135 ls = os.path.realpath("/bin/ls")
136 result = runCmd('recipetool appendfile %s /bin/ls %s -r coreutils' % (self.templayerdir, ls))
137 self.assertIn('WARNING: ', result.output)
138 self.assertIn('is a binary', result.output)
139
140 @OETestID(1173)
141 def test_recipetool_appendfile_add(self):
142 # Try arbitrary file add to a recipe
143 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
144 '\n',
145 'SRC_URI += "file://testfile"\n',
146 '\n',
147 'do_install_append() {\n',
148 ' 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)
156 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
157 '\n',
158 'SRC_URI += "file://testfile \\\n',
159 ' file://%s \\\n' % testfile2name,
160 ' "\n',
161 '\n',
162 'do_install_append() {\n',
163 ' 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
169 @OETestID(1174)
170 def test_recipetool_appendfile_add_bindir(self):
171 # Try arbitrary file add to a recipe, this time to a location such that should be installed as executable
172 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
173 '\n',
174 'SRC_URI += "file://testfile"\n',
175 '\n',
176 'do_install_append() {\n',
177 ' install -d ${D}${bindir}\n',
178 ' install -m 0755 ${WORKDIR}/testfile ${D}${bindir}/selftest-recipetool-testbin\n',
179 '}\n']
180 _, output = self._try_recipetool_appendfile('netbase', '/usr/bin/selftest-recipetool-testbin', self.testfile, '-r netbase', expectedlines, ['testfile'])
181 self.assertNotIn('WARNING: ', output)
182
183 @OETestID(1175)
184 def test_recipetool_appendfile_add_machine(self):
185 # Try arbitrary file add to a recipe, this time to a location such that should be installed as executable
186 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
187 '\n',
188 'PACKAGE_ARCH = "${MACHINE_ARCH}"\n',
189 '\n',
190 'SRC_URI_append_mymachine = " file://testfile"\n',
191 '\n',
192 'do_install_append_mymachine() {\n',
193 ' install -d ${D}${datadir}\n',
194 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n',
195 '}\n']
196 _, output = self._try_recipetool_appendfile('netbase', '/usr/share/something', self.testfile, '-r netbase -m mymachine', expectedlines, ['mymachine/testfile'])
197 self.assertNotIn('WARNING: ', output)
198
199 @OETestID(1184)
200 def test_recipetool_appendfile_orig(self):
201 # A file that's in SRC_URI and in do_install with the same name
202 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
203 '\n']
204 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-orig', self.testfile, '', expectedlines, ['selftest-replaceme-orig'])
205 self.assertNotIn('WARNING: ', output)
206
207 @OETestID(1191)
208 def test_recipetool_appendfile_todir(self):
209 # A file that's in SRC_URI and in do_install with destination directory rather than file
210 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
211 '\n']
212 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-todir', self.testfile, '', expectedlines, ['selftest-replaceme-todir'])
213 self.assertNotIn('WARNING: ', output)
214
215 @OETestID(1187)
216 def test_recipetool_appendfile_renamed(self):
217 # A file that's in SRC_URI with a different name to the destination file
218 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
219 '\n']
220 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-renamed', self.testfile, '', expectedlines, ['file1'])
221 self.assertNotIn('WARNING: ', output)
222
223 @OETestID(1190)
224 def test_recipetool_appendfile_subdir(self):
225 # A file that's in SRC_URI in a subdir
226 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
227 '\n',
228 'SRC_URI += "file://testfile"\n',
229 '\n',
230 'do_install_append() {\n',
231 ' install -d ${D}${datadir}\n',
232 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-subdir\n',
233 '}\n']
234 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-subdir', self.testfile, '', expectedlines, ['testfile'])
235 self.assertNotIn('WARNING: ', output)
236
237 @OETestID(1189)
238 def test_recipetool_appendfile_src_glob(self):
239 # A file that's in SRC_URI as a glob
240 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
241 '\n',
242 'SRC_URI += "file://testfile"\n',
243 '\n',
244 'do_install_append() {\n',
245 ' install -d ${D}${datadir}\n',
246 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-src-globfile\n',
247 '}\n']
248 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-src-globfile', self.testfile, '', expectedlines, ['testfile'])
249 self.assertNotIn('WARNING: ', output)
250
251 @OETestID(1181)
252 def test_recipetool_appendfile_inst_glob(self):
253 # A file that's in do_install as a glob
254 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
255 '\n']
256 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-globfile', self.testfile, '', expectedlines, ['selftest-replaceme-inst-globfile'])
257 self.assertNotIn('WARNING: ', output)
258
259 @OETestID(1182)
260 def test_recipetool_appendfile_inst_todir_glob(self):
261 # A file that's in do_install as a glob with destination as a directory
262 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
263 '\n']
264 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-todir-globfile', self.testfile, '', expectedlines, ['selftest-replaceme-inst-todir-globfile'])
265 self.assertNotIn('WARNING: ', output)
266
267 @OETestID(1185)
268 def test_recipetool_appendfile_patch(self):
269 # A file that's added by a patch in SRC_URI
270 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
271 '\n',
272 'SRC_URI += "file://testfile"\n',
273 '\n',
274 'do_install_append() {\n',
275 ' install -d ${D}${sysconfdir}\n',
276 ' install -m 0644 ${WORKDIR}/testfile ${D}${sysconfdir}/selftest-replaceme-patched\n',
277 '}\n']
278 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/etc/selftest-replaceme-patched', self.testfile, '', expectedlines, ['testfile'])
279 for line in output.splitlines():
280 if 'WARNING: ' in line:
281 self.assertIn('add-file.patch', line, 'Unexpected warning found in output:\n%s' % line)
282 break
283 else:
284 self.fail('Patch warning not found in output:\n%s' % output)
285
286 @OETestID(1188)
287 def test_recipetool_appendfile_script(self):
288 # Now, a file that's in SRC_URI but installed by a script (so no mention in do_install)
289 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
290 '\n',
291 'SRC_URI += "file://testfile"\n',
292 '\n',
293 'do_install_append() {\n',
294 ' install -d ${D}${datadir}\n',
295 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-scripted\n',
296 '}\n']
297 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-scripted', self.testfile, '', expectedlines, ['testfile'])
298 self.assertNotIn('WARNING: ', output)
299
300 @OETestID(1180)
301 def test_recipetool_appendfile_inst_func(self):
302 # A file that's installed from a function called by do_install
303 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
304 '\n']
305 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-func', self.testfile, '', expectedlines, ['selftest-replaceme-inst-func'])
306 self.assertNotIn('WARNING: ', output)
307
308 @OETestID(1186)
309 def test_recipetool_appendfile_postinstall(self):
310 # A file that's created by a postinstall script (and explicitly mentioned in it)
311 # First try without specifying recipe
312 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'])
313 # Now specify recipe
314 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
315 '\n',
316 'SRC_URI += "file://testfile"\n',
317 '\n',
318 'do_install_append() {\n',
319 ' install -d ${D}${datadir}\n',
320 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-postinst\n',
321 '}\n']
322 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-postinst', self.testfile, '-r selftest-recipetool-appendfile', expectedlines, ['testfile'])
323
324 @OETestID(1179)
325 def test_recipetool_appendfile_extlayer(self):
326 # Try creating a bbappend in a layer that's not in bblayers.conf and has a different structure
327 exttemplayerdir = os.path.join(self.tempdir, 'extlayer')
328 self._create_temp_layer(exttemplayerdir, False, 'oeselftestextlayer', recipepathspec='metadata/recipes/recipes-*/*')
329 result = runCmd('recipetool appendfile %s /usr/share/selftest-replaceme-orig %s' % (exttemplayerdir, self.testfile))
330 self.assertNotIn('Traceback', result.output)
331 createdfiles = []
332 for root, _, files in os.walk(exttemplayerdir):
333 for f in files:
334 createdfiles.append(os.path.relpath(os.path.join(root, f), exttemplayerdir))
335 createdfiles.remove('conf/layer.conf')
336 expectedfiles = ['metadata/recipes/recipes-test/selftest-recipetool-appendfile/selftest-recipetool-appendfile.bbappend',
337 'metadata/recipes/recipes-test/selftest-recipetool-appendfile/selftest-recipetool-appendfile/selftest-replaceme-orig']
338 self.assertEqual(sorted(createdfiles), sorted(expectedfiles))
339
340 @OETestID(1192)
341 def test_recipetool_appendfile_wildcard(self):
342
343 def try_appendfile_wc(options):
344 result = runCmd('recipetool appendfile %s /etc/profile %s %s' % (self.templayerdir, self.testfile, options))
345 self.assertNotIn('Traceback', result.output)
346 bbappendfile = None
347 for root, _, files in os.walk(self.templayerdir):
348 for f in files:
349 if f.endswith('.bbappend'):
350 bbappendfile = f
351 break
352 if not bbappendfile:
353 self.fail('No bbappend file created')
354 runCmd('rm -rf %s/recipes-*' % self.templayerdir)
355 return bbappendfile
356
357 # Check without wildcard option
358 recipefn = os.path.basename(get_bb_var('FILE', 'base-files'))
359 filename = try_appendfile_wc('')
360 self.assertEqual(filename, recipefn.replace('.bb', '.bbappend'))
361 # Now check with wildcard option
362 filename = try_appendfile_wc('-w')
363 self.assertEqual(filename, recipefn.split('_')[0] + '_%.bbappend')
364
365 @OETestID(1193)
366 def test_recipetool_create(self):
367 # Try adding a recipe
368 tempsrc = os.path.join(self.tempdir, 'srctree')
369 os.makedirs(tempsrc)
370 recipefile = os.path.join(self.tempdir, 'logrotate_3.12.3.bb')
371 srcuri = 'https://github.com/logrotate/logrotate/releases/download/3.12.3/logrotate-3.12.3.tar.xz'
372 result = runCmd('recipetool create -o %s %s -x %s' % (recipefile, srcuri, tempsrc))
373 self.assertTrue(os.path.isfile(recipefile))
374 checkvars = {}
375 checkvars['LICENSE'] = 'GPLv2'
376 checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263'
377 checkvars['SRC_URI'] = 'https://github.com/logrotate/logrotate/releases/download/${PV}/logrotate-${PV}.tar.xz'
378 checkvars['SRC_URI[md5sum]'] = 'a560c57fac87c45b2fc17406cdf79288'
379 checkvars['SRC_URI[sha256sum]'] = '2e6a401cac9024db2288297e3be1a8ab60e7401ba8e91225218aaf4a27e82a07'
380 self._test_recipe_contents(recipefile, checkvars, [])
381
382 @OETestID(1194)
383 def test_recipetool_create_git(self):
384 if 'x11' not in get_bb_var('DISTRO_FEATURES'):
385 self.skipTest('Test requires x11 as distro feature')
386 # Ensure we have the right data in shlibs/pkgdata
387 bitbake('libpng pango libx11 libxext jpeg libcheck')
388 # Try adding a recipe
389 tempsrc = os.path.join(self.tempdir, 'srctree')
390 os.makedirs(tempsrc)
391 recipefile = os.path.join(self.tempdir, 'libmatchbox.bb')
392 srcuri = 'git://git.yoctoproject.org/libmatchbox'
393 result = runCmd(['recipetool', 'create', '-o', recipefile, srcuri + ";rev=9f7cf8895ae2d39c465c04cc78e918c157420269", '-x', tempsrc])
394 self.assertTrue(os.path.isfile(recipefile), 'recipetool did not create recipe file; output:\n%s' % result.output)
395 checkvars = {}
396 checkvars['LICENSE'] = 'LGPLv2.1'
397 checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=7fbc338309ac38fefcd64b04bb903e34'
398 checkvars['S'] = '${WORKDIR}/git'
399 checkvars['PV'] = '1.11+git${SRCPV}'
400 checkvars['SRC_URI'] = srcuri
401 checkvars['DEPENDS'] = set(['libcheck', 'libjpeg-turbo', 'libpng', 'libx11', 'libxext', 'pango'])
402 inherits = ['autotools', 'pkgconfig']
403 self._test_recipe_contents(recipefile, checkvars, inherits)
404
405 @OETestID(1392)
406 def test_recipetool_create_simple(self):
407 # Try adding a recipe
408 temprecipe = os.path.join(self.tempdir, 'recipe')
409 os.makedirs(temprecipe)
410 pv = '1.7.3.0'
411 srcuri = 'http://www.dest-unreach.org/socat/download/socat-%s.tar.bz2' % pv
412 result = runCmd('recipetool create %s -o %s' % (srcuri, temprecipe))
413 dirlist = os.listdir(temprecipe)
414 if len(dirlist) > 1:
415 self.fail('recipetool created more than just one file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist)))
416 if len(dirlist) < 1 or not os.path.isfile(os.path.join(temprecipe, dirlist[0])):
417 self.fail('recipetool did not create recipe file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist)))
418 self.assertEqual(dirlist[0], 'socat_%s.bb' % pv, 'Recipe file incorrectly named')
419 checkvars = {}
420 checkvars['LICENSE'] = set(['Unknown', 'GPLv2'])
421 checkvars['LIC_FILES_CHKSUM'] = set(['file://COPYING.OpenSSL;md5=5c9bccc77f67a8328ef4ebaf468116f4', 'file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263'])
422 # We don't check DEPENDS since they are variable for this recipe depending on what's in the sysroot
423 checkvars['S'] = None
424 checkvars['SRC_URI'] = srcuri.replace(pv, '${PV}')
425 inherits = ['autotools']
426 self._test_recipe_contents(os.path.join(temprecipe, dirlist[0]), checkvars, inherits)
427
428 @OETestID(1418)
429 def test_recipetool_create_cmake(self):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800430 bitbake('-c packagedata gtk+')
431
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500432 # Try adding a recipe
433 temprecipe = os.path.join(self.tempdir, 'recipe')
434 os.makedirs(temprecipe)
435 recipefile = os.path.join(temprecipe, 'navit_0.5.0.bb')
Brad Bishopc4ea0752018-11-15 14:30:15 -0800436 srcuri = 'http://downloads.yoctoproject.org/mirror/sources/navit-0.5.0.tar.gz'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500437 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
438 self.assertTrue(os.path.isfile(recipefile))
439 checkvars = {}
440 checkvars['LICENSE'] = set(['Unknown', 'GPLv2', 'LGPLv2'])
Brad Bishopc4ea0752018-11-15 14:30:15 -0800441 checkvars['SRC_URI'] = 'http://downloads.yoctoproject.org/mirror/sources/navit-${PV}.tar.gz'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500442 checkvars['SRC_URI[md5sum]'] = '242f398e979a6b8c0f3c802b63435b68'
443 checkvars['SRC_URI[sha256sum]'] = '13353481d7fc01a4f64e385dda460b51496366bba0fd2cc85a89a0747910e94d'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800444 checkvars['DEPENDS'] = set(['freetype', 'zlib', 'openssl', 'glib-2.0', 'virtual/libgl', 'virtual/egl', 'gtk+', 'libpng', 'libsdl', 'freeglut', 'dbus-glib', 'fribidi'])
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500445 inherits = ['cmake', 'python-dir', 'gettext', 'pkgconfig']
446 self._test_recipe_contents(recipefile, checkvars, inherits)
447
448 @OETestID(1638)
449 def test_recipetool_create_github(self):
450 # Basic test to see if github URL mangling works
451 temprecipe = os.path.join(self.tempdir, 'recipe')
452 os.makedirs(temprecipe)
453 recipefile = os.path.join(temprecipe, 'meson_git.bb')
454 srcuri = 'https://github.com/mesonbuild/meson;rev=0.32.0'
455 result = runCmd(['recipetool', 'create', '-o', temprecipe, srcuri])
456 self.assertTrue(os.path.isfile(recipefile))
457 checkvars = {}
458 checkvars['LICENSE'] = set(['Apache-2.0'])
459 checkvars['SRC_URI'] = 'git://github.com/mesonbuild/meson;protocol=https'
460 inherits = ['setuptools']
461 self._test_recipe_contents(recipefile, checkvars, inherits)
462
463 @OETestID(1639)
464 def test_recipetool_create_github_tarball(self):
465 # Basic test to ensure github URL mangling doesn't apply to release tarballs
466 temprecipe = os.path.join(self.tempdir, 'recipe')
467 os.makedirs(temprecipe)
468 pv = '0.32.0'
469 recipefile = os.path.join(temprecipe, 'meson_%s.bb' % pv)
470 srcuri = 'https://github.com/mesonbuild/meson/releases/download/%s/meson-%s.tar.gz' % (pv, pv)
471 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
472 self.assertTrue(os.path.isfile(recipefile))
473 checkvars = {}
474 checkvars['LICENSE'] = set(['Apache-2.0'])
475 checkvars['SRC_URI'] = 'https://github.com/mesonbuild/meson/releases/download/${PV}/meson-${PV}.tar.gz'
476 inherits = ['setuptools']
477 self._test_recipe_contents(recipefile, checkvars, inherits)
478
479 @OETestID(1637)
480 def test_recipetool_create_git_http(self):
481 # Basic test to check http git URL mangling works
482 temprecipe = os.path.join(self.tempdir, 'recipe')
483 os.makedirs(temprecipe)
484 recipefile = os.path.join(temprecipe, 'matchbox-terminal_git.bb')
485 srcuri = 'http://git.yoctoproject.org/git/matchbox-terminal'
486 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
487 self.assertTrue(os.path.isfile(recipefile))
488 checkvars = {}
489 checkvars['LICENSE'] = set(['GPLv2'])
490 checkvars['SRC_URI'] = 'git://git.yoctoproject.org/git/matchbox-terminal;protocol=http'
491 inherits = ['pkgconfig', 'autotools']
492 self._test_recipe_contents(recipefile, checkvars, inherits)
493
494 def _copy_file_with_cleanup(self, srcfile, basedstdir, *paths):
495 dstdir = basedstdir
496 self.assertTrue(os.path.exists(dstdir))
497 for p in paths:
498 dstdir = os.path.join(dstdir, p)
499 if not os.path.exists(dstdir):
500 os.makedirs(dstdir)
501 self.track_for_cleanup(dstdir)
502 dstfile = os.path.join(dstdir, os.path.basename(srcfile))
503 if srcfile != dstfile:
504 shutil.copy(srcfile, dstfile)
505 self.track_for_cleanup(dstfile)
506
507 @OETestID(1640)
508 def test_recipetool_load_plugin(self):
509 """Test that recipetool loads only the first found plugin in BBPATH."""
510
511 recipetool = runCmd("which recipetool")
512 fromname = runCmd("recipetool --quiet pluginfile")
513 srcfile = fromname.output
514 searchpath = self.bbpath.split(':') + [os.path.dirname(recipetool.output)]
515 plugincontent = []
516 with open(srcfile) as fh:
517 plugincontent = fh.readlines()
518 try:
519 self.assertIn('meta-selftest', srcfile, 'wrong bbpath plugin found')
520 for path in searchpath:
521 self._copy_file_with_cleanup(srcfile, path, 'lib', 'recipetool')
522 result = runCmd("recipetool --quiet count")
523 self.assertEqual(result.output, '1')
524 result = runCmd("recipetool --quiet multiloaded")
525 self.assertEqual(result.output, "no")
526 for path in searchpath:
527 result = runCmd("recipetool --quiet bbdir")
528 self.assertEqual(result.output, path)
529 os.unlink(os.path.join(result.output, 'lib', 'recipetool', 'bbpath.py'))
530 finally:
531 with open(srcfile, 'w') as fh:
532 fh.writelines(plugincontent)
533
534
535class RecipetoolAppendsrcBase(RecipetoolBase):
536 def _try_recipetool_appendsrcfile(self, testrecipe, newfile, destfile, options, expectedlines, expectedfiles):
537 cmd = 'recipetool appendsrcfile %s %s %s %s %s' % (options, self.templayerdir, testrecipe, newfile, destfile)
538 return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
539
540 def _try_recipetool_appendsrcfiles(self, testrecipe, newfiles, expectedlines=None, expectedfiles=None, destdir=None, options=''):
541
542 if destdir:
543 options += ' -D %s' % destdir
544
545 if expectedfiles is None:
546 expectedfiles = [os.path.basename(f) for f in newfiles]
547
548 cmd = 'recipetool appendsrcfiles %s %s %s %s' % (options, self.templayerdir, testrecipe, ' '.join(newfiles))
549 return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
550
551 def _try_recipetool_appendsrcfile_fail(self, testrecipe, newfile, destfile, checkerror):
552 cmd = 'recipetool appendsrcfile %s %s %s %s' % (self.templayerdir, testrecipe, newfile, destfile or '')
553 result = runCmd(cmd, ignore_status=True)
554 self.assertNotEqual(result.status, 0, 'Command "%s" should have failed but didn\'t' % cmd)
555 self.assertNotIn('Traceback', result.output)
556 for errorstr in checkerror:
557 self.assertIn(errorstr, result.output)
558
559 @staticmethod
560 def _get_first_file_uri(recipe):
561 '''Return the first file:// in SRC_URI for the specified recipe.'''
562 src_uri = get_bb_var('SRC_URI', recipe).split()
563 for uri in src_uri:
564 p = urllib.parse.urlparse(uri)
565 if p.scheme == 'file':
566 return p.netloc + p.path
567
568 def _test_appendsrcfile(self, testrecipe, filename=None, destdir=None, has_src_uri=True, srcdir=None, newfile=None, options=''):
569 if newfile is None:
570 newfile = self.testfile
571
572 if srcdir:
573 if destdir:
574 expected_subdir = os.path.join(srcdir, destdir)
575 else:
576 expected_subdir = srcdir
577 else:
578 options += " -W"
579 expected_subdir = destdir
580
581 if filename:
582 if destdir:
583 destpath = os.path.join(destdir, filename)
584 else:
585 destpath = filename
586 else:
587 filename = os.path.basename(newfile)
588 if destdir:
589 destpath = destdir + os.sep
590 else:
591 destpath = '.' + os.sep
592
593 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
594 '\n']
595 if has_src_uri:
596 uri = 'file://%s' % filename
597 if expected_subdir:
598 uri += ';subdir=%s' % expected_subdir
599 expectedlines[0:0] = ['SRC_URI += "%s"\n' % uri,
600 '\n']
601
602 return self._try_recipetool_appendsrcfile(testrecipe, newfile, destpath, options, expectedlines, [filename])
603
604 def _test_appendsrcfiles(self, testrecipe, newfiles, expectedfiles=None, destdir=None, options=''):
605 if expectedfiles is None:
606 expectedfiles = [os.path.basename(n) for n in newfiles]
607
608 self._try_recipetool_appendsrcfiles(testrecipe, newfiles, expectedfiles=expectedfiles, destdir=destdir, options=options)
609
610 bb_vars = get_bb_vars(['SRC_URI', 'FILE', 'FILESEXTRAPATHS'], testrecipe)
611 src_uri = bb_vars['SRC_URI'].split()
612 for f in expectedfiles:
613 if destdir:
614 self.assertIn('file://%s;subdir=%s' % (f, destdir), src_uri)
615 else:
616 self.assertIn('file://%s' % f, src_uri)
617
618 recipefile = bb_vars['FILE']
619 bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir)
620 filesdir = os.path.join(os.path.dirname(bbappendfile), testrecipe)
621 filesextrapaths = bb_vars['FILESEXTRAPATHS'].split(':')
622 self.assertIn(filesdir, filesextrapaths)
623
624
625
626
627class RecipetoolAppendsrcTests(RecipetoolAppendsrcBase):
628
629 @OETestID(1273)
630 def test_recipetool_appendsrcfile_basic(self):
631 self._test_appendsrcfile('base-files', 'a-file')
632
633 @OETestID(1274)
634 def test_recipetool_appendsrcfile_basic_wildcard(self):
635 testrecipe = 'base-files'
636 self._test_appendsrcfile(testrecipe, 'a-file', options='-w')
637 recipefile = get_bb_var('FILE', testrecipe)
638 bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir)
639 self.assertEqual(os.path.basename(bbappendfile), '%s_%%.bbappend' % testrecipe)
640
641 @OETestID(1281)
642 def test_recipetool_appendsrcfile_subdir_basic(self):
643 self._test_appendsrcfile('base-files', 'a-file', 'tmp')
644
645 @OETestID(1282)
646 def test_recipetool_appendsrcfile_subdir_basic_dirdest(self):
647 self._test_appendsrcfile('base-files', destdir='tmp')
648
649 @OETestID(1280)
650 def test_recipetool_appendsrcfile_srcdir_basic(self):
651 testrecipe = 'bash'
652 bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe)
653 srcdir = bb_vars['S']
654 workdir = bb_vars['WORKDIR']
655 subdir = os.path.relpath(srcdir, workdir)
656 self._test_appendsrcfile(testrecipe, 'a-file', srcdir=subdir)
657
658 @OETestID(1275)
659 def test_recipetool_appendsrcfile_existing_in_src_uri(self):
660 testrecipe = 'base-files'
661 filepath = self._get_first_file_uri(testrecipe)
662 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe)
663 self._test_appendsrcfile(testrecipe, filepath, has_src_uri=False)
664
665 @OETestID(1276)
666 def test_recipetool_appendsrcfile_existing_in_src_uri_diff_params(self):
667 testrecipe = 'base-files'
668 subdir = 'tmp'
669 filepath = self._get_first_file_uri(testrecipe)
670 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe)
671
672 output = self._test_appendsrcfile(testrecipe, filepath, subdir, has_src_uri=False)
673 self.assertTrue(any('with different parameters' in l for l in output))
674
675 @OETestID(1277)
676 def test_recipetool_appendsrcfile_replace_file_srcdir(self):
677 testrecipe = 'bash'
678 filepath = 'Makefile.in'
679 bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe)
680 srcdir = bb_vars['S']
681 workdir = bb_vars['WORKDIR']
682 subdir = os.path.relpath(srcdir, workdir)
683
684 self._test_appendsrcfile(testrecipe, filepath, srcdir=subdir)
685 bitbake('%s:do_unpack' % testrecipe)
686 self.assertEqual(open(self.testfile, 'r').read(), open(os.path.join(srcdir, filepath), 'r').read())
687
688 @OETestID(1278)
689 def test_recipetool_appendsrcfiles_basic(self, destdir=None):
690 newfiles = [self.testfile]
691 for i in range(1, 5):
692 testfile = os.path.join(self.tempdir, 'testfile%d' % i)
693 with open(testfile, 'w') as f:
694 f.write('Test file %d\n' % i)
695 newfiles.append(testfile)
696 self._test_appendsrcfiles('gcc', newfiles, destdir=destdir, options='-W')
697
698 @OETestID(1279)
699 def test_recipetool_appendsrcfiles_basic_subdir(self):
700 self.test_recipetool_appendsrcfiles_basic(destdir='testdir')