fetch.py 79 KB

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