recipetool.py 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: MIT
  5. #
  6. import errno
  7. import os
  8. import shutil
  9. import tempfile
  10. import urllib.parse
  11. from oeqa.utils.commands import runCmd, bitbake, get_bb_var
  12. from oeqa.utils.commands import get_bb_vars, create_temp_layer
  13. from oeqa.selftest.cases import devtool
  14. templayerdir = None
  15. def setUpModule():
  16. global templayerdir
  17. templayerdir = tempfile.mkdtemp(prefix='recipetoolqa')
  18. create_temp_layer(templayerdir, 'selftestrecipetool')
  19. runCmd('bitbake-layers add-layer %s' % templayerdir)
  20. def tearDownModule():
  21. runCmd('bitbake-layers remove-layer %s' % templayerdir, ignore_status=True)
  22. runCmd('rm -rf %s' % templayerdir)
  23. def needTomllib(test):
  24. # This test require python 3.11 or above for the tomllib module or tomli module to be installed
  25. try:
  26. import tomllib
  27. except ImportError:
  28. try:
  29. import tomli
  30. except ImportError:
  31. test.skipTest('Test requires python 3.11 or above for tomllib module or tomli module')
  32. class RecipetoolBase(devtool.DevtoolTestCase):
  33. def setUpLocal(self):
  34. super(RecipetoolBase, self).setUpLocal()
  35. self.templayerdir = templayerdir
  36. self.tempdir = tempfile.mkdtemp(prefix='recipetoolqa')
  37. self.track_for_cleanup(self.tempdir)
  38. self.testfile = os.path.join(self.tempdir, 'testfile')
  39. with open(self.testfile, 'w') as f:
  40. f.write('Test file\n')
  41. config = 'BBMASK += "meta-poky/recipes-core/base-files/base-files_%.bbappend"\n'
  42. self.append_config(config)
  43. def tearDownLocal(self):
  44. runCmd('rm -rf %s/recipes-*' % self.templayerdir)
  45. super(RecipetoolBase, self).tearDownLocal()
  46. def _try_recipetool_appendcmd(self, cmd, testrecipe, expectedfiles, expectedlines=None):
  47. result = runCmd(cmd)
  48. self.assertNotIn('Traceback', result.output)
  49. # Check the bbappend was created and applies properly
  50. recipefile = get_bb_var('FILE', testrecipe)
  51. bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir)
  52. # Check the bbappend contents
  53. if expectedlines is not None:
  54. with open(bbappendfile, 'r') as f:
  55. self.assertEqual(expectedlines, f.readlines(), "Expected lines are not present in %s" % bbappendfile)
  56. # Check file was copied
  57. filesdir = os.path.join(os.path.dirname(bbappendfile), testrecipe)
  58. for expectedfile in expectedfiles:
  59. self.assertTrue(os.path.isfile(os.path.join(filesdir, expectedfile)), 'Expected file %s to be copied next to bbappend, but it wasn\'t' % expectedfile)
  60. # Check no other files created
  61. createdfiles = []
  62. for root, _, files in os.walk(filesdir):
  63. for f in files:
  64. createdfiles.append(os.path.relpath(os.path.join(root, f), filesdir))
  65. self.assertTrue(sorted(createdfiles), sorted(expectedfiles))
  66. return bbappendfile, result.output
  67. class RecipetoolAppendTests(RecipetoolBase):
  68. @classmethod
  69. def setUpClass(cls):
  70. super(RecipetoolAppendTests, cls).setUpClass()
  71. # Ensure we have the right data in shlibs/pkgdata
  72. cls.logger.info('Running bitbake to generate pkgdata')
  73. bitbake('-c packagedata base-files coreutils busybox selftest-recipetool-appendfile')
  74. bb_vars = get_bb_vars(['COREBASE'])
  75. cls.corebase = bb_vars['COREBASE']
  76. def _try_recipetool_appendfile(self, testrecipe, destfile, newfile, options, expectedlines, expectedfiles):
  77. cmd = 'recipetool appendfile %s %s %s %s' % (self.templayerdir, destfile, newfile, options)
  78. return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
  79. def _try_recipetool_appendfile_fail(self, destfile, newfile, checkerror):
  80. cmd = 'recipetool appendfile %s %s %s' % (self.templayerdir, destfile, newfile)
  81. result = runCmd(cmd, ignore_status=True)
  82. self.assertNotEqual(result.status, 0, 'Command "%s" should have failed but didn\'t' % cmd)
  83. self.assertNotIn('Traceback', result.output)
  84. for errorstr in checkerror:
  85. self.assertIn(errorstr, result.output)
  86. def test_recipetool_appendfile_basic(self):
  87. # Basic test
  88. expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
  89. '\n']
  90. _, output = self._try_recipetool_appendfile('base-files', '/etc/motd', self.testfile, '', expectedlines, ['motd'])
  91. self.assertNotIn('WARNING: ', output)
  92. def test_recipetool_appendfile_invalid(self):
  93. # Test some commands that should error
  94. self._try_recipetool_appendfile_fail('/etc/passwd', self.testfile, ['ERROR: /etc/passwd cannot be handled by this tool', 'useradd', 'extrausers'])
  95. self._try_recipetool_appendfile_fail('/etc/timestamp', self.testfile, ['ERROR: /etc/timestamp cannot be handled by this tool'])
  96. self._try_recipetool_appendfile_fail('/dev/console', self.testfile, ['ERROR: /dev/console cannot be handled by this tool'])
  97. def test_recipetool_appendfile_alternatives(self):
  98. lspath = '/bin/ls'
  99. dirname = "base_bindir"
  100. if "usrmerge" in get_bb_var('DISTRO_FEATURES'):
  101. lspath = '/usr/bin/ls'
  102. dirname = "bindir"
  103. # Now try with a file we know should be an alternative
  104. # (this is very much a fake example, but one we know is reliably an alternative)
  105. self._try_recipetool_appendfile_fail(lspath, self.testfile, ['ERROR: File %s is an alternative possibly provided by the following recipes:' % lspath, 'coreutils', 'busybox'])
  106. # Need a test file - should be executable
  107. testfile2 = os.path.join(self.corebase, 'oe-init-build-env')
  108. testfile2name = os.path.basename(testfile2)
  109. expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
  110. '\n',
  111. 'SRC_URI += "file://%s"\n' % testfile2name,
  112. '\n',
  113. 'do_install:append() {\n',
  114. ' install -d ${D}${%s}\n' % dirname,
  115. ' install -m 0755 ${UNPACKDIR}/%s ${D}${%s}/ls\n' % (testfile2name, dirname),
  116. '}\n']
  117. self._try_recipetool_appendfile('coreutils', lspath, testfile2, '-r coreutils', expectedlines, [testfile2name])
  118. # Now try bbappending the same file again, contents should not change
  119. bbappendfile, _ = self._try_recipetool_appendfile('coreutils', lspath, self.testfile, '-r coreutils', expectedlines, [testfile2name])
  120. # But file should have
  121. copiedfile = os.path.join(os.path.dirname(bbappendfile), 'coreutils', testfile2name)
  122. result = runCmd('diff -q %s %s' % (testfile2, copiedfile), ignore_status=True)
  123. self.assertNotEqual(result.status, 0, 'New file should have been copied but was not %s' % result.output)
  124. def test_recipetool_appendfile_binary(self):
  125. # Try appending a binary file
  126. # /bin/ls can be a symlink to /usr/bin/ls
  127. ls = os.path.realpath("/bin/ls")
  128. result = runCmd('recipetool appendfile %s /bin/ls %s -r coreutils' % (self.templayerdir, ls))
  129. self.assertIn('WARNING: ', result.output)
  130. self.assertIn('is a binary', result.output)
  131. def test_recipetool_appendfile_add(self):
  132. # Try arbitrary file add to a recipe
  133. expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
  134. '\n',
  135. 'SRC_URI += "file://testfile"\n',
  136. '\n',
  137. 'do_install:append() {\n',
  138. ' install -d ${D}${datadir}\n',
  139. ' install -m 0644 ${UNPACKDIR}/testfile ${D}${datadir}/something\n',
  140. '}\n']
  141. self._try_recipetool_appendfile('netbase', '/usr/share/something', self.testfile, '-r netbase', expectedlines, ['testfile'])
  142. # Try adding another file, this time where the source file is executable
  143. # (so we're testing that, plus modifying an existing bbappend)
  144. testfile2 = os.path.join(self.corebase, 'oe-init-build-env')
  145. testfile2name = os.path.basename(testfile2)
  146. expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
  147. '\n',
  148. 'SRC_URI += "file://testfile \\\n',
  149. ' file://%s \\\n' % testfile2name,
  150. ' "\n',
  151. '\n',
  152. 'do_install:append() {\n',
  153. ' install -d ${D}${datadir}\n',
  154. ' install -m 0644 ${UNPACKDIR}/testfile ${D}${datadir}/something\n',
  155. ' install -m 0755 ${UNPACKDIR}/%s ${D}${datadir}/scriptname\n' % testfile2name,
  156. '}\n']
  157. self._try_recipetool_appendfile('netbase', '/usr/share/scriptname', testfile2, '-r netbase', expectedlines, ['testfile', testfile2name])
  158. def test_recipetool_appendfile_add_bindir(self):
  159. # Try arbitrary file add to a recipe, this time to a location such that should be installed as executable
  160. expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
  161. '\n',
  162. 'SRC_URI += "file://testfile"\n',
  163. '\n',
  164. 'do_install:append() {\n',
  165. ' install -d ${D}${bindir}\n',
  166. ' install -m 0755 ${UNPACKDIR}/testfile ${D}${bindir}/selftest-recipetool-testbin\n',
  167. '}\n']
  168. _, output = self._try_recipetool_appendfile('netbase', '/usr/bin/selftest-recipetool-testbin', self.testfile, '-r netbase', expectedlines, ['testfile'])
  169. self.assertNotIn('WARNING: ', output)
  170. def test_recipetool_appendfile_add_machine(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. 'PACKAGE_ARCH = "${MACHINE_ARCH}"\n',
  175. '\n',
  176. 'SRC_URI:append:mymachine = " file://testfile"\n',
  177. '\n',
  178. 'do_install:append:mymachine() {\n',
  179. ' install -d ${D}${datadir}\n',
  180. ' install -m 0644 ${UNPACKDIR}/testfile ${D}${datadir}/something\n',
  181. '}\n']
  182. _, output = self._try_recipetool_appendfile('netbase', '/usr/share/something', self.testfile, '-r netbase -m mymachine', expectedlines, ['mymachine/testfile'])
  183. self.assertNotIn('WARNING: ', output)
  184. def test_recipetool_appendfile_orig(self):
  185. # A file that's in SRC_URI and in do_install with the same name
  186. expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
  187. '\n']
  188. _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-orig', self.testfile, '', expectedlines, ['selftest-replaceme-orig'])
  189. self.assertNotIn('WARNING: ', output)
  190. def test_recipetool_appendfile_todir(self):
  191. # A file that's in SRC_URI and in do_install with destination directory rather than file
  192. expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
  193. '\n']
  194. _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-todir', self.testfile, '', expectedlines, ['selftest-replaceme-todir'])
  195. self.assertNotIn('WARNING: ', output)
  196. def test_recipetool_appendfile_renamed(self):
  197. # A file that's in SRC_URI with a different name to the destination file
  198. expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
  199. '\n']
  200. _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-renamed', self.testfile, '', expectedlines, ['file1'])
  201. self.assertNotIn('WARNING: ', output)
  202. def test_recipetool_appendfile_subdir(self):
  203. # A file that's in SRC_URI in a subdir
  204. expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
  205. '\n',
  206. 'SRC_URI += "file://testfile"\n',
  207. '\n',
  208. 'do_install:append() {\n',
  209. ' install -d ${D}${datadir}\n',
  210. ' install -m 0644 ${UNPACKDIR}/testfile ${D}${datadir}/selftest-replaceme-subdir\n',
  211. '}\n']
  212. _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-subdir', self.testfile, '', expectedlines, ['testfile'])
  213. self.assertNotIn('WARNING: ', output)
  214. def test_recipetool_appendfile_inst_glob(self):
  215. # A file that's in do_install as a glob
  216. expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
  217. '\n']
  218. _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-globfile', self.testfile, '', expectedlines, ['selftest-replaceme-inst-globfile'])
  219. self.assertNotIn('WARNING: ', output)
  220. def test_recipetool_appendfile_inst_todir_glob(self):
  221. # A file that's in do_install as a glob with destination as a directory
  222. expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
  223. '\n']
  224. _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-todir-globfile', self.testfile, '', expectedlines, ['selftest-replaceme-inst-todir-globfile'])
  225. self.assertNotIn('WARNING: ', output)
  226. def test_recipetool_appendfile_patch(self):
  227. # A file that's added by a patch in SRC_URI
  228. expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
  229. '\n',
  230. 'SRC_URI += "file://testfile"\n',
  231. '\n',
  232. 'do_install:append() {\n',
  233. ' install -d ${D}${sysconfdir}\n',
  234. ' install -m 0644 ${UNPACKDIR}/testfile ${D}${sysconfdir}/selftest-replaceme-patched\n',
  235. '}\n']
  236. _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/etc/selftest-replaceme-patched', self.testfile, '', expectedlines, ['testfile'])
  237. for line in output.splitlines():
  238. if 'WARNING: ' in line:
  239. self.assertIn('add-file.patch', line, 'Unexpected warning found in output:\n%s' % line)
  240. break
  241. else:
  242. self.fail('Patch warning not found in output:\n%s' % output)
  243. def test_recipetool_appendfile_script(self):
  244. # Now, a file that's in SRC_URI but installed by a script (so no mention in do_install)
  245. expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
  246. '\n',
  247. 'SRC_URI += "file://testfile"\n',
  248. '\n',
  249. 'do_install:append() {\n',
  250. ' install -d ${D}${datadir}\n',
  251. ' install -m 0644 ${UNPACKDIR}/testfile ${D}${datadir}/selftest-replaceme-scripted\n',
  252. '}\n']
  253. _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-scripted', self.testfile, '', expectedlines, ['testfile'])
  254. self.assertNotIn('WARNING: ', output)
  255. def test_recipetool_appendfile_inst_func(self):
  256. # A file that's installed from a function called by do_install
  257. expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
  258. '\n']
  259. _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-func', self.testfile, '', expectedlines, ['selftest-replaceme-inst-func'])
  260. self.assertNotIn('WARNING: ', output)
  261. def test_recipetool_appendfile_postinstall(self):
  262. # A file that's created by a postinstall script (and explicitly mentioned in it)
  263. # First try without specifying recipe
  264. 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'])
  265. # Now specify recipe
  266. expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
  267. '\n',
  268. 'SRC_URI += "file://testfile"\n',
  269. '\n',
  270. 'do_install:append() {\n',
  271. ' install -d ${D}${datadir}\n',
  272. ' install -m 0644 ${UNPACKDIR}/testfile ${D}${datadir}/selftest-replaceme-postinst\n',
  273. '}\n']
  274. _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-postinst', self.testfile, '-r selftest-recipetool-appendfile', expectedlines, ['testfile'])
  275. def test_recipetool_appendfile_extlayer(self):
  276. # Try creating a bbappend in a layer that's not in bblayers.conf and has a different structure
  277. exttemplayerdir = os.path.join(self.tempdir, 'extlayer')
  278. self._create_temp_layer(exttemplayerdir, False, 'oeselftestextlayer', recipepathspec='metadata/recipes/recipes-*/*')
  279. result = runCmd('recipetool appendfile %s /usr/share/selftest-replaceme-orig %s' % (exttemplayerdir, self.testfile))
  280. self.assertNotIn('Traceback', result.output)
  281. createdfiles = []
  282. for root, _, files in os.walk(exttemplayerdir):
  283. for f in files:
  284. createdfiles.append(os.path.relpath(os.path.join(root, f), exttemplayerdir))
  285. createdfiles.remove('conf/layer.conf')
  286. expectedfiles = ['metadata/recipes/recipes-test/selftest-recipetool-appendfile/selftest-recipetool-appendfile.bbappend',
  287. 'metadata/recipes/recipes-test/selftest-recipetool-appendfile/selftest-recipetool-appendfile/selftest-replaceme-orig']
  288. self.assertEqual(sorted(createdfiles), sorted(expectedfiles))
  289. def test_recipetool_appendfile_wildcard(self):
  290. def try_appendfile_wc(options):
  291. result = runCmd('recipetool appendfile %s /etc/profile %s %s' % (self.templayerdir, self.testfile, options))
  292. self.assertNotIn('Traceback', result.output)
  293. bbappendfile = None
  294. for root, _, files in os.walk(self.templayerdir):
  295. for f in files:
  296. if f.endswith('.bbappend'):
  297. bbappendfile = f
  298. break
  299. if not bbappendfile:
  300. self.fail('No bbappend file created')
  301. runCmd('rm -rf %s/recipes-*' % self.templayerdir)
  302. return bbappendfile
  303. # Check without wildcard option
  304. recipefn = os.path.basename(get_bb_var('FILE', 'base-files'))
  305. filename = try_appendfile_wc('')
  306. self.assertEqual(filename, recipefn.replace('.bb', '.bbappend'))
  307. # Now check with wildcard option
  308. filename = try_appendfile_wc('-w')
  309. self.assertEqual(filename, recipefn.split('_')[0] + '_%.bbappend')
  310. class RecipetoolCreateTests(RecipetoolBase):
  311. def test_recipetool_create(self):
  312. # Try adding a recipe
  313. tempsrc = os.path.join(self.tempdir, 'srctree')
  314. os.makedirs(tempsrc)
  315. recipefile = os.path.join(self.tempdir, 'logrotate_3.12.3.bb')
  316. srcuri = 'https://github.com/logrotate/logrotate/releases/download/3.12.3/logrotate-3.12.3.tar.xz'
  317. result = runCmd('recipetool create -o %s %s -x %s' % (recipefile, srcuri, tempsrc))
  318. self.assertTrue(os.path.isfile(recipefile))
  319. checkvars = {}
  320. checkvars['LICENSE'] = 'GPL-2.0-only'
  321. checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263'
  322. checkvars['SRC_URI'] = 'https://github.com/logrotate/logrotate/releases/download/${PV}/logrotate-${PV}.tar.xz'
  323. checkvars['SRC_URI[sha256sum]'] = '2e6a401cac9024db2288297e3be1a8ab60e7401ba8e91225218aaf4a27e82a07'
  324. self._test_recipe_contents(recipefile, checkvars, [])
  325. def test_recipetool_create_autotools(self):
  326. if 'x11' not in get_bb_var('DISTRO_FEATURES'):
  327. self.skipTest('Test requires x11 as distro feature')
  328. # Ensure we have the right data in shlibs/pkgdata
  329. bitbake('libpng pango libx11 libxext jpeg libcheck')
  330. # Try adding a recipe
  331. tempsrc = os.path.join(self.tempdir, 'srctree')
  332. os.makedirs(tempsrc)
  333. recipefile = os.path.join(self.tempdir, 'libmatchbox.bb')
  334. srcuri = 'git://git.yoctoproject.org/libmatchbox;protocol=https'
  335. result = runCmd(['recipetool', 'create', '-o', recipefile, srcuri + ";rev=9f7cf8895ae2d39c465c04cc78e918c157420269", '-x', tempsrc])
  336. self.assertTrue(os.path.isfile(recipefile), 'recipetool did not create recipe file; output:\n%s' % result.output)
  337. checkvars = {}
  338. checkvars['LICENSE'] = 'LGPL-2.1-only'
  339. checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=7fbc338309ac38fefcd64b04bb903e34'
  340. checkvars['S'] = '${WORKDIR}/git'
  341. checkvars['PV'] = '1.11+git'
  342. checkvars['SRC_URI'] = srcuri + ';branch=master'
  343. checkvars['DEPENDS'] = set(['libcheck', 'libjpeg-turbo', 'libpng', 'libx11', 'libxext', 'pango'])
  344. inherits = ['autotools', 'pkgconfig']
  345. self._test_recipe_contents(recipefile, checkvars, inherits)
  346. def test_recipetool_create_simple(self):
  347. # Try adding a recipe
  348. temprecipe = os.path.join(self.tempdir, 'recipe')
  349. os.makedirs(temprecipe)
  350. pv = '1.7.4.1'
  351. srcuri = 'http://www.dest-unreach.org/socat/download/Archive/socat-%s.tar.bz2' % pv
  352. result = runCmd('recipetool create %s -o %s' % (srcuri, temprecipe))
  353. dirlist = os.listdir(temprecipe)
  354. if len(dirlist) > 1:
  355. self.fail('recipetool created more than just one file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist)))
  356. if len(dirlist) < 1 or not os.path.isfile(os.path.join(temprecipe, dirlist[0])):
  357. self.fail('recipetool did not create recipe file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist)))
  358. self.assertEqual(dirlist[0], 'socat_%s.bb' % pv, 'Recipe file incorrectly named')
  359. checkvars = {}
  360. checkvars['LICENSE'] = set(['Unknown', 'GPL-2.0-only'])
  361. checkvars['LIC_FILES_CHKSUM'] = set(['file://COPYING.OpenSSL;md5=5c9bccc77f67a8328ef4ebaf468116f4', 'file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263'])
  362. # We don't check DEPENDS since they are variable for this recipe depending on what's in the sysroot
  363. checkvars['S'] = None
  364. checkvars['SRC_URI'] = srcuri.replace(pv, '${PV}')
  365. inherits = ['autotools']
  366. self._test_recipe_contents(os.path.join(temprecipe, dirlist[0]), checkvars, inherits)
  367. def test_recipetool_create_cmake(self):
  368. temprecipe = os.path.join(self.tempdir, 'recipe')
  369. os.makedirs(temprecipe)
  370. recipefile = os.path.join(temprecipe, 'taglib_1.11.1.bb')
  371. srcuri = 'http://taglib.github.io/releases/taglib-1.11.1.tar.gz'
  372. result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
  373. self.assertTrue(os.path.isfile(recipefile))
  374. checkvars = {}
  375. checkvars['LICENSE'] = set(['LGPL-2.1-only', 'MPL-1.1-only'])
  376. checkvars['SRC_URI'] = 'http://taglib.github.io/releases/taglib-${PV}.tar.gz'
  377. checkvars['SRC_URI[sha256sum]'] = 'b6d1a5a610aae6ff39d93de5efd0fdc787aa9e9dc1e7026fa4c961b26563526b'
  378. checkvars['DEPENDS'] = set(['boost', 'zlib'])
  379. inherits = ['cmake']
  380. self._test_recipe_contents(recipefile, checkvars, inherits)
  381. def test_recipetool_create_npm(self):
  382. collections = get_bb_var('BBFILE_COLLECTIONS').split()
  383. if "openembedded-layer" not in collections:
  384. self.skipTest("Test needs meta-oe for nodejs")
  385. temprecipe = os.path.join(self.tempdir, 'recipe')
  386. os.makedirs(temprecipe)
  387. recipefile = os.path.join(temprecipe, 'savoirfairelinux-node-server-example_1.0.0.bb')
  388. shrinkwrap = os.path.join(temprecipe, 'savoirfairelinux-node-server-example', 'npm-shrinkwrap.json')
  389. srcuri = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
  390. result = runCmd('recipetool create -o %s \'%s\'' % (temprecipe, srcuri))
  391. self.assertTrue(os.path.isfile(recipefile))
  392. self.assertTrue(os.path.isfile(shrinkwrap))
  393. checkvars = {}
  394. checkvars['SUMMARY'] = 'Node Server Example'
  395. checkvars['HOMEPAGE'] = 'https://github.com/savoirfairelinux/node-server-example#readme'
  396. checkvars['LICENSE'] = 'BSD-3-Clause & ISC & MIT & Unknown'
  397. urls = []
  398. urls.append('npm://registry.npmjs.org/;package=@savoirfairelinux/node-server-example;version=${PV}')
  399. urls.append('npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json')
  400. checkvars['SRC_URI'] = set(urls)
  401. checkvars['S'] = '${WORKDIR}/npm'
  402. checkvars['LICENSE:${PN}'] = 'MIT'
  403. checkvars['LICENSE:${PN}-base64'] = 'Unknown'
  404. checkvars['LICENSE:${PN}-accepts'] = 'MIT'
  405. checkvars['LICENSE:${PN}-inherits'] = 'ISC'
  406. inherits = ['npm']
  407. self._test_recipe_contents(recipefile, checkvars, inherits)
  408. def test_recipetool_create_github(self):
  409. # Basic test to see if github URL mangling works. Deliberately use an
  410. # older release of Meson at present so we don't need a toml parser.
  411. temprecipe = os.path.join(self.tempdir, 'recipe')
  412. os.makedirs(temprecipe)
  413. recipefile = os.path.join(temprecipe, 'python3-meson_git.bb')
  414. srcuri = 'https://github.com/mesonbuild/meson;rev=0.52.1'
  415. cmd = ['recipetool', 'create', '-o', temprecipe, srcuri]
  416. result = runCmd(cmd)
  417. self.assertTrue(os.path.isfile(recipefile), msg="recipe %s not created for command %s, output %s" % (recipefile, " ".join(cmd), result.output))
  418. checkvars = {}
  419. checkvars['LICENSE'] = set(['Apache-2.0', "Unknown"])
  420. checkvars['SRC_URI'] = 'git://github.com/mesonbuild/meson;protocol=https;branch=0.52'
  421. inherits = ['setuptools3']
  422. self._test_recipe_contents(recipefile, checkvars, inherits)
  423. def test_recipetool_create_python3_setuptools(self):
  424. # Test creating python3 package from tarball (using setuptools3 class)
  425. # Use the --no-pypi switch to avoid creating a pypi enabled recipe and
  426. # and check the created recipe as if it was a more general tarball
  427. temprecipe = os.path.join(self.tempdir, 'recipe')
  428. os.makedirs(temprecipe)
  429. pn = 'python-magic'
  430. pv = '0.4.15'
  431. recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, pv))
  432. srcuri = 'https://files.pythonhosted.org/packages/84/30/80932401906eaf787f2e9bd86dc458f1d2e75b064b4c187341f29516945c/python-magic-%s.tar.gz' % pv
  433. result = runCmd('recipetool create --no-pypi -o %s %s' % (temprecipe, srcuri))
  434. self.assertTrue(os.path.isfile(recipefile))
  435. checkvars = {}
  436. checkvars['LICENSE'] = set(['MIT'])
  437. checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88'
  438. checkvars['SRC_URI'] = 'https://files.pythonhosted.org/packages/84/30/80932401906eaf787f2e9bd86dc458f1d2e75b064b4c187341f29516945c/python-magic-${PV}.tar.gz'
  439. checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5'
  440. inherits = ['setuptools3']
  441. self._test_recipe_contents(recipefile, checkvars, inherits)
  442. def test_recipetool_create_python3_setuptools_pypi_tarball(self):
  443. # Test creating python3 package from tarball (using setuptools3 and pypi classes)
  444. temprecipe = os.path.join(self.tempdir, 'recipe')
  445. os.makedirs(temprecipe)
  446. pn = 'python-magic'
  447. pv = '0.4.15'
  448. recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, pv))
  449. srcuri = 'https://files.pythonhosted.org/packages/84/30/80932401906eaf787f2e9bd86dc458f1d2e75b064b4c187341f29516945c/python-magic-%s.tar.gz' % pv
  450. result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
  451. self.assertTrue(os.path.isfile(recipefile))
  452. checkvars = {}
  453. checkvars['LICENSE'] = set(['MIT'])
  454. checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88'
  455. checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5'
  456. checkvars['PYPI_PACKAGE'] = pn
  457. inherits = ['setuptools3', 'pypi']
  458. self._test_recipe_contents(recipefile, checkvars, inherits)
  459. def test_recipetool_create_python3_setuptools_pypi(self):
  460. # Test creating python3 package from pypi url (using setuptools3 and pypi classes)
  461. # Intentionnaly using setuptools3 class here instead of any of the pep517 class
  462. # to avoid the toml dependency and allows this test to run on host autobuilders
  463. # with older version of python
  464. temprecipe = os.path.join(self.tempdir, 'recipe')
  465. os.makedirs(temprecipe)
  466. pn = 'python-magic'
  467. pv = '0.4.15'
  468. recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, pv))
  469. # First specify the required version in the url
  470. srcuri = 'https://pypi.org/project/%s/%s' % (pn, pv)
  471. runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
  472. self.assertTrue(os.path.isfile(recipefile))
  473. checkvars = {}
  474. checkvars['LICENSE'] = set(['MIT'])
  475. checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88'
  476. checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5'
  477. checkvars['PYPI_PACKAGE'] = pn
  478. inherits = ['setuptools3', "pypi"]
  479. self._test_recipe_contents(recipefile, checkvars, inherits)
  480. # Now specify the version as a recipetool parameter
  481. runCmd('rm -rf %s' % recipefile)
  482. self.assertFalse(os.path.isfile(recipefile))
  483. srcuri = 'https://pypi.org/project/%s' % pn
  484. runCmd('recipetool create -o %s %s --version %s' % (temprecipe, srcuri, pv))
  485. self.assertTrue(os.path.isfile(recipefile))
  486. checkvars = {}
  487. checkvars['LICENSE'] = set(['MIT'])
  488. checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88'
  489. checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5'
  490. checkvars['PYPI_PACKAGE'] = pn
  491. inherits = ['setuptools3', "pypi"]
  492. self._test_recipe_contents(recipefile, checkvars, inherits)
  493. # Now, try to grab latest version of the package, so we cannot guess the name of the recipe,
  494. # unless hardcoding the latest version but it means we will need to update the test for each release,
  495. # so use a regexp
  496. runCmd('rm -rf %s' % recipefile)
  497. self.assertFalse(os.path.isfile(recipefile))
  498. recipefile_re = r'%s_(.*)\.bb' % pn
  499. result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
  500. dirlist = os.listdir(temprecipe)
  501. if len(dirlist) > 1:
  502. self.fail('recipetool created more than just one file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist)))
  503. if len(dirlist) < 1 or not os.path.isfile(os.path.join(temprecipe, dirlist[0])):
  504. self.fail('recipetool did not create recipe file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist)))
  505. import re
  506. match = re.match(recipefile_re, dirlist[0])
  507. self.assertTrue(match)
  508. latest_pv = match.group(1)
  509. self.assertTrue(latest_pv != pv)
  510. recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, latest_pv))
  511. # Do not check LIC_FILES_CHKSUM and SRC_URI checksum here to avoid having updating the test on each release
  512. checkvars = {}
  513. checkvars['LICENSE'] = set(['MIT'])
  514. checkvars['PYPI_PACKAGE'] = pn
  515. inherits = ['setuptools3', "pypi"]
  516. self._test_recipe_contents(recipefile, checkvars, inherits)
  517. def test_recipetool_create_python3_pep517_setuptools_build_meta(self):
  518. # This test require python 3.11 or above for the tomllib module or tomli module to be installed
  519. needTomllib(self)
  520. # Test creating python3 package from tarball (using setuptools.build_meta class)
  521. temprecipe = os.path.join(self.tempdir, 'recipe')
  522. os.makedirs(temprecipe)
  523. pn = 'webcolors'
  524. pv = '1.13'
  525. recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
  526. srcuri = 'https://files.pythonhosted.org/packages/a1/fb/f95560c6a5d4469d9c49e24cf1b5d4d21ffab5608251c6020a965fb7791c/%s-%s.tar.gz' % (pn, pv)
  527. result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
  528. self.assertTrue(os.path.isfile(recipefile))
  529. checkvars = {}
  530. checkvars['SUMMARY'] = 'A library for working with the color formats defined by HTML and CSS.'
  531. checkvars['LICENSE'] = set(['BSD-3-Clause'])
  532. checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=702b1ef12cf66832a88f24c8f2ee9c19'
  533. checkvars['SRC_URI[sha256sum]'] = 'c225b674c83fa923be93d235330ce0300373d02885cef23238813b0d5668304a'
  534. inherits = ['python_setuptools_build_meta', 'pypi']
  535. self._test_recipe_contents(recipefile, checkvars, inherits)
  536. def test_recipetool_create_python3_pep517_poetry_core_masonry_api(self):
  537. # This test require python 3.11 or above for the tomllib module or tomli module to be installed
  538. needTomllib(self)
  539. # Test creating python3 package from tarball (using poetry.core.masonry.api class)
  540. temprecipe = os.path.join(self.tempdir, 'recipe')
  541. os.makedirs(temprecipe)
  542. pn = 'iso8601'
  543. pv = '2.1.0'
  544. recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
  545. srcuri = 'https://files.pythonhosted.org/packages/b9/f3/ef59cee614d5e0accf6fd0cbba025b93b272e626ca89fb70a3e9187c5d15/%s-%s.tar.gz' % (pn, pv)
  546. result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
  547. self.assertTrue(os.path.isfile(recipefile))
  548. checkvars = {}
  549. checkvars['SUMMARY'] = 'Simple module to parse ISO 8601 dates'
  550. checkvars['LICENSE'] = set(['MIT'])
  551. checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=aab31f2ef7ba214a5a341eaa47a7f367'
  552. checkvars['SRC_URI[sha256sum]'] = '6b1d3829ee8921c4301998c909f7829fa9ed3cbdac0d3b16af2d743aed1ba8df'
  553. inherits = ['python_poetry_core', 'pypi']
  554. self._test_recipe_contents(recipefile, checkvars, inherits)
  555. def test_recipetool_create_python3_pep517_flit_core_buildapi(self):
  556. # This test require python 3.11 or above for the tomllib module or tomli module to be installed
  557. needTomllib(self)
  558. # Test creating python3 package from tarball (using flit_core.buildapi class)
  559. temprecipe = os.path.join(self.tempdir, 'recipe')
  560. os.makedirs(temprecipe)
  561. pn = 'typing-extensions'
  562. pv = '4.8.0'
  563. recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
  564. srcuri = 'https://files.pythonhosted.org/packages/1f/7a/8b94bb016069caa12fc9f587b28080ac33b4fbb8ca369b98bc0a4828543e/typing_extensions-%s.tar.gz' % pv
  565. result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
  566. self.assertTrue(os.path.isfile(recipefile))
  567. checkvars = {}
  568. checkvars['SUMMARY'] = 'Backported and Experimental Type Hints for Python 3.8+'
  569. checkvars['LICENSE'] = set(['PSF-2.0'])
  570. checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=fcf6b249c2641540219a727f35d8d2c2'
  571. checkvars['SRC_URI[sha256sum]'] = 'df8e4339e9cb77357558cbdbceca33c303714cf861d1eef15e1070055ae8b7ef'
  572. inherits = ['python_flit_core', 'pypi']
  573. self._test_recipe_contents(recipefile, checkvars, inherits)
  574. def test_recipetool_create_python3_pep517_hatchling(self):
  575. # This test require python 3.11 or above for the tomllib module or tomli module to be installed
  576. needTomllib(self)
  577. # Test creating python3 package from tarball (using hatchling class)
  578. temprecipe = os.path.join(self.tempdir, 'recipe')
  579. os.makedirs(temprecipe)
  580. pn = 'jsonschema'
  581. pv = '4.19.1'
  582. recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
  583. srcuri = 'https://files.pythonhosted.org/packages/e4/43/087b24516db11722c8687e0caf0f66c7785c0b1c51b0ab951dfde924e3f5/jsonschema-%s.tar.gz' % pv
  584. result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
  585. self.assertTrue(os.path.isfile(recipefile))
  586. checkvars = {}
  587. checkvars['SUMMARY'] = 'An implementation of JSON Schema validation for Python'
  588. checkvars['HOMEPAGE'] = 'https://github.com/python-jsonschema/jsonschema'
  589. checkvars['LICENSE'] = set(['MIT'])
  590. checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=7a60a81c146ec25599a3e1dabb8610a8 file://json/LICENSE;md5=9d4de43111d33570c8fe49b4cb0e01af'
  591. checkvars['SRC_URI[sha256sum]'] = 'ec84cc37cfa703ef7cd4928db24f9cb31428a5d0fa77747b8b51a847458e0bbf'
  592. inherits = ['python_hatchling', 'pypi']
  593. self._test_recipe_contents(recipefile, checkvars, inherits)
  594. def test_recipetool_create_python3_pep517_maturin(self):
  595. # This test require python 3.11 or above for the tomllib module or tomli module to be installed
  596. needTomllib(self)
  597. # Test creating python3 package from tarball (using maturin class)
  598. temprecipe = os.path.join(self.tempdir, 'recipe')
  599. os.makedirs(temprecipe)
  600. pn = 'pydantic-core'
  601. pv = '2.14.5'
  602. recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
  603. srcuri = 'https://files.pythonhosted.org/packages/64/26/cffb93fe9c6b5a91c497f37fae14a4b073ecbc47fc36a9979c7aa888b245/pydantic_core-%s.tar.gz' % pv
  604. result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
  605. self.assertTrue(os.path.isfile(recipefile))
  606. checkvars = {}
  607. checkvars['HOMEPAGE'] = 'https://github.com/pydantic/pydantic-core'
  608. checkvars['LICENSE'] = set(['MIT'])
  609. checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=ab599c188b4a314d2856b3a55030c75c'
  610. checkvars['SRC_URI[sha256sum]'] = '6d30226dfc816dd0fdf120cae611dd2215117e4f9b124af8c60ab9093b6e8e71'
  611. inherits = ['python_maturin', 'pypi']
  612. self._test_recipe_contents(recipefile, checkvars, inherits)
  613. def test_recipetool_create_python3_pep517_mesonpy(self):
  614. # This test require python 3.11 or above for the tomllib module or tomli module to be installed
  615. needTomllib(self)
  616. # Test creating python3 package from tarball (using mesonpy class)
  617. temprecipe = os.path.join(self.tempdir, 'recipe')
  618. os.makedirs(temprecipe)
  619. pn = 'siphash24'
  620. pv = '1.4'
  621. recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
  622. srcuri = 'https://files.pythonhosted.org/packages/c2/32/b934a70592f314afcfa86c7f7e388804a8061be65b822e2aa07e573b6477/%s-%s.tar.gz' % (pn, pv)
  623. result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
  624. self.assertTrue(os.path.isfile(recipefile))
  625. checkvars = {}
  626. checkvars['SRC_URI[sha256sum]'] = '7fd65e39b2a7c8c4ddc3a168a687f4610751b0ac2ebb518783c0cdfc30bec4a0'
  627. inherits = ['python_mesonpy', 'pypi']
  628. self._test_recipe_contents(recipefile, checkvars, inherits)
  629. def test_recipetool_create_github_tarball(self):
  630. # Basic test to ensure github URL mangling doesn't apply to release tarballs.
  631. # Deliberately use an older release of Meson at present so we don't need a toml parser.
  632. temprecipe = os.path.join(self.tempdir, 'recipe')
  633. os.makedirs(temprecipe)
  634. pv = '0.52.1'
  635. recipefile = os.path.join(temprecipe, 'python3-meson_%s.bb' % pv)
  636. srcuri = 'https://github.com/mesonbuild/meson/releases/download/%s/meson-%s.tar.gz' % (pv, pv)
  637. result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
  638. self.assertTrue(os.path.isfile(recipefile))
  639. checkvars = {}
  640. checkvars['LICENSE'] = set(['Apache-2.0'])
  641. checkvars['SRC_URI'] = 'https://github.com/mesonbuild/meson/releases/download/${PV}/meson-${PV}.tar.gz'
  642. inherits = ['setuptools3']
  643. self._test_recipe_contents(recipefile, checkvars, inherits)
  644. def _test_recipetool_create_git(self, srcuri, branch=None):
  645. # Basic test to check http git URL mangling works
  646. temprecipe = os.path.join(self.tempdir, 'recipe')
  647. os.makedirs(temprecipe)
  648. name = srcuri.split(';')[0].split('/')[-1]
  649. recipefile = os.path.join(temprecipe, name + '_git.bb')
  650. options = ' -B %s' % branch if branch else ''
  651. result = runCmd('recipetool create -o %s%s "%s"' % (temprecipe, options, srcuri))
  652. self.assertTrue(os.path.isfile(recipefile))
  653. checkvars = {}
  654. checkvars['SRC_URI'] = srcuri
  655. for scheme in ['http', 'https']:
  656. if srcuri.startswith(scheme + ":"):
  657. checkvars['SRC_URI'] = 'git%s;protocol=%s' % (srcuri[len(scheme):], scheme)
  658. if ';branch=' not in srcuri:
  659. checkvars['SRC_URI'] += ';branch=' + (branch or 'master')
  660. self._test_recipe_contents(recipefile, checkvars, [])
  661. def test_recipetool_create_git_http(self):
  662. self._test_recipetool_create_git('http://git.yoctoproject.org/git/matchbox-keyboard')
  663. def test_recipetool_create_git_srcuri_master(self):
  664. self._test_recipetool_create_git('git://git.yoctoproject.org/matchbox-keyboard;branch=master;protocol=https')
  665. def test_recipetool_create_git_srcuri_branch(self):
  666. self._test_recipetool_create_git('git://git.yoctoproject.org/matchbox-keyboard;branch=matchbox-keyboard-0-1;protocol=https')
  667. def test_recipetool_create_git_srcbranch(self):
  668. self._test_recipetool_create_git('git://git.yoctoproject.org/matchbox-keyboard;protocol=https', 'matchbox-keyboard-0-1')
  669. def _go_urifiy(self, url, version, modulepath = None, pathmajor = None, subdir = None):
  670. modulepath = ",path='%s'" % modulepath if len(modulepath) else ''
  671. pathmajor = ",pathmajor='%s'" % pathmajor if len(pathmajor) else ''
  672. subdir = ",subdir='%s'" % subdir if len(subdir) else ''
  673. return "${@go_src_uri('%s','%s'%s%s%s)}" % (url, version, modulepath, pathmajor, subdir)
  674. def test_recipetool_create_go(self):
  675. # Basic test to check go recipe generation
  676. temprecipe = os.path.join(self.tempdir, 'recipe')
  677. os.makedirs(temprecipe)
  678. recipefile = os.path.join(temprecipe, 'recipetool-go-test_git.bb')
  679. deps_require_file = os.path.join(temprecipe, 'recipetool-go-test', 'recipetool-go-test-modules.inc')
  680. lics_require_file = os.path.join(temprecipe, 'recipetool-go-test', 'recipetool-go-test-licenses.inc')
  681. modules_txt_file = os.path.join(temprecipe, 'recipetool-go-test', 'modules.txt')
  682. srcuri = 'https://git.yoctoproject.org/recipetool-go-test.git'
  683. srcrev = "c3e213c01b6c1406b430df03ef0d1ae77de5d2f7"
  684. srcbranch = "main"
  685. result = runCmd('recipetool create -o %s %s -S %s -B %s' % (temprecipe, srcuri, srcrev, srcbranch))
  686. self.maxDiff = None
  687. inherits = ['go-vendor']
  688. checkvars = {}
  689. checkvars['GO_IMPORT'] = "git.yoctoproject.org/recipetool-go-test"
  690. checkvars['SRC_URI'] = {'git://${GO_IMPORT};destsuffix=git/src/${GO_IMPORT};nobranch=1;name=${BPN};protocol=https',
  691. 'file://modules.txt'}
  692. checkvars['LIC_FILES_CHKSUM'] = {
  693. 'file://src/${GO_IMPORT}/LICENSE;md5=4e3933dd47afbf115e484d11385fb3bd',
  694. 'file://src/${GO_IMPORT}/is/LICENSE;md5=62beaee5a116dd1e80161667b1df39ab'
  695. }
  696. self._test_recipe_contents(recipefile, checkvars, inherits)
  697. self.assertNotIn('Traceback', result.output)
  698. checkvars = {}
  699. checkvars['VENDORED_LIC_FILES_CHKSUM'] = set(
  700. ['file://src/${GO_IMPORT}/vendor/github.com/godbus/dbus/v5/LICENSE;md5=09042bd5c6c96a2b9e45ddf1bc517eed',
  701. 'file://src/${GO_IMPORT}/vendor/github.com/matryer/is/LICENSE;md5=62beaee5a116dd1e80161667b1df39ab'])
  702. self.assertTrue(os.path.isfile(lics_require_file))
  703. self._test_recipe_contents(lics_require_file, checkvars, [])
  704. # make sure that dependencies don't mention local directory ./matryer/is
  705. dependencies = \
  706. [ ('github.com/godbus/dbus','v5.1.0', 'github.com/godbus/dbus/v5', '/v5', ''),
  707. ]
  708. src_uri = set()
  709. for d in dependencies:
  710. src_uri.add(self._go_urifiy(*d))
  711. checkvars = {}
  712. checkvars['GO_DEPENDENCIES_SRC_URI'] = src_uri
  713. self.assertTrue(os.path.isfile(deps_require_file))
  714. self._test_recipe_contents(deps_require_file, checkvars, [])
  715. class RecipetoolTests(RecipetoolBase):
  716. @classmethod
  717. def setUpClass(cls):
  718. import sys
  719. super(RecipetoolTests, cls).setUpClass()
  720. bb_vars = get_bb_vars(['BBPATH'])
  721. cls.bbpath = bb_vars['BBPATH']
  722. libpath = os.path.join(get_bb_var('COREBASE'), 'scripts', 'lib', 'recipetool')
  723. sys.path.insert(0, libpath)
  724. def _copy_file_with_cleanup(self, srcfile, basedstdir, *paths):
  725. dstdir = basedstdir
  726. self.assertTrue(os.path.exists(dstdir))
  727. for p in paths:
  728. dstdir = os.path.join(dstdir, p)
  729. if not os.path.exists(dstdir):
  730. try:
  731. os.makedirs(dstdir)
  732. except PermissionError:
  733. return False
  734. except OSError as e:
  735. if e.errno == errno.EROFS:
  736. return False
  737. else:
  738. raise e
  739. if p == "lib":
  740. # Can race with other tests
  741. self.add_command_to_tearDown('rmdir --ignore-fail-on-non-empty %s' % dstdir)
  742. else:
  743. self.track_for_cleanup(dstdir)
  744. dstfile = os.path.join(dstdir, os.path.basename(srcfile))
  745. if srcfile != dstfile:
  746. try:
  747. shutil.copy(srcfile, dstfile)
  748. except PermissionError:
  749. return False
  750. self.track_for_cleanup(dstfile)
  751. return True
  752. def test_recipetool_load_plugin(self):
  753. """Test that recipetool loads only the first found plugin in BBPATH."""
  754. recipetool = runCmd("which recipetool")
  755. fromname = runCmd("recipetool --quiet pluginfile")
  756. srcfile = fromname.output
  757. searchpath = self.bbpath.split(':') + [os.path.dirname(recipetool.output)]
  758. plugincontent = []
  759. with open(srcfile) as fh:
  760. plugincontent = fh.readlines()
  761. try:
  762. self.assertIn('meta-selftest', srcfile, 'wrong bbpath plugin found')
  763. searchpath = [
  764. path for path in searchpath
  765. if self._copy_file_with_cleanup(srcfile, path, 'lib', 'recipetool')
  766. ]
  767. result = runCmd("recipetool --quiet count")
  768. self.assertEqual(result.output, '1')
  769. result = runCmd("recipetool --quiet multiloaded")
  770. self.assertEqual(result.output, "no")
  771. for path in searchpath:
  772. result = runCmd("recipetool --quiet bbdir")
  773. self.assertEqual(os.path.realpath(result.output), os.path.realpath(path))
  774. os.unlink(os.path.join(result.output, 'lib', 'recipetool', 'bbpath.py'))
  775. finally:
  776. with open(srcfile, 'w') as fh:
  777. fh.writelines(plugincontent)
  778. def test_recipetool_handle_license_vars(self):
  779. from create import handle_license_vars
  780. from unittest.mock import Mock
  781. commonlicdir = get_bb_var('COMMON_LICENSE_DIR')
  782. class DataConnectorCopy(bb.tinfoil.TinfoilDataStoreConnector):
  783. pass
  784. d = DataConnectorCopy
  785. d.getVar = Mock(return_value=commonlicdir)
  786. d.expand = Mock(side_effect=lambda x: x)
  787. srctree = tempfile.mkdtemp(prefix='recipetoolqa')
  788. self.track_for_cleanup(srctree)
  789. # Multiple licenses
  790. licenses = ['MIT', 'ISC', 'BSD-3-Clause', 'Apache-2.0']
  791. for licence in licenses:
  792. shutil.copy(os.path.join(commonlicdir, licence), os.path.join(srctree, 'LICENSE.' + licence))
  793. # Duplicate license
  794. shutil.copy(os.path.join(commonlicdir, 'MIT'), os.path.join(srctree, 'LICENSE'))
  795. extravalues = {
  796. # Duplicate and missing licenses
  797. 'LICENSE': 'Zlib & BSD-2-Clause & Zlib',
  798. 'LIC_FILES_CHKSUM': [
  799. 'file://README.md;md5=0123456789abcdef0123456789abcd'
  800. ]
  801. }
  802. lines_before = []
  803. handled = []
  804. licvalues = handle_license_vars(srctree, lines_before, handled, extravalues, d)
  805. expected_lines_before = [
  806. '# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is',
  807. '# your responsibility to verify that the values are complete and correct.',
  808. '# NOTE: Original package / source metadata indicates license is: BSD-2-Clause & Zlib',
  809. '#',
  810. '# NOTE: multiple licenses have been detected; they have been separated with &',
  811. '# in the LICENSE value for now since it is a reasonable assumption that all',
  812. '# of the licenses apply. If instead there is a choice between the multiple',
  813. '# licenses then you should change the value to separate the licenses with |',
  814. '# instead of &. If there is any doubt, check the accompanying documentation',
  815. '# to determine which situation is applicable.',
  816. 'LICENSE = "Apache-2.0 & BSD-2-Clause & BSD-3-Clause & ISC & MIT & Zlib"',
  817. 'LIC_FILES_CHKSUM = "file://LICENSE;md5=0835ade698e0bcf8506ecda2f7b4f302 \\\n'
  818. ' file://LICENSE.Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10 \\\n'
  819. ' file://LICENSE.BSD-3-Clause;md5=550794465ba0ec5312d6919e203a55f9 \\\n'
  820. ' file://LICENSE.ISC;md5=f3b90e78ea0cffb20bf5cca7947a896d \\\n'
  821. ' file://LICENSE.MIT;md5=0835ade698e0bcf8506ecda2f7b4f302 \\\n'
  822. ' file://README.md;md5=0123456789abcdef0123456789abcd"',
  823. ''
  824. ]
  825. self.assertEqual(lines_before, expected_lines_before)
  826. expected_licvalues = [
  827. ('MIT', 'LICENSE', '0835ade698e0bcf8506ecda2f7b4f302'),
  828. ('Apache-2.0', 'LICENSE.Apache-2.0', '89aea4e17d99a7cacdbeed46a0096b10'),
  829. ('BSD-3-Clause', 'LICENSE.BSD-3-Clause', '550794465ba0ec5312d6919e203a55f9'),
  830. ('ISC', 'LICENSE.ISC', 'f3b90e78ea0cffb20bf5cca7947a896d'),
  831. ('MIT', 'LICENSE.MIT', '0835ade698e0bcf8506ecda2f7b4f302')
  832. ]
  833. self.assertEqual(handled, [('license', expected_licvalues)])
  834. self.assertEqual(extravalues, {})
  835. self.assertEqual(licvalues, expected_licvalues)
  836. def test_recipetool_split_pkg_licenses(self):
  837. from create import split_pkg_licenses
  838. licvalues = [
  839. # Duplicate licenses
  840. ('BSD-2-Clause', 'x/COPYING', None),
  841. ('BSD-2-Clause', 'x/LICENSE', None),
  842. # Multiple licenses
  843. ('MIT', 'x/a/LICENSE.MIT', None),
  844. ('ISC', 'x/a/LICENSE.ISC', None),
  845. # Alternative licenses
  846. ('(MIT | ISC)', 'x/b/LICENSE', None),
  847. # Alternative licenses without brackets
  848. ('MIT | BSD-2-Clause', 'x/c/LICENSE', None),
  849. # Multi licenses with alternatives
  850. ('MIT', 'x/d/COPYING', None),
  851. ('MIT | BSD-2-Clause', 'x/d/LICENSE', None),
  852. # Multi licenses with alternatives and brackets
  853. ('Apache-2.0 & ((MIT | ISC) & BSD-3-Clause)', 'x/e/LICENSE', None)
  854. ]
  855. packages = {
  856. '${PN}': '',
  857. 'a': 'x/a',
  858. 'b': 'x/b',
  859. 'c': 'x/c',
  860. 'd': 'x/d',
  861. 'e': 'x/e',
  862. 'f': 'x/f',
  863. 'g': 'x/g',
  864. }
  865. fallback_licenses = {
  866. # Ignored
  867. 'a': 'BSD-3-Clause',
  868. # Used
  869. 'f': 'BSD-3-Clause'
  870. }
  871. outlines = []
  872. outlicenses = split_pkg_licenses(licvalues, packages, outlines, fallback_licenses)
  873. expected_outlicenses = {
  874. '${PN}': ['BSD-2-Clause'],
  875. 'a': ['ISC', 'MIT'],
  876. 'b': ['(ISC | MIT)'],
  877. 'c': ['(BSD-2-Clause | MIT)'],
  878. 'd': ['(BSD-2-Clause | MIT)', 'MIT'],
  879. 'e': ['(ISC | MIT)', 'Apache-2.0', 'BSD-3-Clause'],
  880. 'f': ['BSD-3-Clause'],
  881. 'g': ['Unknown']
  882. }
  883. self.assertEqual(outlicenses, expected_outlicenses)
  884. expected_outlines = [
  885. 'LICENSE:${PN} = "BSD-2-Clause"',
  886. 'LICENSE:a = "ISC & MIT"',
  887. 'LICENSE:b = "(ISC | MIT)"',
  888. 'LICENSE:c = "(BSD-2-Clause | MIT)"',
  889. 'LICENSE:d = "(BSD-2-Clause | MIT) & MIT"',
  890. 'LICENSE:e = "(ISC | MIT) & Apache-2.0 & BSD-3-Clause"',
  891. 'LICENSE:f = "BSD-3-Clause"',
  892. 'LICENSE:g = "Unknown"'
  893. ]
  894. self.assertEqual(outlines, expected_outlines)
  895. class RecipetoolAppendsrcBase(RecipetoolBase):
  896. def _try_recipetool_appendsrcfile(self, testrecipe, newfile, destfile, options, expectedlines, expectedfiles):
  897. cmd = 'recipetool appendsrcfile %s %s %s %s %s' % (options, self.templayerdir, testrecipe, newfile, destfile)
  898. return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
  899. def _try_recipetool_appendsrcfiles(self, testrecipe, newfiles, expectedlines=None, expectedfiles=None, destdir=None, options=''):
  900. if destdir:
  901. options += ' -D %s' % destdir
  902. if expectedfiles is None:
  903. expectedfiles = [os.path.basename(f) for f in newfiles]
  904. cmd = 'recipetool appendsrcfiles %s %s %s %s' % (options, self.templayerdir, testrecipe, ' '.join(newfiles))
  905. return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines)
  906. def _try_recipetool_appendsrcfile_fail(self, testrecipe, newfile, destfile, checkerror):
  907. cmd = 'recipetool appendsrcfile %s %s %s %s' % (self.templayerdir, testrecipe, newfile, destfile or '')
  908. result = runCmd(cmd, ignore_status=True)
  909. self.assertNotEqual(result.status, 0, 'Command "%s" should have failed but didn\'t' % cmd)
  910. self.assertNotIn('Traceback', result.output)
  911. for errorstr in checkerror:
  912. self.assertIn(errorstr, result.output)
  913. @staticmethod
  914. def _get_first_file_uri(recipe):
  915. '''Return the first file:// in SRC_URI for the specified recipe.'''
  916. src_uri = get_bb_var('SRC_URI', recipe).split()
  917. for uri in src_uri:
  918. p = urllib.parse.urlparse(uri)
  919. if p.scheme == 'file':
  920. return p.netloc + p.path, uri
  921. def _test_appendsrcfile(self, testrecipe, filename=None, destdir=None, has_src_uri=True, srcdir=None, newfile=None, remove=None, machine=None , options=''):
  922. if newfile is None:
  923. newfile = self.testfile
  924. if srcdir:
  925. if destdir:
  926. expected_subdir = os.path.join(srcdir, destdir)
  927. else:
  928. expected_subdir = srcdir
  929. else:
  930. options += " -W"
  931. expected_subdir = destdir
  932. if filename:
  933. if destdir:
  934. destpath = os.path.join(destdir, filename)
  935. else:
  936. destpath = filename
  937. else:
  938. filename = os.path.basename(newfile)
  939. if destdir:
  940. destpath = destdir + os.sep
  941. else:
  942. destpath = '.' + os.sep
  943. expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
  944. '\n']
  945. override = ""
  946. if machine:
  947. options += ' -m %s' % machine
  948. override = ':append:%s' % machine
  949. expectedlines.extend(['PACKAGE_ARCH = "${MACHINE_ARCH}"\n',
  950. '\n'])
  951. if remove:
  952. for entry in remove:
  953. if machine:
  954. entry_remove_line = 'SRC_URI:remove:%s = " %s"\n' % (machine, entry)
  955. else:
  956. entry_remove_line = 'SRC_URI:remove = "%s"\n' % entry
  957. expectedlines.extend([entry_remove_line,
  958. '\n'])
  959. if has_src_uri:
  960. uri = 'file://%s' % filename
  961. if expected_subdir:
  962. uri += ';subdir=%s' % expected_subdir
  963. if machine:
  964. src_uri_line = 'SRC_URI%s = " %s"\n' % (override, uri)
  965. else:
  966. src_uri_line = 'SRC_URI += "%s"\n' % uri
  967. expectedlines.extend([src_uri_line, '\n'])
  968. with open("/tmp/tmp.txt", "w") as file:
  969. print(expectedlines, file=file)
  970. if machine:
  971. filename = '%s/%s' % (machine, filename)
  972. return self._try_recipetool_appendsrcfile(testrecipe, newfile, destpath, options, expectedlines, [filename])
  973. def _test_appendsrcfiles(self, testrecipe, newfiles, expectedfiles=None, destdir=None, options=''):
  974. if expectedfiles is None:
  975. expectedfiles = [os.path.basename(n) for n in newfiles]
  976. self._try_recipetool_appendsrcfiles(testrecipe, newfiles, expectedfiles=expectedfiles, destdir=destdir, options=options)
  977. bb_vars = get_bb_vars(['SRC_URI', 'FILE', 'FILESEXTRAPATHS'], testrecipe)
  978. src_uri = bb_vars['SRC_URI'].split()
  979. for f in expectedfiles:
  980. if destdir:
  981. self.assertIn('file://%s;subdir=%s' % (f, destdir), src_uri)
  982. else:
  983. self.assertIn('file://%s' % f, src_uri)
  984. recipefile = bb_vars['FILE']
  985. bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir)
  986. filesdir = os.path.join(os.path.dirname(bbappendfile), testrecipe)
  987. filesextrapaths = bb_vars['FILESEXTRAPATHS'].split(':')
  988. self.assertIn(filesdir, filesextrapaths)
  989. class RecipetoolAppendsrcTests(RecipetoolAppendsrcBase):
  990. def test_recipetool_appendsrcfile_basic(self):
  991. self._test_appendsrcfile('base-files', 'a-file')
  992. def test_recipetool_appendsrcfile_basic_wildcard(self):
  993. testrecipe = 'base-files'
  994. self._test_appendsrcfile(testrecipe, 'a-file', options='-w')
  995. recipefile = get_bb_var('FILE', testrecipe)
  996. bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir)
  997. self.assertEqual(os.path.basename(bbappendfile), '%s_%%.bbappend' % testrecipe)
  998. def test_recipetool_appendsrcfile_subdir_basic(self):
  999. self._test_appendsrcfile('base-files', 'a-file', 'tmp')
  1000. def test_recipetool_appendsrcfile_subdir_basic_dirdest(self):
  1001. self._test_appendsrcfile('base-files', destdir='tmp')
  1002. def test_recipetool_appendsrcfile_srcdir_basic(self):
  1003. testrecipe = 'bash'
  1004. bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe)
  1005. srcdir = bb_vars['S']
  1006. workdir = bb_vars['WORKDIR']
  1007. subdir = os.path.relpath(srcdir, workdir)
  1008. self._test_appendsrcfile(testrecipe, 'a-file', srcdir=subdir)
  1009. def test_recipetool_appendsrcfile_existing_in_src_uri(self):
  1010. testrecipe = 'base-files'
  1011. filepath,_ = self._get_first_file_uri(testrecipe)
  1012. self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe)
  1013. self._test_appendsrcfile(testrecipe, filepath, has_src_uri=False)
  1014. def test_recipetool_appendsrcfile_existing_in_src_uri_diff_params(self, machine=None):
  1015. testrecipe = 'base-files'
  1016. subdir = 'tmp'
  1017. filepath, srcuri_entry = self._get_first_file_uri(testrecipe)
  1018. self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe)
  1019. self._test_appendsrcfile(testrecipe, filepath, subdir, machine=machine, remove=[srcuri_entry])
  1020. def test_recipetool_appendsrcfile_machine(self):
  1021. # A very basic test
  1022. self._test_appendsrcfile('base-files', 'a-file', machine='mymachine')
  1023. # Force cleaning the output of previous test
  1024. self.tearDownLocal()
  1025. # A more complex test: existing entry in src_uri with different param
  1026. self.test_recipetool_appendsrcfile_existing_in_src_uri_diff_params(machine='mymachine')
  1027. def test_recipetool_appendsrcfile_update_recipe_basic(self):
  1028. testrecipe = "mtd-utils-selftest"
  1029. recipefile = get_bb_var('FILE', testrecipe)
  1030. self.assertIn('meta-selftest', recipefile, 'This test expect %s recipe to be in meta-selftest')
  1031. cmd = 'recipetool appendsrcfile -W -u meta-selftest %s %s' % (testrecipe, self.testfile)
  1032. result = runCmd(cmd)
  1033. self.assertNotIn('Traceback', result.output)
  1034. self.add_command_to_tearDown('cd %s; rm -f %s/%s; git checkout .' % (os.path.dirname(recipefile), testrecipe, os.path.basename(self.testfile)))
  1035. expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)),
  1036. ('??', '.*/%s/%s$' % (testrecipe, os.path.basename(self.testfile)))]
  1037. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  1038. result = runCmd('git diff %s' % os.path.basename(recipefile), cwd=os.path.dirname(recipefile))
  1039. removelines = []
  1040. addlines = [
  1041. 'file://%s \\\\' % os.path.basename(self.testfile),
  1042. ]
  1043. self._check_diff(result.output, addlines, removelines)
  1044. def test_recipetool_appendsrcfile_replace_file_srcdir(self):
  1045. testrecipe = 'bash'
  1046. filepath = 'Makefile.in'
  1047. bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe)
  1048. srcdir = bb_vars['S']
  1049. workdir = bb_vars['WORKDIR']
  1050. subdir = os.path.relpath(srcdir, workdir)
  1051. self._test_appendsrcfile(testrecipe, filepath, srcdir=subdir)
  1052. bitbake('%s:do_unpack' % testrecipe)
  1053. with open(self.testfile, 'r') as testfile:
  1054. with open(os.path.join(srcdir, filepath), 'r') as makefilein:
  1055. self.assertEqual(testfile.read(), makefilein.read())
  1056. def test_recipetool_appendsrcfiles_basic(self, destdir=None):
  1057. newfiles = [self.testfile]
  1058. for i in range(1, 5):
  1059. testfile = os.path.join(self.tempdir, 'testfile%d' % i)
  1060. with open(testfile, 'w') as f:
  1061. f.write('Test file %d\n' % i)
  1062. newfiles.append(testfile)
  1063. self._test_appendsrcfiles('gcc', newfiles, destdir=destdir, options='-W')
  1064. def test_recipetool_appendsrcfiles_basic_subdir(self):
  1065. self.test_recipetool_appendsrcfiles_basic(destdir='testdir')