fetch.py 80 KB

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