fetch.py 62 KB

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