fetch.py 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838
  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_update_CLI11(self):
  821. """ Prevent regression on update detection not finding missing submodule, or modules without needed commits """
  822. url = "gitsm://github.com/CLIUtils/CLI11;protocol=git;rev=cf6a99fa69aaefe477cc52e3ef4a7d2d7fa40714"
  823. fetcher = bb.fetch.Fetch([url], self.d)
  824. fetcher.download()
  825. # CLI11 that pulls in a newer nlohmann-json
  826. url = "gitsm://github.com/CLIUtils/CLI11;protocol=git;rev=49ac989a9527ee9bb496de9ded7b4872c2e0e5ca"
  827. fetcher = bb.fetch.Fetch([url], self.d)
  828. fetcher.download()
  829. # Previous cwd has been deleted
  830. os.chdir(os.path.dirname(self.unpackdir))
  831. fetcher.unpack(self.unpackdir)
  832. repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
  833. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/googletest/config')), msg='Missing submodule config "extern/googletest"')
  834. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/json/config')), msg='Missing submodule config "extern/json"')
  835. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/sanitizers/config')), msg='Missing submodule config "extern/sanitizers"')
  836. def test_git_submodule_aktualizr(self):
  837. url = "gitsm://github.com/advancedtelematic/aktualizr;branch=master;protocol=git;rev=d00d1a04cc2366d1a5f143b84b9f507f8bd32c44"
  838. fetcher = bb.fetch.Fetch([url], self.d)
  839. fetcher.download()
  840. # Previous cwd has been deleted
  841. os.chdir(os.path.dirname(self.unpackdir))
  842. fetcher.unpack(self.unpackdir)
  843. repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
  844. 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"')
  845. 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"')
  846. 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")
  847. 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"')
  848. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/third_party/googletest/config')), msg='Missing submodule config "third_party/googletest/config"')
  849. 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"')
  850. def test_git_submodule_iotedge(self):
  851. """ Prevent regression on deeply nested submodules not being checked out properly, even though they were fetched. """
  852. # This repository also has submodules where the module (name), path and url do not align
  853. url = "gitsm://github.com/azure/iotedge.git;protocol=git;rev=d76e0316c6f324345d77c48a83ce836d09392699"
  854. fetcher = bb.fetch.Fetch([url], self.d)
  855. fetcher.download()
  856. # Previous cwd has been deleted
  857. os.chdir(os.path.dirname(self.unpackdir))
  858. fetcher.unpack(self.unpackdir)
  859. repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
  860. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/c-shared/README.md')), msg='Missing submodule checkout')
  861. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/c-shared/testtools/ctest/README.md')), msg='Missing submodule checkout')
  862. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/c-shared/testtools/testrunner/readme.md')), msg='Missing submodule checkout')
  863. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/c-shared/testtools/umock-c/readme.md')), msg='Missing submodule checkout')
  864. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/c-shared/testtools/umock-c/deps/ctest/README.md')), msg='Missing submodule checkout')
  865. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/c-shared/testtools/umock-c/deps/testrunner/readme.md')), msg='Missing submodule checkout')
  866. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/README.md')), msg='Missing submodule checkout')
  867. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/deps/c-utility/README.md')), msg='Missing submodule checkout')
  868. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/deps/c-utility/testtools/ctest/README.md')), msg='Missing submodule checkout')
  869. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/deps/c-utility/testtools/testrunner/readme.md')), msg='Missing submodule checkout')
  870. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/deps/c-utility/testtools/umock-c/readme.md')), msg='Missing submodule checkout')
  871. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/deps/c-utility/testtools/umock-c/deps/ctest/README.md')), msg='Missing submodule checkout')
  872. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/deps/c-utility/testtools/umock-c/deps/testrunner/readme.md')), msg='Missing submodule checkout')
  873. class TrustedNetworksTest(FetcherTest):
  874. def test_trusted_network(self):
  875. # Ensure trusted_network returns False when the host IS in the list.
  876. url = "git://Someserver.org/foo;rev=1"
  877. self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org someserver.org server2.org server3.org")
  878. self.assertTrue(bb.fetch.trusted_network(self.d, url))
  879. def test_wild_trusted_network(self):
  880. # Ensure trusted_network returns true when the *.host IS in the list.
  881. url = "git://Someserver.org/foo;rev=1"
  882. self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
  883. self.assertTrue(bb.fetch.trusted_network(self.d, url))
  884. def test_prefix_wild_trusted_network(self):
  885. # Ensure trusted_network returns true when the prefix matches *.host.
  886. url = "git://git.Someserver.org/foo;rev=1"
  887. self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
  888. self.assertTrue(bb.fetch.trusted_network(self.d, url))
  889. def test_two_prefix_wild_trusted_network(self):
  890. # Ensure trusted_network returns true when the prefix matches *.host.
  891. url = "git://something.git.Someserver.org/foo;rev=1"
  892. self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
  893. self.assertTrue(bb.fetch.trusted_network(self.d, url))
  894. def test_port_trusted_network(self):
  895. # Ensure trusted_network returns True, even if the url specifies a port.
  896. url = "git://someserver.org:8080/foo;rev=1"
  897. self.d.setVar("BB_ALLOWED_NETWORKS", "someserver.org")
  898. self.assertTrue(bb.fetch.trusted_network(self.d, url))
  899. def test_untrusted_network(self):
  900. # Ensure trusted_network returns False when the host is NOT in the list.
  901. url = "git://someserver.org/foo;rev=1"
  902. self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org server2.org server3.org")
  903. self.assertFalse(bb.fetch.trusted_network(self.d, url))
  904. def test_wild_untrusted_network(self):
  905. # Ensure trusted_network returns False when the host is NOT in the list.
  906. url = "git://*.someserver.org/foo;rev=1"
  907. self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org server2.org server3.org")
  908. self.assertFalse(bb.fetch.trusted_network(self.d, url))
  909. class URLHandle(unittest.TestCase):
  910. datatable = {
  911. "http://www.google.com/index.html" : ('http', 'www.google.com', '/index.html', '', '', {}),
  912. "cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg" : ('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', '', {'module': 'familiar/dist/ipkg'}),
  913. "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')])),
  914. "git://git.openembedded.org/bitbake;branch=@foo" : ('git', 'git.openembedded.org', '/bitbake', '', '', {'branch': '@foo'}),
  915. "file://somelocation;someparam=1": ('file', '', 'somelocation', '', '', {'someparam': '1'}),
  916. }
  917. # we require a pathname to encodeurl but users can still pass such urls to
  918. # decodeurl and we need to handle them
  919. decodedata = datatable.copy()
  920. decodedata.update({
  921. "http://somesite.net;someparam=1": ('http', 'somesite.net', '/', '', '', {'someparam': '1'}),
  922. })
  923. def test_decodeurl(self):
  924. for k, v in self.decodedata.items():
  925. result = bb.fetch.decodeurl(k)
  926. self.assertEqual(result, v)
  927. def test_encodeurl(self):
  928. for k, v in self.datatable.items():
  929. result = bb.fetch.encodeurl(v)
  930. self.assertEqual(result, k)
  931. class FetchLatestVersionTest(FetcherTest):
  932. test_git_uris = {
  933. # version pattern "X.Y.Z"
  934. ("mx-1.0", "git://github.com/clutter-project/mx.git;branch=mx-1.4", "9b1db6b8060bd00b121a692f942404a24ae2960f", "")
  935. : "1.99.4",
  936. # version pattern "vX.Y"
  937. ("mtd-utils", "git://git.infradead.org/mtd-utils.git", "ca39eb1d98e736109c64ff9c1aa2a6ecca222d8f", "")
  938. : "1.5.0",
  939. # version pattern "pkg_name-X.Y"
  940. ("presentproto", "git://anongit.freedesktop.org/git/xorg/proto/presentproto", "24f3a56e541b0a9e6c6ee76081f441221a120ef9", "")
  941. : "1.0",
  942. # version pattern "pkg_name-vX.Y.Z"
  943. ("dtc", "git://git.qemu.org/dtc.git", "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf", "")
  944. : "1.4.0",
  945. # combination version pattern
  946. ("sysprof", "git://gitlab.gnome.org/GNOME/sysprof.git;protocol=https", "cd44ee6644c3641507fb53b8a2a69137f2971219", "")
  947. : "1.2.0",
  948. ("u-boot-mkimage", "git://git.denx.de/u-boot.git;branch=master;protocol=git", "62c175fbb8a0f9a926c88294ea9f7e88eb898f6c", "")
  949. : "2014.01",
  950. # version pattern "yyyymmdd"
  951. ("mobile-broadband-provider-info", "git://gitlab.gnome.org/GNOME/mobile-broadband-provider-info.git;protocol=https", "4ed19e11c2975105b71b956440acdb25d46a347d", "")
  952. : "20120614",
  953. # packages with a valid UPSTREAM_CHECK_GITTAGREGEX
  954. ("xf86-video-omap", "git://anongit.freedesktop.org/xorg/driver/xf86-video-omap", "ae0394e687f1a77e966cf72f895da91840dffb8f", "(?P<pver>(\d+\.(\d\.?)*))")
  955. : "0.4.3",
  956. ("build-appliance-image", "git://git.yoctoproject.org/poky", "b37dd451a52622d5b570183a81583cc34c2ff555", "(?P<pver>(([0-9][\.|_]?)+[0-9]))")
  957. : "11.0.0",
  958. ("chkconfig-alternatives-native", "git://github.com/kergoth/chkconfig;branch=sysroot", "cd437ecbd8986c894442f8fce1e0061e20f04dee", "chkconfig\-(?P<pver>((\d+[\.\-_]*)+))")
  959. : "1.3.59",
  960. ("remake", "git://github.com/rocky/remake.git", "f05508e521987c8494c92d9c2871aec46307d51d", "(?P<pver>(\d+\.(\d+\.)*\d*(\+dbg\d+(\.\d+)*)*))")
  961. : "3.82+dbg0.9",
  962. }
  963. test_wget_uris = {
  964. # packages with versions inside directory name
  965. ("util-linux", "http://kernel.org/pub/linux/utils/util-linux/v2.23/util-linux-2.24.2.tar.bz2", "", "")
  966. : "2.24.2",
  967. ("enchant", "http://www.abisource.com/downloads/enchant/1.6.0/enchant-1.6.0.tar.gz", "", "")
  968. : "1.6.0",
  969. ("cmake", "http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz", "", "")
  970. : "2.8.12.1",
  971. # packages with versions only in current directory
  972. ("eglic", "http://downloads.yoctoproject.org/releases/eglibc/eglibc-2.18-svnr23787.tar.bz2", "", "")
  973. : "2.19",
  974. ("gnu-config", "http://downloads.yoctoproject.org/releases/gnu-config/gnu-config-20120814.tar.bz2", "", "")
  975. : "20120814",
  976. # packages with "99" in the name of possible version
  977. ("pulseaudio", "http://freedesktop.org/software/pulseaudio/releases/pulseaudio-4.0.tar.xz", "", "")
  978. : "5.0",
  979. ("xserver-xorg", "http://xorg.freedesktop.org/releases/individual/xserver/xorg-server-1.15.1.tar.bz2", "", "")
  980. : "1.15.1",
  981. # packages with valid UPSTREAM_CHECK_URI and UPSTREAM_CHECK_REGEX
  982. ("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")
  983. : "2.0.0",
  984. ("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")
  985. : "6.1.19",
  986. }
  987. @skipIfNoNetwork()
  988. def test_git_latest_versionstring(self):
  989. for k, v in self.test_git_uris.items():
  990. self.d.setVar("PN", k[0])
  991. self.d.setVar("SRCREV", k[2])
  992. self.d.setVar("UPSTREAM_CHECK_GITTAGREGEX", k[3])
  993. ud = bb.fetch2.FetchData(k[1], self.d)
  994. pupver= ud.method.latest_versionstring(ud, self.d)
  995. verstring = pupver[0]
  996. self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0])
  997. r = bb.utils.vercmp_string(v, verstring)
  998. self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring))
  999. @skipIfNoNetwork()
  1000. def test_wget_latest_versionstring(self):
  1001. for k, v in self.test_wget_uris.items():
  1002. self.d.setVar("PN", k[0])
  1003. self.d.setVar("UPSTREAM_CHECK_URI", k[2])
  1004. self.d.setVar("UPSTREAM_CHECK_REGEX", k[3])
  1005. ud = bb.fetch2.FetchData(k[1], self.d)
  1006. pupver = ud.method.latest_versionstring(ud, self.d)
  1007. verstring = pupver[0]
  1008. self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0])
  1009. r = bb.utils.vercmp_string(v, verstring)
  1010. self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring))
  1011. class FetchCheckStatusTest(FetcherTest):
  1012. test_wget_uris = ["http://www.cups.org/software/1.7.2/cups-1.7.2-source.tar.bz2",
  1013. "http://www.cups.org/",
  1014. "http://downloads.yoctoproject.org/releases/sato/sato-engine-0.1.tar.gz",
  1015. "http://downloads.yoctoproject.org/releases/sato/sato-engine-0.2.tar.gz",
  1016. "http://downloads.yoctoproject.org/releases/sato/sato-engine-0.3.tar.gz",
  1017. "https://yoctoproject.org/",
  1018. "https://yoctoproject.org/documentation",
  1019. "http://downloads.yoctoproject.org/releases/opkg/opkg-0.1.7.tar.gz",
  1020. "http://downloads.yoctoproject.org/releases/opkg/opkg-0.3.0.tar.gz",
  1021. "ftp://sourceware.org/pub/libffi/libffi-1.20.tar.gz",
  1022. "http://ftp.gnu.org/gnu/autoconf/autoconf-2.60.tar.gz",
  1023. "https://ftp.gnu.org/gnu/chess/gnuchess-5.08.tar.gz",
  1024. "https://ftp.gnu.org/gnu/gmp/gmp-4.0.tar.gz",
  1025. # GitHub releases are hosted on Amazon S3, which doesn't support HEAD
  1026. "https://github.com/kergoth/tslib/releases/download/1.1/tslib-1.1.tar.xz"
  1027. ]
  1028. @skipIfNoNetwork()
  1029. def test_wget_checkstatus(self):
  1030. fetch = bb.fetch2.Fetch(self.test_wget_uris, self.d)
  1031. for u in self.test_wget_uris:
  1032. with self.subTest(url=u):
  1033. ud = fetch.ud[u]
  1034. m = ud.method
  1035. ret = m.checkstatus(fetch, ud, self.d)
  1036. self.assertTrue(ret, msg="URI %s, can't check status" % (u))
  1037. @skipIfNoNetwork()
  1038. def test_wget_checkstatus_connection_cache(self):
  1039. from bb.fetch2 import FetchConnectionCache
  1040. connection_cache = FetchConnectionCache()
  1041. fetch = bb.fetch2.Fetch(self.test_wget_uris, self.d,
  1042. connection_cache = connection_cache)
  1043. for u in self.test_wget_uris:
  1044. with self.subTest(url=u):
  1045. ud = fetch.ud[u]
  1046. m = ud.method
  1047. ret = m.checkstatus(fetch, ud, self.d)
  1048. self.assertTrue(ret, msg="URI %s, can't check status" % (u))
  1049. connection_cache.close_connections()
  1050. class GitMakeShallowTest(FetcherTest):
  1051. def setUp(self):
  1052. FetcherTest.setUp(self)
  1053. self.gitdir = os.path.join(self.tempdir, 'gitshallow')
  1054. bb.utils.mkdirhier(self.gitdir)
  1055. bb.process.run('git init', cwd=self.gitdir)
  1056. def assertRefs(self, expected_refs):
  1057. actual_refs = self.git(['for-each-ref', '--format=%(refname)']).splitlines()
  1058. full_expected = self.git(['rev-parse', '--symbolic-full-name'] + expected_refs).splitlines()
  1059. self.assertEqual(sorted(full_expected), sorted(actual_refs))
  1060. def assertRevCount(self, expected_count, args=None):
  1061. if args is None:
  1062. args = ['HEAD']
  1063. revs = self.git(['rev-list'] + args)
  1064. actual_count = len(revs.splitlines())
  1065. self.assertEqual(expected_count, actual_count, msg='Object count `%d` is not the expected `%d`' % (actual_count, expected_count))
  1066. def git(self, cmd):
  1067. if isinstance(cmd, str):
  1068. cmd = 'git ' + cmd
  1069. else:
  1070. cmd = ['git'] + cmd
  1071. return bb.process.run(cmd, cwd=self.gitdir)[0]
  1072. def make_shallow(self, args=None):
  1073. if args is None:
  1074. args = ['HEAD']
  1075. return bb.process.run([bb.fetch2.git.Git.make_shallow_path] + args, cwd=self.gitdir)
  1076. def add_empty_file(self, path, msg=None):
  1077. if msg is None:
  1078. msg = path
  1079. open(os.path.join(self.gitdir, path), 'w').close()
  1080. self.git(['add', path])
  1081. self.git(['commit', '-m', msg, path])
  1082. def test_make_shallow_single_branch_no_merge(self):
  1083. self.add_empty_file('a')
  1084. self.add_empty_file('b')
  1085. self.assertRevCount(2)
  1086. self.make_shallow()
  1087. self.assertRevCount(1)
  1088. def test_make_shallow_single_branch_one_merge(self):
  1089. self.add_empty_file('a')
  1090. self.add_empty_file('b')
  1091. self.git('checkout -b a_branch')
  1092. self.add_empty_file('c')
  1093. self.git('checkout master')
  1094. self.add_empty_file('d')
  1095. self.git('merge --no-ff --no-edit a_branch')
  1096. self.git('branch -d a_branch')
  1097. self.add_empty_file('e')
  1098. self.assertRevCount(6)
  1099. self.make_shallow(['HEAD~2'])
  1100. self.assertRevCount(5)
  1101. def test_make_shallow_at_merge(self):
  1102. self.add_empty_file('a')
  1103. self.git('checkout -b a_branch')
  1104. self.add_empty_file('b')
  1105. self.git('checkout master')
  1106. self.git('merge --no-ff --no-edit a_branch')
  1107. self.git('branch -d a_branch')
  1108. self.assertRevCount(3)
  1109. self.make_shallow()
  1110. self.assertRevCount(1)
  1111. def test_make_shallow_annotated_tag(self):
  1112. self.add_empty_file('a')
  1113. self.add_empty_file('b')
  1114. self.git('tag -a -m a_tag a_tag')
  1115. self.assertRevCount(2)
  1116. self.make_shallow(['a_tag'])
  1117. self.assertRevCount(1)
  1118. def test_make_shallow_multi_ref(self):
  1119. self.add_empty_file('a')
  1120. self.add_empty_file('b')
  1121. self.git('checkout -b a_branch')
  1122. self.add_empty_file('c')
  1123. self.git('checkout master')
  1124. self.add_empty_file('d')
  1125. self.git('checkout -b a_branch_2')
  1126. self.add_empty_file('a_tag')
  1127. self.git('tag a_tag')
  1128. self.git('checkout master')
  1129. self.git('branch -D a_branch_2')
  1130. self.add_empty_file('e')
  1131. self.assertRevCount(6, ['--all'])
  1132. self.make_shallow()
  1133. self.assertRevCount(5, ['--all'])
  1134. def test_make_shallow_multi_ref_trim(self):
  1135. self.add_empty_file('a')
  1136. self.git('checkout -b a_branch')
  1137. self.add_empty_file('c')
  1138. self.git('checkout master')
  1139. self.assertRevCount(1)
  1140. self.assertRevCount(2, ['--all'])
  1141. self.assertRefs(['master', 'a_branch'])
  1142. self.make_shallow(['-r', 'master', 'HEAD'])
  1143. self.assertRevCount(1, ['--all'])
  1144. self.assertRefs(['master'])
  1145. def test_make_shallow_noop(self):
  1146. self.add_empty_file('a')
  1147. self.assertRevCount(1)
  1148. self.make_shallow()
  1149. self.assertRevCount(1)
  1150. @skipIfNoNetwork()
  1151. def test_make_shallow_bitbake(self):
  1152. self.git('remote add origin https://github.com/openembedded/bitbake')
  1153. self.git('fetch --tags origin')
  1154. orig_revs = len(self.git('rev-list --all').splitlines())
  1155. self.make_shallow(['refs/tags/1.10.0'])
  1156. self.assertRevCount(orig_revs - 1746, ['--all'])
  1157. class GitShallowTest(FetcherTest):
  1158. def setUp(self):
  1159. FetcherTest.setUp(self)
  1160. self.gitdir = os.path.join(self.tempdir, 'git')
  1161. self.srcdir = os.path.join(self.tempdir, 'gitsource')
  1162. bb.utils.mkdirhier(self.srcdir)
  1163. self.git('init', cwd=self.srcdir)
  1164. self.d.setVar('WORKDIR', self.tempdir)
  1165. self.d.setVar('S', self.gitdir)
  1166. self.d.delVar('PREMIRRORS')
  1167. self.d.delVar('MIRRORS')
  1168. uri = 'git://%s;protocol=file;subdir=${S}' % self.srcdir
  1169. self.d.setVar('SRC_URI', uri)
  1170. self.d.setVar('SRCREV', '${AUTOREV}')
  1171. self.d.setVar('AUTOREV', '${@bb.fetch2.get_autorev(d)}')
  1172. self.d.setVar('BB_GIT_SHALLOW', '1')
  1173. self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '0')
  1174. self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1')
  1175. def assertRefs(self, expected_refs, cwd=None):
  1176. if cwd is None:
  1177. cwd = self.gitdir
  1178. actual_refs = self.git(['for-each-ref', '--format=%(refname)'], cwd=cwd).splitlines()
  1179. full_expected = self.git(['rev-parse', '--symbolic-full-name'] + expected_refs, cwd=cwd).splitlines()
  1180. self.assertEqual(sorted(set(full_expected)), sorted(set(actual_refs)))
  1181. def assertRevCount(self, expected_count, args=None, cwd=None):
  1182. if args is None:
  1183. args = ['HEAD']
  1184. if cwd is None:
  1185. cwd = self.gitdir
  1186. revs = self.git(['rev-list'] + args, cwd=cwd)
  1187. actual_count = len(revs.splitlines())
  1188. self.assertEqual(expected_count, actual_count, msg='Object count `%d` is not the expected `%d`' % (actual_count, expected_count))
  1189. def git(self, cmd, cwd=None):
  1190. if isinstance(cmd, str):
  1191. cmd = 'git ' + cmd
  1192. else:
  1193. cmd = ['git'] + cmd
  1194. if cwd is None:
  1195. cwd = self.gitdir
  1196. return bb.process.run(cmd, cwd=cwd)[0]
  1197. def add_empty_file(self, path, cwd=None, msg=None):
  1198. if msg is None:
  1199. msg = path
  1200. if cwd is None:
  1201. cwd = self.srcdir
  1202. open(os.path.join(cwd, path), 'w').close()
  1203. self.git(['add', path], cwd)
  1204. self.git(['commit', '-m', msg, path], cwd)
  1205. def fetch(self, uri=None):
  1206. if uri is None:
  1207. uris = self.d.getVar('SRC_URI', True).split()
  1208. uri = uris[0]
  1209. d = self.d
  1210. else:
  1211. d = self.d.createCopy()
  1212. d.setVar('SRC_URI', uri)
  1213. uri = d.expand(uri)
  1214. uris = [uri]
  1215. fetcher = bb.fetch2.Fetch(uris, d)
  1216. fetcher.download()
  1217. ud = fetcher.ud[uri]
  1218. return fetcher, ud
  1219. def fetch_and_unpack(self, uri=None):
  1220. fetcher, ud = self.fetch(uri)
  1221. fetcher.unpack(self.d.getVar('WORKDIR'))
  1222. assert os.path.exists(self.d.getVar('S'))
  1223. return fetcher, ud
  1224. def fetch_shallow(self, uri=None, disabled=False, keepclone=False):
  1225. """Fetch a uri, generating a shallow tarball, then unpack using it"""
  1226. fetcher, ud = self.fetch_and_unpack(uri)
  1227. assert os.path.exists(ud.clonedir), 'Git clone in DLDIR (%s) does not exist for uri %s' % (ud.clonedir, uri)
  1228. # Confirm that the unpacked repo is unshallow
  1229. if not disabled:
  1230. assert os.path.exists(os.path.join(self.dldir, ud.mirrortarballs[0]))
  1231. # fetch and unpack, from the shallow tarball
  1232. bb.utils.remove(self.gitdir, recurse=True)
  1233. bb.utils.remove(ud.clonedir, recurse=True)
  1234. bb.utils.remove(ud.clonedir.replace('gitsource', 'gitsubmodule'), recurse=True)
  1235. # confirm that the unpacked repo is used when no git clone or git
  1236. # mirror tarball is available
  1237. fetcher, ud = self.fetch_and_unpack(uri)
  1238. if not disabled:
  1239. assert os.path.exists(os.path.join(self.gitdir, '.git', 'shallow')), 'Unpacked git repository at %s is not shallow' % self.gitdir
  1240. else:
  1241. assert not os.path.exists(os.path.join(self.gitdir, '.git', 'shallow')), 'Unpacked git repository at %s is shallow' % self.gitdir
  1242. return fetcher, ud
  1243. def test_shallow_disabled(self):
  1244. self.add_empty_file('a')
  1245. self.add_empty_file('b')
  1246. self.assertRevCount(2, cwd=self.srcdir)
  1247. self.d.setVar('BB_GIT_SHALLOW', '0')
  1248. self.fetch_shallow(disabled=True)
  1249. self.assertRevCount(2)
  1250. def test_shallow_nobranch(self):
  1251. self.add_empty_file('a')
  1252. self.add_empty_file('b')
  1253. self.assertRevCount(2, cwd=self.srcdir)
  1254. srcrev = self.git('rev-parse HEAD', cwd=self.srcdir).strip()
  1255. self.d.setVar('SRCREV', srcrev)
  1256. uri = self.d.getVar('SRC_URI', True).split()[0]
  1257. uri = '%s;nobranch=1;bare=1' % uri
  1258. self.fetch_shallow(uri)
  1259. self.assertRevCount(1)
  1260. # shallow refs are used to ensure the srcrev sticks around when we
  1261. # have no other branches referencing it
  1262. self.assertRefs(['refs/shallow/default'])
  1263. def test_shallow_default_depth_1(self):
  1264. # Create initial git repo
  1265. self.add_empty_file('a')
  1266. self.add_empty_file('b')
  1267. self.assertRevCount(2, cwd=self.srcdir)
  1268. self.fetch_shallow()
  1269. self.assertRevCount(1)
  1270. def test_shallow_depth_0_disables(self):
  1271. self.add_empty_file('a')
  1272. self.add_empty_file('b')
  1273. self.assertRevCount(2, cwd=self.srcdir)
  1274. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
  1275. self.fetch_shallow(disabled=True)
  1276. self.assertRevCount(2)
  1277. def test_shallow_depth_default_override(self):
  1278. self.add_empty_file('a')
  1279. self.add_empty_file('b')
  1280. self.assertRevCount(2, cwd=self.srcdir)
  1281. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '2')
  1282. self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '1')
  1283. self.fetch_shallow()
  1284. self.assertRevCount(1)
  1285. def test_shallow_depth_default_override_disable(self):
  1286. self.add_empty_file('a')
  1287. self.add_empty_file('b')
  1288. self.add_empty_file('c')
  1289. self.assertRevCount(3, cwd=self.srcdir)
  1290. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
  1291. self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '2')
  1292. self.fetch_shallow()
  1293. self.assertRevCount(2)
  1294. def test_current_shallow_out_of_date_clone(self):
  1295. # Create initial git repo
  1296. self.add_empty_file('a')
  1297. self.add_empty_file('b')
  1298. self.add_empty_file('c')
  1299. self.assertRevCount(3, cwd=self.srcdir)
  1300. # Clone and generate mirror tarball
  1301. fetcher, ud = self.fetch()
  1302. # Ensure we have a current mirror tarball, but an out of date clone
  1303. self.git('update-ref refs/heads/master refs/heads/master~1', cwd=ud.clonedir)
  1304. self.assertRevCount(2, cwd=ud.clonedir)
  1305. # Fetch and unpack, from the current tarball, not the out of date clone
  1306. bb.utils.remove(self.gitdir, recurse=True)
  1307. fetcher, ud = self.fetch()
  1308. fetcher.unpack(self.d.getVar('WORKDIR'))
  1309. self.assertRevCount(1)
  1310. def test_shallow_single_branch_no_merge(self):
  1311. self.add_empty_file('a')
  1312. self.add_empty_file('b')
  1313. self.assertRevCount(2, cwd=self.srcdir)
  1314. self.fetch_shallow()
  1315. self.assertRevCount(1)
  1316. assert os.path.exists(os.path.join(self.gitdir, 'a'))
  1317. assert os.path.exists(os.path.join(self.gitdir, 'b'))
  1318. def test_shallow_no_dangling(self):
  1319. self.add_empty_file('a')
  1320. self.add_empty_file('b')
  1321. self.assertRevCount(2, cwd=self.srcdir)
  1322. self.fetch_shallow()
  1323. self.assertRevCount(1)
  1324. assert not self.git('fsck --dangling')
  1325. def test_shallow_srcrev_branch_truncation(self):
  1326. self.add_empty_file('a')
  1327. self.add_empty_file('b')
  1328. b_commit = self.git('rev-parse HEAD', cwd=self.srcdir).rstrip()
  1329. self.add_empty_file('c')
  1330. self.assertRevCount(3, cwd=self.srcdir)
  1331. self.d.setVar('SRCREV', b_commit)
  1332. self.fetch_shallow()
  1333. # The 'c' commit was removed entirely, and 'a' was removed from history
  1334. self.assertRevCount(1, ['--all'])
  1335. self.assertEqual(self.git('rev-parse HEAD').strip(), b_commit)
  1336. assert os.path.exists(os.path.join(self.gitdir, 'a'))
  1337. assert os.path.exists(os.path.join(self.gitdir, 'b'))
  1338. assert not os.path.exists(os.path.join(self.gitdir, 'c'))
  1339. def test_shallow_ref_pruning(self):
  1340. self.add_empty_file('a')
  1341. self.add_empty_file('b')
  1342. self.git('branch a_branch', cwd=self.srcdir)
  1343. self.assertRefs(['master', 'a_branch'], cwd=self.srcdir)
  1344. self.assertRevCount(2, cwd=self.srcdir)
  1345. self.fetch_shallow()
  1346. self.assertRefs(['master', 'origin/master'])
  1347. self.assertRevCount(1)
  1348. def test_shallow_submodules(self):
  1349. self.add_empty_file('a')
  1350. self.add_empty_file('b')
  1351. smdir = os.path.join(self.tempdir, 'gitsubmodule')
  1352. bb.utils.mkdirhier(smdir)
  1353. self.git('init', cwd=smdir)
  1354. # Make this look like it was cloned from a remote...
  1355. self.git('config --add remote.origin.url "%s"' % smdir, cwd=smdir)
  1356. self.git('config --add remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"', cwd=smdir)
  1357. self.add_empty_file('asub', cwd=smdir)
  1358. self.add_empty_file('bsub', cwd=smdir)
  1359. self.git('submodule init', cwd=self.srcdir)
  1360. self.git('submodule add file://%s' % smdir, cwd=self.srcdir)
  1361. self.git('submodule update', cwd=self.srcdir)
  1362. self.git('commit -m submodule -a', cwd=self.srcdir)
  1363. uri = 'gitsm://%s;protocol=file;subdir=${S}' % self.srcdir
  1364. fetcher, ud = self.fetch_shallow(uri)
  1365. # Verify the main repository is shallow
  1366. self.assertRevCount(1)
  1367. # Verify the gitsubmodule directory is present
  1368. assert os.listdir(os.path.join(self.gitdir, 'gitsubmodule'))
  1369. # Verify the submodule is also shallow
  1370. self.assertRevCount(1, cwd=os.path.join(self.gitdir, 'gitsubmodule'))
  1371. if any(os.path.exists(os.path.join(p, 'git-annex')) for p in os.environ.get('PATH').split(':')):
  1372. def test_shallow_annex(self):
  1373. self.add_empty_file('a')
  1374. self.add_empty_file('b')
  1375. self.git('annex init', cwd=self.srcdir)
  1376. open(os.path.join(self.srcdir, 'c'), 'w').close()
  1377. self.git('annex add c', cwd=self.srcdir)
  1378. self.git('commit -m annex-c -a', cwd=self.srcdir)
  1379. bb.process.run('chmod u+w -R %s' % os.path.join(self.srcdir, '.git', 'annex'))
  1380. uri = 'gitannex://%s;protocol=file;subdir=${S}' % self.srcdir
  1381. fetcher, ud = self.fetch_shallow(uri)
  1382. self.assertRevCount(1)
  1383. assert './.git/annex/' in bb.process.run('tar -tzf %s' % os.path.join(self.dldir, ud.mirrortarballs[0]))[0]
  1384. assert os.path.exists(os.path.join(self.gitdir, 'c'))
  1385. def test_shallow_multi_one_uri(self):
  1386. # Create initial git repo
  1387. self.add_empty_file('a')
  1388. self.add_empty_file('b')
  1389. self.git('checkout -b a_branch', cwd=self.srcdir)
  1390. self.add_empty_file('c')
  1391. self.add_empty_file('d')
  1392. self.git('checkout master', cwd=self.srcdir)
  1393. self.git('tag v0.0 a_branch', 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', True).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_REVS', 'v0.0')
  1402. self.d.setVar('SRCREV_master', '${AUTOREV}')
  1403. self.d.setVar('SRCREV_a_branch', '${AUTOREV}')
  1404. self.fetch_shallow(uri)
  1405. self.assertRevCount(5)
  1406. self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
  1407. def test_shallow_multi_one_uri_depths(self):
  1408. # Create initial git repo
  1409. self.add_empty_file('a')
  1410. self.add_empty_file('b')
  1411. self.git('checkout -b a_branch', cwd=self.srcdir)
  1412. self.add_empty_file('c')
  1413. self.add_empty_file('d')
  1414. self.git('checkout master', cwd=self.srcdir)
  1415. self.add_empty_file('e')
  1416. self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir)
  1417. self.add_empty_file('f')
  1418. self.assertRevCount(7, cwd=self.srcdir)
  1419. uri = self.d.getVar('SRC_URI', True).split()[0]
  1420. uri = '%s;branch=master,a_branch;name=master,a_branch' % uri
  1421. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
  1422. self.d.setVar('BB_GIT_SHALLOW_DEPTH_master', '3')
  1423. self.d.setVar('BB_GIT_SHALLOW_DEPTH_a_branch', '1')
  1424. self.d.setVar('SRCREV_master', '${AUTOREV}')
  1425. self.d.setVar('SRCREV_a_branch', '${AUTOREV}')
  1426. self.fetch_shallow(uri)
  1427. self.assertRevCount(4, ['--all'])
  1428. self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
  1429. def test_shallow_clone_preferred_over_shallow(self):
  1430. self.add_empty_file('a')
  1431. self.add_empty_file('b')
  1432. # Fetch once to generate the shallow tarball
  1433. fetcher, ud = self.fetch()
  1434. assert os.path.exists(os.path.join(self.dldir, ud.mirrortarballs[0]))
  1435. # Fetch and unpack with both the clonedir and shallow tarball available
  1436. bb.utils.remove(self.gitdir, recurse=True)
  1437. fetcher, ud = self.fetch_and_unpack()
  1438. # The unpacked tree should *not* be shallow
  1439. self.assertRevCount(2)
  1440. assert not os.path.exists(os.path.join(self.gitdir, '.git', 'shallow'))
  1441. def test_shallow_mirrors(self):
  1442. self.add_empty_file('a')
  1443. self.add_empty_file('b')
  1444. # Fetch once to generate the shallow tarball
  1445. fetcher, ud = self.fetch()
  1446. mirrortarball = ud.mirrortarballs[0]
  1447. assert os.path.exists(os.path.join(self.dldir, mirrortarball))
  1448. # Set up the mirror
  1449. mirrordir = os.path.join(self.tempdir, 'mirror')
  1450. bb.utils.mkdirhier(mirrordir)
  1451. self.d.setVar('PREMIRRORS', 'git://.*/.* file://%s/\n' % mirrordir)
  1452. os.rename(os.path.join(self.dldir, mirrortarball),
  1453. os.path.join(mirrordir, mirrortarball))
  1454. # Fetch from the mirror
  1455. bb.utils.remove(self.dldir, recurse=True)
  1456. bb.utils.remove(self.gitdir, recurse=True)
  1457. self.fetch_and_unpack()
  1458. self.assertRevCount(1)
  1459. def test_shallow_invalid_depth(self):
  1460. self.add_empty_file('a')
  1461. self.add_empty_file('b')
  1462. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '-12')
  1463. with self.assertRaises(bb.fetch2.FetchError):
  1464. self.fetch()
  1465. def test_shallow_invalid_depth_default(self):
  1466. self.add_empty_file('a')
  1467. self.add_empty_file('b')
  1468. self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '-12')
  1469. with self.assertRaises(bb.fetch2.FetchError):
  1470. self.fetch()
  1471. def test_shallow_extra_refs(self):
  1472. self.add_empty_file('a')
  1473. self.add_empty_file('b')
  1474. self.git('branch a_branch', cwd=self.srcdir)
  1475. self.assertRefs(['master', 'a_branch'], cwd=self.srcdir)
  1476. self.assertRevCount(2, cwd=self.srcdir)
  1477. self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/heads/a_branch')
  1478. self.fetch_shallow()
  1479. self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
  1480. self.assertRevCount(1)
  1481. def test_shallow_extra_refs_wildcard(self):
  1482. self.add_empty_file('a')
  1483. self.add_empty_file('b')
  1484. self.git('branch a_branch', cwd=self.srcdir)
  1485. self.git('tag v1.0', cwd=self.srcdir)
  1486. self.assertRefs(['master', 'a_branch', 'v1.0'], cwd=self.srcdir)
  1487. self.assertRevCount(2, cwd=self.srcdir)
  1488. self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/tags/*')
  1489. self.fetch_shallow()
  1490. self.assertRefs(['master', 'origin/master', 'v1.0'])
  1491. self.assertRevCount(1)
  1492. def test_shallow_missing_extra_refs(self):
  1493. self.add_empty_file('a')
  1494. self.add_empty_file('b')
  1495. self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/heads/foo')
  1496. with self.assertRaises(bb.fetch2.FetchError):
  1497. self.fetch()
  1498. def test_shallow_missing_extra_refs_wildcard(self):
  1499. self.add_empty_file('a')
  1500. self.add_empty_file('b')
  1501. self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/tags/*')
  1502. self.fetch()
  1503. def test_shallow_remove_revs(self):
  1504. # Create initial git repo
  1505. self.add_empty_file('a')
  1506. self.add_empty_file('b')
  1507. self.git('checkout -b a_branch', cwd=self.srcdir)
  1508. self.add_empty_file('c')
  1509. self.add_empty_file('d')
  1510. self.git('checkout master', cwd=self.srcdir)
  1511. self.git('tag v0.0 a_branch', cwd=self.srcdir)
  1512. self.add_empty_file('e')
  1513. self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir)
  1514. self.git('branch -d a_branch', cwd=self.srcdir)
  1515. self.add_empty_file('f')
  1516. self.assertRevCount(7, cwd=self.srcdir)
  1517. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
  1518. self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
  1519. self.fetch_shallow()
  1520. self.assertRevCount(5)
  1521. def test_shallow_invalid_revs(self):
  1522. self.add_empty_file('a')
  1523. self.add_empty_file('b')
  1524. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
  1525. self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
  1526. with self.assertRaises(bb.fetch2.FetchError):
  1527. self.fetch()
  1528. @skipIfNoNetwork()
  1529. def test_bitbake(self):
  1530. self.git('remote add --mirror=fetch origin git://github.com/openembedded/bitbake', cwd=self.srcdir)
  1531. self.git('config core.bare true', cwd=self.srcdir)
  1532. self.git('fetch', cwd=self.srcdir)
  1533. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
  1534. # Note that the 1.10.0 tag is annotated, so this also tests
  1535. # reference of an annotated vs unannotated tag
  1536. self.d.setVar('BB_GIT_SHALLOW_REVS', '1.10.0')
  1537. self.fetch_shallow()
  1538. # Confirm that the history of 1.10.0 was removed
  1539. orig_revs = len(self.git('rev-list master', cwd=self.srcdir).splitlines())
  1540. revs = len(self.git('rev-list master').splitlines())
  1541. self.assertNotEqual(orig_revs, revs)
  1542. self.assertRefs(['master', 'origin/master'])
  1543. self.assertRevCount(orig_revs - 1758)
  1544. def test_that_unpack_throws_an_error_when_the_git_clone_nor_shallow_tarball_exist(self):
  1545. self.add_empty_file('a')
  1546. fetcher, ud = self.fetch()
  1547. bb.utils.remove(self.gitdir, recurse=True)
  1548. bb.utils.remove(self.dldir, recurse=True)
  1549. with self.assertRaises(bb.fetch2.UnpackError) as context:
  1550. fetcher.unpack(self.d.getVar('WORKDIR'))
  1551. self.assertIn("No up to date source found", context.exception.msg)
  1552. self.assertIn("clone directory not available or not up to date", context.exception.msg)
  1553. @skipIfNoNetwork()
  1554. def test_that_unpack_does_work_when_using_git_shallow_tarball_but_tarball_is_not_available(self):
  1555. self.d.setVar('SRCREV', 'e5939ff608b95cdd4d0ab0e1935781ab9a276ac0')
  1556. self.d.setVar('BB_GIT_SHALLOW', '1')
  1557. self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1')
  1558. fetcher = bb.fetch.Fetch(["git://git.yoctoproject.org/fstests"], self.d)
  1559. fetcher.download()
  1560. bb.utils.remove(self.dldir + "/*.tar.gz")
  1561. fetcher.unpack(self.unpackdir)
  1562. dir = os.listdir(self.unpackdir + "/git/")
  1563. self.assertIn("fstests.doap", dir)