devtool.py 96 KB

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