devtool.py 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523
  1. import unittest
  2. import os
  3. import logging
  4. import re
  5. import shutil
  6. import tempfile
  7. import glob
  8. import fnmatch
  9. import oeqa.utils.ftools as ftools
  10. from oeqa.selftest.base import oeSelfTest
  11. from oeqa.utils.commands import runCmd, bitbake, get_bb_var, create_temp_layer, runqemu, get_test_layer
  12. from oeqa.utils.decorators import testcase
  13. class DevtoolBase(oeSelfTest):
  14. def _test_recipe_contents(self, recipefile, checkvars, checkinherits):
  15. with open(recipefile, 'r') as f:
  16. invar = None
  17. invalue = None
  18. for line in f:
  19. var = None
  20. if invar:
  21. value = line.strip().strip('"')
  22. if value.endswith('\\'):
  23. invalue += ' ' + value[:-1].strip()
  24. continue
  25. else:
  26. invalue += ' ' + value.strip()
  27. var = invar
  28. value = invalue
  29. invar = None
  30. elif '=' in line:
  31. splitline = line.split('=', 1)
  32. var = splitline[0].rstrip()
  33. value = splitline[1].strip().strip('"')
  34. if value.endswith('\\'):
  35. invalue = value[:-1].strip()
  36. invar = var
  37. continue
  38. elif line.startswith('inherit '):
  39. inherits = line.split()[1:]
  40. if var and var in checkvars:
  41. needvalue = checkvars.pop(var)
  42. if needvalue is None:
  43. self.fail('Variable %s should not appear in recipe, but value is being set to "%s"' % (var, value))
  44. if isinstance(needvalue, set):
  45. if var == 'LICENSE':
  46. value = set(value.split(' & '))
  47. else:
  48. value = set(value.split())
  49. self.assertEqual(value, needvalue, 'values for %s do not match' % var)
  50. missingvars = {}
  51. for var, value in checkvars.items():
  52. if value is not None:
  53. missingvars[var] = value
  54. self.assertEqual(missingvars, {}, 'Some expected variables not found in recipe: %s' % checkvars)
  55. for inherit in checkinherits:
  56. self.assertIn(inherit, inherits, 'Missing inherit of %s' % inherit)
  57. def _check_bbappend(self, testrecipe, recipefile, appenddir):
  58. result = runCmd('bitbake-layers show-appends', cwd=self.builddir)
  59. resultlines = result.output.splitlines()
  60. inrecipe = False
  61. bbappends = []
  62. bbappendfile = None
  63. for line in resultlines:
  64. if inrecipe:
  65. if line.startswith(' '):
  66. bbappends.append(line.strip())
  67. else:
  68. break
  69. elif line == '%s:' % os.path.basename(recipefile):
  70. inrecipe = True
  71. self.assertLessEqual(len(bbappends), 2, '%s recipe is being bbappended by another layer - bbappends found:\n %s' % (testrecipe, '\n '.join(bbappends)))
  72. for bbappend in bbappends:
  73. if bbappend.startswith(appenddir):
  74. bbappendfile = bbappend
  75. break
  76. else:
  77. self.fail('bbappend for recipe %s does not seem to be created in test layer' % testrecipe)
  78. return bbappendfile
  79. def _create_temp_layer(self, templayerdir, addlayer, templayername, priority=999, recipepathspec='recipes-*/*'):
  80. create_temp_layer(templayerdir, templayername, priority, recipepathspec)
  81. if addlayer:
  82. self.add_command_to_tearDown('bitbake-layers remove-layer %s || true' % templayerdir)
  83. result = runCmd('bitbake-layers add-layer %s' % templayerdir, cwd=self.builddir)
  84. def _process_ls_output(self, output):
  85. """
  86. Convert ls -l output to a format we can reasonably compare from one context
  87. to another (e.g. from host to target)
  88. """
  89. filelist = []
  90. for line in output.splitlines():
  91. splitline = line.split()
  92. if len(splitline) < 8:
  93. self.fail('_process_ls_output: invalid output line: %s' % line)
  94. # Remove trailing . on perms
  95. splitline[0] = splitline[0].rstrip('.')
  96. # Remove leading . on paths
  97. splitline[-1] = splitline[-1].lstrip('.')
  98. # Drop fields we don't want to compare
  99. del splitline[7]
  100. del splitline[6]
  101. del splitline[5]
  102. del splitline[4]
  103. del splitline[1]
  104. filelist.append(' '.join(splitline))
  105. return filelist
  106. class DevtoolTests(DevtoolBase):
  107. def setUp(self):
  108. """Test case setup function"""
  109. super(DevtoolTests, self).setUp()
  110. self.workspacedir = os.path.join(self.builddir, 'workspace')
  111. self.assertTrue(not os.path.exists(self.workspacedir),
  112. 'This test cannot be run with a workspace directory '
  113. 'under the build directory')
  114. def _check_src_repo(self, repo_dir):
  115. """Check srctree git repository"""
  116. self.assertTrue(os.path.isdir(os.path.join(repo_dir, '.git')),
  117. 'git repository for external source tree not found')
  118. result = runCmd('git status --porcelain', cwd=repo_dir)
  119. self.assertEqual(result.output.strip(), "",
  120. 'Created git repo is not clean')
  121. result = runCmd('git symbolic-ref HEAD', cwd=repo_dir)
  122. self.assertEqual(result.output.strip(), "refs/heads/devtool",
  123. 'Wrong branch in git repo')
  124. def _check_repo_status(self, repo_dir, expected_status):
  125. """Check the worktree status of a repository"""
  126. result = runCmd('git status . --porcelain',
  127. cwd=repo_dir)
  128. for line in result.output.splitlines():
  129. for ind, (f_status, fn_re) in enumerate(expected_status):
  130. if re.match(fn_re, line[3:]):
  131. if f_status != line[:2]:
  132. self.fail('Unexpected status in line: %s' % line)
  133. expected_status.pop(ind)
  134. break
  135. else:
  136. self.fail('Unexpected modified file in line: %s' % line)
  137. if expected_status:
  138. self.fail('Missing file changes: %s' % expected_status)
  139. @testcase(1158)
  140. def test_create_workspace(self):
  141. # Check preconditions
  142. result = runCmd('bitbake-layers show-layers')
  143. self.assertTrue('/workspace' not in result.output, 'This test cannot be run with a workspace layer in bblayers.conf')
  144. # Try creating a workspace layer with a specific path
  145. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  146. self.track_for_cleanup(tempdir)
  147. result = runCmd('devtool create-workspace %s' % tempdir)
  148. self.assertTrue(os.path.isfile(os.path.join(tempdir, 'conf', 'layer.conf')), msg = "No workspace created. devtool output: %s " % result.output)
  149. result = runCmd('bitbake-layers show-layers')
  150. self.assertIn(tempdir, result.output)
  151. # Try creating a workspace layer with the default path
  152. self.track_for_cleanup(self.workspacedir)
  153. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  154. result = runCmd('devtool create-workspace')
  155. self.assertTrue(os.path.isfile(os.path.join(self.workspacedir, 'conf', 'layer.conf')), msg = "No workspace created. devtool output: %s " % result.output)
  156. result = runCmd('bitbake-layers show-layers')
  157. self.assertNotIn(tempdir, result.output)
  158. self.assertIn(self.workspacedir, result.output)
  159. @testcase(1159)
  160. def test_devtool_add(self):
  161. # Fetch source
  162. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  163. self.track_for_cleanup(tempdir)
  164. url = 'http://www.ivarch.com/programs/sources/pv-1.5.3.tar.bz2'
  165. result = runCmd('wget %s' % url, cwd=tempdir)
  166. result = runCmd('tar xfv pv-1.5.3.tar.bz2', cwd=tempdir)
  167. srcdir = os.path.join(tempdir, 'pv-1.5.3')
  168. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'configure')), 'Unable to find configure script in source directory')
  169. # Test devtool add
  170. self.track_for_cleanup(self.workspacedir)
  171. self.add_command_to_tearDown('bitbake -c cleansstate pv')
  172. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  173. result = runCmd('devtool add pv %s' % srcdir)
  174. self.assertTrue(os.path.exists(os.path.join(self.workspacedir, 'conf', 'layer.conf')), 'Workspace directory not created')
  175. # Test devtool status
  176. result = runCmd('devtool status')
  177. self.assertIn('pv', result.output)
  178. self.assertIn(srcdir, result.output)
  179. # Clean up anything in the workdir/sysroot/sstate cache (have to do this *after* devtool add since the recipe only exists then)
  180. bitbake('pv -c cleansstate')
  181. # Test devtool build
  182. result = runCmd('devtool build pv')
  183. installdir = get_bb_var('D', 'pv')
  184. self.assertTrue(installdir, 'Could not query installdir variable')
  185. bindir = get_bb_var('bindir', 'pv')
  186. self.assertTrue(bindir, 'Could not query bindir variable')
  187. if bindir[0] == '/':
  188. bindir = bindir[1:]
  189. self.assertTrue(os.path.isfile(os.path.join(installdir, bindir, 'pv')), 'pv binary not found in D')
  190. @testcase(1423)
  191. def test_devtool_add_git_local(self):
  192. # Fetch source from a remote URL, but do it outside of devtool
  193. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  194. self.track_for_cleanup(tempdir)
  195. pn = 'dbus-wait'
  196. srcrev = '6cc6077a36fe2648a5f993fe7c16c9632f946517'
  197. # We choose an https:// git URL here to check rewriting the URL works
  198. url = 'https://git.yoctoproject.org/git/dbus-wait'
  199. # Force fetching to "noname" subdir so we verify we're picking up the name from autoconf
  200. # instead of the directory name
  201. result = runCmd('git clone %s noname' % url, cwd=tempdir)
  202. srcdir = os.path.join(tempdir, 'noname')
  203. result = runCmd('git reset --hard %s' % srcrev, cwd=srcdir)
  204. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'configure.ac')), 'Unable to find configure script in source directory')
  205. # Test devtool add
  206. self.track_for_cleanup(self.workspacedir)
  207. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  208. # Don't specify a name since we should be able to auto-detect it
  209. result = runCmd('devtool add %s' % srcdir)
  210. self.assertTrue(os.path.exists(os.path.join(self.workspacedir, 'conf', 'layer.conf')), 'Workspace directory not created')
  211. # Check the recipe name is correct
  212. recipefile = get_bb_var('FILE', pn)
  213. self.assertIn('%s_git.bb' % pn, recipefile, 'Recipe file incorrectly named')
  214. self.assertIn(recipefile, result.output)
  215. # Test devtool status
  216. result = runCmd('devtool status')
  217. self.assertIn(pn, result.output)
  218. self.assertIn(srcdir, result.output)
  219. self.assertIn(recipefile, result.output)
  220. checkvars = {}
  221. checkvars['LICENSE'] = 'GPLv2'
  222. checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263'
  223. checkvars['S'] = '${WORKDIR}/git'
  224. checkvars['PV'] = '0.1+git${SRCPV}'
  225. checkvars['SRC_URI'] = 'git://git.yoctoproject.org/git/dbus-wait;protocol=https'
  226. checkvars['SRCREV'] = srcrev
  227. checkvars['DEPENDS'] = set(['dbus'])
  228. self._test_recipe_contents(recipefile, checkvars, [])
  229. @testcase(1162)
  230. def test_devtool_add_library(self):
  231. # We don't have the ability to pick up this dependency automatically yet...
  232. bitbake('libusb1')
  233. # Fetch source
  234. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  235. self.track_for_cleanup(tempdir)
  236. version = '1.1'
  237. url = 'https://www.intra2net.com/en/developer/libftdi/download/libftdi1-%s.tar.bz2' % version
  238. result = runCmd('wget %s' % url, cwd=tempdir)
  239. result = runCmd('tar xfv libftdi1-%s.tar.bz2' % version, cwd=tempdir)
  240. srcdir = os.path.join(tempdir, 'libftdi1-%s' % version)
  241. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'CMakeLists.txt')), 'Unable to find CMakeLists.txt in source directory')
  242. # Test devtool add (and use -V so we test that too)
  243. self.track_for_cleanup(self.workspacedir)
  244. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  245. result = runCmd('devtool add libftdi %s -V %s' % (srcdir, version))
  246. self.assertTrue(os.path.exists(os.path.join(self.workspacedir, 'conf', 'layer.conf')), 'Workspace directory not created')
  247. # Test devtool status
  248. result = runCmd('devtool status')
  249. self.assertIn('libftdi', result.output)
  250. self.assertIn(srcdir, result.output)
  251. # Clean up anything in the workdir/sysroot/sstate cache (have to do this *after* devtool add since the recipe only exists then)
  252. bitbake('libftdi -c cleansstate')
  253. # libftdi's python/CMakeLists.txt is a bit broken, so let's just disable it
  254. # There's also the matter of it installing cmake files to a path we don't
  255. # normally cover, which triggers the installed-vs-shipped QA test we have
  256. # within do_package
  257. recipefile = '%s/recipes/libftdi/libftdi_%s.bb' % (self.workspacedir, version)
  258. result = runCmd('recipetool setvar %s EXTRA_OECMAKE -- \'-DPYTHON_BINDINGS=OFF -DLIBFTDI_CMAKE_CONFIG_DIR=${datadir}/cmake/Modules\'' % recipefile)
  259. with open(recipefile, 'a') as f:
  260. f.write('\nFILES_${PN}-dev += "${datadir}/cmake/Modules"\n')
  261. # Test devtool build
  262. result = runCmd('devtool build libftdi')
  263. staging_libdir = get_bb_var('STAGING_LIBDIR', 'libftdi')
  264. self.assertTrue(staging_libdir, 'Could not query STAGING_LIBDIR variable')
  265. self.assertTrue(os.path.isfile(os.path.join(staging_libdir, 'libftdi1.so.2.1.0')), "libftdi binary not found in STAGING_LIBDIR. Output of devtool build libftdi %s" % result.output)
  266. # Test devtool reset
  267. stampprefix = get_bb_var('STAMP', 'libftdi')
  268. result = runCmd('devtool reset libftdi')
  269. result = runCmd('devtool status')
  270. self.assertNotIn('libftdi', result.output)
  271. self.assertTrue(stampprefix, 'Unable to get STAMP value for recipe libftdi')
  272. matches = glob.glob(stampprefix + '*')
  273. self.assertFalse(matches, 'Stamp files exist for recipe libftdi that should have been cleaned')
  274. self.assertFalse(os.path.isfile(os.path.join(staging_libdir, 'libftdi1.so.2.1.0')), 'libftdi binary still found in STAGING_LIBDIR after cleaning')
  275. @testcase(1160)
  276. def test_devtool_add_fetch(self):
  277. # Fetch source
  278. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  279. self.track_for_cleanup(tempdir)
  280. testver = '0.23'
  281. url = 'https://pypi.python.org/packages/source/M/MarkupSafe/MarkupSafe-%s.tar.gz' % testver
  282. testrecipe = 'python-markupsafe'
  283. srcdir = os.path.join(tempdir, testrecipe)
  284. # Test devtool add
  285. self.track_for_cleanup(self.workspacedir)
  286. self.add_command_to_tearDown('bitbake -c cleansstate %s' % testrecipe)
  287. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  288. result = runCmd('devtool add %s %s -f %s' % (testrecipe, srcdir, url))
  289. self.assertTrue(os.path.exists(os.path.join(self.workspacedir, 'conf', 'layer.conf')), 'Workspace directory not created. %s' % result.output)
  290. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'setup.py')), 'Unable to find setup.py in source directory')
  291. self.assertTrue(os.path.isdir(os.path.join(srcdir, '.git')), 'git repository for external source tree was not created')
  292. # Test devtool status
  293. result = runCmd('devtool status')
  294. self.assertIn(testrecipe, result.output)
  295. self.assertIn(srcdir, result.output)
  296. # Check recipe
  297. recipefile = get_bb_var('FILE', testrecipe)
  298. self.assertIn('%s_%s.bb' % (testrecipe, testver), recipefile, 'Recipe file incorrectly named')
  299. checkvars = {}
  300. checkvars['S'] = '${WORKDIR}/MarkupSafe-${PV}'
  301. checkvars['SRC_URI'] = url.replace(testver, '${PV}')
  302. self._test_recipe_contents(recipefile, checkvars, [])
  303. # Try with version specified
  304. result = runCmd('devtool reset -n %s' % testrecipe)
  305. shutil.rmtree(srcdir)
  306. fakever = '1.9'
  307. result = runCmd('devtool add %s %s -f %s -V %s' % (testrecipe, srcdir, url, fakever))
  308. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'setup.py')), 'Unable to find setup.py in source directory')
  309. # Test devtool status
  310. result = runCmd('devtool status')
  311. self.assertIn(testrecipe, result.output)
  312. self.assertIn(srcdir, result.output)
  313. # Check recipe
  314. recipefile = get_bb_var('FILE', testrecipe)
  315. self.assertIn('%s_%s.bb' % (testrecipe, fakever), recipefile, 'Recipe file incorrectly named')
  316. checkvars = {}
  317. checkvars['S'] = '${WORKDIR}/MarkupSafe-%s' % testver
  318. checkvars['SRC_URI'] = url
  319. self._test_recipe_contents(recipefile, checkvars, [])
  320. @testcase(1161)
  321. def test_devtool_add_fetch_git(self):
  322. # Fetch source
  323. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  324. self.track_for_cleanup(tempdir)
  325. url = 'git://git.yoctoproject.org/libmatchbox'
  326. checkrev = '462f0652055d89c648ddd54fd7b03f175c2c6973'
  327. testrecipe = 'libmatchbox2'
  328. srcdir = os.path.join(tempdir, testrecipe)
  329. # Test devtool add
  330. self.track_for_cleanup(self.workspacedir)
  331. self.add_command_to_tearDown('bitbake -c cleansstate %s' % testrecipe)
  332. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  333. result = runCmd('devtool add %s %s -a -f %s' % (testrecipe, srcdir, url))
  334. self.assertTrue(os.path.exists(os.path.join(self.workspacedir, 'conf', 'layer.conf')), 'Workspace directory not created: %s' % result.output)
  335. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'configure.ac')), 'Unable to find configure.ac in source directory')
  336. # Test devtool status
  337. result = runCmd('devtool status')
  338. self.assertIn(testrecipe, result.output)
  339. self.assertIn(srcdir, result.output)
  340. # Check recipe
  341. recipefile = get_bb_var('FILE', testrecipe)
  342. self.assertIn('_git.bb', recipefile, 'Recipe file incorrectly named')
  343. checkvars = {}
  344. checkvars['S'] = '${WORKDIR}/git'
  345. checkvars['PV'] = '1.12+git${SRCPV}'
  346. checkvars['SRC_URI'] = url
  347. checkvars['SRCREV'] = '${AUTOREV}'
  348. self._test_recipe_contents(recipefile, checkvars, [])
  349. # Try with revision and version specified
  350. result = runCmd('devtool reset -n %s' % testrecipe)
  351. shutil.rmtree(srcdir)
  352. url_rev = '%s;rev=%s' % (url, checkrev)
  353. result = runCmd('devtool add %s %s -f "%s" -V 1.5' % (testrecipe, srcdir, url_rev))
  354. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'configure.ac')), 'Unable to find configure.ac in source directory')
  355. # Test devtool status
  356. result = runCmd('devtool status')
  357. self.assertIn(testrecipe, result.output)
  358. self.assertIn(srcdir, result.output)
  359. # Check recipe
  360. recipefile = get_bb_var('FILE', testrecipe)
  361. self.assertIn('_git.bb', recipefile, 'Recipe file incorrectly named')
  362. checkvars = {}
  363. checkvars['S'] = '${WORKDIR}/git'
  364. checkvars['PV'] = '1.5+git${SRCPV}'
  365. checkvars['SRC_URI'] = url
  366. checkvars['SRCREV'] = checkrev
  367. self._test_recipe_contents(recipefile, checkvars, [])
  368. @testcase(1391)
  369. def test_devtool_add_fetch_simple(self):
  370. # Fetch source from a remote URL, auto-detecting name
  371. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  372. self.track_for_cleanup(tempdir)
  373. testver = '1.6.0'
  374. url = 'http://www.ivarch.com/programs/sources/pv-%s.tar.bz2' % testver
  375. testrecipe = 'pv'
  376. srcdir = os.path.join(self.workspacedir, 'sources', testrecipe)
  377. # Test devtool add
  378. self.track_for_cleanup(self.workspacedir)
  379. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  380. result = runCmd('devtool add %s' % url)
  381. self.assertTrue(os.path.exists(os.path.join(self.workspacedir, 'conf', 'layer.conf')), 'Workspace directory not created. %s' % result.output)
  382. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'configure')), 'Unable to find configure script in source directory')
  383. self.assertTrue(os.path.isdir(os.path.join(srcdir, '.git')), 'git repository for external source tree was not created')
  384. # Test devtool status
  385. result = runCmd('devtool status')
  386. self.assertIn(testrecipe, result.output)
  387. self.assertIn(srcdir, result.output)
  388. # Check recipe
  389. recipefile = get_bb_var('FILE', testrecipe)
  390. self.assertIn('%s_%s.bb' % (testrecipe, testver), recipefile, 'Recipe file incorrectly named')
  391. checkvars = {}
  392. checkvars['S'] = None
  393. checkvars['SRC_URI'] = url.replace(testver, '${PV}')
  394. self._test_recipe_contents(recipefile, checkvars, [])
  395. @testcase(1164)
  396. def test_devtool_modify(self):
  397. # Clean up anything in the workdir/sysroot/sstate cache
  398. bitbake('mdadm -c cleansstate')
  399. # Try modifying a recipe
  400. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  401. self.track_for_cleanup(tempdir)
  402. self.track_for_cleanup(self.workspacedir)
  403. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  404. self.add_command_to_tearDown('bitbake -c clean mdadm')
  405. result = runCmd('devtool modify mdadm -x %s' % tempdir)
  406. self.assertTrue(os.path.exists(os.path.join(tempdir, 'Makefile')), 'Extracted source could not be found')
  407. self.assertTrue(os.path.exists(os.path.join(self.workspacedir, 'conf', 'layer.conf')), 'Workspace directory not created')
  408. matches = glob.glob(os.path.join(self.workspacedir, 'appends', 'mdadm_*.bbappend'))
  409. self.assertTrue(matches, 'bbappend not created %s' % result.output)
  410. # Test devtool status
  411. result = runCmd('devtool status')
  412. self.assertIn('mdadm', result.output)
  413. self.assertIn(tempdir, result.output)
  414. # Check git repo
  415. self._check_src_repo(tempdir)
  416. # Try building
  417. bitbake('mdadm')
  418. # Try making (minor) modifications to the source
  419. result = runCmd("sed -i 's!^\.TH.*!.TH MDADM 8 \"\" v9.999-custom!' %s" % os.path.join(tempdir, 'mdadm.8.in'))
  420. bitbake('mdadm -c package')
  421. pkgd = get_bb_var('PKGD', 'mdadm')
  422. self.assertTrue(pkgd, 'Could not query PKGD variable')
  423. mandir = get_bb_var('mandir', 'mdadm')
  424. self.assertTrue(mandir, 'Could not query mandir variable')
  425. if mandir[0] == '/':
  426. mandir = mandir[1:]
  427. with open(os.path.join(pkgd, mandir, 'man8', 'mdadm.8'), 'r') as f:
  428. for line in f:
  429. if line.startswith('.TH'):
  430. self.assertEqual(line.rstrip(), '.TH MDADM 8 "" v9.999-custom', 'man file not modified. man searched file path: %s' % os.path.join(pkgd, mandir, 'man8', 'mdadm.8'))
  431. # Test devtool reset
  432. stampprefix = get_bb_var('STAMP', 'mdadm')
  433. result = runCmd('devtool reset mdadm')
  434. result = runCmd('devtool status')
  435. self.assertNotIn('mdadm', result.output)
  436. self.assertTrue(stampprefix, 'Unable to get STAMP value for recipe mdadm')
  437. matches = glob.glob(stampprefix + '*')
  438. self.assertFalse(matches, 'Stamp files exist for recipe mdadm that should have been cleaned')
  439. @testcase(1166)
  440. def test_devtool_modify_invalid(self):
  441. # Try modifying some recipes
  442. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  443. self.track_for_cleanup(tempdir)
  444. self.track_for_cleanup(self.workspacedir)
  445. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  446. testrecipes = 'perf kernel-devsrc package-index core-image-minimal meta-toolchain packagegroup-core-sdk meta-ide-support'.split()
  447. # Find actual name of gcc-source since it now includes the version - crude, but good enough for this purpose
  448. result = runCmd('bitbake-layers show-recipes gcc-source*')
  449. for line in result.output.splitlines():
  450. # just match those lines that contain a real target
  451. m = re.match('(?P<recipe>^[a-zA-Z0-9.-]+)(?P<colon>:$)', line)
  452. if m:
  453. testrecipes.append(m.group('recipe'))
  454. for testrecipe in testrecipes:
  455. # Check it's a valid recipe
  456. bitbake('%s -e' % testrecipe)
  457. # devtool extract should fail
  458. result = runCmd('devtool extract %s %s' % (testrecipe, os.path.join(tempdir, testrecipe)), ignore_status=True)
  459. self.assertNotEqual(result.status, 0, 'devtool extract on %s should have failed. devtool output: %s' % (testrecipe, result.output))
  460. self.assertNotIn('Fetching ', result.output, 'devtool extract on %s should have errored out before trying to fetch' % testrecipe)
  461. self.assertIn('ERROR: ', result.output, 'devtool extract on %s should have given an ERROR' % testrecipe)
  462. # devtool modify should fail
  463. result = runCmd('devtool modify %s -x %s' % (testrecipe, os.path.join(tempdir, testrecipe)), ignore_status=True)
  464. self.assertNotEqual(result.status, 0, 'devtool modify on %s should have failed. devtool output: %s' % (testrecipe, result.output))
  465. self.assertIn('ERROR: ', result.output, 'devtool modify on %s should have given an ERROR' % testrecipe)
  466. @testcase(1365)
  467. def test_devtool_modify_native(self):
  468. # Check preconditions
  469. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  470. # Try modifying some recipes
  471. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  472. self.track_for_cleanup(tempdir)
  473. self.track_for_cleanup(self.workspacedir)
  474. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  475. bbclassextended = False
  476. inheritnative = False
  477. testrecipes = 'mtools-native apt-native desktop-file-utils-native'.split()
  478. for testrecipe in testrecipes:
  479. checkextend = 'native' in (get_bb_var('BBCLASSEXTEND', testrecipe) or '').split()
  480. if not bbclassextended:
  481. bbclassextended = checkextend
  482. if not inheritnative:
  483. inheritnative = not checkextend
  484. result = runCmd('devtool modify %s -x %s' % (testrecipe, os.path.join(tempdir, testrecipe)))
  485. self.assertNotIn('ERROR: ', result.output, 'ERROR in devtool modify output: %s' % result.output)
  486. result = runCmd('devtool build %s' % testrecipe)
  487. self.assertNotIn('ERROR: ', result.output, 'ERROR in devtool build output: %s' % result.output)
  488. result = runCmd('devtool reset %s' % testrecipe)
  489. self.assertNotIn('ERROR: ', result.output, 'ERROR in devtool reset output: %s' % result.output)
  490. self.assertTrue(bbclassextended, 'None of these recipes are BBCLASSEXTENDed to native - need to adjust testrecipes list: %s' % ', '.join(testrecipes))
  491. self.assertTrue(inheritnative, 'None of these recipes do "inherit native" - need to adjust testrecipes list: %s' % ', '.join(testrecipes))
  492. @testcase(1165)
  493. def test_devtool_modify_git(self):
  494. # Check preconditions
  495. testrecipe = 'mkelfimage'
  496. src_uri = get_bb_var('SRC_URI', testrecipe)
  497. self.assertIn('git://', src_uri, 'This test expects the %s recipe to be a git recipe' % testrecipe)
  498. # Clean up anything in the workdir/sysroot/sstate cache
  499. bitbake('%s -c cleansstate' % testrecipe)
  500. # Try modifying a recipe
  501. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  502. self.track_for_cleanup(tempdir)
  503. self.track_for_cleanup(self.workspacedir)
  504. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  505. self.add_command_to_tearDown('bitbake -c clean %s' % testrecipe)
  506. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  507. self.assertTrue(os.path.exists(os.path.join(tempdir, 'Makefile')), 'Extracted source could not be found')
  508. self.assertTrue(os.path.exists(os.path.join(self.workspacedir, 'conf', 'layer.conf')), 'Workspace directory not created. devtool output: %s' % result.output)
  509. matches = glob.glob(os.path.join(self.workspacedir, 'appends', 'mkelfimage_*.bbappend'))
  510. self.assertTrue(matches, 'bbappend not created')
  511. # Test devtool status
  512. result = runCmd('devtool status')
  513. self.assertIn(testrecipe, result.output)
  514. self.assertIn(tempdir, result.output)
  515. # Check git repo
  516. self._check_src_repo(tempdir)
  517. # Try building
  518. bitbake(testrecipe)
  519. @testcase(1167)
  520. def test_devtool_modify_localfiles(self):
  521. # Check preconditions
  522. testrecipe = 'lighttpd'
  523. src_uri = (get_bb_var('SRC_URI', testrecipe) or '').split()
  524. foundlocal = False
  525. for item in src_uri:
  526. if item.startswith('file://') and '.patch' not in item:
  527. foundlocal = True
  528. break
  529. self.assertTrue(foundlocal, 'This test expects the %s recipe to fetch local files and it seems that it no longer does' % testrecipe)
  530. # Clean up anything in the workdir/sysroot/sstate cache
  531. bitbake('%s -c cleansstate' % testrecipe)
  532. # Try modifying a recipe
  533. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  534. self.track_for_cleanup(tempdir)
  535. self.track_for_cleanup(self.workspacedir)
  536. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  537. self.add_command_to_tearDown('bitbake -c clean %s' % testrecipe)
  538. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  539. self.assertTrue(os.path.exists(os.path.join(tempdir, 'configure.ac')), 'Extracted source could not be found')
  540. self.assertTrue(os.path.exists(os.path.join(self.workspacedir, 'conf', 'layer.conf')), 'Workspace directory not created')
  541. matches = glob.glob(os.path.join(self.workspacedir, 'appends', '%s_*.bbappend' % testrecipe))
  542. self.assertTrue(matches, 'bbappend not created')
  543. # Test devtool status
  544. result = runCmd('devtool status')
  545. self.assertIn(testrecipe, result.output)
  546. self.assertIn(tempdir, result.output)
  547. # Try building
  548. bitbake(testrecipe)
  549. @testcase(1378)
  550. def test_devtool_modify_virtual(self):
  551. # Try modifying a virtual recipe
  552. virtrecipe = 'virtual/libx11'
  553. realrecipe = 'libx11'
  554. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  555. self.track_for_cleanup(tempdir)
  556. self.track_for_cleanup(self.workspacedir)
  557. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  558. result = runCmd('devtool modify %s -x %s' % (virtrecipe, tempdir))
  559. self.assertTrue(os.path.exists(os.path.join(tempdir, 'Makefile.am')), 'Extracted source could not be found')
  560. self.assertTrue(os.path.exists(os.path.join(self.workspacedir, 'conf', 'layer.conf')), 'Workspace directory not created')
  561. matches = glob.glob(os.path.join(self.workspacedir, 'appends', '%s_*.bbappend' % realrecipe))
  562. self.assertTrue(matches, 'bbappend not created %s' % result.output)
  563. # Test devtool status
  564. result = runCmd('devtool status')
  565. self.assertNotIn(virtrecipe, result.output)
  566. self.assertIn(realrecipe, result.output)
  567. # Check git repo
  568. self._check_src_repo(tempdir)
  569. # This is probably sufficient
  570. @testcase(1169)
  571. def test_devtool_update_recipe(self):
  572. # Check preconditions
  573. testrecipe = 'minicom'
  574. recipefile = get_bb_var('FILE', testrecipe)
  575. src_uri = get_bb_var('SRC_URI', testrecipe)
  576. self.assertNotIn('git://', src_uri, 'This test expects the %s recipe to NOT be a git recipe' % testrecipe)
  577. self._check_repo_status(os.path.dirname(recipefile), [])
  578. # First, modify a recipe
  579. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  580. self.track_for_cleanup(tempdir)
  581. self.track_for_cleanup(self.workspacedir)
  582. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  583. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  584. # We don't use -x here so that we test the behaviour of devtool modify without it
  585. result = runCmd('devtool modify %s %s' % (testrecipe, tempdir))
  586. # Check git repo
  587. self._check_src_repo(tempdir)
  588. # Add a couple of commits
  589. # FIXME: this only tests adding, need to also test update and remove
  590. result = runCmd('echo "Additional line" >> README', cwd=tempdir)
  591. result = runCmd('git commit -a -m "Change the README"', cwd=tempdir)
  592. result = runCmd('echo "A new file" > devtool-new-file', cwd=tempdir)
  593. result = runCmd('git add devtool-new-file', cwd=tempdir)
  594. result = runCmd('git commit -m "Add a new file"', cwd=tempdir)
  595. self.add_command_to_tearDown('cd %s; rm %s/*.patch; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
  596. result = runCmd('devtool update-recipe %s' % testrecipe)
  597. expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)),
  598. ('??', '.*/0001-Change-the-README.patch$'),
  599. ('??', '.*/0002-Add-a-new-file.patch$')]
  600. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  601. @testcase(1172)
  602. def test_devtool_update_recipe_git(self):
  603. # Check preconditions
  604. testrecipe = 'mtd-utils'
  605. recipefile = get_bb_var('FILE', testrecipe)
  606. src_uri = get_bb_var('SRC_URI', testrecipe)
  607. self.assertIn('git://', src_uri, 'This test expects the %s recipe to be a git recipe' % testrecipe)
  608. patches = []
  609. for entry in src_uri.split():
  610. if entry.startswith('file://') and entry.endswith('.patch'):
  611. patches.append(entry[7:].split(';')[0])
  612. self.assertGreater(len(patches), 0, 'The %s recipe does not appear to contain any patches, so this test will not be effective' % testrecipe)
  613. self._check_repo_status(os.path.dirname(recipefile), [])
  614. # First, modify a recipe
  615. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  616. self.track_for_cleanup(tempdir)
  617. self.track_for_cleanup(self.workspacedir)
  618. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  619. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  620. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  621. # Check git repo
  622. self._check_src_repo(tempdir)
  623. # Add a couple of commits
  624. # FIXME: this only tests adding, need to also test update and remove
  625. result = runCmd('echo "# Additional line" >> Makefile', cwd=tempdir)
  626. result = runCmd('git commit -a -m "Change the Makefile"', cwd=tempdir)
  627. result = runCmd('echo "A new file" > devtool-new-file', cwd=tempdir)
  628. result = runCmd('git add devtool-new-file', cwd=tempdir)
  629. result = runCmd('git commit -m "Add a new file"', cwd=tempdir)
  630. self.add_command_to_tearDown('cd %s; rm -rf %s; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
  631. result = runCmd('devtool update-recipe -m srcrev %s' % testrecipe)
  632. expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile))] + \
  633. [(' D', '.*/%s$' % patch) for patch in patches]
  634. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  635. result = runCmd('git diff %s' % os.path.basename(recipefile), cwd=os.path.dirname(recipefile))
  636. addlines = ['SRCREV = ".*"', 'SRC_URI = "git://git.infradead.org/mtd-utils.git"']
  637. srcurilines = src_uri.split()
  638. srcurilines[0] = 'SRC_URI = "' + srcurilines[0]
  639. srcurilines.append('"')
  640. removelines = ['SRCREV = ".*"'] + srcurilines
  641. for line in result.output.splitlines():
  642. if line.startswith('+++') or line.startswith('---'):
  643. continue
  644. elif line.startswith('+'):
  645. matched = False
  646. for item in addlines:
  647. if re.match(item, line[1:].strip()):
  648. matched = True
  649. break
  650. self.assertTrue(matched, 'Unexpected diff add line: %s' % line)
  651. elif line.startswith('-'):
  652. matched = False
  653. for item in removelines:
  654. if re.match(item, line[1:].strip()):
  655. matched = True
  656. break
  657. self.assertTrue(matched, 'Unexpected diff remove line: %s' % line)
  658. # Now try with auto mode
  659. runCmd('cd %s; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, os.path.basename(recipefile)))
  660. result = runCmd('devtool update-recipe %s' % testrecipe)
  661. result = runCmd('git rev-parse --show-toplevel', cwd=os.path.dirname(recipefile))
  662. topleveldir = result.output.strip()
  663. relpatchpath = os.path.join(os.path.relpath(os.path.dirname(recipefile), topleveldir), testrecipe)
  664. expected_status = [(' M', os.path.relpath(recipefile, topleveldir)),
  665. ('??', '%s/0001-Change-the-Makefile.patch' % relpatchpath),
  666. ('??', '%s/0002-Add-a-new-file.patch' % relpatchpath)]
  667. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  668. @testcase(1170)
  669. def test_devtool_update_recipe_append(self):
  670. # Check preconditions
  671. testrecipe = 'mdadm'
  672. recipefile = get_bb_var('FILE', testrecipe)
  673. src_uri = get_bb_var('SRC_URI', testrecipe)
  674. self.assertNotIn('git://', src_uri, 'This test expects the %s recipe to NOT be a git recipe' % testrecipe)
  675. self._check_repo_status(os.path.dirname(recipefile), [])
  676. # First, modify a recipe
  677. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  678. tempsrcdir = os.path.join(tempdir, 'source')
  679. templayerdir = os.path.join(tempdir, 'layer')
  680. self.track_for_cleanup(tempdir)
  681. self.track_for_cleanup(self.workspacedir)
  682. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  683. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  684. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempsrcdir))
  685. # Check git repo
  686. self._check_src_repo(tempsrcdir)
  687. # Add a commit
  688. result = runCmd("sed 's!\\(#define VERSION\\W*\"[^\"]*\\)\"!\\1-custom\"!' -i ReadMe.c", cwd=tempsrcdir)
  689. result = runCmd('git commit -a -m "Add our custom version"', cwd=tempsrcdir)
  690. self.add_command_to_tearDown('cd %s; rm -f %s/*.patch; git checkout .' % (os.path.dirname(recipefile), testrecipe))
  691. # Create a temporary layer and add it to bblayers.conf
  692. self._create_temp_layer(templayerdir, True, 'selftestupdaterecipe')
  693. # Create the bbappend
  694. result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir))
  695. self.assertNotIn('WARNING:', result.output)
  696. # Check recipe is still clean
  697. self._check_repo_status(os.path.dirname(recipefile), [])
  698. # Check bbappend was created
  699. splitpath = os.path.dirname(recipefile).split(os.sep)
  700. appenddir = os.path.join(templayerdir, splitpath[-2], splitpath[-1])
  701. bbappendfile = self._check_bbappend(testrecipe, recipefile, appenddir)
  702. patchfile = os.path.join(appenddir, testrecipe, '0001-Add-our-custom-version.patch')
  703. self.assertTrue(os.path.exists(patchfile), 'Patch file not created')
  704. # Check bbappend contents
  705. expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
  706. '\n',
  707. 'SRC_URI += "file://0001-Add-our-custom-version.patch"\n',
  708. '\n']
  709. with open(bbappendfile, 'r') as f:
  710. self.assertEqual(expectedlines, f.readlines())
  711. # Check we can run it again and bbappend isn't modified
  712. result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir))
  713. with open(bbappendfile, 'r') as f:
  714. self.assertEqual(expectedlines, f.readlines())
  715. # Drop new commit and check patch gets deleted
  716. result = runCmd('git reset HEAD^', cwd=tempsrcdir)
  717. result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir))
  718. self.assertFalse(os.path.exists(patchfile), 'Patch file not deleted')
  719. expectedlines2 = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
  720. '\n']
  721. with open(bbappendfile, 'r') as f:
  722. self.assertEqual(expectedlines2, f.readlines())
  723. # Put commit back and check we can run it if layer isn't in bblayers.conf
  724. os.remove(bbappendfile)
  725. result = runCmd('git commit -a -m "Add our custom version"', cwd=tempsrcdir)
  726. result = runCmd('bitbake-layers remove-layer %s' % templayerdir, cwd=self.builddir)
  727. result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir))
  728. self.assertIn('WARNING: Specified layer is not currently enabled in bblayers.conf', result.output)
  729. self.assertTrue(os.path.exists(patchfile), 'Patch file not created (with disabled layer)')
  730. with open(bbappendfile, 'r') as f:
  731. self.assertEqual(expectedlines, f.readlines())
  732. # Deleting isn't expected to work under these circumstances
  733. @testcase(1171)
  734. def test_devtool_update_recipe_append_git(self):
  735. # Check preconditions
  736. testrecipe = 'mtd-utils'
  737. recipefile = get_bb_var('FILE', testrecipe)
  738. src_uri = get_bb_var('SRC_URI', testrecipe)
  739. self.assertIn('git://', src_uri, 'This test expects the %s recipe to be a git recipe' % testrecipe)
  740. for entry in src_uri.split():
  741. if entry.startswith('git://'):
  742. git_uri = entry
  743. break
  744. self._check_repo_status(os.path.dirname(recipefile), [])
  745. # First, modify a recipe
  746. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  747. tempsrcdir = os.path.join(tempdir, 'source')
  748. templayerdir = os.path.join(tempdir, 'layer')
  749. self.track_for_cleanup(tempdir)
  750. self.track_for_cleanup(self.workspacedir)
  751. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  752. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  753. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempsrcdir))
  754. # Check git repo
  755. self._check_src_repo(tempsrcdir)
  756. # Add a commit
  757. result = runCmd('echo "# Additional line" >> Makefile', cwd=tempsrcdir)
  758. result = runCmd('git commit -a -m "Change the Makefile"', cwd=tempsrcdir)
  759. self.add_command_to_tearDown('cd %s; rm -f %s/*.patch; git checkout .' % (os.path.dirname(recipefile), testrecipe))
  760. # Create a temporary layer
  761. os.makedirs(os.path.join(templayerdir, 'conf'))
  762. with open(os.path.join(templayerdir, 'conf', 'layer.conf'), 'w') as f:
  763. f.write('BBPATH .= ":${LAYERDIR}"\n')
  764. f.write('BBFILES += "${LAYERDIR}/recipes-*/*/*.bbappend"\n')
  765. f.write('BBFILE_COLLECTIONS += "oeselftesttemplayer"\n')
  766. f.write('BBFILE_PATTERN_oeselftesttemplayer = "^${LAYERDIR}/"\n')
  767. f.write('BBFILE_PRIORITY_oeselftesttemplayer = "999"\n')
  768. f.write('BBFILE_PATTERN_IGNORE_EMPTY_oeselftesttemplayer = "1"\n')
  769. self.add_command_to_tearDown('bitbake-layers remove-layer %s || true' % templayerdir)
  770. result = runCmd('bitbake-layers add-layer %s' % templayerdir, cwd=self.builddir)
  771. # Create the bbappend
  772. result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir))
  773. self.assertNotIn('WARNING:', result.output)
  774. # Check recipe is still clean
  775. self._check_repo_status(os.path.dirname(recipefile), [])
  776. # Check bbappend was created
  777. splitpath = os.path.dirname(recipefile).split(os.sep)
  778. appenddir = os.path.join(templayerdir, splitpath[-2], splitpath[-1])
  779. bbappendfile = self._check_bbappend(testrecipe, recipefile, appenddir)
  780. self.assertFalse(os.path.exists(os.path.join(appenddir, testrecipe)), 'Patch directory should not be created')
  781. # Check bbappend contents
  782. result = runCmd('git rev-parse HEAD', cwd=tempsrcdir)
  783. expectedlines = set(['SRCREV = "%s"\n' % result.output,
  784. '\n',
  785. 'SRC_URI = "%s"\n' % git_uri,
  786. '\n'])
  787. with open(bbappendfile, 'r') as f:
  788. self.assertEqual(expectedlines, set(f.readlines()))
  789. # Check we can run it again and bbappend isn't modified
  790. result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir))
  791. with open(bbappendfile, 'r') as f:
  792. self.assertEqual(expectedlines, set(f.readlines()))
  793. # Drop new commit and check SRCREV changes
  794. result = runCmd('git reset HEAD^', cwd=tempsrcdir)
  795. result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir))
  796. self.assertFalse(os.path.exists(os.path.join(appenddir, testrecipe)), 'Patch directory should not be created')
  797. result = runCmd('git rev-parse HEAD', cwd=tempsrcdir)
  798. expectedlines = set(['SRCREV = "%s"\n' % result.output,
  799. '\n',
  800. 'SRC_URI = "%s"\n' % git_uri,
  801. '\n'])
  802. with open(bbappendfile, 'r') as f:
  803. self.assertEqual(expectedlines, set(f.readlines()))
  804. # Put commit back and check we can run it if layer isn't in bblayers.conf
  805. os.remove(bbappendfile)
  806. result = runCmd('git commit -a -m "Change the Makefile"', cwd=tempsrcdir)
  807. result = runCmd('bitbake-layers remove-layer %s' % templayerdir, cwd=self.builddir)
  808. result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir))
  809. self.assertIn('WARNING: Specified layer is not currently enabled in bblayers.conf', result.output)
  810. self.assertFalse(os.path.exists(os.path.join(appenddir, testrecipe)), 'Patch directory should not be created')
  811. result = runCmd('git rev-parse HEAD', cwd=tempsrcdir)
  812. expectedlines = set(['SRCREV = "%s"\n' % result.output,
  813. '\n',
  814. 'SRC_URI = "%s"\n' % git_uri,
  815. '\n'])
  816. with open(bbappendfile, 'r') as f:
  817. self.assertEqual(expectedlines, set(f.readlines()))
  818. # Deleting isn't expected to work under these circumstances
  819. @testcase(1370)
  820. def test_devtool_update_recipe_local_files(self):
  821. """Check that local source files are copied over instead of patched"""
  822. testrecipe = 'makedevs'
  823. recipefile = get_bb_var('FILE', testrecipe)
  824. # Setup srctree for modifying the recipe
  825. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  826. self.track_for_cleanup(tempdir)
  827. self.track_for_cleanup(self.workspacedir)
  828. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  829. # (don't bother with cleaning the recipe on teardown, we won't be
  830. # building it)
  831. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  832. # Check git repo
  833. self._check_src_repo(tempdir)
  834. # Try building just to ensure we haven't broken that
  835. bitbake("%s" % testrecipe)
  836. # Edit / commit local source
  837. runCmd('echo "/* Foobar */" >> oe-local-files/makedevs.c', cwd=tempdir)
  838. runCmd('echo "Foo" > oe-local-files/new-local', cwd=tempdir)
  839. runCmd('echo "Bar" > new-file', cwd=tempdir)
  840. runCmd('git add new-file', cwd=tempdir)
  841. runCmd('git commit -m "Add new file"', cwd=tempdir)
  842. self.add_command_to_tearDown('cd %s; git clean -fd .; git checkout .' %
  843. os.path.dirname(recipefile))
  844. runCmd('devtool update-recipe %s' % testrecipe)
  845. expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)),
  846. (' M', '.*/makedevs/makedevs.c$'),
  847. ('??', '.*/makedevs/new-local$'),
  848. ('??', '.*/makedevs/0001-Add-new-file.patch$')]
  849. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  850. @testcase(1371)
  851. def test_devtool_update_recipe_local_files_2(self):
  852. """Check local source files support when oe-local-files is in Git"""
  853. testrecipe = 'lzo'
  854. recipefile = get_bb_var('FILE', testrecipe)
  855. # Setup srctree for modifying the recipe
  856. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  857. self.track_for_cleanup(tempdir)
  858. self.track_for_cleanup(self.workspacedir)
  859. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  860. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  861. # Check git repo
  862. self._check_src_repo(tempdir)
  863. # Add oe-local-files to Git
  864. runCmd('rm oe-local-files/.gitignore', cwd=tempdir)
  865. runCmd('git add oe-local-files', cwd=tempdir)
  866. runCmd('git commit -m "Add local sources"', cwd=tempdir)
  867. # Edit / commit local sources
  868. runCmd('echo "# Foobar" >> oe-local-files/acinclude.m4', cwd=tempdir)
  869. runCmd('git commit -am "Edit existing file"', cwd=tempdir)
  870. runCmd('git rm oe-local-files/run-ptest', cwd=tempdir)
  871. runCmd('git commit -m"Remove file"', cwd=tempdir)
  872. runCmd('echo "Foo" > oe-local-files/new-local', cwd=tempdir)
  873. runCmd('git add oe-local-files/new-local', cwd=tempdir)
  874. runCmd('git commit -m "Add new local file"', cwd=tempdir)
  875. runCmd('echo "Gar" > new-file', cwd=tempdir)
  876. runCmd('git add new-file', cwd=tempdir)
  877. runCmd('git commit -m "Add new file"', cwd=tempdir)
  878. self.add_command_to_tearDown('cd %s; git clean -fd .; git checkout .' %
  879. os.path.dirname(recipefile))
  880. # Checkout unmodified file to working copy -> devtool should still pick
  881. # the modified version from HEAD
  882. runCmd('git checkout HEAD^ -- oe-local-files/acinclude.m4', cwd=tempdir)
  883. runCmd('devtool update-recipe %s' % testrecipe)
  884. expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)),
  885. (' M', '.*/acinclude.m4$'),
  886. (' D', '.*/run-ptest$'),
  887. ('??', '.*/new-local$'),
  888. ('??', '.*/0001-Add-new-file.patch$')]
  889. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  890. def test_devtool_update_recipe_local_files_3(self):
  891. # First, modify the recipe
  892. testrecipe = 'devtool-test-localonly'
  893. recipefile = get_bb_var('FILE', testrecipe)
  894. src_uri = get_bb_var('SRC_URI', testrecipe)
  895. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  896. self.track_for_cleanup(tempdir)
  897. self.track_for_cleanup(self.workspacedir)
  898. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  899. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  900. result = runCmd('devtool modify %s' % testrecipe)
  901. # Modify one file
  902. runCmd('echo "Another line" >> file2', cwd=os.path.join(self.workspacedir, 'sources', testrecipe, 'oe-local-files'))
  903. self.add_command_to_tearDown('cd %s; rm %s/*; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
  904. result = runCmd('devtool update-recipe %s' % testrecipe)
  905. expected_status = [(' M', '.*/%s/file2$' % testrecipe)]
  906. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  907. def test_devtool_update_recipe_local_patch_gz(self):
  908. # First, modify the recipe
  909. testrecipe = 'devtool-test-patch-gz'
  910. recipefile = get_bb_var('FILE', testrecipe)
  911. src_uri = get_bb_var('SRC_URI', testrecipe)
  912. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  913. self.track_for_cleanup(tempdir)
  914. self.track_for_cleanup(self.workspacedir)
  915. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  916. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  917. result = runCmd('devtool modify %s' % testrecipe)
  918. # Modify one file
  919. srctree = os.path.join(self.workspacedir, 'sources', testrecipe)
  920. runCmd('echo "Another line" >> README', cwd=srctree)
  921. runCmd('git commit -a --amend --no-edit', cwd=srctree)
  922. self.add_command_to_tearDown('cd %s; rm %s/*; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
  923. result = runCmd('devtool update-recipe %s' % testrecipe)
  924. expected_status = [(' M', '.*/%s/readme.patch.gz$' % testrecipe)]
  925. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  926. patch_gz = os.path.join(os.path.dirname(recipefile), testrecipe, 'readme.patch.gz')
  927. result = runCmd('file %s' % patch_gz)
  928. if 'gzip compressed data' not in result.output:
  929. self.fail('New patch file is not gzipped - file reports:\n%s' % result.output)
  930. def test_devtool_update_recipe_local_files_subdir(self):
  931. # Try devtool extract on a recipe that has a file with subdir= set in
  932. # SRC_URI such that it overwrites a file that was in an archive that
  933. # was also in SRC_URI
  934. # First, modify the recipe
  935. testrecipe = 'devtool-test-subdir'
  936. recipefile = get_bb_var('FILE', testrecipe)
  937. src_uri = get_bb_var('SRC_URI', testrecipe)
  938. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  939. self.track_for_cleanup(tempdir)
  940. self.track_for_cleanup(self.workspacedir)
  941. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  942. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  943. result = runCmd('devtool modify %s' % testrecipe)
  944. testfile = os.path.join(self.workspacedir, 'sources', testrecipe, 'testfile')
  945. self.assertTrue(os.path.exists(testfile), 'Extracted source could not be found')
  946. with open(testfile, 'r') as f:
  947. contents = f.read().rstrip()
  948. self.assertEqual(contents, 'Modified version', 'File has apparently not been overwritten as it should have been')
  949. # Test devtool update-recipe without modifying any files
  950. self.add_command_to_tearDown('cd %s; rm %s/*; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
  951. result = runCmd('devtool update-recipe %s' % testrecipe)
  952. expected_status = []
  953. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  954. @testcase(1163)
  955. def test_devtool_extract(self):
  956. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  957. # Try devtool extract
  958. self.track_for_cleanup(tempdir)
  959. self.append_config('PREFERRED_PROVIDER_virtual/make = "remake"')
  960. result = runCmd('devtool extract remake %s' % tempdir)
  961. self.assertTrue(os.path.exists(os.path.join(tempdir, 'Makefile.am')), 'Extracted source could not be found')
  962. # devtool extract shouldn't create the workspace
  963. self.assertFalse(os.path.exists(self.workspacedir))
  964. self._check_src_repo(tempdir)
  965. @testcase(1379)
  966. def test_devtool_extract_virtual(self):
  967. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  968. # Try devtool extract
  969. self.track_for_cleanup(tempdir)
  970. result = runCmd('devtool extract virtual/libx11 %s' % tempdir)
  971. self.assertTrue(os.path.exists(os.path.join(tempdir, 'Makefile.am')), 'Extracted source could not be found')
  972. # devtool extract shouldn't create the workspace
  973. self.assertFalse(os.path.exists(self.workspacedir))
  974. self._check_src_repo(tempdir)
  975. @testcase(1168)
  976. def test_devtool_reset_all(self):
  977. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  978. self.track_for_cleanup(tempdir)
  979. self.track_for_cleanup(self.workspacedir)
  980. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  981. testrecipe1 = 'mdadm'
  982. testrecipe2 = 'cronie'
  983. result = runCmd('devtool modify -x %s %s' % (testrecipe1, os.path.join(tempdir, testrecipe1)))
  984. result = runCmd('devtool modify -x %s %s' % (testrecipe2, os.path.join(tempdir, testrecipe2)))
  985. result = runCmd('devtool build %s' % testrecipe1)
  986. result = runCmd('devtool build %s' % testrecipe2)
  987. stampprefix1 = get_bb_var('STAMP', testrecipe1)
  988. self.assertTrue(stampprefix1, 'Unable to get STAMP value for recipe %s' % testrecipe1)
  989. stampprefix2 = get_bb_var('STAMP', testrecipe2)
  990. self.assertTrue(stampprefix2, 'Unable to get STAMP value for recipe %s' % testrecipe2)
  991. result = runCmd('devtool reset -a')
  992. self.assertIn(testrecipe1, result.output)
  993. self.assertIn(testrecipe2, result.output)
  994. result = runCmd('devtool status')
  995. self.assertNotIn(testrecipe1, result.output)
  996. self.assertNotIn(testrecipe2, result.output)
  997. matches1 = glob.glob(stampprefix1 + '*')
  998. self.assertFalse(matches1, 'Stamp files exist for recipe %s that should have been cleaned' % testrecipe1)
  999. matches2 = glob.glob(stampprefix2 + '*')
  1000. self.assertFalse(matches2, 'Stamp files exist for recipe %s that should have been cleaned' % testrecipe2)
  1001. @testcase(1272)
  1002. def test_devtool_deploy_target(self):
  1003. # NOTE: Whilst this test would seemingly be better placed as a runtime test,
  1004. # unfortunately the runtime tests run under bitbake and you can't run
  1005. # devtool within bitbake (since devtool needs to run bitbake itself).
  1006. # Additionally we are testing build-time functionality as well, so
  1007. # really this has to be done as an oe-selftest test.
  1008. #
  1009. # Check preconditions
  1010. machine = get_bb_var('MACHINE')
  1011. if not machine.startswith('qemu'):
  1012. self.skipTest('This test only works with qemu machines')
  1013. if not os.path.exists('/etc/runqemu-nosudo'):
  1014. self.skipTest('You must set up tap devices with scripts/runqemu-gen-tapdevs before running this test')
  1015. result = runCmd('PATH="$PATH:/sbin:/usr/sbin" ip tuntap show', ignore_status=True)
  1016. if result.status != 0:
  1017. result = runCmd('PATH="$PATH:/sbin:/usr/sbin" ifconfig -a', ignore_status=True)
  1018. if result.status != 0:
  1019. self.skipTest('Failed to determine if tap devices exist with ifconfig or ip: %s' % result.output)
  1020. for line in result.output.splitlines():
  1021. if line.startswith('tap'):
  1022. break
  1023. else:
  1024. self.skipTest('No tap devices found - you must set up tap devices with scripts/runqemu-gen-tapdevs before running this test')
  1025. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1026. # Definitions
  1027. testrecipe = 'mdadm'
  1028. testfile = '/sbin/mdadm'
  1029. testimage = 'oe-selftest-image'
  1030. testcommand = '/sbin/mdadm --help'
  1031. # Build an image to run
  1032. bitbake("%s qemu-native qemu-helper-native" % testimage)
  1033. deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
  1034. self.add_command_to_tearDown('bitbake -c clean %s' % testimage)
  1035. self.add_command_to_tearDown('rm -f %s/%s*' % (deploy_dir_image, testimage))
  1036. # Clean recipe so the first deploy will fail
  1037. bitbake("%s -c clean" % testrecipe)
  1038. # Try devtool modify
  1039. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1040. self.track_for_cleanup(tempdir)
  1041. self.track_for_cleanup(self.workspacedir)
  1042. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1043. self.add_command_to_tearDown('bitbake -c clean %s' % testrecipe)
  1044. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  1045. # Test that deploy-target at this point fails (properly)
  1046. result = runCmd('devtool deploy-target -n %s root@localhost' % testrecipe, ignore_status=True)
  1047. self.assertNotEqual(result.output, 0, 'devtool deploy-target should have failed, output: %s' % result.output)
  1048. self.assertNotIn(result.output, 'Traceback', 'devtool deploy-target should have failed with a proper error not a traceback, output: %s' % result.output)
  1049. result = runCmd('devtool build %s' % testrecipe)
  1050. # First try a dry-run of deploy-target
  1051. result = runCmd('devtool deploy-target -n %s root@localhost' % testrecipe)
  1052. self.assertIn(' %s' % testfile, result.output)
  1053. # Boot the image
  1054. with runqemu(testimage) as qemu:
  1055. # Now really test deploy-target
  1056. result = runCmd('devtool deploy-target -c %s root@%s' % (testrecipe, qemu.ip))
  1057. # Run a test command to see if it was installed properly
  1058. sshargs = '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
  1059. result = runCmd('ssh %s root@%s %s' % (sshargs, qemu.ip, testcommand))
  1060. # Check if it deployed all of the files with the right ownership/perms
  1061. # First look on the host - need to do this under pseudo to get the correct ownership/perms
  1062. installdir = get_bb_var('D', testrecipe)
  1063. fakerootenv = get_bb_var('FAKEROOTENV', testrecipe)
  1064. fakerootcmd = get_bb_var('FAKEROOTCMD', testrecipe)
  1065. result = runCmd('%s %s find . -type f -exec ls -l {} \;' % (fakerootenv, fakerootcmd), cwd=installdir)
  1066. filelist1 = self._process_ls_output(result.output)
  1067. # Now look on the target
  1068. tempdir2 = tempfile.mkdtemp(prefix='devtoolqa')
  1069. self.track_for_cleanup(tempdir2)
  1070. tmpfilelist = os.path.join(tempdir2, 'files.txt')
  1071. with open(tmpfilelist, 'w') as f:
  1072. for line in filelist1:
  1073. splitline = line.split()
  1074. f.write(splitline[-1] + '\n')
  1075. result = runCmd('cat %s | ssh -q %s root@%s \'xargs ls -l\'' % (tmpfilelist, sshargs, qemu.ip))
  1076. filelist2 = self._process_ls_output(result.output)
  1077. filelist1.sort(key=lambda item: item.split()[-1])
  1078. filelist2.sort(key=lambda item: item.split()[-1])
  1079. self.assertEqual(filelist1, filelist2)
  1080. # Test undeploy-target
  1081. result = runCmd('devtool undeploy-target -c %s root@%s' % (testrecipe, qemu.ip))
  1082. result = runCmd('ssh %s root@%s %s' % (sshargs, qemu.ip, testcommand), ignore_status=True)
  1083. self.assertNotEqual(result, 0, 'undeploy-target did not remove command as it should have')
  1084. @testcase(1366)
  1085. def test_devtool_build_image(self):
  1086. """Test devtool build-image plugin"""
  1087. # Check preconditions
  1088. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1089. image = 'core-image-minimal'
  1090. self.track_for_cleanup(self.workspacedir)
  1091. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1092. self.add_command_to_tearDown('bitbake -c clean %s' % image)
  1093. bitbake('%s -c clean' % image)
  1094. # Add target and native recipes to workspace
  1095. recipes = ['mdadm', 'parted-native']
  1096. for recipe in recipes:
  1097. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1098. self.track_for_cleanup(tempdir)
  1099. self.add_command_to_tearDown('bitbake -c clean %s' % recipe)
  1100. runCmd('devtool modify %s -x %s' % (recipe, tempdir))
  1101. # Try to build image
  1102. result = runCmd('devtool build-image %s' % image)
  1103. self.assertNotEqual(result, 0, 'devtool build-image failed')
  1104. # Check if image contains expected packages
  1105. deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
  1106. image_link_name = get_bb_var('IMAGE_LINK_NAME', image)
  1107. reqpkgs = [item for item in recipes if not item.endswith('-native')]
  1108. with open(os.path.join(deploy_dir_image, image_link_name + '.manifest'), 'r') as f:
  1109. for line in f:
  1110. splitval = line.split()
  1111. if splitval:
  1112. pkg = splitval[0]
  1113. if pkg in reqpkgs:
  1114. reqpkgs.remove(pkg)
  1115. if reqpkgs:
  1116. self.fail('The following packages were not present in the image as expected: %s' % ', '.join(reqpkgs))
  1117. @testcase(1367)
  1118. def test_devtool_upgrade(self):
  1119. # Check preconditions
  1120. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1121. self.track_for_cleanup(self.workspacedir)
  1122. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1123. # Check parameters
  1124. result = runCmd('devtool upgrade -h')
  1125. for param in 'recipename srctree --version -V --branch -b --keep-temp --no-patch'.split():
  1126. self.assertIn(param, result.output)
  1127. # For the moment, we are using a real recipe.
  1128. recipe = 'devtool-upgrade-test1'
  1129. version = '1.6.0'
  1130. oldrecipefile = get_bb_var('FILE', recipe)
  1131. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1132. self.track_for_cleanup(tempdir)
  1133. # Check that recipe is not already under devtool control
  1134. result = runCmd('devtool status')
  1135. self.assertNotIn(recipe, result.output)
  1136. # Check upgrade. Code does not check if new PV is older or newer that current PV, so, it may be that
  1137. # we are downgrading instead of upgrading.
  1138. result = runCmd('devtool upgrade %s %s -V %s' % (recipe, tempdir, version))
  1139. # Check if srctree at least is populated
  1140. self.assertTrue(len(os.listdir(tempdir)) > 0, 'srctree (%s) should be populated with new (%s) source code' % (tempdir, version))
  1141. # Check new recipe subdirectory is present
  1142. self.assertTrue(os.path.exists(os.path.join(self.workspacedir, 'recipes', recipe, '%s-%s' % (recipe, version))), 'Recipe folder should exist')
  1143. # Check new recipe file is present
  1144. newrecipefile = os.path.join(self.workspacedir, 'recipes', recipe, '%s_%s.bb' % (recipe, version))
  1145. self.assertTrue(os.path.exists(newrecipefile), 'Recipe file should exist after upgrade')
  1146. # Check devtool status and make sure recipe is present
  1147. result = runCmd('devtool status')
  1148. self.assertIn(recipe, result.output)
  1149. self.assertIn(tempdir, result.output)
  1150. # Check recipe got changed as expected
  1151. with open(oldrecipefile + '.upgraded', 'r') as f:
  1152. desiredlines = f.readlines()
  1153. with open(newrecipefile, 'r') as f:
  1154. newlines = f.readlines()
  1155. self.assertEqual(desiredlines, newlines)
  1156. # Check devtool reset recipe
  1157. result = runCmd('devtool reset %s -n' % recipe)
  1158. result = runCmd('devtool status')
  1159. self.assertNotIn(recipe, result.output)
  1160. self.assertFalse(os.path.exists(os.path.join(self.workspacedir, 'recipes', recipe)), 'Recipe directory should not exist after resetting')
  1161. @testcase(1433)
  1162. def test_devtool_upgrade_git(self):
  1163. # Check preconditions
  1164. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1165. self.track_for_cleanup(self.workspacedir)
  1166. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1167. recipe = 'devtool-upgrade-test2'
  1168. commit = '6cc6077a36fe2648a5f993fe7c16c9632f946517'
  1169. oldrecipefile = get_bb_var('FILE', recipe)
  1170. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1171. self.track_for_cleanup(tempdir)
  1172. # Check that recipe is not already under devtool control
  1173. result = runCmd('devtool status')
  1174. self.assertNotIn(recipe, result.output)
  1175. # Check upgrade
  1176. result = runCmd('devtool upgrade %s %s -S %s' % (recipe, tempdir, commit))
  1177. # Check if srctree at least is populated
  1178. self.assertTrue(len(os.listdir(tempdir)) > 0, 'srctree (%s) should be populated with new (%s) source code' % (tempdir, commit))
  1179. # Check new recipe file is present
  1180. newrecipefile = os.path.join(self.workspacedir, 'recipes', recipe, os.path.basename(oldrecipefile))
  1181. self.assertTrue(os.path.exists(newrecipefile), 'Recipe file should exist after upgrade')
  1182. # Check devtool status and make sure recipe is present
  1183. result = runCmd('devtool status')
  1184. self.assertIn(recipe, result.output)
  1185. self.assertIn(tempdir, result.output)
  1186. # Check recipe got changed as expected
  1187. with open(oldrecipefile + '.upgraded', 'r') as f:
  1188. desiredlines = f.readlines()
  1189. with open(newrecipefile, 'r') as f:
  1190. newlines = f.readlines()
  1191. self.assertEqual(desiredlines, newlines)
  1192. # Check devtool reset recipe
  1193. result = runCmd('devtool reset %s -n' % recipe)
  1194. result = runCmd('devtool status')
  1195. self.assertNotIn(recipe, result.output)
  1196. self.assertFalse(os.path.exists(os.path.join(self.workspacedir, 'recipes', recipe)), 'Recipe directory should not exist after resetting')
  1197. @testcase(1352)
  1198. def test_devtool_layer_plugins(self):
  1199. """Test that devtool can use plugins from other layers.
  1200. This test executes the selftest-reverse command from meta-selftest."""
  1201. self.track_for_cleanup(self.workspacedir)
  1202. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1203. s = "Microsoft Made No Profit From Anyone's Zunes Yo"
  1204. result = runCmd("devtool --quiet selftest-reverse \"%s\"" % s)
  1205. self.assertEqual(result.output, s[::-1])
  1206. def _copy_file_with_cleanup(self, srcfile, basedstdir, *paths):
  1207. dstdir = basedstdir
  1208. self.assertTrue(os.path.exists(dstdir))
  1209. for p in paths:
  1210. dstdir = os.path.join(dstdir, p)
  1211. if not os.path.exists(dstdir):
  1212. os.makedirs(dstdir)
  1213. self.track_for_cleanup(dstdir)
  1214. dstfile = os.path.join(dstdir, os.path.basename(srcfile))
  1215. if srcfile != dstfile:
  1216. shutil.copy(srcfile, dstfile)
  1217. self.track_for_cleanup(dstfile)
  1218. def test_devtool_load_plugin(self):
  1219. """Test that devtool loads only the first found plugin in BBPATH."""
  1220. self.track_for_cleanup(self.workspacedir)
  1221. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1222. devtool = runCmd("which devtool")
  1223. fromname = runCmd("devtool --quiet pluginfile")
  1224. srcfile = fromname.output
  1225. bbpath = get_bb_var('BBPATH')
  1226. searchpath = bbpath.split(':') + [os.path.dirname(devtool.output)]
  1227. plugincontent = []
  1228. with open(srcfile) as fh:
  1229. plugincontent = fh.readlines()
  1230. try:
  1231. self.assertIn('meta-selftest', srcfile, 'wrong bbpath plugin found')
  1232. for path in searchpath:
  1233. self._copy_file_with_cleanup(srcfile, path, 'lib', 'devtool')
  1234. result = runCmd("devtool --quiet count")
  1235. self.assertEqual(result.output, '1')
  1236. result = runCmd("devtool --quiet multiloaded")
  1237. self.assertEqual(result.output, "no")
  1238. for path in searchpath:
  1239. result = runCmd("devtool --quiet bbdir")
  1240. self.assertEqual(result.output, path)
  1241. os.unlink(os.path.join(result.output, 'lib', 'devtool', 'bbpath.py'))
  1242. finally:
  1243. with open(srcfile, 'w') as fh:
  1244. fh.writelines(plugincontent)
  1245. def _setup_test_devtool_finish_upgrade(self):
  1246. # Check preconditions
  1247. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1248. self.track_for_cleanup(self.workspacedir)
  1249. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1250. # Use a "real" recipe from meta-selftest
  1251. recipe = 'devtool-upgrade-test1'
  1252. oldversion = '1.5.3'
  1253. newversion = '1.6.0'
  1254. oldrecipefile = get_bb_var('FILE', recipe)
  1255. recipedir = os.path.dirname(oldrecipefile)
  1256. result = runCmd('git status --porcelain .', cwd=recipedir)
  1257. if result.output.strip():
  1258. self.fail('Recipe directory for %s contains uncommitted changes' % recipe)
  1259. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1260. self.track_for_cleanup(tempdir)
  1261. # Check that recipe is not already under devtool control
  1262. result = runCmd('devtool status')
  1263. self.assertNotIn(recipe, result.output)
  1264. # Do the upgrade
  1265. result = runCmd('devtool upgrade %s %s -V %s' % (recipe, tempdir, newversion))
  1266. # Check devtool status and make sure recipe is present
  1267. result = runCmd('devtool status')
  1268. self.assertIn(recipe, result.output)
  1269. self.assertIn(tempdir, result.output)
  1270. # Make a change to the source
  1271. result = runCmd('sed -i \'/^#include "pv.h"/a \\/* Here is a new comment *\\/\' src/pv/number.c', cwd=tempdir)
  1272. result = runCmd('git status --porcelain', cwd=tempdir)
  1273. self.assertIn('M src/pv/number.c', result.output)
  1274. result = runCmd('git commit src/pv/number.c -m "Add a comment to the code"', cwd=tempdir)
  1275. # Check if patch is there
  1276. recipedir = os.path.dirname(oldrecipefile)
  1277. olddir = os.path.join(recipedir, recipe + '-' + oldversion)
  1278. patchfn = '0001-Add-a-note-line-to-the-quick-reference.patch'
  1279. self.assertTrue(os.path.exists(os.path.join(olddir, patchfn)), 'Original patch file does not exist')
  1280. return recipe, oldrecipefile, recipedir, olddir, newversion, patchfn
  1281. def test_devtool_finish_upgrade_origlayer(self):
  1282. recipe, oldrecipefile, recipedir, olddir, newversion, patchfn = self._setup_test_devtool_finish_upgrade()
  1283. # Ensure the recipe is where we think it should be (so that cleanup doesn't trash things)
  1284. self.assertIn('/meta-selftest/', recipedir)
  1285. # Try finish to the original layer
  1286. self.add_command_to_tearDown('rm -rf %s ; cd %s ; git checkout %s' % (recipedir, os.path.dirname(recipedir), recipedir))
  1287. result = runCmd('devtool finish %s meta-selftest' % recipe)
  1288. result = runCmd('devtool status')
  1289. self.assertNotIn(recipe, result.output, 'Recipe should have been reset by finish but wasn\'t')
  1290. self.assertFalse(os.path.exists(os.path.join(self.workspacedir, 'recipes', recipe)), 'Recipe directory should not exist after finish')
  1291. self.assertFalse(os.path.exists(oldrecipefile), 'Old recipe file should have been deleted but wasn\'t')
  1292. self.assertFalse(os.path.exists(os.path.join(olddir, patchfn)), 'Old patch file should have been deleted but wasn\'t')
  1293. newrecipefile = os.path.join(recipedir, '%s_%s.bb' % (recipe, newversion))
  1294. newdir = os.path.join(recipedir, recipe + '-' + newversion)
  1295. self.assertTrue(os.path.exists(newrecipefile), 'New recipe file should have been copied into existing layer but wasn\'t')
  1296. self.assertTrue(os.path.exists(os.path.join(newdir, patchfn)), 'Patch file should have been copied into new directory but wasn\'t')
  1297. self.assertTrue(os.path.exists(os.path.join(newdir, '0002-Add-a-comment-to-the-code.patch')), 'New patch file should have been created but wasn\'t')
  1298. def test_devtool_finish_upgrade_otherlayer(self):
  1299. recipe, oldrecipefile, recipedir, olddir, newversion, patchfn = self._setup_test_devtool_finish_upgrade()
  1300. # Ensure the recipe is where we think it should be (so that cleanup doesn't trash things)
  1301. self.assertIn('/meta-selftest/', recipedir)
  1302. # Try finish to a different layer - should create a bbappend
  1303. # This cleanup isn't strictly necessary but do it anyway just in case it goes wrong and writes to here
  1304. self.add_command_to_tearDown('rm -rf %s ; cd %s ; git checkout %s' % (recipedir, os.path.dirname(recipedir), recipedir))
  1305. oe_core_dir = os.path.join(get_bb_var('COREBASE'), 'meta')
  1306. newrecipedir = os.path.join(oe_core_dir, 'recipes-test', 'devtool')
  1307. newrecipefile = os.path.join(newrecipedir, '%s_%s.bb' % (recipe, newversion))
  1308. self.track_for_cleanup(newrecipedir)
  1309. result = runCmd('devtool finish %s oe-core' % recipe)
  1310. result = runCmd('devtool status')
  1311. self.assertNotIn(recipe, result.output, 'Recipe should have been reset by finish but wasn\'t')
  1312. self.assertFalse(os.path.exists(os.path.join(self.workspacedir, 'recipes', recipe)), 'Recipe directory should not exist after finish')
  1313. self.assertTrue(os.path.exists(oldrecipefile), 'Old recipe file should not have been deleted')
  1314. self.assertTrue(os.path.exists(os.path.join(olddir, patchfn)), 'Old patch file should not have been deleted')
  1315. newdir = os.path.join(newrecipedir, recipe + '-' + newversion)
  1316. self.assertTrue(os.path.exists(newrecipefile), 'New recipe file should have been copied into existing layer but wasn\'t')
  1317. self.assertTrue(os.path.exists(os.path.join(newdir, patchfn)), 'Patch file should have been copied into new directory but wasn\'t')
  1318. self.assertTrue(os.path.exists(os.path.join(newdir, '0002-Add-a-comment-to-the-code.patch')), 'New patch file should have been created but wasn\'t')
  1319. def _setup_test_devtool_finish_modify(self):
  1320. # Check preconditions
  1321. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1322. # Try modifying a recipe
  1323. self.track_for_cleanup(self.workspacedir)
  1324. recipe = 'mdadm'
  1325. oldrecipefile = get_bb_var('FILE', recipe)
  1326. recipedir = os.path.dirname(oldrecipefile)
  1327. result = runCmd('git status --porcelain .', cwd=recipedir)
  1328. if result.output.strip():
  1329. self.fail('Recipe directory for %s contains uncommitted changes' % recipe)
  1330. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1331. self.track_for_cleanup(tempdir)
  1332. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1333. result = runCmd('devtool modify %s %s' % (recipe, tempdir))
  1334. self.assertTrue(os.path.exists(os.path.join(tempdir, 'Makefile')), 'Extracted source could not be found')
  1335. # Test devtool status
  1336. result = runCmd('devtool status')
  1337. self.assertIn(recipe, result.output)
  1338. self.assertIn(tempdir, result.output)
  1339. # Make a change to the source
  1340. result = runCmd('sed -i \'/^#include "mdadm.h"/a \\/* Here is a new comment *\\/\' maps.c', cwd=tempdir)
  1341. result = runCmd('git status --porcelain', cwd=tempdir)
  1342. self.assertIn('M maps.c', result.output)
  1343. result = runCmd('git commit maps.c -m "Add a comment to the code"', cwd=tempdir)
  1344. for entry in os.listdir(recipedir):
  1345. filesdir = os.path.join(recipedir, entry)
  1346. if os.path.isdir(filesdir):
  1347. break
  1348. else:
  1349. self.fail('Unable to find recipe files directory for %s' % recipe)
  1350. return recipe, oldrecipefile, recipedir, filesdir
  1351. def test_devtool_finish_modify_origlayer(self):
  1352. recipe, oldrecipefile, recipedir, filesdir = self._setup_test_devtool_finish_modify()
  1353. # Ensure the recipe is where we think it should be (so that cleanup doesn't trash things)
  1354. self.assertIn('/meta/', recipedir)
  1355. # Try finish to the original layer
  1356. self.add_command_to_tearDown('rm -rf %s ; cd %s ; git checkout %s' % (recipedir, os.path.dirname(recipedir), recipedir))
  1357. result = runCmd('devtool finish %s meta' % recipe)
  1358. result = runCmd('devtool status')
  1359. self.assertNotIn(recipe, result.output, 'Recipe should have been reset by finish but wasn\'t')
  1360. self.assertFalse(os.path.exists(os.path.join(self.workspacedir, 'recipes', recipe)), 'Recipe directory should not exist after finish')
  1361. expected_status = [(' M', '.*/%s$' % os.path.basename(oldrecipefile)),
  1362. ('??', '.*/.*-Add-a-comment-to-the-code.patch$')]
  1363. self._check_repo_status(recipedir, expected_status)
  1364. def test_devtool_finish_modify_otherlayer(self):
  1365. recipe, oldrecipefile, recipedir, filesdir = self._setup_test_devtool_finish_modify()
  1366. # Ensure the recipe is where we think it should be (so that cleanup doesn't trash things)
  1367. self.assertIn('/meta/', recipedir)
  1368. relpth = os.path.relpath(recipedir, os.path.join(get_bb_var('COREBASE'), 'meta'))
  1369. appenddir = os.path.join(get_test_layer(), relpth)
  1370. self.track_for_cleanup(appenddir)
  1371. # Try finish to the original layer
  1372. self.add_command_to_tearDown('rm -rf %s ; cd %s ; git checkout %s' % (recipedir, os.path.dirname(recipedir), recipedir))
  1373. result = runCmd('devtool finish %s meta-selftest' % recipe)
  1374. result = runCmd('devtool status')
  1375. self.assertNotIn(recipe, result.output, 'Recipe should have been reset by finish but wasn\'t')
  1376. self.assertFalse(os.path.exists(os.path.join(self.workspacedir, 'recipes', recipe)), 'Recipe directory should not exist after finish')
  1377. result = runCmd('git status --porcelain .', cwd=recipedir)
  1378. if result.output.strip():
  1379. self.fail('Recipe directory for %s contains the following unexpected changes after finish:\n%s' % (recipe, result.output.strip()))
  1380. recipefn = os.path.splitext(os.path.basename(oldrecipefile))[0]
  1381. recipefn = recipefn.split('_')[0] + '_%'
  1382. appendfile = os.path.join(appenddir, recipefn + '.bbappend')
  1383. self.assertTrue(os.path.exists(appendfile), 'bbappend %s should have been created but wasn\'t' % appendfile)
  1384. newdir = os.path.join(appenddir, recipe)
  1385. files = os.listdir(newdir)
  1386. foundpatch = None
  1387. for fn in files:
  1388. if fnmatch.fnmatch(fn, '*-Add-a-comment-to-the-code.patch'):
  1389. foundpatch = fn
  1390. if not foundpatch:
  1391. self.fail('No patch file created next to bbappend')
  1392. files.remove(foundpatch)
  1393. if files:
  1394. self.fail('Unexpected file(s) copied next to bbappend: %s' % ', '.join(files))
  1395. def test_devtool_rename(self):
  1396. # Check preconditions
  1397. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1398. self.track_for_cleanup(self.workspacedir)
  1399. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1400. # First run devtool add
  1401. # We already have this recipe in OE-Core, but that doesn't matter
  1402. recipename = 'i2c-tools'
  1403. recipever = '3.1.2'
  1404. recipefile = os.path.join(self.workspacedir, 'recipes', recipename, '%s_%s.bb' % (recipename, recipever))
  1405. url = 'http://downloads.yoctoproject.org/mirror/sources/i2c-tools-%s.tar.bz2' % recipever
  1406. def add_recipe():
  1407. result = runCmd('devtool add %s' % url)
  1408. self.assertTrue(os.path.exists(recipefile), 'Expected recipe file not created')
  1409. self.assertTrue(os.path.exists(os.path.join(self.workspacedir, 'sources', recipename)), 'Source directory not created')
  1410. checkvars = {}
  1411. checkvars['S'] = None
  1412. checkvars['SRC_URI'] = url.replace(recipever, '${PV}')
  1413. self._test_recipe_contents(recipefile, checkvars, [])
  1414. add_recipe()
  1415. # Now rename it - change both name and version
  1416. newrecipename = 'mynewrecipe'
  1417. newrecipever = '456'
  1418. newrecipefile = os.path.join(self.workspacedir, 'recipes', newrecipename, '%s_%s.bb' % (newrecipename, newrecipever))
  1419. result = runCmd('devtool rename %s %s -V %s' % (recipename, newrecipename, newrecipever))
  1420. self.assertTrue(os.path.exists(newrecipefile), 'Recipe file not renamed')
  1421. self.assertFalse(os.path.exists(os.path.join(self.workspacedir, 'recipes', recipename)), 'Old recipe directory still exists')
  1422. newsrctree = os.path.join(self.workspacedir, 'sources', newrecipename)
  1423. self.assertTrue(os.path.exists(newsrctree), 'Source directory not renamed')
  1424. checkvars = {}
  1425. checkvars['S'] = '${WORKDIR}/%s-%s' % (recipename, recipever)
  1426. checkvars['SRC_URI'] = url
  1427. self._test_recipe_contents(newrecipefile, checkvars, [])
  1428. # Try again - change just name this time
  1429. result = runCmd('devtool reset -n %s' % newrecipename)
  1430. shutil.rmtree(newsrctree)
  1431. add_recipe()
  1432. newrecipefile = os.path.join(self.workspacedir, 'recipes', newrecipename, '%s_%s.bb' % (newrecipename, recipever))
  1433. result = runCmd('devtool rename %s %s' % (recipename, newrecipename))
  1434. self.assertTrue(os.path.exists(newrecipefile), 'Recipe file not renamed')
  1435. self.assertFalse(os.path.exists(os.path.join(self.workspacedir, 'recipes', recipename)), 'Old recipe directory still exists')
  1436. self.assertTrue(os.path.exists(os.path.join(self.workspacedir, 'sources', newrecipename)), 'Source directory not renamed')
  1437. checkvars = {}
  1438. checkvars['S'] = '${WORKDIR}/%s-${PV}' % recipename
  1439. checkvars['SRC_URI'] = url.replace(recipever, '${PV}')
  1440. self._test_recipe_contents(newrecipefile, checkvars, [])
  1441. # Try again - change just version this time
  1442. result = runCmd('devtool reset -n %s' % newrecipename)
  1443. shutil.rmtree(newsrctree)
  1444. add_recipe()
  1445. newrecipefile = os.path.join(self.workspacedir, 'recipes', recipename, '%s_%s.bb' % (recipename, newrecipever))
  1446. result = runCmd('devtool rename %s -V %s' % (recipename, newrecipever))
  1447. self.assertTrue(os.path.exists(newrecipefile), 'Recipe file not renamed')
  1448. self.assertTrue(os.path.exists(os.path.join(self.workspacedir, 'sources', recipename)), 'Source directory no longer exists')
  1449. checkvars = {}
  1450. checkvars['S'] = '${WORKDIR}/${BPN}-%s' % recipever
  1451. checkvars['SRC_URI'] = url
  1452. self._test_recipe_contents(newrecipefile, checkvars, [])