blob: 754ea94982454e934b5971b2ee5159a72b2c0a3f [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):
430 # Try adding a recipe
431 temprecipe = os.path.join(self.tempdir, 'recipe')
432 os.makedirs(temprecipe)
433 recipefile = os.path.join(temprecipe, 'navit_0.5.0.bb')
434 srcuri = 'http://downloads.sourceforge.net/project/navit/v0.5.0/navit-0.5.0.tar.gz'
435 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
436 self.assertTrue(os.path.isfile(recipefile))
437 checkvars = {}
438 checkvars['LICENSE'] = set(['Unknown', 'GPLv2', 'LGPLv2'])
439 checkvars['SRC_URI'] = 'http://downloads.sourceforge.net/project/navit/v${PV}/navit-${PV}.tar.gz'
440 checkvars['SRC_URI[md5sum]'] = '242f398e979a6b8c0f3c802b63435b68'
441 checkvars['SRC_URI[sha256sum]'] = '13353481d7fc01a4f64e385dda460b51496366bba0fd2cc85a89a0747910e94d'
442 checkvars['DEPENDS'] = set(['freetype', 'zlib', 'openssl', 'glib-2.0', 'virtual/libgl', 'virtual/egl', 'gtk+', 'libpng', 'libsdl', 'freeglut', 'dbus-glib'])
443 inherits = ['cmake', 'python-dir', 'gettext', 'pkgconfig']
444 self._test_recipe_contents(recipefile, checkvars, inherits)
445
446 @OETestID(1638)
447 def test_recipetool_create_github(self):
448 # Basic test to see if github URL mangling works
449 temprecipe = os.path.join(self.tempdir, 'recipe')
450 os.makedirs(temprecipe)
451 recipefile = os.path.join(temprecipe, 'meson_git.bb')
452 srcuri = 'https://github.com/mesonbuild/meson;rev=0.32.0'
453 result = runCmd(['recipetool', 'create', '-o', temprecipe, srcuri])
454 self.assertTrue(os.path.isfile(recipefile))
455 checkvars = {}
456 checkvars['LICENSE'] = set(['Apache-2.0'])
457 checkvars['SRC_URI'] = 'git://github.com/mesonbuild/meson;protocol=https'
458 inherits = ['setuptools']
459 self._test_recipe_contents(recipefile, checkvars, inherits)
460
461 @OETestID(1639)
462 def test_recipetool_create_github_tarball(self):
463 # Basic test to ensure github URL mangling doesn't apply to release tarballs
464 temprecipe = os.path.join(self.tempdir, 'recipe')
465 os.makedirs(temprecipe)
466 pv = '0.32.0'
467 recipefile = os.path.join(temprecipe, 'meson_%s.bb' % pv)
468 srcuri = 'https://github.com/mesonbuild/meson/releases/download/%s/meson-%s.tar.gz' % (pv, pv)
469 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
470 self.assertTrue(os.path.isfile(recipefile))
471 checkvars = {}
472 checkvars['LICENSE'] = set(['Apache-2.0'])
473 checkvars['SRC_URI'] = 'https://github.com/mesonbuild/meson/releases/download/${PV}/meson-${PV}.tar.gz'
474 inherits = ['setuptools']
475 self._test_recipe_contents(recipefile, checkvars, inherits)
476
477 @OETestID(1637)
478 def test_recipetool_create_git_http(self):
479 # Basic test to check http git URL mangling works
480 temprecipe = os.path.join(self.tempdir, 'recipe')
481 os.makedirs(temprecipe)
482 recipefile = os.path.join(temprecipe, 'matchbox-terminal_git.bb')
483 srcuri = 'http://git.yoctoproject.org/git/matchbox-terminal'
484 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
485 self.assertTrue(os.path.isfile(recipefile))
486 checkvars = {}
487 checkvars['LICENSE'] = set(['GPLv2'])
488 checkvars['SRC_URI'] = 'git://git.yoctoproject.org/git/matchbox-terminal;protocol=http'
489 inherits = ['pkgconfig', 'autotools']
490 self._test_recipe_contents(recipefile, checkvars, inherits)
491
492 def _copy_file_with_cleanup(self, srcfile, basedstdir, *paths):
493 dstdir = basedstdir
494 self.assertTrue(os.path.exists(dstdir))
495 for p in paths:
496 dstdir = os.path.join(dstdir, p)
497 if not os.path.exists(dstdir):
498 os.makedirs(dstdir)
499 self.track_for_cleanup(dstdir)
500 dstfile = os.path.join(dstdir, os.path.basename(srcfile))
501 if srcfile != dstfile:
502 shutil.copy(srcfile, dstfile)
503 self.track_for_cleanup(dstfile)
504
505 @OETestID(1640)
506 def test_recipetool_load_plugin(self):
507 """Test that recipetool loads only the first found plugin in BBPATH."""
508
509 recipetool = runCmd("which recipetool")
510 fromname = runCmd("recipetool --quiet pluginfile")
511 srcfile = fromname.output
512 searchpath = self.bbpath.split(':') + [os.path.dirname(recipetool.output)]
513 plugincontent = []
514 with open(srcfile) as fh:
515 plugincontent = fh.readlines()
516 try:
517 self.assertIn('meta-selftest', srcfile, 'wrong bbpath plugin found')
518 for path in searchpath:
519 self._copy_file_with_cleanup(srcfile, path, 'lib', 'recipetool')
520 result = runCmd("recipetool --quiet count")
521 self.assertEqual(result.output, '1')
522 result = runCmd("recipetool --quiet multiloaded")
523 self.assertEqual(result.output, "no")
524 for path in searchpath:
525 result = runCmd("recipetool --quiet bbdir")
526 self.assertEqual(result.output, path)
527 os.unlink(os.path.join(result.output, 'lib', 'recipetool', 'bbpath.py'))
528 finally:
529 with open(srcfile, 'w') as fh:
530 fh.writelines(plugincontent)
531
532
533class RecipetoolAppendsrcBase(RecipetoolBase):
534 def _try_recipetool_appendsrcfile(self, testrecipe, newfile, destfile, options, expectedlines, expectedfiles):
535 cmd = 'recipetool appendsrcfile %s %s %s %s %s' % (options, self.templayerdir, testrecipe, newfile, destfile)
536 return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
537
538 def _try_recipetool_appendsrcfiles(self, testrecipe, newfiles, expectedlines=None, expectedfiles=None, destdir=None, options=''):
539
540 if destdir:
541 options += ' -D %s' % destdir
542
543 if expectedfiles is None:
544 expectedfiles = [os.path.basename(f) for f in newfiles]
545
546 cmd = 'recipetool appendsrcfiles %s %s %s %s' % (options, self.templayerdir, testrecipe, ' '.join(newfiles))
547 return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
548
549 def _try_recipetool_appendsrcfile_fail(self, testrecipe, newfile, destfile, checkerror):
550 cmd = 'recipetool appendsrcfile %s %s %s %s' % (self.templayerdir, testrecipe, newfile, destfile or '')
551 result = runCmd(cmd, ignore_status=True)
552 self.assertNotEqual(result.status, 0, 'Command "%s" should have failed but didn\'t' % cmd)
553 self.assertNotIn('Traceback', result.output)
554 for errorstr in checkerror:
555 self.assertIn(errorstr, result.output)
556
557 @staticmethod
558 def _get_first_file_uri(recipe):
559 '''Return the first file:// in SRC_URI for the specified recipe.'''
560 src_uri = get_bb_var('SRC_URI', recipe).split()
561 for uri in src_uri:
562 p = urllib.parse.urlparse(uri)
563 if p.scheme == 'file':
564 return p.netloc + p.path
565
566 def _test_appendsrcfile(self, testrecipe, filename=None, destdir=None, has_src_uri=True, srcdir=None, newfile=None, options=''):
567 if newfile is None:
568 newfile = self.testfile
569
570 if srcdir:
571 if destdir:
572 expected_subdir = os.path.join(srcdir, destdir)
573 else:
574 expected_subdir = srcdir
575 else:
576 options += " -W"
577 expected_subdir = destdir
578
579 if filename:
580 if destdir:
581 destpath = os.path.join(destdir, filename)
582 else:
583 destpath = filename
584 else:
585 filename = os.path.basename(newfile)
586 if destdir:
587 destpath = destdir + os.sep
588 else:
589 destpath = '.' + os.sep
590
591 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
592 '\n']
593 if has_src_uri:
594 uri = 'file://%s' % filename
595 if expected_subdir:
596 uri += ';subdir=%s' % expected_subdir
597 expectedlines[0:0] = ['SRC_URI += "%s"\n' % uri,
598 '\n']
599
600 return self._try_recipetool_appendsrcfile(testrecipe, newfile, destpath, options, expectedlines, [filename])
601
602 def _test_appendsrcfiles(self, testrecipe, newfiles, expectedfiles=None, destdir=None, options=''):
603 if expectedfiles is None:
604 expectedfiles = [os.path.basename(n) for n in newfiles]
605
606 self._try_recipetool_appendsrcfiles(testrecipe, newfiles, expectedfiles=expectedfiles, destdir=destdir, options=options)
607
608 bb_vars = get_bb_vars(['SRC_URI', 'FILE', 'FILESEXTRAPATHS'], testrecipe)
609 src_uri = bb_vars['SRC_URI'].split()
610 for f in expectedfiles:
611 if destdir:
612 self.assertIn('file://%s;subdir=%s' % (f, destdir), src_uri)
613 else:
614 self.assertIn('file://%s' % f, src_uri)
615
616 recipefile = bb_vars['FILE']
617 bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir)
618 filesdir = os.path.join(os.path.dirname(bbappendfile), testrecipe)
619 filesextrapaths = bb_vars['FILESEXTRAPATHS'].split(':')
620 self.assertIn(filesdir, filesextrapaths)
621
622
623
624
625class RecipetoolAppendsrcTests(RecipetoolAppendsrcBase):
626
627 @OETestID(1273)
628 def test_recipetool_appendsrcfile_basic(self):
629 self._test_appendsrcfile('base-files', 'a-file')
630
631 @OETestID(1274)
632 def test_recipetool_appendsrcfile_basic_wildcard(self):
633 testrecipe = 'base-files'
634 self._test_appendsrcfile(testrecipe, 'a-file', options='-w')
635 recipefile = get_bb_var('FILE', testrecipe)
636 bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir)
637 self.assertEqual(os.path.basename(bbappendfile), '%s_%%.bbappend' % testrecipe)
638
639 @OETestID(1281)
640 def test_recipetool_appendsrcfile_subdir_basic(self):
641 self._test_appendsrcfile('base-files', 'a-file', 'tmp')
642
643 @OETestID(1282)
644 def test_recipetool_appendsrcfile_subdir_basic_dirdest(self):
645 self._test_appendsrcfile('base-files', destdir='tmp')
646
647 @OETestID(1280)
648 def test_recipetool_appendsrcfile_srcdir_basic(self):
649 testrecipe = 'bash'
650 bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe)
651 srcdir = bb_vars['S']
652 workdir = bb_vars['WORKDIR']
653 subdir = os.path.relpath(srcdir, workdir)
654 self._test_appendsrcfile(testrecipe, 'a-file', srcdir=subdir)
655
656 @OETestID(1275)
657 def test_recipetool_appendsrcfile_existing_in_src_uri(self):
658 testrecipe = 'base-files'
659 filepath = self._get_first_file_uri(testrecipe)
660 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe)
661 self._test_appendsrcfile(testrecipe, filepath, has_src_uri=False)
662
663 @OETestID(1276)
664 def test_recipetool_appendsrcfile_existing_in_src_uri_diff_params(self):
665 testrecipe = 'base-files'
666 subdir = 'tmp'
667 filepath = self._get_first_file_uri(testrecipe)
668 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe)
669
670 output = self._test_appendsrcfile(testrecipe, filepath, subdir, has_src_uri=False)
671 self.assertTrue(any('with different parameters' in l for l in output))
672
673 @OETestID(1277)
674 def test_recipetool_appendsrcfile_replace_file_srcdir(self):
675 testrecipe = 'bash'
676 filepath = 'Makefile.in'
677 bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe)
678 srcdir = bb_vars['S']
679 workdir = bb_vars['WORKDIR']
680 subdir = os.path.relpath(srcdir, workdir)
681
682 self._test_appendsrcfile(testrecipe, filepath, srcdir=subdir)
683 bitbake('%s:do_unpack' % testrecipe)
684 self.assertEqual(open(self.testfile, 'r').read(), open(os.path.join(srcdir, filepath), 'r').read())
685
686 @OETestID(1278)
687 def test_recipetool_appendsrcfiles_basic(self, destdir=None):
688 newfiles = [self.testfile]
689 for i in range(1, 5):
690 testfile = os.path.join(self.tempdir, 'testfile%d' % i)
691 with open(testfile, 'w') as f:
692 f.write('Test file %d\n' % i)
693 newfiles.append(testfile)
694 self._test_appendsrcfiles('gcc', newfiles, destdir=destdir, options='-W')
695
696 @OETestID(1279)
697 def test_recipetool_appendsrcfiles_basic_subdir(self):
698 self.test_recipetool_appendsrcfiles_basic(destdir='testdir')