fetch.py 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792
  1. # ex:ts=4:sw=4:sts=4:et
  2. # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
  3. #
  4. # BitBake Tests for the Fetcher (fetch2/)
  5. #
  6. # Copyright (C) 2012 Richard Purdie
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License version 2 as
  10. # published by the Free Software Foundation.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. #
  21. import unittest
  22. import hashlib
  23. import tempfile
  24. import subprocess
  25. import collections
  26. import os
  27. from bb.fetch2 import URI
  28. from bb.fetch2 import FetchMethod
  29. import bb
  30. def skipIfNoNetwork():
  31. if os.environ.get("BB_SKIP_NETTESTS") == "yes":
  32. return unittest.skip("Network tests being skipped")
  33. return lambda f: f
  34. class URITest(unittest.TestCase):
  35. test_uris = {
  36. "http://www.google.com/index.html" : {
  37. 'uri': 'http://www.google.com/index.html',
  38. 'scheme': 'http',
  39. 'hostname': 'www.google.com',
  40. 'port': None,
  41. 'hostport': 'www.google.com',
  42. 'path': '/index.html',
  43. 'userinfo': '',
  44. 'username': '',
  45. 'password': '',
  46. 'params': {},
  47. 'query': {},
  48. 'relative': False
  49. },
  50. "http://www.google.com/index.html;param1=value1" : {
  51. 'uri': 'http://www.google.com/index.html;param1=value1',
  52. 'scheme': 'http',
  53. 'hostname': 'www.google.com',
  54. 'port': None,
  55. 'hostport': 'www.google.com',
  56. 'path': '/index.html',
  57. 'userinfo': '',
  58. 'username': '',
  59. 'password': '',
  60. 'params': {
  61. 'param1': 'value1'
  62. },
  63. 'query': {},
  64. 'relative': False
  65. },
  66. "http://www.example.org/index.html?param1=value1" : {
  67. 'uri': 'http://www.example.org/index.html?param1=value1',
  68. 'scheme': 'http',
  69. 'hostname': 'www.example.org',
  70. 'port': None,
  71. 'hostport': 'www.example.org',
  72. 'path': '/index.html',
  73. 'userinfo': '',
  74. 'username': '',
  75. 'password': '',
  76. 'params': {},
  77. 'query': {
  78. 'param1': 'value1'
  79. },
  80. 'relative': False
  81. },
  82. "http://www.example.org/index.html?qparam1=qvalue1;param2=value2" : {
  83. 'uri': 'http://www.example.org/index.html?qparam1=qvalue1;param2=value2',
  84. 'scheme': 'http',
  85. 'hostname': 'www.example.org',
  86. 'port': None,
  87. 'hostport': 'www.example.org',
  88. 'path': '/index.html',
  89. 'userinfo': '',
  90. 'username': '',
  91. 'password': '',
  92. 'params': {
  93. 'param2': 'value2'
  94. },
  95. 'query': {
  96. 'qparam1': 'qvalue1'
  97. },
  98. 'relative': False
  99. },
  100. "http://www.example.com:8080/index.html" : {
  101. 'uri': 'http://www.example.com:8080/index.html',
  102. 'scheme': 'http',
  103. 'hostname': 'www.example.com',
  104. 'port': 8080,
  105. 'hostport': 'www.example.com:8080',
  106. 'path': '/index.html',
  107. 'userinfo': '',
  108. 'username': '',
  109. 'password': '',
  110. 'params': {},
  111. 'query': {},
  112. 'relative': False
  113. },
  114. "cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg" : {
  115. 'uri': 'cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg',
  116. 'scheme': 'cvs',
  117. 'hostname': 'cvs.handhelds.org',
  118. 'port': None,
  119. 'hostport': 'cvs.handhelds.org',
  120. 'path': '/cvs',
  121. 'userinfo': 'anoncvs',
  122. 'username': 'anoncvs',
  123. 'password': '',
  124. 'params': {
  125. 'module': 'familiar/dist/ipkg'
  126. },
  127. 'query': {},
  128. 'relative': False
  129. },
  130. "cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg": {
  131. 'uri': 'cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg',
  132. 'scheme': 'cvs',
  133. 'hostname': 'cvs.handhelds.org',
  134. 'port': None,
  135. 'hostport': 'cvs.handhelds.org',
  136. 'path': '/cvs',
  137. 'userinfo': 'anoncvs:anonymous',
  138. 'username': 'anoncvs',
  139. 'password': 'anonymous',
  140. 'params': collections.OrderedDict([
  141. ('tag', 'V0-99-81'),
  142. ('module', 'familiar/dist/ipkg')
  143. ]),
  144. 'query': {},
  145. 'relative': False
  146. },
  147. "file://example.diff": { # NOTE: Not RFC compliant!
  148. 'uri': 'file:example.diff',
  149. 'scheme': 'file',
  150. 'hostname': '',
  151. 'port': None,
  152. 'hostport': '',
  153. 'path': 'example.diff',
  154. 'userinfo': '',
  155. 'username': '',
  156. 'password': '',
  157. 'params': {},
  158. 'query': {},
  159. 'relative': True
  160. },
  161. "file:example.diff": { # NOTE: RFC compliant version of the former
  162. 'uri': 'file:example.diff',
  163. 'scheme': 'file',
  164. 'hostname': '',
  165. 'port': None,
  166. 'hostport': '',
  167. 'path': 'example.diff',
  168. 'userinfo': '',
  169. 'userinfo': '',
  170. 'username': '',
  171. 'password': '',
  172. 'params': {},
  173. 'query': {},
  174. 'relative': True
  175. },
  176. "file:///tmp/example.diff": {
  177. 'uri': 'file:///tmp/example.diff',
  178. 'scheme': 'file',
  179. 'hostname': '',
  180. 'port': None,
  181. 'hostport': '',
  182. 'path': '/tmp/example.diff',
  183. 'userinfo': '',
  184. 'userinfo': '',
  185. 'username': '',
  186. 'password': '',
  187. 'params': {},
  188. 'query': {},
  189. 'relative': False
  190. },
  191. "git:///path/example.git": {
  192. 'uri': 'git:///path/example.git',
  193. 'scheme': 'git',
  194. 'hostname': '',
  195. 'port': None,
  196. 'hostport': '',
  197. 'path': '/path/example.git',
  198. 'userinfo': '',
  199. 'userinfo': '',
  200. 'username': '',
  201. 'password': '',
  202. 'params': {},
  203. 'query': {},
  204. 'relative': False
  205. },
  206. "git:path/example.git": {
  207. 'uri': 'git:path/example.git',
  208. 'scheme': 'git',
  209. 'hostname': '',
  210. 'port': None,
  211. 'hostport': '',
  212. 'path': 'path/example.git',
  213. 'userinfo': '',
  214. 'userinfo': '',
  215. 'username': '',
  216. 'password': '',
  217. 'params': {},
  218. 'query': {},
  219. 'relative': True
  220. },
  221. "git://example.net/path/example.git": {
  222. 'uri': 'git://example.net/path/example.git',
  223. 'scheme': 'git',
  224. 'hostname': 'example.net',
  225. 'port': None,
  226. 'hostport': 'example.net',
  227. 'path': '/path/example.git',
  228. 'userinfo': '',
  229. 'userinfo': '',
  230. 'username': '',
  231. 'password': '',
  232. 'params': {},
  233. 'query': {},
  234. 'relative': False
  235. },
  236. "http://somesite.net;someparam=1": {
  237. 'uri': 'http://somesite.net;someparam=1',
  238. 'scheme': 'http',
  239. 'hostname': 'somesite.net',
  240. 'port': None,
  241. 'hostport': 'somesite.net',
  242. 'path': '',
  243. 'userinfo': '',
  244. 'userinfo': '',
  245. 'username': '',
  246. 'password': '',
  247. 'params': {"someparam" : "1"},
  248. 'query': {},
  249. 'relative': False
  250. },
  251. "file://somelocation;someparam=1": {
  252. 'uri': 'file:somelocation;someparam=1',
  253. 'scheme': 'file',
  254. 'hostname': '',
  255. 'port': None,
  256. 'hostport': '',
  257. 'path': 'somelocation',
  258. 'userinfo': '',
  259. 'userinfo': '',
  260. 'username': '',
  261. 'password': '',
  262. 'params': {"someparam" : "1"},
  263. 'query': {},
  264. 'relative': True
  265. }
  266. }
  267. def test_uri(self):
  268. for test_uri, ref in self.test_uris.items():
  269. uri = URI(test_uri)
  270. self.assertEqual(str(uri), ref['uri'])
  271. # expected attributes
  272. self.assertEqual(uri.scheme, ref['scheme'])
  273. self.assertEqual(uri.userinfo, ref['userinfo'])
  274. self.assertEqual(uri.username, ref['username'])
  275. self.assertEqual(uri.password, ref['password'])
  276. self.assertEqual(uri.hostname, ref['hostname'])
  277. self.assertEqual(uri.port, ref['port'])
  278. self.assertEqual(uri.hostport, ref['hostport'])
  279. self.assertEqual(uri.path, ref['path'])
  280. self.assertEqual(uri.params, ref['params'])
  281. self.assertEqual(uri.relative, ref['relative'])
  282. def test_dict(self):
  283. for test in self.test_uris.values():
  284. uri = URI()
  285. self.assertEqual(uri.scheme, '')
  286. self.assertEqual(uri.userinfo, '')
  287. self.assertEqual(uri.username, '')
  288. self.assertEqual(uri.password, '')
  289. self.assertEqual(uri.hostname, '')
  290. self.assertEqual(uri.port, None)
  291. self.assertEqual(uri.path, '')
  292. self.assertEqual(uri.params, {})
  293. uri.scheme = test['scheme']
  294. self.assertEqual(uri.scheme, test['scheme'])
  295. uri.userinfo = test['userinfo']
  296. self.assertEqual(uri.userinfo, test['userinfo'])
  297. self.assertEqual(uri.username, test['username'])
  298. self.assertEqual(uri.password, test['password'])
  299. # make sure changing the values doesn't do anything unexpected
  300. uri.username = 'changeme'
  301. self.assertEqual(uri.username, 'changeme')
  302. self.assertEqual(uri.password, test['password'])
  303. uri.password = 'insecure'
  304. self.assertEqual(uri.username, 'changeme')
  305. self.assertEqual(uri.password, 'insecure')
  306. # reset back after our trickery
  307. uri.userinfo = test['userinfo']
  308. self.assertEqual(uri.userinfo, test['userinfo'])
  309. self.assertEqual(uri.username, test['username'])
  310. self.assertEqual(uri.password, test['password'])
  311. uri.hostname = test['hostname']
  312. self.assertEqual(uri.hostname, test['hostname'])
  313. self.assertEqual(uri.hostport, test['hostname'])
  314. uri.port = test['port']
  315. self.assertEqual(uri.port, test['port'])
  316. self.assertEqual(uri.hostport, test['hostport'])
  317. uri.path = test['path']
  318. self.assertEqual(uri.path, test['path'])
  319. uri.params = test['params']
  320. self.assertEqual(uri.params, test['params'])
  321. uri.query = test['query']
  322. self.assertEqual(uri.query, test['query'])
  323. self.assertEqual(str(uri), test['uri'])
  324. uri.params = {}
  325. self.assertEqual(uri.params, {})
  326. self.assertEqual(str(uri), (str(uri).split(";"))[0])
  327. class FetcherTest(unittest.TestCase):
  328. def setUp(self):
  329. self.origdir = os.getcwd()
  330. self.d = bb.data.init()
  331. self.tempdir = tempfile.mkdtemp()
  332. self.dldir = os.path.join(self.tempdir, "download")
  333. os.mkdir(self.dldir)
  334. self.d.setVar("DL_DIR", self.dldir)
  335. self.unpackdir = os.path.join(self.tempdir, "unpacked")
  336. os.mkdir(self.unpackdir)
  337. persistdir = os.path.join(self.tempdir, "persistdata")
  338. self.d.setVar("PERSISTENT_DIR", persistdir)
  339. def tearDown(self):
  340. os.chdir(self.origdir)
  341. if os.environ.get("BB_TMPDIR_NOCLEAN") == "yes":
  342. print("Not cleaning up %s. Please remove manually." % self.tempdir)
  343. else:
  344. bb.utils.prunedir(self.tempdir)
  345. class MirrorUriTest(FetcherTest):
  346. replaceuris = {
  347. ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "http://somewhere.org/somedir/")
  348. : "http://somewhere.org/somedir/git2_git.invalid.infradead.org.mtd-utils.git.tar.gz",
  349. ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http")
  350. : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
  351. ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http")
  352. : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
  353. ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/\\2;protocol=http")
  354. : "git://somewhere.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
  355. ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890", "git://someserver.org/bitbake", "git://git.openembedded.org/bitbake")
  356. : "git://git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890",
  357. ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache")
  358. : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
  359. ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache/")
  360. : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
  361. ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org/somedir3")
  362. : "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz",
  363. ("http://somewhere.org/somedir1/somefile_1.2.3.tar.gz", "http://somewhere.org/somedir1/somefile_1.2.3.tar.gz", "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz")
  364. : "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz",
  365. ("http://www.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", "http://www.apache.org/dist", "http://archive.apache.org/dist")
  366. : "http://archive.apache.org/dist/subversion/subversion-1.7.1.tar.bz2",
  367. ("http://www.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", "http://.*/.*", "file:///somepath/downloads/")
  368. : "file:///somepath/downloads/subversion-1.7.1.tar.bz2",
  369. ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http")
  370. : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
  371. ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http")
  372. : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
  373. ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/MIRRORNAME;protocol=http")
  374. : "git://somewhere.org/somedir/git.invalid.infradead.org.foo.mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
  375. ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org")
  376. : "http://somewhere2.org/somefile_1.2.3.tar.gz",
  377. ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org/")
  378. : "http://somewhere2.org/somefile_1.2.3.tar.gz",
  379. ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master", "git://someserver.org/bitbake;branch=master", "git://git.openembedded.org/bitbake;protocol=http")
  380. : "git://git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master;protocol=http",
  381. #Renaming files doesn't work
  382. #("http://somewhere.org/somedir1/somefile_1.2.3.tar.gz", "http://somewhere.org/somedir1/somefile_1.2.3.tar.gz", "http://somewhere2.org/somedir3/somefile_2.3.4.tar.gz") : "http://somewhere2.org/somedir3/somefile_2.3.4.tar.gz"
  383. #("file://sstate-xyz.tgz", "file://.*/.*", "file:///somewhere/1234/sstate-cache") : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
  384. }
  385. mirrorvar = "http://.*/.* file:///somepath/downloads/ \n" \
  386. "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n" \
  387. "https://.*/.* file:///someotherpath/downloads/ \n" \
  388. "http://.*/.* file:///someotherpath/downloads/ \n"
  389. def test_urireplace(self):
  390. for k, v in self.replaceuris.items():
  391. ud = bb.fetch.FetchData(k[0], self.d)
  392. ud.setup_localpath(self.d)
  393. mirrors = bb.fetch2.mirror_from_string("%s %s" % (k[1], k[2]))
  394. newuris, uds = bb.fetch2.build_mirroruris(ud, mirrors, self.d)
  395. self.assertEqual([v], newuris)
  396. def test_urilist1(self):
  397. fetcher = bb.fetch.FetchData("http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
  398. mirrors = bb.fetch2.mirror_from_string(self.mirrorvar)
  399. uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
  400. self.assertEqual(uris, ['file:///somepath/downloads/bitbake-1.0.tar.gz', 'file:///someotherpath/downloads/bitbake-1.0.tar.gz'])
  401. def test_urilist2(self):
  402. # Catch https:// -> files:// bug
  403. fetcher = bb.fetch.FetchData("https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
  404. mirrors = bb.fetch2.mirror_from_string(self.mirrorvar)
  405. uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
  406. self.assertEqual(uris, ['file:///someotherpath/downloads/bitbake-1.0.tar.gz'])
  407. def test_mirror_of_mirror(self):
  408. # Test if mirror of a mirror works
  409. mirrorvar = self.mirrorvar + " http://.*/.* http://otherdownloads.yoctoproject.org/downloads/ \n"
  410. mirrorvar = mirrorvar + " http://otherdownloads.yoctoproject.org/.* http://downloads2.yoctoproject.org/downloads/ \n"
  411. fetcher = bb.fetch.FetchData("http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
  412. mirrors = bb.fetch2.mirror_from_string(mirrorvar)
  413. uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
  414. self.assertEqual(uris, ['file:///somepath/downloads/bitbake-1.0.tar.gz',
  415. 'file:///someotherpath/downloads/bitbake-1.0.tar.gz',
  416. 'http://otherdownloads.yoctoproject.org/downloads/bitbake-1.0.tar.gz',
  417. 'http://downloads2.yoctoproject.org/downloads/bitbake-1.0.tar.gz'])
  418. recmirrorvar = "https://.*/[^/]* http://AAAA/A/A/A/ \n" \
  419. "https://.*/[^/]* https://BBBB/B/B/B/ \n"
  420. def test_recursive(self):
  421. fetcher = bb.fetch.FetchData("https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
  422. mirrors = bb.fetch2.mirror_from_string(self.recmirrorvar)
  423. uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
  424. self.assertEqual(uris, ['http://AAAA/A/A/A/bitbake/bitbake-1.0.tar.gz',
  425. 'https://BBBB/B/B/B/bitbake/bitbake-1.0.tar.gz',
  426. 'http://AAAA/A/A/A/B/B/bitbake/bitbake-1.0.tar.gz'])
  427. class GitDownloadDirectoryNamingTest(FetcherTest):
  428. def setUp(self):
  429. super(GitDownloadDirectoryNamingTest, self).setUp()
  430. self.recipe_url = "git://git.openembedded.org/bitbake"
  431. self.recipe_dir = "git.openembedded.org.bitbake"
  432. self.mirror_url = "git://github.com/openembedded/bitbake.git"
  433. self.mirror_dir = "github.com.openembedded.bitbake.git"
  434. self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
  435. def setup_mirror_rewrite(self):
  436. self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url + " \n")
  437. @skipIfNoNetwork()
  438. def test_that_directory_is_named_after_recipe_url_when_no_mirroring_is_used(self):
  439. self.setup_mirror_rewrite()
  440. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  441. fetcher.download()
  442. dir = os.listdir(self.dldir + "/git2")
  443. self.assertIn(self.recipe_dir, dir)
  444. @skipIfNoNetwork()
  445. def test_that_directory_exists_for_mirrored_url_and_recipe_url_when_mirroring_is_used(self):
  446. self.setup_mirror_rewrite()
  447. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  448. fetcher.download()
  449. dir = os.listdir(self.dldir + "/git2")
  450. self.assertIn(self.mirror_dir, dir)
  451. self.assertIn(self.recipe_dir, dir)
  452. @skipIfNoNetwork()
  453. def test_that_recipe_directory_and_mirrored_directory_exists_when_mirroring_is_used_and_the_mirrored_directory_already_exists(self):
  454. self.setup_mirror_rewrite()
  455. fetcher = bb.fetch.Fetch([self.mirror_url], self.d)
  456. fetcher.download()
  457. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  458. fetcher.download()
  459. dir = os.listdir(self.dldir + "/git2")
  460. self.assertIn(self.mirror_dir, dir)
  461. self.assertIn(self.recipe_dir, dir)
  462. class TarballNamingTest(FetcherTest):
  463. def setUp(self):
  464. super(TarballNamingTest, self).setUp()
  465. self.recipe_url = "git://git.openembedded.org/bitbake"
  466. self.recipe_tarball = "git2_git.openembedded.org.bitbake.tar.gz"
  467. self.mirror_url = "git://github.com/openembedded/bitbake.git"
  468. self.mirror_tarball = "git2_github.com.openembedded.bitbake.git.tar.gz"
  469. self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '1')
  470. self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
  471. def setup_mirror_rewrite(self):
  472. self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url + " \n")
  473. @skipIfNoNetwork()
  474. def test_that_the_recipe_tarball_is_created_when_no_mirroring_is_used(self):
  475. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  476. fetcher.download()
  477. dir = os.listdir(self.dldir)
  478. self.assertIn(self.recipe_tarball, dir)
  479. @skipIfNoNetwork()
  480. def test_that_the_mirror_tarball_is_created_when_mirroring_is_used(self):
  481. self.setup_mirror_rewrite()
  482. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  483. fetcher.download()
  484. dir = os.listdir(self.dldir)
  485. self.assertIn(self.mirror_tarball, dir)
  486. class GitShallowTarballNamingTest(FetcherTest):
  487. def setUp(self):
  488. super(GitShallowTarballNamingTest, self).setUp()
  489. self.recipe_url = "git://git.openembedded.org/bitbake"
  490. self.recipe_tarball = "gitshallow_git.openembedded.org.bitbake_82ea737-1_master.tar.gz"
  491. self.mirror_url = "git://github.com/openembedded/bitbake.git"
  492. self.mirror_tarball = "gitshallow_github.com.openembedded.bitbake.git_82ea737-1_master.tar.gz"
  493. self.d.setVar('BB_GIT_SHALLOW', '1')
  494. self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1')
  495. self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
  496. def setup_mirror_rewrite(self):
  497. self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url + " \n")
  498. @skipIfNoNetwork()
  499. def test_that_the_tarball_is_named_after_recipe_url_when_no_mirroring_is_used(self):
  500. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  501. fetcher.download()
  502. dir = os.listdir(self.dldir)
  503. self.assertIn(self.recipe_tarball, dir)
  504. @skipIfNoNetwork()
  505. def test_that_the_mirror_tarball_is_created_when_mirroring_is_used(self):
  506. self.setup_mirror_rewrite()
  507. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  508. fetcher.download()
  509. dir = os.listdir(self.dldir)
  510. self.assertIn(self.mirror_tarball, dir)
  511. class FetcherLocalTest(FetcherTest):
  512. def setUp(self):
  513. def touch(fn):
  514. with open(fn, 'a'):
  515. os.utime(fn, None)
  516. super(FetcherLocalTest, self).setUp()
  517. self.localsrcdir = os.path.join(self.tempdir, 'localsrc')
  518. os.makedirs(self.localsrcdir)
  519. touch(os.path.join(self.localsrcdir, 'a'))
  520. touch(os.path.join(self.localsrcdir, 'b'))
  521. os.makedirs(os.path.join(self.localsrcdir, 'dir'))
  522. touch(os.path.join(self.localsrcdir, 'dir', 'c'))
  523. touch(os.path.join(self.localsrcdir, 'dir', 'd'))
  524. os.makedirs(os.path.join(self.localsrcdir, 'dir', 'subdir'))
  525. touch(os.path.join(self.localsrcdir, 'dir', 'subdir', 'e'))
  526. self.d.setVar("FILESPATH", self.localsrcdir)
  527. def fetchUnpack(self, uris):
  528. fetcher = bb.fetch.Fetch(uris, self.d)
  529. fetcher.download()
  530. fetcher.unpack(self.unpackdir)
  531. flst = []
  532. for root, dirs, files in os.walk(self.unpackdir):
  533. for f in files:
  534. flst.append(os.path.relpath(os.path.join(root, f), self.unpackdir))
  535. flst.sort()
  536. return flst
  537. def test_local(self):
  538. tree = self.fetchUnpack(['file://a', 'file://dir/c'])
  539. self.assertEqual(tree, ['a', 'dir/c'])
  540. def test_local_wildcard(self):
  541. tree = self.fetchUnpack(['file://a', 'file://dir/*'])
  542. self.assertEqual(tree, ['a', 'dir/c', 'dir/d', 'dir/subdir/e'])
  543. def test_local_dir(self):
  544. tree = self.fetchUnpack(['file://a', 'file://dir'])
  545. self.assertEqual(tree, ['a', 'dir/c', 'dir/d', 'dir/subdir/e'])
  546. def test_local_subdir(self):
  547. tree = self.fetchUnpack(['file://dir/subdir'])
  548. self.assertEqual(tree, ['dir/subdir/e'])
  549. def test_local_subdir_file(self):
  550. tree = self.fetchUnpack(['file://dir/subdir/e'])
  551. self.assertEqual(tree, ['dir/subdir/e'])
  552. def test_local_subdirparam(self):
  553. tree = self.fetchUnpack(['file://a;subdir=bar', 'file://dir;subdir=foo/moo'])
  554. self.assertEqual(tree, ['bar/a', 'foo/moo/dir/c', 'foo/moo/dir/d', 'foo/moo/dir/subdir/e'])
  555. def test_local_deepsubdirparam(self):
  556. tree = self.fetchUnpack(['file://dir/subdir/e;subdir=bar'])
  557. self.assertEqual(tree, ['bar/dir/subdir/e'])
  558. def test_local_absolutedir(self):
  559. # Unpacking to an absolute path that is a subdirectory of the root
  560. # should work
  561. tree = self.fetchUnpack(['file://a;subdir=%s' % os.path.join(self.unpackdir, 'bar')])
  562. # Unpacking to an absolute path outside of the root should fail
  563. with self.assertRaises(bb.fetch2.UnpackError):
  564. self.fetchUnpack(['file://a;subdir=/bin/sh'])
  565. class FetcherNoNetworkTest(FetcherTest):
  566. def setUp(self):
  567. super().setUp()
  568. # all test cases are based on not having network
  569. self.d.setVar("BB_NO_NETWORK", "1")
  570. def test_missing(self):
  571. string = "this is a test file\n".encode("utf-8")
  572. self.d.setVarFlag("SRC_URI", "md5sum", hashlib.md5(string).hexdigest())
  573. self.d.setVarFlag("SRC_URI", "sha256sum", hashlib.sha256(string).hexdigest())
  574. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
  575. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
  576. fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/test-file.tar.gz"], self.d)
  577. with self.assertRaises(bb.fetch2.NetworkAccess):
  578. fetcher.download()
  579. def test_valid_missing_donestamp(self):
  580. # create the file in the download directory with correct hash
  581. string = "this is a test file\n".encode("utf-8")
  582. with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb") as f:
  583. f.write(string)
  584. self.d.setVarFlag("SRC_URI", "md5sum", hashlib.md5(string).hexdigest())
  585. self.d.setVarFlag("SRC_URI", "sha256sum", hashlib.sha256(string).hexdigest())
  586. self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
  587. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
  588. fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/test-file.tar.gz"], self.d)
  589. fetcher.download()
  590. self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
  591. def test_invalid_missing_donestamp(self):
  592. # create an invalid file in the download directory with incorrect hash
  593. string = "this is a test file\n".encode("utf-8")
  594. with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb"):
  595. pass
  596. self.d.setVarFlag("SRC_URI", "md5sum", hashlib.md5(string).hexdigest())
  597. self.d.setVarFlag("SRC_URI", "sha256sum", hashlib.sha256(string).hexdigest())
  598. self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
  599. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
  600. fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/test-file.tar.gz"], self.d)
  601. with self.assertRaises(bb.fetch2.NetworkAccess):
  602. fetcher.download()
  603. # the existing file should not exist or should have be moved to "bad-checksum"
  604. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
  605. def test_nochecksums_missing(self):
  606. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
  607. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
  608. # ssh fetch does not support checksums
  609. fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d)
  610. # attempts to download with missing donestamp
  611. with self.assertRaises(bb.fetch2.NetworkAccess):
  612. fetcher.download()
  613. def test_nochecksums_missing_donestamp(self):
  614. # create a file in the download directory
  615. with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb"):
  616. pass
  617. self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
  618. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
  619. # ssh fetch does not support checksums
  620. fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d)
  621. # attempts to download with missing donestamp
  622. with self.assertRaises(bb.fetch2.NetworkAccess):
  623. fetcher.download()
  624. def test_nochecksums_has_donestamp(self):
  625. # create a file in the download directory with the donestamp
  626. with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb"):
  627. pass
  628. with open(os.path.join(self.dldir, "test-file.tar.gz.done"), "wb"):
  629. pass
  630. self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
  631. self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
  632. # ssh fetch does not support checksums
  633. fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d)
  634. # should not fetch
  635. fetcher.download()
  636. # both files should still exist
  637. self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
  638. self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
  639. def test_nochecksums_missing_has_donestamp(self):
  640. # create a file in the download directory with the donestamp
  641. with open(os.path.join(self.dldir, "test-file.tar.gz.done"), "wb"):
  642. pass
  643. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
  644. self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
  645. # ssh fetch does not support checksums
  646. fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d)
  647. with self.assertRaises(bb.fetch2.NetworkAccess):
  648. fetcher.download()
  649. # both files should still exist
  650. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
  651. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
  652. class FetcherNetworkTest(FetcherTest):
  653. @skipIfNoNetwork()
  654. def test_fetch(self):
  655. fetcher = bb.fetch.Fetch(["http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", "http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.1.tar.gz"], self.d)
  656. fetcher.download()
  657. self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
  658. self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.1.tar.gz"), 57892)
  659. self.d.setVar("BB_NO_NETWORK", "1")
  660. fetcher = bb.fetch.Fetch(["http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", "http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.1.tar.gz"], self.d)
  661. fetcher.download()
  662. fetcher.unpack(self.unpackdir)
  663. self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.0/")), 9)
  664. self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.1/")), 9)
  665. @skipIfNoNetwork()
  666. def test_fetch_mirror(self):
  667. self.d.setVar("MIRRORS", "http://.*/.* http://downloads.yoctoproject.org/releases/bitbake")
  668. fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
  669. fetcher.download()
  670. self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
  671. @skipIfNoNetwork()
  672. def test_fetch_mirror_of_mirror(self):
  673. self.d.setVar("MIRRORS", "http://.*/.* http://invalid2.yoctoproject.org/ \n http://invalid2.yoctoproject.org/.* http://downloads.yoctoproject.org/releases/bitbake")
  674. fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
  675. fetcher.download()
  676. self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
  677. @skipIfNoNetwork()
  678. def test_fetch_file_mirror_of_mirror(self):
  679. self.d.setVar("MIRRORS", "http://.*/.* file:///some1where/ \n file:///some1where/.* file://some2where/ \n file://some2where/.* http://downloads.yoctoproject.org/releases/bitbake")
  680. fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
  681. os.mkdir(self.dldir + "/some2where")
  682. fetcher.download()
  683. self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
  684. @skipIfNoNetwork()
  685. def test_fetch_premirror(self):
  686. self.d.setVar("PREMIRRORS", "http://.*/.* http://downloads.yoctoproject.org/releases/bitbake")
  687. fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
  688. fetcher.download()
  689. self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
  690. @skipIfNoNetwork()
  691. def gitfetcher(self, url1, url2):
  692. def checkrevision(self, fetcher):
  693. fetcher.unpack(self.unpackdir)
  694. revision = bb.process.run("git rev-parse HEAD", shell=True, cwd=self.unpackdir + "/git")[0].strip()
  695. self.assertEqual(revision, "270a05b0b4ba0959fe0624d2a4885d7b70426da5")
  696. self.d.setVar("BB_GENERATE_MIRROR_TARBALLS", "1")
  697. self.d.setVar("SRCREV", "270a05b0b4ba0959fe0624d2a4885d7b70426da5")
  698. fetcher = bb.fetch.Fetch([url1], self.d)
  699. fetcher.download()
  700. checkrevision(self, fetcher)
  701. # Wipe out the dldir clone and the unpacked source, turn off the network and check mirror tarball works
  702. bb.utils.prunedir(self.dldir + "/git2/")
  703. bb.utils.prunedir(self.unpackdir)
  704. self.d.setVar("BB_NO_NETWORK", "1")
  705. fetcher = bb.fetch.Fetch([url2], self.d)
  706. fetcher.download()
  707. checkrevision(self, fetcher)
  708. @skipIfNoNetwork()
  709. def test_gitfetch(self):
  710. url1 = url2 = "git://git.openembedded.org/bitbake"
  711. self.gitfetcher(url1, url2)
  712. @skipIfNoNetwork()
  713. def test_gitfetch_goodsrcrev(self):
  714. # SRCREV is set but matches rev= parameter
  715. url1 = url2 = "git://git.openembedded.org/bitbake;rev=270a05b0b4ba0959fe0624d2a4885d7b70426da5"
  716. self.gitfetcher(url1, url2)
  717. @skipIfNoNetwork()
  718. def test_gitfetch_badsrcrev(self):
  719. # SRCREV is set but does not match rev= parameter
  720. url1 = url2 = "git://git.openembedded.org/bitbake;rev=dead05b0b4ba0959fe0624d2a4885d7b70426da5"
  721. self.assertRaises(bb.fetch.FetchError, self.gitfetcher, url1, url2)
  722. @skipIfNoNetwork()
  723. def test_gitfetch_tagandrev(self):
  724. # SRCREV is set but does not match rev= parameter
  725. url1 = url2 = "git://git.openembedded.org/bitbake;rev=270a05b0b4ba0959fe0624d2a4885d7b70426da5;tag=270a05b0b4ba0959fe0624d2a4885d7b70426da5"
  726. self.assertRaises(bb.fetch.FetchError, self.gitfetcher, url1, url2)
  727. @skipIfNoNetwork()
  728. def test_gitfetch_localusehead(self):
  729. # Create dummy local Git repo
  730. src_dir = tempfile.mkdtemp(dir=self.tempdir,
  731. prefix='gitfetch_localusehead_')
  732. src_dir = os.path.abspath(src_dir)
  733. bb.process.run("git init", cwd=src_dir)
  734. bb.process.run("git commit --allow-empty -m'Dummy commit'",
  735. cwd=src_dir)
  736. # Use other branch than master
  737. bb.process.run("git checkout -b my-devel", cwd=src_dir)
  738. bb.process.run("git commit --allow-empty -m'Dummy commit 2'",
  739. cwd=src_dir)
  740. stdout = bb.process.run("git rev-parse HEAD", cwd=src_dir)
  741. orig_rev = stdout[0].strip()
  742. # Fetch and check revision
  743. self.d.setVar("SRCREV", "AUTOINC")
  744. url = "git://" + src_dir + ";protocol=file;usehead=1"
  745. fetcher = bb.fetch.Fetch([url], self.d)
  746. fetcher.download()
  747. fetcher.unpack(self.unpackdir)
  748. stdout = bb.process.run("git rev-parse HEAD",
  749. cwd=os.path.join(self.unpackdir, 'git'))
  750. unpack_rev = stdout[0].strip()
  751. self.assertEqual(orig_rev, unpack_rev)
  752. @skipIfNoNetwork()
  753. def test_gitfetch_remoteusehead(self):
  754. url = "git://git.openembedded.org/bitbake;usehead=1"
  755. self.assertRaises(bb.fetch.ParameterError, self.gitfetcher, url, url)
  756. @skipIfNoNetwork()
  757. def test_gitfetch_finds_local_tarball_for_mirrored_url_when_previous_downloaded_by_the_recipe_url(self):
  758. recipeurl = "git://git.openembedded.org/bitbake"
  759. mirrorurl = "git://someserver.org/bitbake"
  760. self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n")
  761. self.gitfetcher(recipeurl, mirrorurl)
  762. @skipIfNoNetwork()
  763. def test_gitfetch_finds_local_tarball_when_previous_downloaded_from_a_premirror(self):
  764. recipeurl = "git://someserver.org/bitbake"
  765. self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n")
  766. self.gitfetcher(recipeurl, recipeurl)
  767. @skipIfNoNetwork()
  768. def test_gitfetch_finds_local_repository_when_premirror_rewrites_the_recipe_url(self):
  769. realurl = "git://git.openembedded.org/bitbake"
  770. recipeurl = "git://someserver.org/bitbake"
  771. self.sourcedir = self.unpackdir.replace("unpacked", "sourcemirror.git")
  772. os.chdir(self.tempdir)
  773. bb.process.run("git clone %s %s 2> /dev/null" % (realurl, self.sourcedir), shell=True)
  774. self.d.setVar("PREMIRRORS", "%s git://%s;protocol=file \n" % (recipeurl, self.sourcedir))
  775. self.gitfetcher(recipeurl, recipeurl)
  776. @skipIfNoNetwork()
  777. def test_git_submodule(self):
  778. # URL with ssh submodules
  779. url = "gitsm://git.yoctoproject.org/git-submodule-test;branch=ssh-gitsm-tests;rev=049da4a6cb198d7c0302e9e8b243a1443cb809a7"
  780. # Original URL (comment this if you have ssh access to git.yoctoproject.org)
  781. url = "gitsm://git.yoctoproject.org/git-submodule-test;branch=master;rev=a2885dd7d25380d23627e7544b7bbb55014b16ee"
  782. fetcher = bb.fetch.Fetch([url], self.d)
  783. fetcher.download()
  784. # Previous cwd has been deleted
  785. os.chdir(os.path.dirname(self.unpackdir))
  786. fetcher.unpack(self.unpackdir)
  787. repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
  788. self.assertTrue(os.path.exists(repo_path), msg='Unpacked repository missing')
  789. self.assertTrue(os.path.exists(os.path.join(repo_path, 'bitbake')), msg='bitbake submodule missing')
  790. self.assertFalse(os.path.exists(os.path.join(repo_path, 'na')), msg='uninitialized submodule present')
  791. # Only when we're running the extended test with a submodule's submodule, can we check this.
  792. if os.path.exists(os.path.join(repo_path, 'bitbake-gitsm-test1')):
  793. self.assertTrue(os.path.exists(os.path.join(repo_path, 'bitbake-gitsm-test1', 'bitbake')), msg='submodule of submodule missing')
  794. def test_git_submodule_dbus_broker(self):
  795. # The following external repositories have show failures in fetch and unpack operations
  796. # We want to avoid regressions!
  797. url = "gitsm://github.com/bus1/dbus-broker;protocol=git;rev=fc874afa0992d0c75ec25acb43d344679f0ee7d2"
  798. fetcher = bb.fetch.Fetch([url], self.d)
  799. fetcher.download()
  800. # Previous cwd has been deleted
  801. os.chdir(os.path.dirname(self.unpackdir))
  802. fetcher.unpack(self.unpackdir)
  803. repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
  804. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-dvar/config')), msg='Missing submodule config "subprojects/c-dvar"')
  805. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-list/config')), msg='Missing submodule config "subprojects/c-list"')
  806. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-rbtree/config')), msg='Missing submodule config "subprojects/c-rbtree"')
  807. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-sundry/config')), msg='Missing submodule config "subprojects/c-sundry"')
  808. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-utf8/config')), msg='Missing submodule config "subprojects/c-utf8"')
  809. def test_git_submodule_CLI11(self):
  810. url = "gitsm://github.com/CLIUtils/CLI11;protocol=git;rev=bd4dc911847d0cde7a6b41dfa626a85aab213baf"
  811. fetcher = bb.fetch.Fetch([url], self.d)
  812. fetcher.download()
  813. # Previous cwd has been deleted
  814. os.chdir(os.path.dirname(self.unpackdir))
  815. fetcher.unpack(self.unpackdir)
  816. repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
  817. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/googletest/config')), msg='Missing submodule config "extern/googletest"')
  818. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/json/config')), msg='Missing submodule config "extern/json"')
  819. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/sanitizers/config')), msg='Missing submodule config "extern/sanitizers"')
  820. def test_git_submodule_aktualizr(self):
  821. url = "gitsm://github.com/advancedtelematic/aktualizr;branch=master;protocol=git;rev=d00d1a04cc2366d1a5f143b84b9f507f8bd32c44"
  822. fetcher = bb.fetch.Fetch([url], self.d)
  823. fetcher.download()
  824. # Previous cwd has been deleted
  825. os.chdir(os.path.dirname(self.unpackdir))
  826. fetcher.unpack(self.unpackdir)
  827. repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
  828. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/partial/extern/isotp-c/config')), msg='Missing submodule config "partial/extern/isotp-c/config"')
  829. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/partial/extern/isotp-c/modules/deps/bitfield-c/config')), msg='Missing submodule config "partial/extern/isotp-c/modules/deps/bitfield-c/config"')
  830. self.assertTrue(os.path.exists(os.path.join(repo_path, 'partial/extern/isotp-c/deps/bitfield-c/.git')), msg="Submodule of submodule isotp-c did not unpack properly")
  831. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/tests/tuf-test-vectors/config')), msg='Missing submodule config "tests/tuf-test-vectors/config"')
  832. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/third_party/googletest/config')), msg='Missing submodule config "third_party/googletest/config"')
  833. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/third_party/HdrHistogram_c/config')), msg='Missing submodule config "third_party/HdrHistogram_c/config"')
  834. class TrustedNetworksTest(FetcherTest):
  835. def test_trusted_network(self):
  836. # Ensure trusted_network returns False when the host IS in the list.
  837. url = "git://Someserver.org/foo;rev=1"
  838. self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org someserver.org server2.org server3.org")
  839. self.assertTrue(bb.fetch.trusted_network(self.d, url))
  840. def test_wild_trusted_network(self):
  841. # Ensure trusted_network returns true when the *.host IS in the list.
  842. url = "git://Someserver.org/foo;rev=1"
  843. self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
  844. self.assertTrue(bb.fetch.trusted_network(self.d, url))
  845. def test_prefix_wild_trusted_network(self):
  846. # Ensure trusted_network returns true when the prefix matches *.host.
  847. url = "git://git.Someserver.org/foo;rev=1"
  848. self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
  849. self.assertTrue(bb.fetch.trusted_network(self.d, url))
  850. def test_two_prefix_wild_trusted_network(self):
  851. # Ensure trusted_network returns true when the prefix matches *.host.
  852. url = "git://something.git.Someserver.org/foo;rev=1"
  853. self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
  854. self.assertTrue(bb.fetch.trusted_network(self.d, url))
  855. def test_port_trusted_network(self):
  856. # Ensure trusted_network returns True, even if the url specifies a port.
  857. url = "git://someserver.org:8080/foo;rev=1"
  858. self.d.setVar("BB_ALLOWED_NETWORKS", "someserver.org")
  859. self.assertTrue(bb.fetch.trusted_network(self.d, url))
  860. def test_untrusted_network(self):
  861. # Ensure trusted_network returns False when the host is NOT in the list.
  862. url = "git://someserver.org/foo;rev=1"
  863. self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org server2.org server3.org")
  864. self.assertFalse(bb.fetch.trusted_network(self.d, url))
  865. def test_wild_untrusted_network(self):
  866. # Ensure trusted_network returns False when the host is NOT in the list.
  867. url = "git://*.someserver.org/foo;rev=1"
  868. self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org server2.org server3.org")
  869. self.assertFalse(bb.fetch.trusted_network(self.d, url))
  870. class URLHandle(unittest.TestCase):
  871. datatable = {
  872. "http://www.google.com/index.html" : ('http', 'www.google.com', '/index.html', '', '', {}),
  873. "cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg" : ('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', '', {'module': 'familiar/dist/ipkg'}),
  874. "cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg" : ('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', 'anonymous', collections.OrderedDict([('tag', 'V0-99-81'), ('module', 'familiar/dist/ipkg')])),
  875. "git://git.openembedded.org/bitbake;branch=@foo" : ('git', 'git.openembedded.org', '/bitbake', '', '', {'branch': '@foo'}),
  876. "file://somelocation;someparam=1": ('file', '', 'somelocation', '', '', {'someparam': '1'}),
  877. }
  878. # we require a pathname to encodeurl but users can still pass such urls to
  879. # decodeurl and we need to handle them
  880. decodedata = datatable.copy()
  881. decodedata.update({
  882. "http://somesite.net;someparam=1": ('http', 'somesite.net', '/', '', '', {'someparam': '1'}),
  883. })
  884. def test_decodeurl(self):
  885. for k, v in self.decodedata.items():
  886. result = bb.fetch.decodeurl(k)
  887. self.assertEqual(result, v)
  888. def test_encodeurl(self):
  889. for k, v in self.datatable.items():
  890. result = bb.fetch.encodeurl(v)
  891. self.assertEqual(result, k)
  892. class FetchLatestVersionTest(FetcherTest):
  893. test_git_uris = {
  894. # version pattern "X.Y.Z"
  895. ("mx-1.0", "git://github.com/clutter-project/mx.git;branch=mx-1.4", "9b1db6b8060bd00b121a692f942404a24ae2960f", "")
  896. : "1.99.4",
  897. # version pattern "vX.Y"
  898. ("mtd-utils", "git://git.infradead.org/mtd-utils.git", "ca39eb1d98e736109c64ff9c1aa2a6ecca222d8f", "")
  899. : "1.5.0",
  900. # version pattern "pkg_name-X.Y"
  901. ("presentproto", "git://anongit.freedesktop.org/git/xorg/proto/presentproto", "24f3a56e541b0a9e6c6ee76081f441221a120ef9", "")
  902. : "1.0",
  903. # version pattern "pkg_name-vX.Y.Z"
  904. ("dtc", "git://git.qemu.org/dtc.git", "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf", "")
  905. : "1.4.0",
  906. # combination version pattern
  907. ("sysprof", "git://gitlab.gnome.org/GNOME/sysprof.git;protocol=https", "cd44ee6644c3641507fb53b8a2a69137f2971219", "")
  908. : "1.2.0",
  909. ("u-boot-mkimage", "git://git.denx.de/u-boot.git;branch=master;protocol=git", "62c175fbb8a0f9a926c88294ea9f7e88eb898f6c", "")
  910. : "2014.01",
  911. # version pattern "yyyymmdd"
  912. ("mobile-broadband-provider-info", "git://gitlab.gnome.org/GNOME/mobile-broadband-provider-info.git;protocol=https", "4ed19e11c2975105b71b956440acdb25d46a347d", "")
  913. : "20120614",
  914. # packages with a valid UPSTREAM_CHECK_GITTAGREGEX
  915. ("xf86-video-omap", "git://anongit.freedesktop.org/xorg/driver/xf86-video-omap", "ae0394e687f1a77e966cf72f895da91840dffb8f", "(?P<pver>(\d+\.(\d\.?)*))")
  916. : "0.4.3",
  917. ("build-appliance-image", "git://git.yoctoproject.org/poky", "b37dd451a52622d5b570183a81583cc34c2ff555", "(?P<pver>(([0-9][\.|_]?)+[0-9]))")
  918. : "11.0.0",
  919. ("chkconfig-alternatives-native", "git://github.com/kergoth/chkconfig;branch=sysroot", "cd437ecbd8986c894442f8fce1e0061e20f04dee", "chkconfig\-(?P<pver>((\d+[\.\-_]*)+))")
  920. : "1.3.59",
  921. ("remake", "git://github.com/rocky/remake.git", "f05508e521987c8494c92d9c2871aec46307d51d", "(?P<pver>(\d+\.(\d+\.)*\d*(\+dbg\d+(\.\d+)*)*))")
  922. : "3.82+dbg0.9",
  923. }
  924. test_wget_uris = {
  925. # packages with versions inside directory name
  926. ("util-linux", "http://kernel.org/pub/linux/utils/util-linux/v2.23/util-linux-2.24.2.tar.bz2", "", "")
  927. : "2.24.2",
  928. ("enchant", "http://www.abisource.com/downloads/enchant/1.6.0/enchant-1.6.0.tar.gz", "", "")
  929. : "1.6.0",
  930. ("cmake", "http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz", "", "")
  931. : "2.8.12.1",
  932. # packages with versions only in current directory
  933. ("eglic", "http://downloads.yoctoproject.org/releases/eglibc/eglibc-2.18-svnr23787.tar.bz2", "", "")
  934. : "2.19",
  935. ("gnu-config", "http://downloads.yoctoproject.org/releases/gnu-config/gnu-config-20120814.tar.bz2", "", "")
  936. : "20120814",
  937. # packages with "99" in the name of possible version
  938. ("pulseaudio", "http://freedesktop.org/software/pulseaudio/releases/pulseaudio-4.0.tar.xz", "", "")
  939. : "5.0",
  940. ("xserver-xorg", "http://xorg.freedesktop.org/releases/individual/xserver/xorg-server-1.15.1.tar.bz2", "", "")
  941. : "1.15.1",
  942. # packages with valid UPSTREAM_CHECK_URI and UPSTREAM_CHECK_REGEX
  943. ("cups", "http://www.cups.org/software/1.7.2/cups-1.7.2-source.tar.bz2", "https://github.com/apple/cups/releases", "(?P<name>cups\-)(?P<pver>((\d+[\.\-_]*)+))\-source\.tar\.gz")
  944. : "2.0.0",
  945. ("db", "http://download.oracle.com/berkeley-db/db-5.3.21.tar.gz", "http://www.oracle.com/technetwork/products/berkeleydb/downloads/index-082944.html", "http://download.oracle.com/otn/berkeley-db/(?P<name>db-)(?P<pver>((\d+[\.\-_]*)+))\.tar\.gz")
  946. : "6.1.19",
  947. }
  948. @skipIfNoNetwork()
  949. def test_git_latest_versionstring(self):
  950. for k, v in self.test_git_uris.items():
  951. self.d.setVar("PN", k[0])
  952. self.d.setVar("SRCREV", k[2])
  953. self.d.setVar("UPSTREAM_CHECK_GITTAGREGEX", k[3])
  954. ud = bb.fetch2.FetchData(k[1], self.d)
  955. pupver= ud.method.latest_versionstring(ud, self.d)
  956. verstring = pupver[0]
  957. self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0])
  958. r = bb.utils.vercmp_string(v, verstring)
  959. self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring))
  960. @skipIfNoNetwork()
  961. def test_wget_latest_versionstring(self):
  962. for k, v in self.test_wget_uris.items():
  963. self.d.setVar("PN", k[0])
  964. self.d.setVar("UPSTREAM_CHECK_URI", k[2])
  965. self.d.setVar("UPSTREAM_CHECK_REGEX", k[3])
  966. ud = bb.fetch2.FetchData(k[1], self.d)
  967. pupver = ud.method.latest_versionstring(ud, self.d)
  968. verstring = pupver[0]
  969. self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0])
  970. r = bb.utils.vercmp_string(v, verstring)
  971. self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring))
  972. class FetchCheckStatusTest(FetcherTest):
  973. test_wget_uris = ["http://www.cups.org/software/1.7.2/cups-1.7.2-source.tar.bz2",
  974. "http://www.cups.org/",
  975. "http://downloads.yoctoproject.org/releases/sato/sato-engine-0.1.tar.gz",
  976. "http://downloads.yoctoproject.org/releases/sato/sato-engine-0.2.tar.gz",
  977. "http://downloads.yoctoproject.org/releases/sato/sato-engine-0.3.tar.gz",
  978. "https://yoctoproject.org/",
  979. "https://yoctoproject.org/documentation",
  980. "http://downloads.yoctoproject.org/releases/opkg/opkg-0.1.7.tar.gz",
  981. "http://downloads.yoctoproject.org/releases/opkg/opkg-0.3.0.tar.gz",
  982. "ftp://sourceware.org/pub/libffi/libffi-1.20.tar.gz",
  983. "http://ftp.gnu.org/gnu/autoconf/autoconf-2.60.tar.gz",
  984. "https://ftp.gnu.org/gnu/chess/gnuchess-5.08.tar.gz",
  985. "https://ftp.gnu.org/gnu/gmp/gmp-4.0.tar.gz",
  986. # GitHub releases are hosted on Amazon S3, which doesn't support HEAD
  987. "https://github.com/kergoth/tslib/releases/download/1.1/tslib-1.1.tar.xz"
  988. ]
  989. @skipIfNoNetwork()
  990. def test_wget_checkstatus(self):
  991. fetch = bb.fetch2.Fetch(self.test_wget_uris, self.d)
  992. for u in self.test_wget_uris:
  993. with self.subTest(url=u):
  994. ud = fetch.ud[u]
  995. m = ud.method
  996. ret = m.checkstatus(fetch, ud, self.d)
  997. self.assertTrue(ret, msg="URI %s, can't check status" % (u))
  998. @skipIfNoNetwork()
  999. def test_wget_checkstatus_connection_cache(self):
  1000. from bb.fetch2 import FetchConnectionCache
  1001. connection_cache = FetchConnectionCache()
  1002. fetch = bb.fetch2.Fetch(self.test_wget_uris, self.d,
  1003. connection_cache = connection_cache)
  1004. for u in self.test_wget_uris:
  1005. with self.subTest(url=u):
  1006. ud = fetch.ud[u]
  1007. m = ud.method
  1008. ret = m.checkstatus(fetch, ud, self.d)
  1009. self.assertTrue(ret, msg="URI %s, can't check status" % (u))
  1010. connection_cache.close_connections()
  1011. class GitMakeShallowTest(FetcherTest):
  1012. def setUp(self):
  1013. FetcherTest.setUp(self)
  1014. self.gitdir = os.path.join(self.tempdir, 'gitshallow')
  1015. bb.utils.mkdirhier(self.gitdir)
  1016. bb.process.run('git init', cwd=self.gitdir)
  1017. def assertRefs(self, expected_refs):
  1018. actual_refs = self.git(['for-each-ref', '--format=%(refname)']).splitlines()
  1019. full_expected = self.git(['rev-parse', '--symbolic-full-name'] + expected_refs).splitlines()
  1020. self.assertEqual(sorted(full_expected), sorted(actual_refs))
  1021. def assertRevCount(self, expected_count, args=None):
  1022. if args is None:
  1023. args = ['HEAD']
  1024. revs = self.git(['rev-list'] + args)
  1025. actual_count = len(revs.splitlines())
  1026. self.assertEqual(expected_count, actual_count, msg='Object count `%d` is not the expected `%d`' % (actual_count, expected_count))
  1027. def git(self, cmd):
  1028. if isinstance(cmd, str):
  1029. cmd = 'git ' + cmd
  1030. else:
  1031. cmd = ['git'] + cmd
  1032. return bb.process.run(cmd, cwd=self.gitdir)[0]
  1033. def make_shallow(self, args=None):
  1034. if args is None:
  1035. args = ['HEAD']
  1036. return bb.process.run([bb.fetch2.git.Git.make_shallow_path] + args, cwd=self.gitdir)
  1037. def add_empty_file(self, path, msg=None):
  1038. if msg is None:
  1039. msg = path
  1040. open(os.path.join(self.gitdir, path), 'w').close()
  1041. self.git(['add', path])
  1042. self.git(['commit', '-m', msg, path])
  1043. def test_make_shallow_single_branch_no_merge(self):
  1044. self.add_empty_file('a')
  1045. self.add_empty_file('b')
  1046. self.assertRevCount(2)
  1047. self.make_shallow()
  1048. self.assertRevCount(1)
  1049. def test_make_shallow_single_branch_one_merge(self):
  1050. self.add_empty_file('a')
  1051. self.add_empty_file('b')
  1052. self.git('checkout -b a_branch')
  1053. self.add_empty_file('c')
  1054. self.git('checkout master')
  1055. self.add_empty_file('d')
  1056. self.git('merge --no-ff --no-edit a_branch')
  1057. self.git('branch -d a_branch')
  1058. self.add_empty_file('e')
  1059. self.assertRevCount(6)
  1060. self.make_shallow(['HEAD~2'])
  1061. self.assertRevCount(5)
  1062. def test_make_shallow_at_merge(self):
  1063. self.add_empty_file('a')
  1064. self.git('checkout -b a_branch')
  1065. self.add_empty_file('b')
  1066. self.git('checkout master')
  1067. self.git('merge --no-ff --no-edit a_branch')
  1068. self.git('branch -d a_branch')
  1069. self.assertRevCount(3)
  1070. self.make_shallow()
  1071. self.assertRevCount(1)
  1072. def test_make_shallow_annotated_tag(self):
  1073. self.add_empty_file('a')
  1074. self.add_empty_file('b')
  1075. self.git('tag -a -m a_tag a_tag')
  1076. self.assertRevCount(2)
  1077. self.make_shallow(['a_tag'])
  1078. self.assertRevCount(1)
  1079. def test_make_shallow_multi_ref(self):
  1080. self.add_empty_file('a')
  1081. self.add_empty_file('b')
  1082. self.git('checkout -b a_branch')
  1083. self.add_empty_file('c')
  1084. self.git('checkout master')
  1085. self.add_empty_file('d')
  1086. self.git('checkout -b a_branch_2')
  1087. self.add_empty_file('a_tag')
  1088. self.git('tag a_tag')
  1089. self.git('checkout master')
  1090. self.git('branch -D a_branch_2')
  1091. self.add_empty_file('e')
  1092. self.assertRevCount(6, ['--all'])
  1093. self.make_shallow()
  1094. self.assertRevCount(5, ['--all'])
  1095. def test_make_shallow_multi_ref_trim(self):
  1096. self.add_empty_file('a')
  1097. self.git('checkout -b a_branch')
  1098. self.add_empty_file('c')
  1099. self.git('checkout master')
  1100. self.assertRevCount(1)
  1101. self.assertRevCount(2, ['--all'])
  1102. self.assertRefs(['master', 'a_branch'])
  1103. self.make_shallow(['-r', 'master', 'HEAD'])
  1104. self.assertRevCount(1, ['--all'])
  1105. self.assertRefs(['master'])
  1106. def test_make_shallow_noop(self):
  1107. self.add_empty_file('a')
  1108. self.assertRevCount(1)
  1109. self.make_shallow()
  1110. self.assertRevCount(1)
  1111. @skipIfNoNetwork()
  1112. def test_make_shallow_bitbake(self):
  1113. self.git('remote add origin https://github.com/openembedded/bitbake')
  1114. self.git('fetch --tags origin')
  1115. orig_revs = len(self.git('rev-list --all').splitlines())
  1116. self.make_shallow(['refs/tags/1.10.0'])
  1117. self.assertRevCount(orig_revs - 1746, ['--all'])
  1118. class GitShallowTest(FetcherTest):
  1119. def setUp(self):
  1120. FetcherTest.setUp(self)
  1121. self.gitdir = os.path.join(self.tempdir, 'git')
  1122. self.srcdir = os.path.join(self.tempdir, 'gitsource')
  1123. bb.utils.mkdirhier(self.srcdir)
  1124. self.git('init', cwd=self.srcdir)
  1125. self.d.setVar('WORKDIR', self.tempdir)
  1126. self.d.setVar('S', self.gitdir)
  1127. self.d.delVar('PREMIRRORS')
  1128. self.d.delVar('MIRRORS')
  1129. uri = 'git://%s;protocol=file;subdir=${S}' % self.srcdir
  1130. self.d.setVar('SRC_URI', uri)
  1131. self.d.setVar('SRCREV', '${AUTOREV}')
  1132. self.d.setVar('AUTOREV', '${@bb.fetch2.get_autorev(d)}')
  1133. self.d.setVar('BB_GIT_SHALLOW', '1')
  1134. self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '0')
  1135. self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1')
  1136. def assertRefs(self, expected_refs, cwd=None):
  1137. if cwd is None:
  1138. cwd = self.gitdir
  1139. actual_refs = self.git(['for-each-ref', '--format=%(refname)'], cwd=cwd).splitlines()
  1140. full_expected = self.git(['rev-parse', '--symbolic-full-name'] + expected_refs, cwd=cwd).splitlines()
  1141. self.assertEqual(sorted(set(full_expected)), sorted(set(actual_refs)))
  1142. def assertRevCount(self, expected_count, args=None, cwd=None):
  1143. if args is None:
  1144. args = ['HEAD']
  1145. if cwd is None:
  1146. cwd = self.gitdir
  1147. revs = self.git(['rev-list'] + args, cwd=cwd)
  1148. actual_count = len(revs.splitlines())
  1149. self.assertEqual(expected_count, actual_count, msg='Object count `%d` is not the expected `%d`' % (actual_count, expected_count))
  1150. def git(self, cmd, cwd=None):
  1151. if isinstance(cmd, str):
  1152. cmd = 'git ' + cmd
  1153. else:
  1154. cmd = ['git'] + cmd
  1155. if cwd is None:
  1156. cwd = self.gitdir
  1157. return bb.process.run(cmd, cwd=cwd)[0]
  1158. def add_empty_file(self, path, cwd=None, msg=None):
  1159. if msg is None:
  1160. msg = path
  1161. if cwd is None:
  1162. cwd = self.srcdir
  1163. open(os.path.join(cwd, path), 'w').close()
  1164. self.git(['add', path], cwd)
  1165. self.git(['commit', '-m', msg, path], cwd)
  1166. def fetch(self, uri=None):
  1167. if uri is None:
  1168. uris = self.d.getVar('SRC_URI').split()
  1169. uri = uris[0]
  1170. d = self.d
  1171. else:
  1172. d = self.d.createCopy()
  1173. d.setVar('SRC_URI', uri)
  1174. uri = d.expand(uri)
  1175. uris = [uri]
  1176. fetcher = bb.fetch2.Fetch(uris, d)
  1177. fetcher.download()
  1178. ud = fetcher.ud[uri]
  1179. return fetcher, ud
  1180. def fetch_and_unpack(self, uri=None):
  1181. fetcher, ud = self.fetch(uri)
  1182. fetcher.unpack(self.d.getVar('WORKDIR'))
  1183. assert os.path.exists(self.d.getVar('S'))
  1184. return fetcher, ud
  1185. def fetch_shallow(self, uri=None, disabled=False, keepclone=False):
  1186. """Fetch a uri, generating a shallow tarball, then unpack using it"""
  1187. fetcher, ud = self.fetch_and_unpack(uri)
  1188. assert os.path.exists(ud.clonedir), 'Git clone in DLDIR (%s) does not exist for uri %s' % (ud.clonedir, uri)
  1189. # Confirm that the unpacked repo is unshallow
  1190. if not disabled:
  1191. assert os.path.exists(os.path.join(self.dldir, ud.mirrortarballs[0]))
  1192. # fetch and unpack, from the shallow tarball
  1193. bb.utils.remove(self.gitdir, recurse=True)
  1194. bb.utils.remove(ud.clonedir, recurse=True)
  1195. bb.utils.remove(ud.clonedir.replace('gitsource', 'gitsubmodule'), recurse=True)
  1196. # confirm that the unpacked repo is used when no git clone or git
  1197. # mirror tarball is available
  1198. fetcher, ud = self.fetch_and_unpack(uri)
  1199. if not disabled:
  1200. assert os.path.exists(os.path.join(self.gitdir, '.git', 'shallow')), 'Unpacked git repository at %s is not shallow' % self.gitdir
  1201. else:
  1202. assert not os.path.exists(os.path.join(self.gitdir, '.git', 'shallow')), 'Unpacked git repository at %s is shallow' % self.gitdir
  1203. return fetcher, ud
  1204. def test_shallow_disabled(self):
  1205. self.add_empty_file('a')
  1206. self.add_empty_file('b')
  1207. self.assertRevCount(2, cwd=self.srcdir)
  1208. self.d.setVar('BB_GIT_SHALLOW', '0')
  1209. self.fetch_shallow(disabled=True)
  1210. self.assertRevCount(2)
  1211. def test_shallow_nobranch(self):
  1212. self.add_empty_file('a')
  1213. self.add_empty_file('b')
  1214. self.assertRevCount(2, cwd=self.srcdir)
  1215. srcrev = self.git('rev-parse HEAD', cwd=self.srcdir).strip()
  1216. self.d.setVar('SRCREV', srcrev)
  1217. uri = self.d.getVar('SRC_URI').split()[0]
  1218. uri = '%s;nobranch=1;bare=1' % uri
  1219. self.fetch_shallow(uri)
  1220. self.assertRevCount(1)
  1221. # shallow refs are used to ensure the srcrev sticks around when we
  1222. # have no other branches referencing it
  1223. self.assertRefs(['refs/shallow/default'])
  1224. def test_shallow_default_depth_1(self):
  1225. # Create initial git repo
  1226. self.add_empty_file('a')
  1227. self.add_empty_file('b')
  1228. self.assertRevCount(2, cwd=self.srcdir)
  1229. self.fetch_shallow()
  1230. self.assertRevCount(1)
  1231. def test_shallow_depth_0_disables(self):
  1232. self.add_empty_file('a')
  1233. self.add_empty_file('b')
  1234. self.assertRevCount(2, cwd=self.srcdir)
  1235. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
  1236. self.fetch_shallow(disabled=True)
  1237. self.assertRevCount(2)
  1238. def test_shallow_depth_default_override(self):
  1239. self.add_empty_file('a')
  1240. self.add_empty_file('b')
  1241. self.assertRevCount(2, cwd=self.srcdir)
  1242. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '2')
  1243. self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '1')
  1244. self.fetch_shallow()
  1245. self.assertRevCount(1)
  1246. def test_shallow_depth_default_override_disable(self):
  1247. self.add_empty_file('a')
  1248. self.add_empty_file('b')
  1249. self.add_empty_file('c')
  1250. self.assertRevCount(3, cwd=self.srcdir)
  1251. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
  1252. self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '2')
  1253. self.fetch_shallow()
  1254. self.assertRevCount(2)
  1255. def test_current_shallow_out_of_date_clone(self):
  1256. # Create initial git repo
  1257. self.add_empty_file('a')
  1258. self.add_empty_file('b')
  1259. self.add_empty_file('c')
  1260. self.assertRevCount(3, cwd=self.srcdir)
  1261. # Clone and generate mirror tarball
  1262. fetcher, ud = self.fetch()
  1263. # Ensure we have a current mirror tarball, but an out of date clone
  1264. self.git('update-ref refs/heads/master refs/heads/master~1', cwd=ud.clonedir)
  1265. self.assertRevCount(2, cwd=ud.clonedir)
  1266. # Fetch and unpack, from the current tarball, not the out of date clone
  1267. bb.utils.remove(self.gitdir, recurse=True)
  1268. fetcher, ud = self.fetch()
  1269. fetcher.unpack(self.d.getVar('WORKDIR'))
  1270. self.assertRevCount(1)
  1271. def test_shallow_single_branch_no_merge(self):
  1272. self.add_empty_file('a')
  1273. self.add_empty_file('b')
  1274. self.assertRevCount(2, cwd=self.srcdir)
  1275. self.fetch_shallow()
  1276. self.assertRevCount(1)
  1277. assert os.path.exists(os.path.join(self.gitdir, 'a'))
  1278. assert os.path.exists(os.path.join(self.gitdir, 'b'))
  1279. def test_shallow_no_dangling(self):
  1280. self.add_empty_file('a')
  1281. self.add_empty_file('b')
  1282. self.assertRevCount(2, cwd=self.srcdir)
  1283. self.fetch_shallow()
  1284. self.assertRevCount(1)
  1285. assert not self.git('fsck --dangling')
  1286. def test_shallow_srcrev_branch_truncation(self):
  1287. self.add_empty_file('a')
  1288. self.add_empty_file('b')
  1289. b_commit = self.git('rev-parse HEAD', cwd=self.srcdir).rstrip()
  1290. self.add_empty_file('c')
  1291. self.assertRevCount(3, cwd=self.srcdir)
  1292. self.d.setVar('SRCREV', b_commit)
  1293. self.fetch_shallow()
  1294. # The 'c' commit was removed entirely, and 'a' was removed from history
  1295. self.assertRevCount(1, ['--all'])
  1296. self.assertEqual(self.git('rev-parse HEAD').strip(), b_commit)
  1297. assert os.path.exists(os.path.join(self.gitdir, 'a'))
  1298. assert os.path.exists(os.path.join(self.gitdir, 'b'))
  1299. assert not os.path.exists(os.path.join(self.gitdir, 'c'))
  1300. def test_shallow_ref_pruning(self):
  1301. self.add_empty_file('a')
  1302. self.add_empty_file('b')
  1303. self.git('branch a_branch', cwd=self.srcdir)
  1304. self.assertRefs(['master', 'a_branch'], cwd=self.srcdir)
  1305. self.assertRevCount(2, cwd=self.srcdir)
  1306. self.fetch_shallow()
  1307. self.assertRefs(['master', 'origin/master'])
  1308. self.assertRevCount(1)
  1309. def test_shallow_submodules(self):
  1310. self.add_empty_file('a')
  1311. self.add_empty_file('b')
  1312. smdir = os.path.join(self.tempdir, 'gitsubmodule')
  1313. bb.utils.mkdirhier(smdir)
  1314. self.git('init', cwd=smdir)
  1315. # Make this look like it was cloned from a remote...
  1316. self.git('config --add remote.origin.url "%s"' % smdir, cwd=smdir)
  1317. self.git('config --add remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"', cwd=smdir)
  1318. self.add_empty_file('asub', cwd=smdir)
  1319. self.add_empty_file('bsub', cwd=smdir)
  1320. self.git('submodule init', cwd=self.srcdir)
  1321. self.git('submodule add file://%s' % smdir, cwd=self.srcdir)
  1322. self.git('submodule update', cwd=self.srcdir)
  1323. self.git('commit -m submodule -a', cwd=self.srcdir)
  1324. uri = 'gitsm://%s;protocol=file;subdir=${S}' % self.srcdir
  1325. fetcher, ud = self.fetch_shallow(uri)
  1326. # Verify the main repository is shallow
  1327. self.assertRevCount(1)
  1328. # Verify the gitsubmodule directory is present
  1329. assert os.listdir(os.path.join(self.gitdir, 'gitsubmodule'))
  1330. # Verify the submodule is also shallow
  1331. self.assertRevCount(1, cwd=os.path.join(self.gitdir, 'gitsubmodule'))
  1332. if any(os.path.exists(os.path.join(p, 'git-annex')) for p in os.environ.get('PATH').split(':')):
  1333. def test_shallow_annex(self):
  1334. self.add_empty_file('a')
  1335. self.add_empty_file('b')
  1336. self.git('annex init', cwd=self.srcdir)
  1337. open(os.path.join(self.srcdir, 'c'), 'w').close()
  1338. self.git('annex add c', cwd=self.srcdir)
  1339. self.git('commit -m annex-c -a', cwd=self.srcdir)
  1340. bb.process.run('chmod u+w -R %s' % os.path.join(self.srcdir, '.git', 'annex'))
  1341. uri = 'gitannex://%s;protocol=file;subdir=${S}' % self.srcdir
  1342. fetcher, ud = self.fetch_shallow(uri)
  1343. self.assertRevCount(1)
  1344. assert './.git/annex/' in bb.process.run('tar -tzf %s' % os.path.join(self.dldir, ud.mirrortarballs[0]))[0]
  1345. assert os.path.exists(os.path.join(self.gitdir, 'c'))
  1346. def test_shallow_multi_one_uri(self):
  1347. # Create initial git repo
  1348. self.add_empty_file('a')
  1349. self.add_empty_file('b')
  1350. self.git('checkout -b a_branch', cwd=self.srcdir)
  1351. self.add_empty_file('c')
  1352. self.add_empty_file('d')
  1353. self.git('checkout master', cwd=self.srcdir)
  1354. self.git('tag v0.0 a_branch', cwd=self.srcdir)
  1355. self.add_empty_file('e')
  1356. self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir)
  1357. self.add_empty_file('f')
  1358. self.assertRevCount(7, cwd=self.srcdir)
  1359. uri = self.d.getVar('SRC_URI').split()[0]
  1360. uri = '%s;branch=master,a_branch;name=master,a_branch' % uri
  1361. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
  1362. self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
  1363. self.d.setVar('SRCREV_master', '${AUTOREV}')
  1364. self.d.setVar('SRCREV_a_branch', '${AUTOREV}')
  1365. self.fetch_shallow(uri)
  1366. self.assertRevCount(5)
  1367. self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
  1368. def test_shallow_multi_one_uri_depths(self):
  1369. # Create initial git repo
  1370. self.add_empty_file('a')
  1371. self.add_empty_file('b')
  1372. self.git('checkout -b a_branch', cwd=self.srcdir)
  1373. self.add_empty_file('c')
  1374. self.add_empty_file('d')
  1375. self.git('checkout master', cwd=self.srcdir)
  1376. self.add_empty_file('e')
  1377. self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir)
  1378. self.add_empty_file('f')
  1379. self.assertRevCount(7, cwd=self.srcdir)
  1380. uri = self.d.getVar('SRC_URI').split()[0]
  1381. uri = '%s;branch=master,a_branch;name=master,a_branch' % uri
  1382. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
  1383. self.d.setVar('BB_GIT_SHALLOW_DEPTH_master', '3')
  1384. self.d.setVar('BB_GIT_SHALLOW_DEPTH_a_branch', '1')
  1385. self.d.setVar('SRCREV_master', '${AUTOREV}')
  1386. self.d.setVar('SRCREV_a_branch', '${AUTOREV}')
  1387. self.fetch_shallow(uri)
  1388. self.assertRevCount(4, ['--all'])
  1389. self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
  1390. def test_shallow_clone_preferred_over_shallow(self):
  1391. self.add_empty_file('a')
  1392. self.add_empty_file('b')
  1393. # Fetch once to generate the shallow tarball
  1394. fetcher, ud = self.fetch()
  1395. assert os.path.exists(os.path.join(self.dldir, ud.mirrortarballs[0]))
  1396. # Fetch and unpack with both the clonedir and shallow tarball available
  1397. bb.utils.remove(self.gitdir, recurse=True)
  1398. fetcher, ud = self.fetch_and_unpack()
  1399. # The unpacked tree should *not* be shallow
  1400. self.assertRevCount(2)
  1401. assert not os.path.exists(os.path.join(self.gitdir, '.git', 'shallow'))
  1402. def test_shallow_mirrors(self):
  1403. self.add_empty_file('a')
  1404. self.add_empty_file('b')
  1405. # Fetch once to generate the shallow tarball
  1406. fetcher, ud = self.fetch()
  1407. mirrortarball = ud.mirrortarballs[0]
  1408. assert os.path.exists(os.path.join(self.dldir, mirrortarball))
  1409. # Set up the mirror
  1410. mirrordir = os.path.join(self.tempdir, 'mirror')
  1411. bb.utils.mkdirhier(mirrordir)
  1412. self.d.setVar('PREMIRRORS', 'git://.*/.* file://%s/\n' % mirrordir)
  1413. os.rename(os.path.join(self.dldir, mirrortarball),
  1414. os.path.join(mirrordir, mirrortarball))
  1415. # Fetch from the mirror
  1416. bb.utils.remove(self.dldir, recurse=True)
  1417. bb.utils.remove(self.gitdir, recurse=True)
  1418. self.fetch_and_unpack()
  1419. self.assertRevCount(1)
  1420. def test_shallow_invalid_depth(self):
  1421. self.add_empty_file('a')
  1422. self.add_empty_file('b')
  1423. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '-12')
  1424. with self.assertRaises(bb.fetch2.FetchError):
  1425. self.fetch()
  1426. def test_shallow_invalid_depth_default(self):
  1427. self.add_empty_file('a')
  1428. self.add_empty_file('b')
  1429. self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '-12')
  1430. with self.assertRaises(bb.fetch2.FetchError):
  1431. self.fetch()
  1432. def test_shallow_extra_refs(self):
  1433. self.add_empty_file('a')
  1434. self.add_empty_file('b')
  1435. self.git('branch a_branch', cwd=self.srcdir)
  1436. self.assertRefs(['master', 'a_branch'], cwd=self.srcdir)
  1437. self.assertRevCount(2, cwd=self.srcdir)
  1438. self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/heads/a_branch')
  1439. self.fetch_shallow()
  1440. self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
  1441. self.assertRevCount(1)
  1442. def test_shallow_extra_refs_wildcard(self):
  1443. self.add_empty_file('a')
  1444. self.add_empty_file('b')
  1445. self.git('branch a_branch', cwd=self.srcdir)
  1446. self.git('tag v1.0', cwd=self.srcdir)
  1447. self.assertRefs(['master', 'a_branch', 'v1.0'], cwd=self.srcdir)
  1448. self.assertRevCount(2, cwd=self.srcdir)
  1449. self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/tags/*')
  1450. self.fetch_shallow()
  1451. self.assertRefs(['master', 'origin/master', 'v1.0'])
  1452. self.assertRevCount(1)
  1453. def test_shallow_missing_extra_refs(self):
  1454. self.add_empty_file('a')
  1455. self.add_empty_file('b')
  1456. self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/heads/foo')
  1457. with self.assertRaises(bb.fetch2.FetchError):
  1458. self.fetch()
  1459. def test_shallow_missing_extra_refs_wildcard(self):
  1460. self.add_empty_file('a')
  1461. self.add_empty_file('b')
  1462. self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/tags/*')
  1463. self.fetch()
  1464. def test_shallow_remove_revs(self):
  1465. # Create initial git repo
  1466. self.add_empty_file('a')
  1467. self.add_empty_file('b')
  1468. self.git('checkout -b a_branch', cwd=self.srcdir)
  1469. self.add_empty_file('c')
  1470. self.add_empty_file('d')
  1471. self.git('checkout master', cwd=self.srcdir)
  1472. self.git('tag v0.0 a_branch', cwd=self.srcdir)
  1473. self.add_empty_file('e')
  1474. self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir)
  1475. self.git('branch -d a_branch', cwd=self.srcdir)
  1476. self.add_empty_file('f')
  1477. self.assertRevCount(7, cwd=self.srcdir)
  1478. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
  1479. self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
  1480. self.fetch_shallow()
  1481. self.assertRevCount(5)
  1482. def test_shallow_invalid_revs(self):
  1483. self.add_empty_file('a')
  1484. self.add_empty_file('b')
  1485. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
  1486. self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
  1487. with self.assertRaises(bb.fetch2.FetchError):
  1488. self.fetch()
  1489. @skipIfNoNetwork()
  1490. def test_bitbake(self):
  1491. self.git('remote add --mirror=fetch origin git://github.com/openembedded/bitbake', cwd=self.srcdir)
  1492. self.git('config core.bare true', cwd=self.srcdir)
  1493. self.git('fetch', cwd=self.srcdir)
  1494. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
  1495. # Note that the 1.10.0 tag is annotated, so this also tests
  1496. # reference of an annotated vs unannotated tag
  1497. self.d.setVar('BB_GIT_SHALLOW_REVS', '1.10.0')
  1498. self.fetch_shallow()
  1499. # Confirm that the history of 1.10.0 was removed
  1500. orig_revs = len(self.git('rev-list master', cwd=self.srcdir).splitlines())
  1501. revs = len(self.git('rev-list master').splitlines())
  1502. self.assertNotEqual(orig_revs, revs)
  1503. self.assertRefs(['master', 'origin/master'])
  1504. self.assertRevCount(orig_revs - 1758)
  1505. def test_that_unpack_throws_an_error_when_the_git_clone_nor_shallow_tarball_exist(self):
  1506. self.add_empty_file('a')
  1507. fetcher, ud = self.fetch()
  1508. bb.utils.remove(self.gitdir, recurse=True)
  1509. bb.utils.remove(self.dldir, recurse=True)
  1510. with self.assertRaises(bb.fetch2.UnpackError) as context:
  1511. fetcher.unpack(self.d.getVar('WORKDIR'))
  1512. self.assertIn("No up to date source found", context.exception.msg)
  1513. self.assertIn("clone directory not available or not up to date", context.exception.msg)
  1514. @skipIfNoNetwork()
  1515. def test_that_unpack_does_work_when_using_git_shallow_tarball_but_tarball_is_not_available(self):
  1516. self.d.setVar('SRCREV', 'e5939ff608b95cdd4d0ab0e1935781ab9a276ac0')
  1517. self.d.setVar('BB_GIT_SHALLOW', '1')
  1518. self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1')
  1519. fetcher = bb.fetch.Fetch(["git://git.yoctoproject.org/fstests"], self.d)
  1520. fetcher.download()
  1521. bb.utils.remove(self.dldir + "/*.tar.gz")
  1522. fetcher.unpack(self.unpackdir)
  1523. dir = os.listdir(self.unpackdir + "/git/")
  1524. self.assertIn("fstests.doap", dir)