blob: e72911b0aa44b8a9d4eaf127db372c3c3ad9fed2 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001import os
2import logging
3import tempfile
4import urlparse
5
6from oeqa.utils.commands import runCmd, bitbake, get_bb_var, create_temp_layer
7from oeqa.utils.decorators import testcase
8from oeqa.selftest import devtool
9
10
11templayerdir = None
12
13
14def setUpModule():
15 global templayerdir
16 templayerdir = tempfile.mkdtemp(prefix='recipetoolqa')
17 create_temp_layer(templayerdir, 'selftestrecipetool')
18 runCmd('bitbake-layers add-layer %s' % templayerdir)
19
20
21def tearDownModule():
22 runCmd('bitbake-layers remove-layer %s' % templayerdir, ignore_status=True)
23 runCmd('rm -rf %s' % templayerdir)
24
25
26class RecipetoolBase(devtool.DevtoolBase):
27 def setUpLocal(self):
28 self.templayerdir = templayerdir
29 self.tempdir = tempfile.mkdtemp(prefix='recipetoolqa')
30 self.track_for_cleanup(self.tempdir)
31 self.testfile = os.path.join(self.tempdir, 'testfile')
32 with open(self.testfile, 'w') as f:
33 f.write('Test file\n')
34
35 def tearDownLocal(self):
36 runCmd('rm -rf %s/recipes-*' % self.templayerdir)
37
38 def _try_recipetool_appendcmd(self, cmd, testrecipe, expectedfiles, expectedlines=None):
39 result = runCmd(cmd)
40 self.assertNotIn('Traceback', result.output)
41
42 # Check the bbappend was created and applies properly
43 recipefile = get_bb_var('FILE', testrecipe)
44 bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir)
45
46 # Check the bbappend contents
47 if expectedlines is not None:
48 with open(bbappendfile, 'r') as f:
49 self.assertEqual(expectedlines, f.readlines(), "Expected lines are not present in %s" % bbappendfile)
50
51 # Check file was copied
52 filesdir = os.path.join(os.path.dirname(bbappendfile), testrecipe)
53 for expectedfile in expectedfiles:
54 self.assertTrue(os.path.isfile(os.path.join(filesdir, expectedfile)), 'Expected file %s to be copied next to bbappend, but it wasn\'t' % expectedfile)
55
56 # Check no other files created
57 createdfiles = []
58 for root, _, files in os.walk(filesdir):
59 for f in files:
60 createdfiles.append(os.path.relpath(os.path.join(root, f), filesdir))
61 self.assertTrue(sorted(createdfiles), sorted(expectedfiles))
62
63 return bbappendfile, result.output
64
65
66class RecipetoolTests(RecipetoolBase):
67 @classmethod
68 def setUpClass(cls):
69 # Ensure we have the right data in shlibs/pkgdata
70 logger = logging.getLogger("selftest")
71 logger.info('Running bitbake to generate pkgdata')
72 bitbake('-c packagedata base-files coreutils busybox selftest-recipetool-appendfile')
73
74 @classmethod
75 def tearDownClass(cls):
76 # Shouldn't leave any traces of this artificial recipe behind
77 bitbake('-c cleansstate selftest-recipetool-appendfile')
78
79 def _try_recipetool_appendfile(self, testrecipe, destfile, newfile, options, expectedlines, expectedfiles):
80 cmd = 'recipetool appendfile %s %s %s %s' % (self.templayerdir, destfile, newfile, options)
81 return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
82
83 def _try_recipetool_appendfile_fail(self, destfile, newfile, checkerror):
84 cmd = 'recipetool appendfile %s %s %s' % (self.templayerdir, destfile, newfile)
85 result = runCmd(cmd, ignore_status=True)
86 self.assertNotEqual(result.status, 0, 'Command "%s" should have failed but didn\'t' % cmd)
87 self.assertNotIn('Traceback', result.output)
88 for errorstr in checkerror:
89 self.assertIn(errorstr, result.output)
90
91 @testcase(1177)
92 def test_recipetool_appendfile_basic(self):
93 # Basic test
94 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
95 '\n']
96 _, output = self._try_recipetool_appendfile('base-files', '/etc/motd', self.testfile, '', expectedlines, ['motd'])
97 self.assertNotIn('WARNING: ', output)
98
99 @testcase(1183)
100 def test_recipetool_appendfile_invalid(self):
101 # Test some commands that should error
102 self._try_recipetool_appendfile_fail('/etc/passwd', self.testfile, ['ERROR: /etc/passwd cannot be handled by this tool', 'useradd', 'extrausers'])
103 self._try_recipetool_appendfile_fail('/etc/timestamp', self.testfile, ['ERROR: /etc/timestamp cannot be handled by this tool'])
104 self._try_recipetool_appendfile_fail('/dev/console', self.testfile, ['ERROR: /dev/console cannot be handled by this tool'])
105
106 @testcase(1176)
107 def test_recipetool_appendfile_alternatives(self):
108 # Now try with a file we know should be an alternative
109 # (this is very much a fake example, but one we know is reliably an alternative)
110 self._try_recipetool_appendfile_fail('/bin/ls', self.testfile, ['ERROR: File /bin/ls is an alternative possibly provided by the following recipes:', 'coreutils', 'busybox'])
111 corebase = get_bb_var('COREBASE')
112 # Need a test file - should be executable
113 testfile2 = os.path.join(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 @testcase(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 @testcase(1173)
141 def test_recipetool_appendfile_add(self):
142 corebase = get_bb_var('COREBASE')
143 # Try arbitrary file add to a recipe
144 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
145 '\n',
146 'SRC_URI += "file://testfile"\n',
147 '\n',
148 'do_install_append() {\n',
149 ' install -d ${D}${datadir}\n',
150 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n',
151 '}\n']
152 self._try_recipetool_appendfile('netbase', '/usr/share/something', self.testfile, '-r netbase', expectedlines, ['testfile'])
153 # Try adding another file, this time where the source file is executable
154 # (so we're testing that, plus modifying an existing bbappend)
155 testfile2 = os.path.join(corebase, 'oe-init-build-env')
156 testfile2name = os.path.basename(testfile2)
157 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
158 '\n',
159 'SRC_URI += "file://testfile \\\n',
160 ' file://%s \\\n' % testfile2name,
161 ' "\n',
162 '\n',
163 'do_install_append() {\n',
164 ' install -d ${D}${datadir}\n',
165 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n',
166 ' install -m 0755 ${WORKDIR}/%s ${D}${datadir}/scriptname\n' % testfile2name,
167 '}\n']
168 self._try_recipetool_appendfile('netbase', '/usr/share/scriptname', testfile2, '-r netbase', expectedlines, ['testfile', testfile2name])
169
170 @testcase(1174)
171 def test_recipetool_appendfile_add_bindir(self):
172 # Try arbitrary file add to a recipe, this time to a location such that should be installed as executable
173 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
174 '\n',
175 'SRC_URI += "file://testfile"\n',
176 '\n',
177 'do_install_append() {\n',
178 ' install -d ${D}${bindir}\n',
179 ' install -m 0755 ${WORKDIR}/testfile ${D}${bindir}/selftest-recipetool-testbin\n',
180 '}\n']
181 _, output = self._try_recipetool_appendfile('netbase', '/usr/bin/selftest-recipetool-testbin', self.testfile, '-r netbase', expectedlines, ['testfile'])
182 self.assertNotIn('WARNING: ', output)
183
184 @testcase(1175)
185 def test_recipetool_appendfile_add_machine(self):
186 # Try arbitrary file add to a recipe, this time to a location such that should be installed as executable
187 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
188 '\n',
189 'PACKAGE_ARCH = "${MACHINE_ARCH}"\n',
190 '\n',
191 'SRC_URI_append_mymachine = " file://testfile"\n',
192 '\n',
193 'do_install_append_mymachine() {\n',
194 ' install -d ${D}${datadir}\n',
195 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n',
196 '}\n']
197 _, output = self._try_recipetool_appendfile('netbase', '/usr/share/something', self.testfile, '-r netbase -m mymachine', expectedlines, ['mymachine/testfile'])
198 self.assertNotIn('WARNING: ', output)
199
200 @testcase(1184)
201 def test_recipetool_appendfile_orig(self):
202 # A file that's in SRC_URI and in do_install with the same name
203 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
204 '\n']
205 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-orig', self.testfile, '', expectedlines, ['selftest-replaceme-orig'])
206 self.assertNotIn('WARNING: ', output)
207
208 @testcase(1191)
209 def test_recipetool_appendfile_todir(self):
210 # A file that's in SRC_URI and in do_install with destination directory rather than file
211 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
212 '\n']
213 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-todir', self.testfile, '', expectedlines, ['selftest-replaceme-todir'])
214 self.assertNotIn('WARNING: ', output)
215
216 @testcase(1187)
217 def test_recipetool_appendfile_renamed(self):
218 # A file that's in SRC_URI with a different name to the destination file
219 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
220 '\n']
221 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-renamed', self.testfile, '', expectedlines, ['file1'])
222 self.assertNotIn('WARNING: ', output)
223
224 @testcase(1190)
225 def test_recipetool_appendfile_subdir(self):
226 # A file that's in SRC_URI in a subdir
227 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
228 '\n',
229 'SRC_URI += "file://testfile"\n',
230 '\n',
231 'do_install_append() {\n',
232 ' install -d ${D}${datadir}\n',
233 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-subdir\n',
234 '}\n']
235 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-subdir', self.testfile, '', expectedlines, ['testfile'])
236 self.assertNotIn('WARNING: ', output)
237
238 @testcase(1189)
239 def test_recipetool_appendfile_src_glob(self):
240 # A file that's in SRC_URI as a glob
241 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
242 '\n',
243 'SRC_URI += "file://testfile"\n',
244 '\n',
245 'do_install_append() {\n',
246 ' install -d ${D}${datadir}\n',
247 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-src-globfile\n',
248 '}\n']
249 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-src-globfile', self.testfile, '', expectedlines, ['testfile'])
250 self.assertNotIn('WARNING: ', output)
251
252 @testcase(1181)
253 def test_recipetool_appendfile_inst_glob(self):
254 # A file that's in do_install as a glob
255 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
256 '\n']
257 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-globfile', self.testfile, '', expectedlines, ['selftest-replaceme-inst-globfile'])
258 self.assertNotIn('WARNING: ', output)
259
260 @testcase(1182)
261 def test_recipetool_appendfile_inst_todir_glob(self):
262 # A file that's in do_install as a glob with destination as a directory
263 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
264 '\n']
265 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-todir-globfile', self.testfile, '', expectedlines, ['selftest-replaceme-inst-todir-globfile'])
266 self.assertNotIn('WARNING: ', output)
267
268 @testcase(1185)
269 def test_recipetool_appendfile_patch(self):
270 # A file that's added by a patch in SRC_URI
271 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
272 '\n',
273 'SRC_URI += "file://testfile"\n',
274 '\n',
275 'do_install_append() {\n',
276 ' install -d ${D}${sysconfdir}\n',
277 ' install -m 0644 ${WORKDIR}/testfile ${D}${sysconfdir}/selftest-replaceme-patched\n',
278 '}\n']
279 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/etc/selftest-replaceme-patched', self.testfile, '', expectedlines, ['testfile'])
280 for line in output.splitlines():
281 if line.startswith('WARNING: '):
282 self.assertIn('add-file.patch', line, 'Unexpected warning found in output:\n%s' % line)
283 break
284 else:
285 self.fail('Patch warning not found in output:\n%s' % output)
286
287 @testcase(1188)
288 def test_recipetool_appendfile_script(self):
289 # Now, a file that's in SRC_URI but installed by a script (so no mention in do_install)
290 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
291 '\n',
292 'SRC_URI += "file://testfile"\n',
293 '\n',
294 'do_install_append() {\n',
295 ' install -d ${D}${datadir}\n',
296 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-scripted\n',
297 '}\n']
298 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-scripted', self.testfile, '', expectedlines, ['testfile'])
299 self.assertNotIn('WARNING: ', output)
300
301 @testcase(1180)
302 def test_recipetool_appendfile_inst_func(self):
303 # A file that's installed from a function called by do_install
304 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
305 '\n']
306 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-func', self.testfile, '', expectedlines, ['selftest-replaceme-inst-func'])
307 self.assertNotIn('WARNING: ', output)
308
309 @testcase(1186)
310 def test_recipetool_appendfile_postinstall(self):
311 # A file that's created by a postinstall script (and explicitly mentioned in it)
312 # First try without specifying recipe
313 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'])
314 # Now specify recipe
315 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
316 '\n',
317 'SRC_URI += "file://testfile"\n',
318 '\n',
319 'do_install_append() {\n',
320 ' install -d ${D}${datadir}\n',
321 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-postinst\n',
322 '}\n']
323 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-postinst', self.testfile, '-r selftest-recipetool-appendfile', expectedlines, ['testfile'])
324
325 @testcase(1179)
326 def test_recipetool_appendfile_extlayer(self):
327 # Try creating a bbappend in a layer that's not in bblayers.conf and has a different structure
328 exttemplayerdir = os.path.join(self.tempdir, 'extlayer')
329 self._create_temp_layer(exttemplayerdir, False, 'oeselftestextlayer', recipepathspec='metadata/recipes/recipes-*/*')
330 result = runCmd('recipetool appendfile %s /usr/share/selftest-replaceme-orig %s' % (exttemplayerdir, self.testfile))
331 self.assertNotIn('Traceback', result.output)
332 createdfiles = []
333 for root, _, files in os.walk(exttemplayerdir):
334 for f in files:
335 createdfiles.append(os.path.relpath(os.path.join(root, f), exttemplayerdir))
336 createdfiles.remove('conf/layer.conf')
337 expectedfiles = ['metadata/recipes/recipes-test/selftest-recipetool-appendfile/selftest-recipetool-appendfile.bbappend',
338 'metadata/recipes/recipes-test/selftest-recipetool-appendfile/selftest-recipetool-appendfile/selftest-replaceme-orig']
339 self.assertEqual(sorted(createdfiles), sorted(expectedfiles))
340
341 @testcase(1192)
342 def test_recipetool_appendfile_wildcard(self):
343
344 def try_appendfile_wc(options):
345 result = runCmd('recipetool appendfile %s /etc/profile %s %s' % (self.templayerdir, self.testfile, options))
346 self.assertNotIn('Traceback', result.output)
347 bbappendfile = None
348 for root, _, files in os.walk(self.templayerdir):
349 for f in files:
350 if f.endswith('.bbappend'):
351 bbappendfile = f
352 break
353 if not bbappendfile:
354 self.fail('No bbappend file created')
355 runCmd('rm -rf %s/recipes-*' % self.templayerdir)
356 return bbappendfile
357
358 # Check without wildcard option
359 recipefn = os.path.basename(get_bb_var('FILE', 'base-files'))
360 filename = try_appendfile_wc('')
361 self.assertEqual(filename, recipefn.replace('.bb', '.bbappend'))
362 # Now check with wildcard option
363 filename = try_appendfile_wc('-w')
364 self.assertEqual(filename, recipefn.split('_')[0] + '_%.bbappend')
365
366 @testcase(1193)
367 def test_recipetool_create(self):
368 # Try adding a recipe
369 tempsrc = os.path.join(self.tempdir, 'srctree')
370 os.makedirs(tempsrc)
371 recipefile = os.path.join(self.tempdir, 'logrotate_3.8.7.bb')
372 srcuri = 'https://fedorahosted.org/releases/l/o/logrotate/logrotate-3.8.7.tar.gz'
373 result = runCmd('recipetool create -o %s %s -x %s' % (recipefile, srcuri, tempsrc))
374 self.assertTrue(os.path.isfile(recipefile))
375 checkvars = {}
376 checkvars['LICENSE'] = 'GPLv2'
377 checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=18810669f13b87348459e611d31ab760'
378 checkvars['SRC_URI'] = 'https://fedorahosted.org/releases/l/o/logrotate/logrotate-${PV}.tar.gz'
379 checkvars['SRC_URI[md5sum]'] = '99e08503ef24c3e2e3ff74cc5f3be213'
380 checkvars['SRC_URI[sha256sum]'] = 'f6ba691f40e30e640efa2752c1f9499a3f9738257660994de70a45fe00d12b64'
381 self._test_recipe_contents(recipefile, checkvars, [])
382
383 @testcase(1194)
384 def test_recipetool_create_git(self):
385 # Ensure we have the right data in shlibs/pkgdata
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500386 bitbake('libpng pango libx11 libxext jpeg libxsettings-client libcheck')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500387 # Try adding a recipe
388 tempsrc = os.path.join(self.tempdir, 'srctree')
389 os.makedirs(tempsrc)
390 recipefile = os.path.join(self.tempdir, 'libmatchbox.bb')
391 srcuri = 'git://git.yoctoproject.org/libmatchbox'
392 result = runCmd('recipetool create -o %s %s -x %s' % (recipefile, srcuri, tempsrc))
393 self.assertTrue(os.path.isfile(recipefile), 'recipetool did not create recipe file; output:\n%s' % result.output)
394 checkvars = {}
395 checkvars['LICENSE'] = 'LGPLv2.1'
396 checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=7fbc338309ac38fefcd64b04bb903e34'
397 checkvars['S'] = '${WORKDIR}/git'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500398 checkvars['PV'] = '1.11+git${SRCPV}'
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500399 checkvars['SRC_URI'] = srcuri
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500400 checkvars['DEPENDS'] = set(['libcheck', 'libjpeg-turbo', 'libpng', 'libx11', 'libxsettings-client', 'libxext', 'pango'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500401 inherits = ['autotools', 'pkgconfig']
402 self._test_recipe_contents(recipefile, checkvars, inherits)
403
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500404 @testcase(1392)
405 def test_recipetool_create_simple(self):
406 # Try adding a recipe
407 temprecipe = os.path.join(self.tempdir, 'recipe')
408 os.makedirs(temprecipe)
409 pv = '1.7.3.0'
410 srcuri = 'http://www.dest-unreach.org/socat/download/socat-%s.tar.bz2' % pv
411 result = runCmd('recipetool create %s -o %s' % (srcuri, temprecipe))
412 dirlist = os.listdir(temprecipe)
413 if len(dirlist) > 1:
414 self.fail('recipetool created more than just one file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist)))
415 if len(dirlist) < 1 or not os.path.isfile(os.path.join(temprecipe, dirlist[0])):
416 self.fail('recipetool did not create recipe file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist)))
417 self.assertEqual(dirlist[0], 'socat_%s.bb' % pv, 'Recipe file incorrectly named')
418 checkvars = {}
419 checkvars['LICENSE'] = set(['Unknown', 'GPLv2'])
420 checkvars['LIC_FILES_CHKSUM'] = set(['file://COPYING.OpenSSL;md5=5c9bccc77f67a8328ef4ebaf468116f4', 'file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263'])
421 # We don't check DEPENDS since they are variable for this recipe depending on what's in the sysroot
422 checkvars['S'] = None
423 checkvars['SRC_URI'] = srcuri.replace(pv, '${PV}')
424 inherits = ['autotools']
425 self._test_recipe_contents(os.path.join(temprecipe, dirlist[0]), checkvars, inherits)
426
427 @testcase(1418)
428 def test_recipetool_create_cmake(self):
429 # Try adding a recipe
430 temprecipe = os.path.join(self.tempdir, 'recipe')
431 os.makedirs(temprecipe)
432 recipefile = os.path.join(temprecipe, 'navit_0.5.0.bb')
433 srcuri = 'http://downloads.sourceforge.net/project/navit/v0.5.0/navit-0.5.0.tar.gz'
434 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
435 self.assertTrue(os.path.isfile(recipefile))
436 checkvars = {}
437 checkvars['LICENSE'] = set(['Unknown', 'GPLv2', 'LGPLv2'])
438 checkvars['SRC_URI'] = 'http://downloads.sourceforge.net/project/navit/v${PV}/navit-${PV}.tar.gz'
439 checkvars['SRC_URI[md5sum]'] = '242f398e979a6b8c0f3c802b63435b68'
440 checkvars['SRC_URI[sha256sum]'] = '13353481d7fc01a4f64e385dda460b51496366bba0fd2cc85a89a0747910e94d'
441 checkvars['DEPENDS'] = set(['freetype', 'zlib', 'openssl', 'glib-2.0', 'virtual/libgl', 'virtual/egl', 'gtk+', 'libpng', 'libsdl', 'freeglut', 'dbus-glib'])
442 inherits = ['cmake', 'python-dir', 'gettext', 'pkgconfig']
443 self._test_recipe_contents(recipefile, checkvars, inherits)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500444
445class RecipetoolAppendsrcBase(RecipetoolBase):
446 def _try_recipetool_appendsrcfile(self, testrecipe, newfile, destfile, options, expectedlines, expectedfiles):
447 cmd = 'recipetool appendsrcfile %s %s %s %s %s' % (options, self.templayerdir, testrecipe, newfile, destfile)
448 return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
449
450 def _try_recipetool_appendsrcfiles(self, testrecipe, newfiles, expectedlines=None, expectedfiles=None, destdir=None, options=''):
451
452 if destdir:
453 options += ' -D %s' % destdir
454
455 if expectedfiles is None:
456 expectedfiles = [os.path.basename(f) for f in newfiles]
457
458 cmd = 'recipetool appendsrcfiles %s %s %s %s' % (options, self.templayerdir, testrecipe, ' '.join(newfiles))
459 return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
460
461 def _try_recipetool_appendsrcfile_fail(self, testrecipe, newfile, destfile, checkerror):
462 cmd = 'recipetool appendsrcfile %s %s %s %s' % (self.templayerdir, testrecipe, newfile, destfile or '')
463 result = runCmd(cmd, ignore_status=True)
464 self.assertNotEqual(result.status, 0, 'Command "%s" should have failed but didn\'t' % cmd)
465 self.assertNotIn('Traceback', result.output)
466 for errorstr in checkerror:
467 self.assertIn(errorstr, result.output)
468
469 @staticmethod
470 def _get_first_file_uri(recipe):
471 '''Return the first file:// in SRC_URI for the specified recipe.'''
472 src_uri = get_bb_var('SRC_URI', recipe).split()
473 for uri in src_uri:
474 p = urlparse.urlparse(uri)
475 if p.scheme == 'file':
476 return p.netloc + p.path
477
478 def _test_appendsrcfile(self, testrecipe, filename=None, destdir=None, has_src_uri=True, srcdir=None, newfile=None, options=''):
479 if newfile is None:
480 newfile = self.testfile
481
482 if srcdir:
483 if destdir:
484 expected_subdir = os.path.join(srcdir, destdir)
485 else:
486 expected_subdir = srcdir
487 else:
488 options += " -W"
489 expected_subdir = destdir
490
491 if filename:
492 if destdir:
493 destpath = os.path.join(destdir, filename)
494 else:
495 destpath = filename
496 else:
497 filename = os.path.basename(newfile)
498 if destdir:
499 destpath = destdir + os.sep
500 else:
501 destpath = '.' + os.sep
502
503 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
504 '\n']
505 if has_src_uri:
506 uri = 'file://%s' % filename
507 if expected_subdir:
508 uri += ';subdir=%s' % expected_subdir
509 expectedlines[0:0] = ['SRC_URI += "%s"\n' % uri,
510 '\n']
511
512 return self._try_recipetool_appendsrcfile(testrecipe, newfile, destpath, options, expectedlines, [filename])
513
514 def _test_appendsrcfiles(self, testrecipe, newfiles, expectedfiles=None, destdir=None, options=''):
515 if expectedfiles is None:
516 expectedfiles = [os.path.basename(n) for n in newfiles]
517
518 self._try_recipetool_appendsrcfiles(testrecipe, newfiles, expectedfiles=expectedfiles, destdir=destdir, options=options)
519
520 src_uri = get_bb_var('SRC_URI', testrecipe).split()
521 for f in expectedfiles:
522 if destdir:
523 self.assertIn('file://%s;subdir=%s' % (f, destdir), src_uri)
524 else:
525 self.assertIn('file://%s' % f, src_uri)
526
527 recipefile = get_bb_var('FILE', testrecipe)
528 bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir)
529 filesdir = os.path.join(os.path.dirname(bbappendfile), testrecipe)
530 filesextrapaths = get_bb_var('FILESEXTRAPATHS', testrecipe).split(':')
531 self.assertIn(filesdir, filesextrapaths)
532
533
534class RecipetoolAppendsrcTests(RecipetoolAppendsrcBase):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500535
536 @testcase(1273)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500537 def test_recipetool_appendsrcfile_basic(self):
538 self._test_appendsrcfile('base-files', 'a-file')
539
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500540 @testcase(1274)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500541 def test_recipetool_appendsrcfile_basic_wildcard(self):
542 testrecipe = 'base-files'
543 self._test_appendsrcfile(testrecipe, 'a-file', options='-w')
544 recipefile = get_bb_var('FILE', testrecipe)
545 bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir)
546 self.assertEqual(os.path.basename(bbappendfile), '%s_%%.bbappend' % testrecipe)
547
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500548 @testcase(1281)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500549 def test_recipetool_appendsrcfile_subdir_basic(self):
550 self._test_appendsrcfile('base-files', 'a-file', 'tmp')
551
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500552 @testcase(1282)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500553 def test_recipetool_appendsrcfile_subdir_basic_dirdest(self):
554 self._test_appendsrcfile('base-files', destdir='tmp')
555
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500556 @testcase(1280)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500557 def test_recipetool_appendsrcfile_srcdir_basic(self):
558 testrecipe = 'bash'
559 srcdir = get_bb_var('S', testrecipe)
560 workdir = get_bb_var('WORKDIR', testrecipe)
561 subdir = os.path.relpath(srcdir, workdir)
562 self._test_appendsrcfile(testrecipe, 'a-file', srcdir=subdir)
563
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500564 @testcase(1275)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500565 def test_recipetool_appendsrcfile_existing_in_src_uri(self):
566 testrecipe = 'base-files'
567 filepath = self._get_first_file_uri(testrecipe)
568 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe)
569 self._test_appendsrcfile(testrecipe, filepath, has_src_uri=False)
570
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500571 @testcase(1276)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500572 def test_recipetool_appendsrcfile_existing_in_src_uri_diff_params(self):
573 testrecipe = 'base-files'
574 subdir = 'tmp'
575 filepath = self._get_first_file_uri(testrecipe)
576 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe)
577
578 output = self._test_appendsrcfile(testrecipe, filepath, subdir, has_src_uri=False)
579 self.assertTrue(any('with different parameters' in l for l in output))
580
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500581 @testcase(1277)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500582 def test_recipetool_appendsrcfile_replace_file_srcdir(self):
583 testrecipe = 'bash'
584 filepath = 'Makefile.in'
585 srcdir = get_bb_var('S', testrecipe)
586 workdir = get_bb_var('WORKDIR', testrecipe)
587 subdir = os.path.relpath(srcdir, workdir)
588
589 self._test_appendsrcfile(testrecipe, filepath, srcdir=subdir)
590 bitbake('%s:do_unpack' % testrecipe)
591 self.assertEqual(open(self.testfile, 'r').read(), open(os.path.join(srcdir, filepath), 'r').read())
592
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500593 @testcase(1278)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500594 def test_recipetool_appendsrcfiles_basic(self, destdir=None):
595 newfiles = [self.testfile]
596 for i in range(1, 5):
597 testfile = os.path.join(self.tempdir, 'testfile%d' % i)
598 with open(testfile, 'w') as f:
599 f.write('Test file %d\n' % i)
600 newfiles.append(testfile)
601 self._test_appendsrcfiles('gcc', newfiles, destdir=destdir, options='-W')
602
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500603 @testcase(1279)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500604 def test_recipetool_appendsrcfiles_basic_subdir(self):
605 self.test_recipetool_appendsrcfiles_basic(destdir='testdir')