fetch.py 166 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595
  1. #
  2. # BitBake Tests for the Fetcher (fetch2/)
  3. #
  4. # Copyright (C) 2012 Richard Purdie
  5. #
  6. # SPDX-License-Identifier: GPL-2.0-only
  7. #
  8. import contextlib
  9. import unittest
  10. import hashlib
  11. import tempfile
  12. import collections
  13. import os
  14. import signal
  15. import tarfile
  16. from bb.fetch2 import URI
  17. from bb.fetch2 import FetchMethod
  18. import bb
  19. from bb.tests.support.httpserver import HTTPService
  20. def skipIfNoNetwork():
  21. if os.environ.get("BB_SKIP_NETTESTS") == "yes":
  22. return unittest.skip("network test")
  23. return lambda f: f
  24. class TestTimeout(Exception):
  25. # Indicate to pytest that this is not a test suite
  26. __test__ = False
  27. class Timeout():
  28. def __init__(self, seconds):
  29. self.seconds = seconds
  30. def handle_timeout(self, signum, frame):
  31. raise TestTimeout("Test failed: timeout reached")
  32. def __enter__(self):
  33. signal.signal(signal.SIGALRM, self.handle_timeout)
  34. signal.alarm(self.seconds)
  35. def __exit__(self, exc_type, exc_val, exc_tb):
  36. signal.alarm(0)
  37. class URITest(unittest.TestCase):
  38. test_uris = {
  39. "http://www.google.com/index.html" : {
  40. 'uri': 'http://www.google.com/index.html',
  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. 'query': {},
  51. 'relative': False
  52. },
  53. "http://www.google.com/index.html;param1=value1" : {
  54. 'uri': 'http://www.google.com/index.html;param1=value1',
  55. 'scheme': 'http',
  56. 'hostname': 'www.google.com',
  57. 'port': None,
  58. 'hostport': 'www.google.com',
  59. 'path': '/index.html',
  60. 'userinfo': '',
  61. 'username': '',
  62. 'password': '',
  63. 'params': {
  64. 'param1': 'value1'
  65. },
  66. 'query': {},
  67. 'relative': False
  68. },
  69. "http://www.example.org/index.html?param1=value1" : {
  70. 'uri': 'http://www.example.org/index.html?param1=value1',
  71. 'scheme': 'http',
  72. 'hostname': 'www.example.org',
  73. 'port': None,
  74. 'hostport': 'www.example.org',
  75. 'path': '/index.html',
  76. 'userinfo': '',
  77. 'username': '',
  78. 'password': '',
  79. 'params': {},
  80. 'query': {
  81. 'param1': 'value1'
  82. },
  83. 'relative': False
  84. },
  85. "http://www.example.org/index.html?qparam1=qvalue1;param2=value2" : {
  86. 'uri': 'http://www.example.org/index.html?qparam1=qvalue1;param2=value2',
  87. 'scheme': 'http',
  88. 'hostname': 'www.example.org',
  89. 'port': None,
  90. 'hostport': 'www.example.org',
  91. 'path': '/index.html',
  92. 'userinfo': '',
  93. 'username': '',
  94. 'password': '',
  95. 'params': {
  96. 'param2': 'value2'
  97. },
  98. 'query': {
  99. 'qparam1': 'qvalue1'
  100. },
  101. 'relative': False
  102. },
  103. # Check that trailing semicolons are handled correctly
  104. "http://www.example.org/index.html?qparam1=qvalue1;param2=value2;" : {
  105. 'uri': 'http://www.example.org/index.html?qparam1=qvalue1;param2=value2',
  106. 'scheme': 'http',
  107. 'hostname': 'www.example.org',
  108. 'port': None,
  109. 'hostport': 'www.example.org',
  110. 'path': '/index.html',
  111. 'userinfo': '',
  112. 'username': '',
  113. 'password': '',
  114. 'params': {
  115. 'param2': 'value2'
  116. },
  117. 'query': {
  118. 'qparam1': 'qvalue1'
  119. },
  120. 'relative': False
  121. },
  122. "http://www.example.com:8080/index.html" : {
  123. 'uri': 'http://www.example.com:8080/index.html',
  124. 'scheme': 'http',
  125. 'hostname': 'www.example.com',
  126. 'port': 8080,
  127. 'hostport': 'www.example.com:8080',
  128. 'path': '/index.html',
  129. 'userinfo': '',
  130. 'username': '',
  131. 'password': '',
  132. 'params': {},
  133. 'query': {},
  134. 'relative': False
  135. },
  136. "cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg" : {
  137. 'uri': 'cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg',
  138. 'scheme': 'cvs',
  139. 'hostname': 'cvs.handhelds.org',
  140. 'port': None,
  141. 'hostport': 'cvs.handhelds.org',
  142. 'path': '/cvs',
  143. 'userinfo': 'anoncvs',
  144. 'username': 'anoncvs',
  145. 'password': '',
  146. 'params': {
  147. 'module': 'familiar/dist/ipkg'
  148. },
  149. 'query': {},
  150. 'relative': False
  151. },
  152. "cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg": {
  153. 'uri': 'cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg',
  154. 'scheme': 'cvs',
  155. 'hostname': 'cvs.handhelds.org',
  156. 'port': None,
  157. 'hostport': 'cvs.handhelds.org',
  158. 'path': '/cvs',
  159. 'userinfo': 'anoncvs:anonymous',
  160. 'username': 'anoncvs',
  161. 'password': 'anonymous',
  162. 'params': collections.OrderedDict([
  163. ('tag', 'V0-99-81'),
  164. ('module', 'familiar/dist/ipkg')
  165. ]),
  166. 'query': {},
  167. 'relative': False
  168. },
  169. "file://example.diff": { # NOTE: Not RFC compliant!
  170. 'uri': 'file:example.diff',
  171. 'scheme': 'file',
  172. 'hostname': '',
  173. 'port': None,
  174. 'hostport': '',
  175. 'path': 'example.diff',
  176. 'userinfo': '',
  177. 'username': '',
  178. 'password': '',
  179. 'params': {},
  180. 'query': {},
  181. 'relative': True
  182. },
  183. "file:example.diff": { # NOTE: RFC compliant version of the former
  184. 'uri': 'file:example.diff',
  185. 'scheme': 'file',
  186. 'hostname': '',
  187. 'port': None,
  188. 'hostport': '',
  189. 'path': 'example.diff',
  190. 'userinfo': '',
  191. 'userinfo': '',
  192. 'username': '',
  193. 'password': '',
  194. 'params': {},
  195. 'query': {},
  196. 'relative': True
  197. },
  198. "file:///tmp/example.diff": {
  199. 'uri': 'file:///tmp/example.diff',
  200. 'scheme': 'file',
  201. 'hostname': '',
  202. 'port': None,
  203. 'hostport': '',
  204. 'path': '/tmp/example.diff',
  205. 'userinfo': '',
  206. 'userinfo': '',
  207. 'username': '',
  208. 'password': '',
  209. 'params': {},
  210. 'query': {},
  211. 'relative': False
  212. },
  213. "git:///path/example.git": {
  214. 'uri': 'git:///path/example.git',
  215. 'scheme': 'git',
  216. 'hostname': '',
  217. 'port': None,
  218. 'hostport': '',
  219. 'path': '/path/example.git',
  220. 'userinfo': '',
  221. 'userinfo': '',
  222. 'username': '',
  223. 'password': '',
  224. 'params': {},
  225. 'query': {},
  226. 'relative': False
  227. },
  228. "git:path/example.git": {
  229. 'uri': 'git:path/example.git',
  230. 'scheme': 'git',
  231. 'hostname': '',
  232. 'port': None,
  233. 'hostport': '',
  234. 'path': 'path/example.git',
  235. 'userinfo': '',
  236. 'userinfo': '',
  237. 'username': '',
  238. 'password': '',
  239. 'params': {},
  240. 'query': {},
  241. 'relative': True
  242. },
  243. "git://example.net/path/example.git": {
  244. 'uri': 'git://example.net/path/example.git',
  245. 'scheme': 'git',
  246. 'hostname': 'example.net',
  247. 'port': None,
  248. 'hostport': 'example.net',
  249. 'path': '/path/example.git',
  250. 'userinfo': '',
  251. 'userinfo': '',
  252. 'username': '',
  253. 'password': '',
  254. 'params': {},
  255. 'query': {},
  256. 'relative': False
  257. },
  258. "git://tfs-example.org:22/tfs/example%20path/example.git": {
  259. 'uri': 'git://tfs-example.org:22/tfs/example%20path/example.git',
  260. 'scheme': 'git',
  261. 'hostname': 'tfs-example.org',
  262. 'port': 22,
  263. 'hostport': 'tfs-example.org:22',
  264. 'path': '/tfs/example path/example.git',
  265. 'userinfo': '',
  266. 'userinfo': '',
  267. 'username': '',
  268. 'password': '',
  269. 'params': {},
  270. 'query': {},
  271. 'relative': False
  272. },
  273. "http://somesite.net;someparam=1": {
  274. 'uri': 'http://somesite.net;someparam=1',
  275. 'scheme': 'http',
  276. 'hostname': 'somesite.net',
  277. 'port': None,
  278. 'hostport': 'somesite.net',
  279. 'path': '',
  280. 'userinfo': '',
  281. 'userinfo': '',
  282. 'username': '',
  283. 'password': '',
  284. 'params': {"someparam" : "1"},
  285. 'query': {},
  286. 'relative': False
  287. },
  288. "file://somelocation;someparam=1": {
  289. 'uri': 'file:somelocation;someparam=1',
  290. 'scheme': 'file',
  291. 'hostname': '',
  292. 'port': None,
  293. 'hostport': '',
  294. 'path': 'somelocation',
  295. 'userinfo': '',
  296. 'userinfo': '',
  297. 'username': '',
  298. 'password': '',
  299. 'params': {"someparam" : "1"},
  300. 'query': {},
  301. 'relative': True
  302. },
  303. "https://www.innodisk.com/Download_file?9BE0BF6657;downloadfilename=EGPL-T101.zip": {
  304. 'uri': 'https://www.innodisk.com/Download_file?9BE0BF6657;downloadfilename=EGPL-T101.zip',
  305. 'scheme': 'https',
  306. 'hostname': 'www.innodisk.com',
  307. 'port': None,
  308. 'hostport': 'www.innodisk.com',
  309. 'path': '/Download_file',
  310. 'userinfo': '',
  311. 'userinfo': '',
  312. 'username': '',
  313. 'password': '',
  314. 'params': {"downloadfilename" : "EGPL-T101.zip"},
  315. 'query': {"9BE0BF6657": None},
  316. 'relative': False
  317. },
  318. "file://example@.service": {
  319. 'uri': 'file:example%40.service',
  320. 'scheme': 'file',
  321. 'hostname': '',
  322. 'port': None,
  323. 'hostport': '',
  324. 'path': 'example@.service',
  325. 'userinfo': '',
  326. 'userinfo': '',
  327. 'username': '',
  328. 'password': '',
  329. 'params': {},
  330. 'query': {},
  331. 'relative': True
  332. }
  333. }
  334. def test_uri(self):
  335. for test_uri, ref in self.test_uris.items():
  336. uri = URI(test_uri)
  337. self.assertEqual(str(uri), ref['uri'])
  338. # expected attributes
  339. self.assertEqual(uri.scheme, ref['scheme'])
  340. self.assertEqual(uri.userinfo, ref['userinfo'])
  341. self.assertEqual(uri.username, ref['username'])
  342. self.assertEqual(uri.password, ref['password'])
  343. self.assertEqual(uri.hostname, ref['hostname'])
  344. self.assertEqual(uri.port, ref['port'])
  345. self.assertEqual(uri.hostport, ref['hostport'])
  346. self.assertEqual(uri.path, ref['path'])
  347. self.assertEqual(uri.params, ref['params'])
  348. self.assertEqual(uri.relative, ref['relative'])
  349. def test_dict(self):
  350. for test in self.test_uris.values():
  351. uri = URI()
  352. self.assertEqual(uri.scheme, '')
  353. self.assertEqual(uri.userinfo, '')
  354. self.assertEqual(uri.username, '')
  355. self.assertEqual(uri.password, '')
  356. self.assertEqual(uri.hostname, '')
  357. self.assertEqual(uri.port, None)
  358. self.assertEqual(uri.path, '')
  359. self.assertEqual(uri.params, {})
  360. uri.scheme = test['scheme']
  361. self.assertEqual(uri.scheme, test['scheme'])
  362. uri.userinfo = test['userinfo']
  363. self.assertEqual(uri.userinfo, test['userinfo'])
  364. self.assertEqual(uri.username, test['username'])
  365. self.assertEqual(uri.password, test['password'])
  366. # make sure changing the values doesn't do anything unexpected
  367. uri.username = 'changeme'
  368. self.assertEqual(uri.username, 'changeme')
  369. self.assertEqual(uri.password, test['password'])
  370. uri.password = 'insecure'
  371. self.assertEqual(uri.username, 'changeme')
  372. self.assertEqual(uri.password, 'insecure')
  373. # reset back after our trickery
  374. uri.userinfo = test['userinfo']
  375. self.assertEqual(uri.userinfo, test['userinfo'])
  376. self.assertEqual(uri.username, test['username'])
  377. self.assertEqual(uri.password, test['password'])
  378. uri.hostname = test['hostname']
  379. self.assertEqual(uri.hostname, test['hostname'])
  380. self.assertEqual(uri.hostport, test['hostname'])
  381. uri.port = test['port']
  382. self.assertEqual(uri.port, test['port'])
  383. self.assertEqual(uri.hostport, test['hostport'])
  384. uri.path = test['path']
  385. self.assertEqual(uri.path, test['path'])
  386. uri.params = test['params']
  387. self.assertEqual(uri.params, test['params'])
  388. uri.query = test['query']
  389. self.assertEqual(uri.query, test['query'])
  390. self.assertEqual(str(uri), test['uri'])
  391. uri.params = {}
  392. self.assertEqual(uri.params, {})
  393. self.assertEqual(str(uri), (str(uri).split(";"))[0])
  394. class FetcherTest(unittest.TestCase):
  395. def setUp(self):
  396. self.origdir = os.getcwd()
  397. self.d = bb.data.init()
  398. self.tempdir = tempfile.mkdtemp(prefix="bitbake-fetch-")
  399. self.dldir = os.path.join(self.tempdir, "download")
  400. os.mkdir(self.dldir)
  401. self.d.setVar("DL_DIR", self.dldir)
  402. self.unpackdir = os.path.join(self.tempdir, "unpacked")
  403. os.mkdir(self.unpackdir)
  404. persistdir = os.path.join(self.tempdir, "persistdata")
  405. self.d.setVar("PERSISTENT_DIR", persistdir)
  406. def tearDown(self):
  407. os.chdir(self.origdir)
  408. if os.environ.get("BB_TMPDIR_NOCLEAN") == "yes":
  409. print("Not cleaning up %s. Please remove manually." % self.tempdir)
  410. else:
  411. bb.process.run('chmod u+rw -R %s' % self.tempdir)
  412. bb.utils.prunedir(self.tempdir)
  413. def git(self, cmd, cwd=None):
  414. if isinstance(cmd, str):
  415. cmd = 'git -c safe.bareRepository=all ' + cmd
  416. else:
  417. cmd = ['git', '-c', 'safe.bareRepository=all'] + cmd
  418. if cwd is None:
  419. cwd = self.gitdir
  420. return bb.process.run(cmd, cwd=cwd)[0]
  421. def git_init(self, cwd=None):
  422. self.git('init', cwd=cwd)
  423. # Explicitly set initial branch to master as
  424. # a common setup is to use other default
  425. # branch than master.
  426. self.git(['checkout', '-b', 'master'], cwd=cwd)
  427. try:
  428. self.git(['config', 'user.email'], cwd=cwd)
  429. except bb.process.ExecutionError:
  430. self.git(['config', 'user.email', 'you@example.com'], cwd=cwd)
  431. try:
  432. self.git(['config', 'user.name'], cwd=cwd)
  433. except bb.process.ExecutionError:
  434. self.git(['config', 'user.name', 'Your Name'], cwd=cwd)
  435. class MirrorUriTest(FetcherTest):
  436. replaceuris = {
  437. ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master", "git://.*/.*", "http://somewhere.org/somedir/")
  438. : "http://somewhere.org/somedir/git2_git.invalid.infradead.org.mtd-utils.git.tar.gz",
  439. ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http")
  440. : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master;protocol=http",
  441. ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http")
  442. : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master;protocol=http",
  443. ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/\\2;protocol=http")
  444. : "git://somewhere.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master;protocol=http",
  445. ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master", "git://someserver.org/bitbake", "git://git.openembedded.org/bitbake")
  446. : "git://git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master",
  447. ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache")
  448. : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
  449. ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache/")
  450. : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
  451. ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org/somedir3")
  452. : "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz",
  453. ("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")
  454. : "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz",
  455. ("http://www.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", "http://www.apache.org/dist", "http://archive.apache.org/dist")
  456. : "http://archive.apache.org/dist/subversion/subversion-1.7.1.tar.bz2",
  457. ("http://www.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", "http://.*/.*", "file:///somepath/downloads/")
  458. : "file:///somepath/downloads/subversion-1.7.1.tar.bz2",
  459. ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http")
  460. : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master;protocol=http",
  461. ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http")
  462. : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master;protocol=http",
  463. ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master", "git://.*/.*", "git://somewhere.org/somedir/MIRRORNAME;protocol=http")
  464. : "git://somewhere.org/somedir/git.invalid.infradead.org.foo.mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master;protocol=http",
  465. ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org")
  466. : "http://somewhere2.org/somefile_1.2.3.tar.gz",
  467. ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org/")
  468. : "http://somewhere2.org/somefile_1.2.3.tar.gz",
  469. ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master", "git://someserver.org/bitbake;branch=master", "git://git.openembedded.org/bitbake;protocol=http")
  470. : "git://git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master;protocol=http",
  471. ("git://user1@someserver.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master", "git://someserver.org/bitbake;branch=master", "git://user2@git.openembedded.org/bitbake;protocol=http")
  472. : "git://user2@git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master;protocol=http",
  473. ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890;protocol=git;branch=master", "git://someserver.org/bitbake", "git://someotherserver.org/bitbake;protocol=https")
  474. : "git://someotherserver.org/bitbake;tag=1234567890123456789012345678901234567890;protocol=https;branch=master",
  475. ("gitsm://git.qemu.org/git/seabios.git/;protocol=https;name=roms/seabios;subpath=roms/seabios;bareclone=1;nobranch=1;rev=1234567890123456789012345678901234567890", "gitsm://.*/.*", "http://petalinux.xilinx.com/sswreleases/rel-v${XILINX_VER_MAIN}/downloads") : "http://petalinux.xilinx.com/sswreleases/rel-v%24%7BXILINX_VER_MAIN%7D/downloads/git2_git.qemu.org.git.seabios.git..tar.gz",
  476. ("https://somewhere.org/example/1.0.0/example;downloadfilename=some-example-1.0.0.tgz", "https://.*/.*", "file:///mirror/PATH")
  477. : "file:///mirror/example/1.0.0/some-example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz",
  478. ("https://somewhere.org/example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz", "https://.*/.*", "file:///mirror/some-example-1.0.0.tgz")
  479. : "file:///mirror/some-example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz",
  480. ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master", r"git://(?!internal\.git\.server).*/.*", "http://somewhere.org/somedir/")
  481. : "http://somewhere.org/somedir/git2_git.invalid.infradead.org.mtd-utils.git.tar.gz",
  482. ("git://internal.git.server.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master", r"git://(?!internal\.git\.server).*/.*", "http://somewhere.org/somedir/")
  483. : None,
  484. #Renaming files doesn't work
  485. #("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"
  486. #("file://sstate-xyz.tgz", "file://.*/.*", "file:///somewhere/1234/sstate-cache") : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
  487. }
  488. mirrorvar = "http://.*/.* file:///somepath/downloads/ " \
  489. "git://someserver.org/bitbake git://git.openembedded.org/bitbake " \
  490. "https?://.*/.* file:///someotherpath/downloads/ " \
  491. "svn://svn.server1.com/ svn://svn.server2.com/"
  492. def test_urireplace(self):
  493. self.d.setVar("FILESPATH", ".")
  494. for k, v in self.replaceuris.items():
  495. ud = bb.fetch.FetchData(k[0], self.d)
  496. ud.setup_localpath(self.d)
  497. mirrors = bb.fetch2.mirror_from_string("%s %s" % (k[1], k[2]))
  498. newuris, uds = bb.fetch2.build_mirroruris(ud, mirrors, self.d)
  499. self.assertEqual([v] if v else [], newuris)
  500. def test_urilist1(self):
  501. fetcher = bb.fetch.FetchData("http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
  502. mirrors = bb.fetch2.mirror_from_string(self.mirrorvar)
  503. uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
  504. self.assertEqual(uris, ['file:///somepath/downloads/bitbake-1.0.tar.gz', 'file:///someotherpath/downloads/bitbake-1.0.tar.gz'])
  505. def test_urilist2(self):
  506. # Catch https:// -> files:// bug
  507. fetcher = bb.fetch.FetchData("https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
  508. mirrors = bb.fetch2.mirror_from_string(self.mirrorvar)
  509. uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
  510. self.assertEqual(uris, ['file:///someotherpath/downloads/bitbake-1.0.tar.gz'])
  511. def test_urilistsvn(self):
  512. # Catch svn:// -> svn:// bug
  513. fetcher = bb.fetch.FetchData("svn://svn.server1.com/isource/svnroot/reponame/tags/tagname;module=path_in_tagnamefolder;protocol=https;rev=2", self.d)
  514. mirrors = bb.fetch2.mirror_from_string(self.mirrorvar)
  515. uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
  516. self.assertEqual(uris, ['svn://svn.server2.com/isource/svnroot/reponame/tags/tagname;module=path_in_tagnamefolder;protocol=https;rev=2'])
  517. def test_mirror_of_mirror(self):
  518. # Test if mirror of a mirror works
  519. mirrorvar = self.mirrorvar + " http://.*/.* http://otherdownloads.yoctoproject.org/downloads/"
  520. mirrorvar = mirrorvar + " http://otherdownloads.yoctoproject.org/.* http://downloads2.yoctoproject.org/downloads/"
  521. fetcher = bb.fetch.FetchData("http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
  522. mirrors = bb.fetch2.mirror_from_string(mirrorvar)
  523. uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
  524. self.assertEqual(uris, ['file:///somepath/downloads/bitbake-1.0.tar.gz',
  525. 'file:///someotherpath/downloads/bitbake-1.0.tar.gz',
  526. 'http://otherdownloads.yoctoproject.org/downloads/bitbake-1.0.tar.gz',
  527. 'http://downloads2.yoctoproject.org/downloads/bitbake-1.0.tar.gz'])
  528. recmirrorvar = "https://.*/[^/]* http://aaaa/A/A/A/ " \
  529. "https://.*/[^/]* https://bbbb/B/B/B/"
  530. def test_recursive(self):
  531. fetcher = bb.fetch.FetchData("https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
  532. mirrors = bb.fetch2.mirror_from_string(self.recmirrorvar)
  533. uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
  534. self.assertEqual(uris, ['http://aaaa/A/A/A/bitbake/bitbake-1.0.tar.gz',
  535. 'https://bbbb/B/B/B/bitbake/bitbake-1.0.tar.gz',
  536. 'http://aaaa/A/A/A/B/B/bitbake/bitbake-1.0.tar.gz'])
  537. class GitDownloadDirectoryNamingTest(FetcherTest):
  538. def setUp(self):
  539. super(GitDownloadDirectoryNamingTest, self).setUp()
  540. self.recipe_url = "git://git.openembedded.org/bitbake;branch=master;protocol=https"
  541. self.recipe_dir = "git.openembedded.org.bitbake"
  542. self.mirror_url = "git://github.com/openembedded/bitbake.git;protocol=https;branch=master"
  543. self.mirror_dir = "github.com.openembedded.bitbake.git"
  544. self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
  545. def setup_mirror_rewrite(self):
  546. self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url)
  547. @skipIfNoNetwork()
  548. def test_that_directory_is_named_after_recipe_url_when_no_mirroring_is_used(self):
  549. self.setup_mirror_rewrite()
  550. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  551. fetcher.download()
  552. dir = os.listdir(self.dldir + "/git2")
  553. self.assertIn(self.recipe_dir, dir)
  554. @skipIfNoNetwork()
  555. def test_that_directory_exists_for_mirrored_url_and_recipe_url_when_mirroring_is_used(self):
  556. self.setup_mirror_rewrite()
  557. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  558. fetcher.download()
  559. dir = os.listdir(self.dldir + "/git2")
  560. self.assertIn(self.mirror_dir, dir)
  561. self.assertIn(self.recipe_dir, dir)
  562. @skipIfNoNetwork()
  563. def test_that_recipe_directory_and_mirrored_directory_exists_when_mirroring_is_used_and_the_mirrored_directory_already_exists(self):
  564. self.setup_mirror_rewrite()
  565. fetcher = bb.fetch.Fetch([self.mirror_url], self.d)
  566. fetcher.download()
  567. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  568. fetcher.download()
  569. dir = os.listdir(self.dldir + "/git2")
  570. self.assertIn(self.mirror_dir, dir)
  571. self.assertIn(self.recipe_dir, dir)
  572. class TarballNamingTest(FetcherTest):
  573. def setUp(self):
  574. super(TarballNamingTest, self).setUp()
  575. self.recipe_url = "git://git.openembedded.org/bitbake;branch=master;protocol=https"
  576. self.recipe_tarball = "git2_git.openembedded.org.bitbake.tar.gz"
  577. self.mirror_url = "git://github.com/openembedded/bitbake.git;protocol=https;branch=master"
  578. self.mirror_tarball = "git2_github.com.openembedded.bitbake.git.tar.gz"
  579. self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '1')
  580. self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
  581. def setup_mirror_rewrite(self):
  582. self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url)
  583. @skipIfNoNetwork()
  584. def test_that_the_recipe_tarball_is_created_when_no_mirroring_is_used(self):
  585. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  586. fetcher.download()
  587. dir = os.listdir(self.dldir)
  588. self.assertIn(self.recipe_tarball, dir)
  589. @skipIfNoNetwork()
  590. def test_that_the_mirror_tarball_is_created_when_mirroring_is_used(self):
  591. self.setup_mirror_rewrite()
  592. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  593. fetcher.download()
  594. dir = os.listdir(self.dldir)
  595. self.assertIn(self.mirror_tarball, dir)
  596. class GitShallowTarballNamingTest(FetcherTest):
  597. def setUp(self):
  598. super(GitShallowTarballNamingTest, self).setUp()
  599. self.recipe_url = "git://git.openembedded.org/bitbake;branch=master;protocol=https"
  600. self.recipe_tarball = "gitshallow_git.openembedded.org.bitbake_82ea737-1_master.tar.gz"
  601. self.mirror_url = "git://github.com/openembedded/bitbake.git;protocol=https;branch=master"
  602. self.mirror_tarball = "gitshallow_github.com.openembedded.bitbake.git_82ea737-1_master.tar.gz"
  603. self.d.setVar('BB_GIT_SHALLOW', '1')
  604. self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1')
  605. self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
  606. def setup_mirror_rewrite(self):
  607. self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url)
  608. @skipIfNoNetwork()
  609. def test_that_the_tarball_is_named_after_recipe_url_when_no_mirroring_is_used(self):
  610. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  611. fetcher.download()
  612. dir = os.listdir(self.dldir)
  613. self.assertIn(self.recipe_tarball, dir)
  614. @skipIfNoNetwork()
  615. def test_that_the_mirror_tarball_is_created_when_mirroring_is_used(self):
  616. self.setup_mirror_rewrite()
  617. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  618. fetcher.download()
  619. dir = os.listdir(self.dldir)
  620. self.assertIn(self.mirror_tarball, dir)
  621. class CleanTarballTest(FetcherTest):
  622. def setUp(self):
  623. super(CleanTarballTest, self).setUp()
  624. self.recipe_url = "git://git.openembedded.org/bitbake;protocol=https;branch=master"
  625. self.recipe_tarball = "git2_git.openembedded.org.bitbake.tar.gz"
  626. self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '1')
  627. self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
  628. @skipIfNoNetwork()
  629. def test_that_the_tarball_contents_does_not_leak_info(self):
  630. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  631. fetcher.download()
  632. fetcher.unpack(self.unpackdir)
  633. mtime = bb.process.run('git log --all -1 --format=%ct',
  634. cwd=os.path.join(self.unpackdir, 'git'))
  635. self.assertEqual(len(mtime), 2)
  636. mtime = int(mtime[0])
  637. archive = tarfile.open(os.path.join(self.dldir, self.recipe_tarball))
  638. self.assertNotEqual(len(archive.members), 0)
  639. for member in archive.members:
  640. if member.name == ".":
  641. continue
  642. self.assertEqual(member.uname, 'oe', "user name for %s differs" % member.name)
  643. self.assertEqual(member.uid, 0, "uid for %s differs" % member.name)
  644. self.assertEqual(member.gname, 'oe', "group name for %s differs" % member.name)
  645. self.assertEqual(member.gid, 0, "gid for %s differs" % member.name)
  646. self.assertEqual(member.mtime, mtime, "mtime for %s differs" % member.name)
  647. class FetcherLocalTest(FetcherTest):
  648. def setUp(self):
  649. def touch(fn):
  650. with open(fn, 'a'):
  651. os.utime(fn, None)
  652. super(FetcherLocalTest, self).setUp()
  653. self.localsrcdir = os.path.join(self.tempdir, 'localsrc')
  654. os.makedirs(self.localsrcdir)
  655. touch(os.path.join(self.localsrcdir, 'a'))
  656. touch(os.path.join(self.localsrcdir, 'b'))
  657. touch(os.path.join(self.localsrcdir, 'c@d'))
  658. os.makedirs(os.path.join(self.localsrcdir, 'dir'))
  659. touch(os.path.join(self.localsrcdir, 'dir', 'c'))
  660. touch(os.path.join(self.localsrcdir, 'dir', 'd'))
  661. os.makedirs(os.path.join(self.localsrcdir, 'dir', 'subdir'))
  662. touch(os.path.join(self.localsrcdir, 'dir', 'subdir', 'e'))
  663. touch(os.path.join(self.localsrcdir, r'backslash\x2dsystemd-unit.device'))
  664. bb.process.run('tar cf archive.tar -C dir .', cwd=self.localsrcdir)
  665. bb.process.run('tar czf archive.tar.gz -C dir .', cwd=self.localsrcdir)
  666. bb.process.run('tar cjf archive.tar.bz2 -C dir .', cwd=self.localsrcdir)
  667. self.d.setVar("FILESPATH", self.localsrcdir)
  668. def fetchUnpack(self, uris):
  669. fetcher = bb.fetch.Fetch(uris, self.d)
  670. fetcher.download()
  671. fetcher.unpack(self.unpackdir)
  672. flst = []
  673. for root, dirs, files in os.walk(self.unpackdir):
  674. for f in files:
  675. flst.append(os.path.relpath(os.path.join(root, f), self.unpackdir))
  676. flst.sort()
  677. return flst
  678. def test_local_checksum_fails_no_file(self):
  679. self.d.setVar("SRC_URI", "file://404")
  680. with self.assertRaises(bb.BBHandledException):
  681. bb.fetch.get_checksum_file_list(self.d)
  682. def test_local(self):
  683. tree = self.fetchUnpack(['file://a', 'file://dir/c'])
  684. self.assertEqual(tree, ['a', 'dir/c'])
  685. def test_local_at(self):
  686. tree = self.fetchUnpack(['file://c@d'])
  687. self.assertEqual(tree, ['c@d'])
  688. def test_local_backslash(self):
  689. tree = self.fetchUnpack([r'file://backslash\x2dsystemd-unit.device'])
  690. self.assertEqual(tree, [r'backslash\x2dsystemd-unit.device'])
  691. def test_local_wildcard(self):
  692. with self.assertRaises(bb.fetch2.ParameterError):
  693. tree = self.fetchUnpack(['file://a', 'file://dir/*'])
  694. def test_local_dir(self):
  695. tree = self.fetchUnpack(['file://a', 'file://dir'])
  696. self.assertEqual(tree, ['a', 'dir/c', 'dir/d', 'dir/subdir/e'])
  697. def test_local_subdir(self):
  698. tree = self.fetchUnpack(['file://dir/subdir'])
  699. self.assertEqual(tree, ['dir/subdir/e'])
  700. def test_local_subdir_file(self):
  701. tree = self.fetchUnpack(['file://dir/subdir/e'])
  702. self.assertEqual(tree, ['dir/subdir/e'])
  703. def test_local_subdirparam(self):
  704. tree = self.fetchUnpack(['file://a;subdir=bar', 'file://dir;subdir=foo/moo'])
  705. self.assertEqual(tree, ['bar/a', 'foo/moo/dir/c', 'foo/moo/dir/d', 'foo/moo/dir/subdir/e'])
  706. def test_local_deepsubdirparam(self):
  707. tree = self.fetchUnpack(['file://dir/subdir/e;subdir=bar'])
  708. self.assertEqual(tree, ['bar/dir/subdir/e'])
  709. def test_local_absolutedir(self):
  710. # Unpacking to an absolute path that is a subdirectory of the root
  711. # should work
  712. tree = self.fetchUnpack(['file://a;subdir=%s' % os.path.join(self.unpackdir, 'bar')])
  713. # Unpacking to an absolute path outside of the root should fail
  714. with self.assertRaises(bb.fetch2.UnpackError):
  715. self.fetchUnpack(['file://a;subdir=/bin/sh'])
  716. def test_local_striplevel(self):
  717. tree = self.fetchUnpack(['file://archive.tar;subdir=bar;striplevel=1'])
  718. self.assertEqual(tree, ['bar/c', 'bar/d', 'bar/subdir/e'])
  719. def test_local_striplevel_gzip(self):
  720. tree = self.fetchUnpack(['file://archive.tar.gz;subdir=bar;striplevel=1'])
  721. self.assertEqual(tree, ['bar/c', 'bar/d', 'bar/subdir/e'])
  722. def test_local_striplevel_bzip2(self):
  723. tree = self.fetchUnpack(['file://archive.tar.bz2;subdir=bar;striplevel=1'])
  724. self.assertEqual(tree, ['bar/c', 'bar/d', 'bar/subdir/e'])
  725. def dummyGitTest(self, suffix):
  726. # Create dummy local Git repo
  727. src_dir = tempfile.mkdtemp(dir=self.tempdir,
  728. prefix='gitfetch_localusehead_')
  729. self.gitdir = os.path.abspath(src_dir)
  730. self.git_init()
  731. self.git(['commit', '--allow-empty', '-m', 'Dummy commit'])
  732. # Use other branch than master
  733. self.git(['checkout', '-b', 'my-devel'])
  734. self.git(['commit', '--allow-empty', '-m', 'Dummy commit 2'])
  735. orig_rev = self.git(['rev-parse', 'HEAD']).strip()
  736. # Fetch and check revision
  737. self.d.setVar("SRCREV", "AUTOINC")
  738. self.d.setVar("__BBSRCREV_SEEN", "1")
  739. url = "git://" + self.gitdir + ";branch=master;protocol=file;" + suffix
  740. fetcher = bb.fetch.Fetch([url], self.d)
  741. fetcher.download()
  742. fetcher.unpack(self.unpackdir)
  743. unpack_rev = self.git(['rev-parse', 'HEAD'],
  744. cwd=os.path.join(self.unpackdir, 'git')).strip()
  745. self.assertEqual(orig_rev, unpack_rev)
  746. def test_local_gitfetch_usehead(self):
  747. self.dummyGitTest("usehead=1")
  748. def test_local_gitfetch_usehead_withname(self):
  749. self.dummyGitTest("usehead=1;name=newName")
  750. def test_local_gitfetch_shared(self):
  751. self.dummyGitTest("usehead=1;name=sharedName")
  752. alt = os.path.join(self.unpackdir, 'git/.git/objects/info/alternates')
  753. self.assertTrue(os.path.exists(alt))
  754. def test_local_gitfetch_noshared(self):
  755. self.d.setVar('BB_GIT_NOSHARED', '1')
  756. self.unpackdir += '_noshared'
  757. self.dummyGitTest("usehead=1;name=noSharedName")
  758. alt = os.path.join(self.unpackdir, 'git/.git/objects/info/alternates')
  759. self.assertFalse(os.path.exists(alt))
  760. class FetcherNoNetworkTest(FetcherTest):
  761. def setUp(self):
  762. super().setUp()
  763. # all test cases are based on not having network
  764. self.d.setVar("BB_NO_NETWORK", "1")
  765. def test_missing(self):
  766. string = "this is a test file\n".encode("utf-8")
  767. self.d.setVarFlag("SRC_URI", "md5sum", hashlib.md5(string).hexdigest())
  768. self.d.setVarFlag("SRC_URI", "sha256sum", hashlib.sha256(string).hexdigest())
  769. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
  770. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
  771. fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/test-file.tar.gz"], self.d)
  772. with self.assertRaises(bb.fetch2.NetworkAccess):
  773. fetcher.download()
  774. def test_valid_missing_donestamp(self):
  775. # create the file in the download directory with correct hash
  776. string = "this is a test file\n".encode("utf-8")
  777. with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb") as f:
  778. f.write(string)
  779. self.d.setVarFlag("SRC_URI", "md5sum", hashlib.md5(string).hexdigest())
  780. self.d.setVarFlag("SRC_URI", "sha256sum", hashlib.sha256(string).hexdigest())
  781. self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
  782. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
  783. fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/test-file.tar.gz"], self.d)
  784. fetcher.download()
  785. self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
  786. def test_invalid_missing_donestamp(self):
  787. # create an invalid file in the download directory with incorrect hash
  788. string = "this is a test file\n".encode("utf-8")
  789. with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb"):
  790. pass
  791. self.d.setVarFlag("SRC_URI", "md5sum", hashlib.md5(string).hexdigest())
  792. self.d.setVarFlag("SRC_URI", "sha256sum", hashlib.sha256(string).hexdigest())
  793. self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
  794. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
  795. fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/test-file.tar.gz"], self.d)
  796. with self.assertRaises(bb.fetch2.NetworkAccess):
  797. fetcher.download()
  798. # the existing file should not exist or should have be moved to "bad-checksum"
  799. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
  800. def test_nochecksums_missing(self):
  801. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
  802. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
  803. # ssh fetch does not support checksums
  804. fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d)
  805. # attempts to download with missing donestamp
  806. with self.assertRaises(bb.fetch2.NetworkAccess):
  807. fetcher.download()
  808. def test_nochecksums_missing_donestamp(self):
  809. # create a file in the download directory
  810. with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb"):
  811. pass
  812. self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
  813. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
  814. # ssh fetch does not support checksums
  815. fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d)
  816. # attempts to download with missing donestamp
  817. with self.assertRaises(bb.fetch2.NetworkAccess):
  818. fetcher.download()
  819. def test_nochecksums_has_donestamp(self):
  820. # create a file in the download directory with the donestamp
  821. with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb"):
  822. pass
  823. with open(os.path.join(self.dldir, "test-file.tar.gz.done"), "wb"):
  824. pass
  825. self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
  826. self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
  827. # ssh fetch does not support checksums
  828. fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d)
  829. # should not fetch
  830. fetcher.download()
  831. # both files should still exist
  832. self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
  833. self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
  834. def test_nochecksums_missing_has_donestamp(self):
  835. # create a file in the download directory with the donestamp
  836. with open(os.path.join(self.dldir, "test-file.tar.gz.done"), "wb"):
  837. pass
  838. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
  839. self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
  840. # ssh fetch does not support checksums
  841. fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d)
  842. with self.assertRaises(bb.fetch2.NetworkAccess):
  843. fetcher.download()
  844. # both files should still exist
  845. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
  846. self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
  847. class FetcherNetworkTest(FetcherTest):
  848. @skipIfNoNetwork()
  849. def test_fetch(self):
  850. fetcher = bb.fetch.Fetch(["https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", "https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.1.tar.gz"], self.d)
  851. fetcher.download()
  852. self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
  853. self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.1.tar.gz"), 57892)
  854. self.d.setVar("BB_NO_NETWORK", "1")
  855. fetcher = bb.fetch.Fetch(["https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", "https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.1.tar.gz"], self.d)
  856. fetcher.download()
  857. fetcher.unpack(self.unpackdir)
  858. self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.0/")), 9)
  859. self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.1/")), 9)
  860. @skipIfNoNetwork()
  861. def test_fetch_mirror(self):
  862. self.d.setVar("MIRRORS", "http://.*/.* https://downloads.yoctoproject.org/releases/bitbake")
  863. fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
  864. fetcher.download()
  865. self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
  866. @skipIfNoNetwork()
  867. def test_fetch_mirror_of_mirror(self):
  868. self.d.setVar("MIRRORS", "http://.*/.* http://invalid2.yoctoproject.org/ http://invalid2.yoctoproject.org/.* https://downloads.yoctoproject.org/releases/bitbake")
  869. fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
  870. fetcher.download()
  871. self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
  872. @skipIfNoNetwork()
  873. def test_fetch_file_mirror_of_mirror(self):
  874. self.d.setVar("FILESPATH", ".")
  875. self.d.setVar("MIRRORS", "http://.*/.* file:///some1where/ file:///some1where/.* file://some2where/ file://some2where/.* https://downloads.yoctoproject.org/releases/bitbake")
  876. fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
  877. os.mkdir(self.dldir + "/some2where")
  878. fetcher.download()
  879. self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
  880. @skipIfNoNetwork()
  881. def test_fetch_premirror(self):
  882. self.d.setVar("PREMIRRORS", "http://.*/.* https://downloads.yoctoproject.org/releases/bitbake")
  883. fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
  884. fetcher.download()
  885. self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
  886. @skipIfNoNetwork()
  887. def test_fetch_specify_downloadfilename(self):
  888. fetcher = bb.fetch.Fetch(["https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz;downloadfilename=bitbake-v1.0.0.tar.gz"], self.d)
  889. fetcher.download()
  890. self.assertEqual(os.path.getsize(self.dldir + "/bitbake-v1.0.0.tar.gz"), 57749)
  891. @skipIfNoNetwork()
  892. def test_fetch_premirror_specify_downloadfilename_regex_uri(self):
  893. self.d.setVar("PREMIRRORS", "http://.*/.* https://downloads.yoctoproject.org/releases/bitbake/")
  894. fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/1.0.tar.gz;downloadfilename=bitbake-1.0.tar.gz"], self.d)
  895. fetcher.download()
  896. self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
  897. @skipIfNoNetwork()
  898. # BZ13039
  899. def test_fetch_premirror_specify_downloadfilename_specific_uri(self):
  900. self.d.setVar("PREMIRRORS", "http://invalid.yoctoproject.org/releases/bitbake https://downloads.yoctoproject.org/releases/bitbake")
  901. fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/1.0.tar.gz;downloadfilename=bitbake-1.0.tar.gz"], self.d)
  902. fetcher.download()
  903. self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
  904. @skipIfNoNetwork()
  905. def test_fetch_premirror_use_downloadfilename_to_fetch(self):
  906. # Ensure downloadfilename is used when fetching from premirror.
  907. self.d.setVar("PREMIRRORS", "http://.*/.* https://downloads.yoctoproject.org/releases/bitbake")
  908. fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.1.tar.gz;downloadfilename=bitbake-1.0.tar.gz"], self.d)
  909. fetcher.download()
  910. self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
  911. @skipIfNoNetwork()
  912. def gitfetcher(self, url1, url2):
  913. def checkrevision(self, fetcher):
  914. fetcher.unpack(self.unpackdir)
  915. revision = self.git(['rev-parse', 'HEAD'],
  916. cwd=os.path.join(self.unpackdir, 'git')).strip()
  917. self.assertEqual(revision, "270a05b0b4ba0959fe0624d2a4885d7b70426da5")
  918. self.d.setVar("BB_GENERATE_MIRROR_TARBALLS", "1")
  919. self.d.setVar("SRCREV", "270a05b0b4ba0959fe0624d2a4885d7b70426da5")
  920. fetcher = bb.fetch.Fetch([url1], self.d)
  921. fetcher.download()
  922. checkrevision(self, fetcher)
  923. # Wipe out the dldir clone and the unpacked source, turn off the network and check mirror tarball works
  924. bb.utils.prunedir(self.dldir + "/git2/")
  925. bb.utils.prunedir(self.unpackdir)
  926. self.d.setVar("BB_NO_NETWORK", "1")
  927. fetcher = bb.fetch.Fetch([url2], self.d)
  928. fetcher.download()
  929. checkrevision(self, fetcher)
  930. @skipIfNoNetwork()
  931. def test_gitfetch(self):
  932. url1 = url2 = "git://git.openembedded.org/bitbake;branch=master;protocol=https"
  933. self.gitfetcher(url1, url2)
  934. @skipIfNoNetwork()
  935. def test_gitfetch_goodsrcrev(self):
  936. # SRCREV is set but matches rev= parameter
  937. url1 = url2 = "git://git.openembedded.org/bitbake;rev=270a05b0b4ba0959fe0624d2a4885d7b70426da5;branch=master;protocol=https"
  938. self.gitfetcher(url1, url2)
  939. @skipIfNoNetwork()
  940. def test_gitfetch_badsrcrev(self):
  941. # SRCREV is set but does not match rev= parameter
  942. url1 = url2 = "git://git.openembedded.org/bitbake;rev=dead05b0b4ba0959fe0624d2a4885d7b70426da5;branch=master;protocol=https"
  943. self.assertRaises(bb.fetch.FetchError, self.gitfetcher, url1, url2)
  944. @skipIfNoNetwork()
  945. def test_gitfetch_usehead(self):
  946. # Since self.gitfetcher() sets SRCREV we expect this to override
  947. # `usehead=1' and instead fetch the specified SRCREV. See
  948. # test_local_gitfetch_usehead() for a positive use of the usehead
  949. # feature.
  950. url = "git://git.openembedded.org/bitbake;usehead=1;branch=master;protocol=https"
  951. self.assertRaises(bb.fetch.ParameterError, self.gitfetcher, url, url)
  952. @skipIfNoNetwork()
  953. def test_gitfetch_usehead_withname(self):
  954. # Since self.gitfetcher() sets SRCREV we expect this to override
  955. # `usehead=1' and instead fetch the specified SRCREV. See
  956. # test_local_gitfetch_usehead() for a positive use of the usehead
  957. # feature.
  958. url = "git://git.openembedded.org/bitbake;usehead=1;name=newName;branch=master;protocol=https"
  959. self.assertRaises(bb.fetch.ParameterError, self.gitfetcher, url, url)
  960. @skipIfNoNetwork()
  961. def test_gitfetch_finds_local_tarball_for_mirrored_url_when_previous_downloaded_by_the_recipe_url(self):
  962. recipeurl = "git://git.openembedded.org/bitbake;branch=master;protocol=https"
  963. mirrorurl = "git://someserver.org/bitbake;branch=master;protocol=https"
  964. self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake")
  965. self.gitfetcher(recipeurl, mirrorurl)
  966. @skipIfNoNetwork()
  967. def test_gitfetch_finds_local_tarball_when_previous_downloaded_from_a_premirror(self):
  968. recipeurl = "git://someserver.org/bitbake;branch=master;protocol=https"
  969. self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake")
  970. self.gitfetcher(recipeurl, recipeurl)
  971. @skipIfNoNetwork()
  972. def test_gitfetch_finds_local_repository_when_premirror_rewrites_the_recipe_url(self):
  973. realurl = "https://git.openembedded.org/bitbake"
  974. recipeurl = "git://someserver.org/bitbake;protocol=https;branch=master"
  975. self.sourcedir = self.unpackdir.replace("unpacked", "sourcemirror.git")
  976. os.chdir(self.tempdir)
  977. self.git(['clone', realurl, self.sourcedir], cwd=self.tempdir)
  978. self.d.setVar("PREMIRRORS", "%s git://%s;protocol=file" % (recipeurl, self.sourcedir))
  979. self.gitfetcher(recipeurl, recipeurl)
  980. @skipIfNoNetwork()
  981. def test_git_submodule(self):
  982. # URL with ssh submodules
  983. url = "gitsm://git.yoctoproject.org/git-submodule-test;branch=ssh-gitsm-tests;rev=049da4a6cb198d7c0302e9e8b243a1443cb809a7;branch=master;protocol=https"
  984. # Original URL (comment this if you have ssh access to git.yoctoproject.org)
  985. url = "gitsm://git.yoctoproject.org/git-submodule-test;branch=master;rev=a2885dd7d25380d23627e7544b7bbb55014b16ee;branch=master;protocol=https"
  986. fetcher = bb.fetch.Fetch([url], self.d)
  987. fetcher.download()
  988. # Previous cwd has been deleted
  989. os.chdir(os.path.dirname(self.unpackdir))
  990. fetcher.unpack(self.unpackdir)
  991. repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
  992. self.assertTrue(os.path.exists(repo_path), msg='Unpacked repository missing')
  993. self.assertTrue(os.path.exists(os.path.join(repo_path, 'bitbake')), msg='bitbake submodule missing')
  994. self.assertFalse(os.path.exists(os.path.join(repo_path, 'na')), msg='uninitialized submodule present')
  995. # Only when we're running the extended test with a submodule's submodule, can we check this.
  996. if os.path.exists(os.path.join(repo_path, 'bitbake-gitsm-test1')):
  997. self.assertTrue(os.path.exists(os.path.join(repo_path, 'bitbake-gitsm-test1', 'bitbake')), msg='submodule of submodule missing')
  998. @skipIfNoNetwork()
  999. def test_git_submodule_restricted_network_premirrors(self):
  1000. # this test is to ensure that premirrors will be tried in restricted network
  1001. # that is, BB_ALLOWED_NETWORKS does not contain the domain the url uses
  1002. url = "gitsm://github.com/grpc/grpc.git;protocol=https;name=grpc;branch=v1.60.x;rev=0ef13a7555dbaadd4633399242524129eef5e231"
  1003. # create a download directory to be used as premirror later
  1004. tempdir = tempfile.mkdtemp(prefix="bitbake-fetch-")
  1005. dl_premirror = os.path.join(tempdir, "download-premirror")
  1006. os.mkdir(dl_premirror)
  1007. self.d.setVar("DL_DIR", dl_premirror)
  1008. fetcher = bb.fetch.Fetch([url], self.d)
  1009. fetcher.download()
  1010. # now use the premirror in restricted network
  1011. self.d.setVar("DL_DIR", self.dldir)
  1012. self.d.setVar("PREMIRRORS", "gitsm://.*/.* gitsm://%s/git2/MIRRORNAME;protocol=file" % dl_premirror)
  1013. self.d.setVar("BB_ALLOWED_NETWORKS", "*.some.domain")
  1014. fetcher = bb.fetch.Fetch([url], self.d)
  1015. fetcher.download()
  1016. @skipIfNoNetwork()
  1017. def test_git_submodule_dbus_broker(self):
  1018. # The following external repositories have show failures in fetch and unpack operations
  1019. # We want to avoid regressions!
  1020. url = "gitsm://github.com/bus1/dbus-broker;protocol=https;rev=fc874afa0992d0c75ec25acb43d344679f0ee7d2;branch=main"
  1021. fetcher = bb.fetch.Fetch([url], self.d)
  1022. fetcher.download()
  1023. # Previous cwd has been deleted
  1024. os.chdir(os.path.dirname(self.unpackdir))
  1025. fetcher.unpack(self.unpackdir)
  1026. repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
  1027. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-dvar/config')), msg='Missing submodule config "subprojects/c-dvar"')
  1028. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-list/config')), msg='Missing submodule config "subprojects/c-list"')
  1029. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-rbtree/config')), msg='Missing submodule config "subprojects/c-rbtree"')
  1030. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-sundry/config')), msg='Missing submodule config "subprojects/c-sundry"')
  1031. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-utf8/config')), msg='Missing submodule config "subprojects/c-utf8"')
  1032. @skipIfNoNetwork()
  1033. def test_git_submodule_CLI11(self):
  1034. url = "gitsm://github.com/CLIUtils/CLI11;protocol=https;rev=bd4dc911847d0cde7a6b41dfa626a85aab213baf;branch=main"
  1035. fetcher = bb.fetch.Fetch([url], self.d)
  1036. fetcher.download()
  1037. # Previous cwd has been deleted
  1038. os.chdir(os.path.dirname(self.unpackdir))
  1039. fetcher.unpack(self.unpackdir)
  1040. repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
  1041. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/googletest/config')), msg='Missing submodule config "extern/googletest"')
  1042. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/json/config')), msg='Missing submodule config "extern/json"')
  1043. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/sanitizers/config')), msg='Missing submodule config "extern/sanitizers"')
  1044. @skipIfNoNetwork()
  1045. def test_git_submodule_update_CLI11(self):
  1046. """ Prevent regression on update detection not finding missing submodule, or modules without needed commits """
  1047. url = "gitsm://github.com/CLIUtils/CLI11;protocol=https;rev=cf6a99fa69aaefe477cc52e3ef4a7d2d7fa40714;branch=main"
  1048. fetcher = bb.fetch.Fetch([url], self.d)
  1049. fetcher.download()
  1050. # CLI11 that pulls in a newer nlohmann-json
  1051. url = "gitsm://github.com/CLIUtils/CLI11;protocol=https;rev=49ac989a9527ee9bb496de9ded7b4872c2e0e5ca;branch=main"
  1052. fetcher = bb.fetch.Fetch([url], self.d)
  1053. fetcher.download()
  1054. # Previous cwd has been deleted
  1055. os.chdir(os.path.dirname(self.unpackdir))
  1056. fetcher.unpack(self.unpackdir)
  1057. repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
  1058. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/googletest/config')), msg='Missing submodule config "extern/googletest"')
  1059. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/json/config')), msg='Missing submodule config "extern/json"')
  1060. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/sanitizers/config')), msg='Missing submodule config "extern/sanitizers"')
  1061. @skipIfNoNetwork()
  1062. def test_git_submodule_aktualizr(self):
  1063. url = "gitsm://github.com/advancedtelematic/aktualizr;branch=master;protocol=https;rev=d00d1a04cc2366d1a5f143b84b9f507f8bd32c44"
  1064. fetcher = bb.fetch.Fetch([url], self.d)
  1065. fetcher.download()
  1066. # Previous cwd has been deleted
  1067. os.chdir(os.path.dirname(self.unpackdir))
  1068. fetcher.unpack(self.unpackdir)
  1069. repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
  1070. 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"')
  1071. 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"')
  1072. 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")
  1073. 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"')
  1074. self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/third_party/googletest/config')), msg='Missing submodule config "third_party/googletest/config"')
  1075. 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"')
  1076. @skipIfNoNetwork()
  1077. def test_git_submodule_iotedge(self):
  1078. """ Prevent regression on deeply nested submodules not being checked out properly, even though they were fetched. """
  1079. # This repository also has submodules where the module (name), path and url do not align
  1080. url = "gitsm://github.com/azure/iotedge.git;protocol=https;rev=d76e0316c6f324345d77c48a83ce836d09392699;branch=main"
  1081. fetcher = bb.fetch.Fetch([url], self.d)
  1082. fetcher.download()
  1083. # Previous cwd has been deleted
  1084. os.chdir(os.path.dirname(self.unpackdir))
  1085. fetcher.unpack(self.unpackdir)
  1086. repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
  1087. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/c-shared/README.md')), msg='Missing submodule checkout')
  1088. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/c-shared/testtools/ctest/README.md')), msg='Missing submodule checkout')
  1089. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/c-shared/testtools/testrunner/readme.md')), msg='Missing submodule checkout')
  1090. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/c-shared/testtools/umock-c/readme.md')), msg='Missing submodule checkout')
  1091. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/c-shared/testtools/umock-c/deps/ctest/README.md')), msg='Missing submodule checkout')
  1092. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/c-shared/testtools/umock-c/deps/testrunner/readme.md')), msg='Missing submodule checkout')
  1093. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/README.md')), msg='Missing submodule checkout')
  1094. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/deps/c-utility/README.md')), msg='Missing submodule checkout')
  1095. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/deps/c-utility/testtools/ctest/README.md')), msg='Missing submodule checkout')
  1096. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/deps/c-utility/testtools/testrunner/readme.md')), msg='Missing submodule checkout')
  1097. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/deps/c-utility/testtools/umock-c/readme.md')), msg='Missing submodule checkout')
  1098. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/deps/c-utility/testtools/umock-c/deps/ctest/README.md')), msg='Missing submodule checkout')
  1099. self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/deps/c-utility/testtools/umock-c/deps/testrunner/readme.md')), msg='Missing submodule checkout')
  1100. @skipIfNoNetwork()
  1101. def test_git_submodule_reference_to_parent(self):
  1102. self.recipe_url = "gitsm://github.com/gflags/gflags.git;protocol=https;branch=master"
  1103. self.d.setVar("SRCREV", "14e1138441bbbb584160cb1c0a0426ec1bac35f1")
  1104. with Timeout(60):
  1105. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  1106. with self.assertRaises(bb.fetch2.FetchError):
  1107. fetcher.download()
  1108. class SVNTest(FetcherTest):
  1109. def skipIfNoSvn():
  1110. import shutil
  1111. if not shutil.which("svn"):
  1112. return unittest.skip("svn not installed, tests being skipped")
  1113. if not shutil.which("svnadmin"):
  1114. return unittest.skip("svnadmin not installed, tests being skipped")
  1115. return lambda f: f
  1116. @skipIfNoSvn()
  1117. def setUp(self):
  1118. """ Create a local repository """
  1119. super(SVNTest, self).setUp()
  1120. # Create something we can fetch
  1121. src_dir = tempfile.mkdtemp(dir=self.tempdir,
  1122. prefix='svnfetch_srcdir_')
  1123. src_dir = os.path.abspath(src_dir)
  1124. bb.process.run("echo readme > README.md", cwd=src_dir)
  1125. # Store it in a local SVN repository
  1126. repo_dir = tempfile.mkdtemp(dir=self.tempdir,
  1127. prefix='svnfetch_localrepo_')
  1128. repo_dir = os.path.abspath(repo_dir)
  1129. bb.process.run("svnadmin create project", cwd=repo_dir)
  1130. self.repo_url = "file://%s/project" % repo_dir
  1131. bb.process.run("svn import --non-interactive -m 'Initial import' %s %s/trunk" % (src_dir, self.repo_url),
  1132. cwd=repo_dir)
  1133. bb.process.run("svn co %s svnfetch_co" % self.repo_url, cwd=self.tempdir)
  1134. # Github won't emulate SVN anymore (see https://github.blog/2023-01-20-sunsetting-subversion-support/)
  1135. # Use still accessible svn repo (only trunk to avoid longer downloads)
  1136. bb.process.run("svn propset svn:externals 'bitbake https://svn.apache.org/repos/asf/serf/trunk' .",
  1137. cwd=os.path.join(self.tempdir, 'svnfetch_co', 'trunk'))
  1138. bb.process.run("svn commit --non-interactive -m 'Add external'",
  1139. cwd=os.path.join(self.tempdir, 'svnfetch_co', 'trunk'))
  1140. self.src_dir = src_dir
  1141. self.repo_dir = repo_dir
  1142. @skipIfNoSvn()
  1143. def tearDown(self):
  1144. os.chdir(self.origdir)
  1145. if os.environ.get("BB_TMPDIR_NOCLEAN") == "yes":
  1146. print("Not cleaning up %s. Please remove manually." % self.tempdir)
  1147. else:
  1148. bb.utils.prunedir(self.tempdir)
  1149. @skipIfNoSvn()
  1150. @skipIfNoNetwork()
  1151. def test_noexternal_svn(self):
  1152. # Always match the rev count from setUp (currently rev 2)
  1153. url = "svn://%s;module=trunk;protocol=file;rev=2" % self.repo_url.replace('file://', '')
  1154. fetcher = bb.fetch.Fetch([url], self.d)
  1155. fetcher.download()
  1156. os.chdir(os.path.dirname(self.unpackdir))
  1157. fetcher.unpack(self.unpackdir)
  1158. self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk')), msg="Missing trunk")
  1159. self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk', 'README.md')), msg="Missing contents")
  1160. self.assertFalse(os.path.exists(os.path.join(self.unpackdir, 'trunk/bitbake/protocols')), msg="External dir should NOT exist")
  1161. self.assertFalse(os.path.exists(os.path.join(self.unpackdir, 'trunk/bitbake/protocols', 'fcgi_buckets.h')), msg="External fcgi_buckets.h should NOT exit")
  1162. @skipIfNoSvn()
  1163. def test_external_svn(self):
  1164. # Always match the rev count from setUp (currently rev 2)
  1165. url = "svn://%s;module=trunk;protocol=file;externals=allowed;rev=2" % self.repo_url.replace('file://', '')
  1166. fetcher = bb.fetch.Fetch([url], self.d)
  1167. fetcher.download()
  1168. os.chdir(os.path.dirname(self.unpackdir))
  1169. fetcher.unpack(self.unpackdir)
  1170. self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk')), msg="Missing trunk")
  1171. self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk', 'README.md')), msg="Missing contents")
  1172. self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk/bitbake/protocols')), msg="External dir should exist")
  1173. self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk/bitbake/protocols', 'fcgi_buckets.h')), msg="External fcgi_buckets.h should exit")
  1174. class TrustedNetworksTest(FetcherTest):
  1175. def test_trusted_network(self):
  1176. # Ensure trusted_network returns False when the host IS in the list.
  1177. url = "git://Someserver.org/foo;rev=1;branch=master"
  1178. self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org someserver.org server2.org server3.org")
  1179. self.assertTrue(bb.fetch.trusted_network(self.d, url))
  1180. def test_wild_trusted_network(self):
  1181. # Ensure trusted_network returns true when the *.host IS in the list.
  1182. url = "git://Someserver.org/foo;rev=1;branch=master"
  1183. self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
  1184. self.assertTrue(bb.fetch.trusted_network(self.d, url))
  1185. def test_prefix_wild_trusted_network(self):
  1186. # Ensure trusted_network returns true when the prefix matches *.host.
  1187. url = "git://git.Someserver.org/foo;rev=1;branch=master"
  1188. self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
  1189. self.assertTrue(bb.fetch.trusted_network(self.d, url))
  1190. def test_two_prefix_wild_trusted_network(self):
  1191. # Ensure trusted_network returns true when the prefix matches *.host.
  1192. url = "git://something.git.Someserver.org/foo;rev=1;branch=master"
  1193. self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
  1194. self.assertTrue(bb.fetch.trusted_network(self.d, url))
  1195. def test_port_trusted_network(self):
  1196. # Ensure trusted_network returns True, even if the url specifies a port.
  1197. url = "git://someserver.org:8080/foo;rev=1;branch=master"
  1198. self.d.setVar("BB_ALLOWED_NETWORKS", "someserver.org")
  1199. self.assertTrue(bb.fetch.trusted_network(self.d, url))
  1200. def test_untrusted_network(self):
  1201. # Ensure trusted_network returns False when the host is NOT in the list.
  1202. url = "git://someserver.org/foo;rev=1;branch=master"
  1203. self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org server2.org server3.org")
  1204. self.assertFalse(bb.fetch.trusted_network(self.d, url))
  1205. def test_wild_untrusted_network(self):
  1206. # Ensure trusted_network returns False when the host is NOT in the list.
  1207. url = "git://*.someserver.org/foo;rev=1;branch=master"
  1208. self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org server2.org server3.org")
  1209. self.assertFalse(bb.fetch.trusted_network(self.d, url))
  1210. class URLHandle(unittest.TestCase):
  1211. import urllib.parse
  1212. # Quote password as per RFC3986
  1213. password = urllib.parse.quote(r"!#$%^&*()-_={}[]\|:?,.<>~`", r"!$&'/()*+,;=")
  1214. datatable = {
  1215. "http://www.google.com/index.html" : ('http', 'www.google.com', '/index.html', '', '', {}),
  1216. "cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg" : ('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', '', {'module': 'familiar/dist/ipkg'}),
  1217. "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')])),
  1218. "git://git.openembedded.org/bitbake;branch=@foo;protocol=https" : ('git', 'git.openembedded.org', '/bitbake', '', '', {'branch': '@foo', 'protocol' : 'https'}),
  1219. "file://somelocation;someparam=1": ('file', '', 'somelocation', '', '', {'someparam': '1'}),
  1220. "file://example@.service": ('file', '', 'example@.service', '', '', {}),
  1221. "https://somesite.com/somerepo.git;user=anyUser:idtoken=1234" : ('https', 'somesite.com', '/somerepo.git', '', '', {'user': 'anyUser:idtoken=1234'}),
  1222. 'git://s.o-me_ONE:%s@git.openembedded.org/bitbake;branch=main;protocol=https' % password: ('git', 'git.openembedded.org', '/bitbake', 's.o-me_ONE', password, {'branch': 'main', 'protocol' : 'https'}),
  1223. }
  1224. # we require a pathname to encodeurl but users can still pass such urls to
  1225. # decodeurl and we need to handle them
  1226. decodedata = datatable.copy()
  1227. decodedata.update({
  1228. "http://somesite.net;someparam=1": ('http', 'somesite.net', '/', '', '', {'someparam': '1'}),
  1229. "npmsw://some.registry.url;package=@pkg;version=latest": ('npmsw', 'some.registry.url', '/', '', '', {'package': '@pkg', 'version': 'latest'}),
  1230. })
  1231. def test_decodeurl(self):
  1232. for k, v in self.decodedata.items():
  1233. result = bb.fetch.decodeurl(k)
  1234. self.assertEqual(result, v)
  1235. def test_encodeurl(self):
  1236. import urllib.parse
  1237. for k, v in self.datatable.items():
  1238. result = bb.fetch.encodeurl(v)
  1239. if result.startswith("file:"):
  1240. result = urllib.parse.unquote(result)
  1241. self.assertEqual(result, k)
  1242. class FetchLatestVersionTest(FetcherTest):
  1243. test_git_uris = {
  1244. # version pattern "X.Y.Z"
  1245. ("mx-1.0", "git://github.com/clutter-project/mx.git;branch=mx-1.4;protocol=https", "9b1db6b8060bd00b121a692f942404a24ae2960f", "", "")
  1246. : "1.99.4",
  1247. # version pattern "vX.Y"
  1248. # mirror of git.infradead.org since network issues interfered with testing
  1249. ("mtd-utils", "git://git.yoctoproject.org/mtd-utils.git;branch=master;protocol=https", "ca39eb1d98e736109c64ff9c1aa2a6ecca222d8f", "", "")
  1250. : "1.5.0",
  1251. # version pattern "pkg_name-X.Y"
  1252. # mirror of git://anongit.freedesktop.org/git/xorg/proto/presentproto since network issues interfered with testing
  1253. ("presentproto", "git://git.yoctoproject.org/bbfetchtests-presentproto;branch=master;protocol=https", "24f3a56e541b0a9e6c6ee76081f441221a120ef9", "", "")
  1254. : "1.0",
  1255. # version pattern "pkg_name-vX.Y.Z"
  1256. ("dtc", "git://git.yoctoproject.org/bbfetchtests-dtc.git;branch=master;protocol=https", "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf", "", "")
  1257. : "1.4.0",
  1258. # combination version pattern
  1259. ("sysprof", "git://git.yoctoproject.org/sysprof.git;protocol=https;branch=master", "cd44ee6644c3641507fb53b8a2a69137f2971219", "", "")
  1260. : "1.2.0",
  1261. ("u-boot-mkimage", "git://git.yoctoproject.org/bbfetchtests-u-boot.git;branch=master;protocol=https", "62c175fbb8a0f9a926c88294ea9f7e88eb898f6c", "", "")
  1262. : "2014.01",
  1263. # version pattern "yyyymmdd"
  1264. ("mobile-broadband-provider-info", "git://git.yoctoproject.org/mobile-broadband-provider-info.git;protocol=https;branch=master", "4ed19e11c2975105b71b956440acdb25d46a347d", "", "")
  1265. : "20120614",
  1266. # packages with a valid UPSTREAM_CHECK_GITTAGREGEX
  1267. # mirror of git://anongit.freedesktop.org/xorg/driver/xf86-video-omap since network issues interfered with testing
  1268. ("xf86-video-omap", "git://git.yoctoproject.org/bbfetchtests-xf86-video-omap;branch=master;protocol=https", "ae0394e687f1a77e966cf72f895da91840dffb8f", r"(?P<pver>(\d+\.(\d\.?)*))", "")
  1269. : "0.4.3",
  1270. ("build-appliance-image", "git://git.yoctoproject.org/poky;branch=master;protocol=https", "b37dd451a52622d5b570183a81583cc34c2ff555", r"(?P<pver>(([0-9][\.|_]?)+[0-9]))", "")
  1271. : "11.0.0",
  1272. ("chkconfig-alternatives-native", "git://github.com/kergoth/chkconfig;branch=sysroot;protocol=https", "cd437ecbd8986c894442f8fce1e0061e20f04dee", r"chkconfig\-(?P<pver>((\d+[\.\-_]*)+))", "")
  1273. : "1.3.59",
  1274. ("remake", "git://github.com/rocky/remake.git;protocol=https;branch=master", "f05508e521987c8494c92d9c2871aec46307d51d", r"(?P<pver>(\d+\.(\d+\.)*\d*(\+dbg\d+(\.\d+)*)*))", "")
  1275. : "3.82+dbg0.9",
  1276. ("sysdig", "git://github.com/draios/sysdig.git;branch=dev;protocol=https", "4fb6288275f567f63515df0ff0a6518043ecfa9b", r"^(?P<pver>\d+(\.\d+)+)", "10.0.0")
  1277. : "0.28.0",
  1278. }
  1279. WgetTestData = collections.namedtuple("WgetTestData", ["pn", "path", "pv", "check_uri", "check_regex"], defaults=[None, None, None])
  1280. test_wget_uris = {
  1281. #
  1282. # packages with versions inside directory name
  1283. #
  1284. # http://kernel.org/pub/linux/utils/util-linux/v2.23/util-linux-2.24.2.tar.bz2
  1285. WgetTestData("util-linux", "/pub/linux/utils/util-linux/v2.23/util-linux-2.24.2.tar.bz2")
  1286. : "2.24.2",
  1287. # http://www.abisource.com/downloads/enchant/1.6.0/enchant-1.6.0.tar.gz
  1288. WgetTestData("enchant", "/downloads/enchant/1.6.0/enchant-1.6.0.tar.gz")
  1289. : "1.6.0",
  1290. # http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz
  1291. WgetTestData("cmake", "/files/v2.8/cmake-2.8.12.1.tar.gz")
  1292. : "2.8.12.1",
  1293. # https://download.gnome.org/sources/libxml2/2.9/libxml2-2.9.14.tar.xz
  1294. WgetTestData("libxml2", "/software/libxml2/2.9/libxml2-2.9.14.tar.xz")
  1295. : "2.10.3",
  1296. #
  1297. # packages with versions only in current directory
  1298. #
  1299. # https://downloads.yoctoproject.org/releases/eglibc/eglibc-2.18-svnr23787.tar.bz2
  1300. WgetTestData("eglic", "/releases/eglibc/eglibc-2.18-svnr23787.tar.bz2")
  1301. : "2.19",
  1302. # https://downloads.yoctoproject.org/releases/gnu-config/gnu-config-20120814.tar.bz2
  1303. WgetTestData("gnu-config", "/releases/gnu-config/gnu-config-20120814.tar.bz2")
  1304. : "20120814",
  1305. #
  1306. # packages with "99" in the name of possible version
  1307. #
  1308. # http://freedesktop.org/software/pulseaudio/releases/pulseaudio-4.0.tar.xz
  1309. WgetTestData("pulseaudio", "/software/pulseaudio/releases/pulseaudio-4.0.tar.xz")
  1310. : "5.0",
  1311. # http://xorg.freedesktop.org/releases/individual/xserver/xorg-server-1.15.1.tar.bz2
  1312. WgetTestData("xserver-xorg", "/releases/individual/xserver/xorg-server-1.15.1.tar.bz2")
  1313. : "1.15.1",
  1314. #
  1315. # packages with valid UPSTREAM_CHECK_URI and UPSTREAM_CHECK_REGEX
  1316. #
  1317. # http://www.cups.org/software/1.7.2/cups-1.7.2-source.tar.bz2
  1318. # https://github.com/apple/cups/releases
  1319. WgetTestData("cups", "/software/1.7.2/cups-1.7.2-source.tar.bz2", check_uri="/apple/cups/releases", check_regex=r"(?P<name>cups\-)(?P<pver>((\d+[\.\-_]*)+))\-source\.tar\.gz")
  1320. : "2.0.0",
  1321. # http://download.oracle.com/berkeley-db/db-5.3.21.tar.gz
  1322. # http://ftp.debian.org/debian/pool/main/d/db5.3/
  1323. WgetTestData("db", "/berkeley-db/db-5.3.21.tar.gz", check_uri="/debian/pool/main/d/db5.3/", check_regex=r"(?P<name>db5\.3_)(?P<pver>\d+(\.\d+)+).+\.orig\.tar\.xz")
  1324. : "5.3.10",
  1325. #
  1326. # packages where the tarball compression changed in the new version
  1327. #
  1328. # http://ftp.debian.org/debian/pool/main/m/minicom/minicom_2.7.1.orig.tar.gz
  1329. WgetTestData("minicom", "/debian/pool/main/m/minicom/minicom_2.7.1.orig.tar.gz")
  1330. : "2.8",
  1331. #
  1332. # packages where the path doesn't actually contain the filename, so downloadfilename should be respected
  1333. #
  1334. WgetTestData("miniupnpd", "/software/miniupnp/download.php?file=miniupnpd_2.1.20191006.tar.gz;downloadfilename=miniupnpd_2.1.20191006.tar.gz", pv="2.1.20191006", check_uri="/software/miniupnp/download.php", check_regex=r"miniupnpd-(?P<pver>\d+(\.\d+)+)\.tar")
  1335. : "2.3.7",
  1336. }
  1337. test_crate_uris = {
  1338. # basic example; version pattern "A.B.C+cargo-D.E.F"
  1339. ("cargo-c", "crate://crates.io/cargo-c/0.9.18+cargo-0.69")
  1340. : "0.9.29"
  1341. }
  1342. @skipIfNoNetwork()
  1343. def test_git_latest_versionstring(self):
  1344. for k, v in self.test_git_uris.items():
  1345. with self.subTest(pn=k[0]):
  1346. self.d.setVar("PN", k[0])
  1347. self.d.setVar("SRCREV", k[2])
  1348. self.d.setVar("UPSTREAM_CHECK_GITTAGREGEX", k[3])
  1349. ud = bb.fetch2.FetchData(k[1], self.d)
  1350. pupver= ud.method.latest_versionstring(ud, self.d)
  1351. verstring = pupver[0]
  1352. self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0])
  1353. r = bb.utils.vercmp_string(v, verstring)
  1354. self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring))
  1355. if k[4]:
  1356. r = bb.utils.vercmp_string(verstring, k[4])
  1357. self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], verstring, k[4]))
  1358. def test_wget_latest_versionstring(self):
  1359. testdata = os.path.dirname(os.path.abspath(__file__)) + "/fetch-testdata"
  1360. server = HTTPService(testdata, host="127.0.0.1")
  1361. server.start()
  1362. port = server.port
  1363. try:
  1364. for data, v in self.test_wget_uris.items():
  1365. with self.subTest(pn=data.pn):
  1366. self.d.setVar("PN", data.pn)
  1367. self.d.setVar("PV", data.pv)
  1368. if data.check_uri:
  1369. checkuri = "http://127.0.0.1:%s/%s" % (port, data.check_uri)
  1370. self.d.setVar("UPSTREAM_CHECK_URI", checkuri)
  1371. if data.check_regex:
  1372. self.d.setVar("UPSTREAM_CHECK_REGEX", data.check_regex)
  1373. url = "http://127.0.0.1:%s/%s" % (port, data.path)
  1374. ud = bb.fetch2.FetchData(url, self.d)
  1375. pupver = ud.method.latest_versionstring(ud, self.d)
  1376. verstring = pupver[0]
  1377. self.assertTrue(verstring, msg="Could not find upstream version for %s" % data.pn)
  1378. r = bb.utils.vercmp_string(v, verstring)
  1379. self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (data.pn, v, verstring))
  1380. finally:
  1381. server.stop()
  1382. @skipIfNoNetwork()
  1383. def test_crate_latest_versionstring(self):
  1384. for k, v in self.test_crate_uris.items():
  1385. with self.subTest(pn=k[0]):
  1386. self.d.setVar("PN", k[0])
  1387. ud = bb.fetch2.FetchData(k[1], self.d)
  1388. pupver = ud.method.latest_versionstring(ud, self.d)
  1389. verstring = pupver[0]
  1390. self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0])
  1391. r = bb.utils.vercmp_string(v, verstring)
  1392. self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring))
  1393. class FetchCheckStatusTest(FetcherTest):
  1394. test_wget_uris = ["https://downloads.yoctoproject.org/releases/sato/sato-engine-0.1.tar.gz",
  1395. "https://downloads.yoctoproject.org/releases/sato/sato-engine-0.2.tar.gz",
  1396. "https://downloads.yoctoproject.org/releases/sato/sato-engine-0.3.tar.gz",
  1397. "https://yoctoproject.org/",
  1398. "https://docs.yoctoproject.org",
  1399. "https://downloads.yoctoproject.org/releases/opkg/opkg-0.1.7.tar.gz",
  1400. "https://downloads.yoctoproject.org/releases/opkg/opkg-0.3.0.tar.gz",
  1401. "ftp://sourceware.org/pub/libffi/libffi-1.20.tar.gz",
  1402. # GitHub releases are hosted on Amazon S3, which doesn't support HEAD
  1403. "https://github.com/kergoth/tslib/releases/download/1.1/tslib-1.1.tar.xz"
  1404. ]
  1405. @skipIfNoNetwork()
  1406. def test_wget_checkstatus(self):
  1407. fetch = bb.fetch2.Fetch(self.test_wget_uris, self.d)
  1408. for u in self.test_wget_uris:
  1409. with self.subTest(url=u):
  1410. ud = fetch.ud[u]
  1411. m = ud.method
  1412. ret = m.checkstatus(fetch, ud, self.d)
  1413. self.assertTrue(ret, msg="URI %s, can't check status" % (u))
  1414. @skipIfNoNetwork()
  1415. def test_wget_checkstatus_connection_cache(self):
  1416. from bb.fetch2 import FetchConnectionCache
  1417. connection_cache = FetchConnectionCache()
  1418. fetch = bb.fetch2.Fetch(self.test_wget_uris, self.d,
  1419. connection_cache = connection_cache)
  1420. for u in self.test_wget_uris:
  1421. with self.subTest(url=u):
  1422. ud = fetch.ud[u]
  1423. m = ud.method
  1424. ret = m.checkstatus(fetch, ud, self.d)
  1425. self.assertTrue(ret, msg="URI %s, can't check status" % (u))
  1426. connection_cache.close_connections()
  1427. class GitMakeShallowTest(FetcherTest):
  1428. def setUp(self):
  1429. FetcherTest.setUp(self)
  1430. self.gitdir = os.path.join(self.tempdir, 'gitshallow')
  1431. bb.utils.mkdirhier(self.gitdir)
  1432. self.git_init()
  1433. def assertRefs(self, expected_refs):
  1434. actual_refs = self.git(['for-each-ref', '--format=%(refname)']).splitlines()
  1435. full_expected = self.git(['rev-parse', '--symbolic-full-name'] + expected_refs).splitlines()
  1436. self.assertEqual(sorted(full_expected), sorted(actual_refs))
  1437. def assertRevCount(self, expected_count, args=None):
  1438. if args is None:
  1439. args = ['HEAD']
  1440. revs = self.git(['rev-list'] + args)
  1441. actual_count = len(revs.splitlines())
  1442. self.assertEqual(expected_count, actual_count, msg='Object count `%d` is not the expected `%d`' % (actual_count, expected_count))
  1443. def make_shallow(self, args=None):
  1444. if args is None:
  1445. args = ['HEAD']
  1446. return bb.process.run([bb.fetch2.git.Git.make_shallow_path] + args, cwd=self.gitdir)
  1447. def add_empty_file(self, path, msg=None):
  1448. if msg is None:
  1449. msg = path
  1450. open(os.path.join(self.gitdir, path), 'w').close()
  1451. self.git(['add', path])
  1452. self.git(['commit', '-m', msg, path])
  1453. def test_make_shallow_single_branch_no_merge(self):
  1454. self.add_empty_file('a')
  1455. self.add_empty_file('b')
  1456. self.assertRevCount(2)
  1457. self.make_shallow()
  1458. self.assertRevCount(1)
  1459. def test_make_shallow_single_branch_one_merge(self):
  1460. self.add_empty_file('a')
  1461. self.add_empty_file('b')
  1462. self.git('checkout -b a_branch')
  1463. self.add_empty_file('c')
  1464. self.git('checkout master')
  1465. self.add_empty_file('d')
  1466. self.git('merge --no-ff --no-edit a_branch')
  1467. self.git('branch -d a_branch')
  1468. self.add_empty_file('e')
  1469. self.assertRevCount(6)
  1470. self.make_shallow(['HEAD~2'])
  1471. self.assertRevCount(5)
  1472. def test_make_shallow_at_merge(self):
  1473. self.add_empty_file('a')
  1474. self.git('checkout -b a_branch')
  1475. self.add_empty_file('b')
  1476. self.git('checkout master')
  1477. self.git('merge --no-ff --no-edit a_branch')
  1478. self.git('branch -d a_branch')
  1479. self.assertRevCount(3)
  1480. self.make_shallow()
  1481. self.assertRevCount(1)
  1482. def test_make_shallow_annotated_tag(self):
  1483. self.add_empty_file('a')
  1484. self.add_empty_file('b')
  1485. self.git('tag -a -m a_tag a_tag')
  1486. self.assertRevCount(2)
  1487. self.make_shallow(['a_tag'])
  1488. self.assertRevCount(1)
  1489. def test_make_shallow_multi_ref(self):
  1490. self.add_empty_file('a')
  1491. self.add_empty_file('b')
  1492. self.git('checkout -b a_branch')
  1493. self.add_empty_file('c')
  1494. self.git('checkout master')
  1495. self.add_empty_file('d')
  1496. self.git('checkout -b a_branch_2')
  1497. self.add_empty_file('a_tag')
  1498. self.git('tag a_tag')
  1499. self.git('checkout master')
  1500. self.git('branch -D a_branch_2')
  1501. self.add_empty_file('e')
  1502. self.assertRevCount(6, ['--all'])
  1503. self.make_shallow()
  1504. self.assertRevCount(5, ['--all'])
  1505. def test_make_shallow_multi_ref_trim(self):
  1506. self.add_empty_file('a')
  1507. self.git('checkout -b a_branch')
  1508. self.add_empty_file('c')
  1509. self.git('checkout master')
  1510. self.assertRevCount(1)
  1511. self.assertRevCount(2, ['--all'])
  1512. self.assertRefs(['master', 'a_branch'])
  1513. self.make_shallow(['-r', 'master', 'HEAD'])
  1514. self.assertRevCount(1, ['--all'])
  1515. self.assertRefs(['master'])
  1516. def test_make_shallow_noop(self):
  1517. self.add_empty_file('a')
  1518. self.assertRevCount(1)
  1519. self.make_shallow()
  1520. self.assertRevCount(1)
  1521. @skipIfNoNetwork()
  1522. def test_make_shallow_bitbake(self):
  1523. self.git('remote add origin https://github.com/openembedded/bitbake')
  1524. self.git('fetch --tags origin')
  1525. orig_revs = len(self.git('rev-list --all').splitlines())
  1526. self.make_shallow(['refs/tags/1.10.0'])
  1527. self.assertRevCount(orig_revs - 1746, ['--all'])
  1528. class GitShallowTest(FetcherTest):
  1529. def setUp(self):
  1530. FetcherTest.setUp(self)
  1531. self.gitdir = os.path.join(self.tempdir, 'git')
  1532. self.srcdir = os.path.join(self.tempdir, 'gitsource')
  1533. bb.utils.mkdirhier(self.srcdir)
  1534. self.git_init(cwd=self.srcdir)
  1535. self.d.setVar('WORKDIR', self.tempdir)
  1536. self.d.setVar('S', self.gitdir)
  1537. self.d.delVar('PREMIRRORS')
  1538. self.d.delVar('MIRRORS')
  1539. uri = 'git://%s;protocol=file;subdir=${S};branch=master' % self.srcdir
  1540. self.d.setVar('SRC_URI', uri)
  1541. self.d.setVar('SRCREV', '${AUTOREV}')
  1542. self.d.setVar('AUTOREV', '${@bb.fetch2.get_autorev(d)}')
  1543. self.d.setVar('BB_GIT_SHALLOW', '1')
  1544. self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '0')
  1545. self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1')
  1546. self.d.setVar("__BBSRCREV_SEEN", "1")
  1547. def assertRefs(self, expected_refs, cwd=None):
  1548. if cwd is None:
  1549. cwd = self.gitdir
  1550. actual_refs = self.git(['for-each-ref', '--format=%(refname)'], cwd=cwd).splitlines()
  1551. # Resolve references into the same format as the comparision (needed by git 2.48 onwards)
  1552. actual_refs = self.git(['rev-parse', '--symbolic-full-name'] + actual_refs, cwd=cwd).splitlines()
  1553. full_expected = self.git(['rev-parse', '--symbolic-full-name'] + expected_refs, cwd=cwd).splitlines()
  1554. self.assertEqual(sorted(set(full_expected)), sorted(set(actual_refs)))
  1555. def assertRevCount(self, expected_count, args=None, cwd=None):
  1556. if args is None:
  1557. args = ['HEAD']
  1558. if cwd is None:
  1559. cwd = self.gitdir
  1560. revs = self.git(['rev-list'] + args, cwd=cwd)
  1561. actual_count = len(revs.splitlines())
  1562. self.assertEqual(expected_count, actual_count, msg='Object count `%d` is not the expected `%d`' % (actual_count, expected_count))
  1563. def add_empty_file(self, path, cwd=None, msg=None):
  1564. if msg is None:
  1565. msg = path
  1566. if cwd is None:
  1567. cwd = self.srcdir
  1568. open(os.path.join(cwd, path), 'w').close()
  1569. self.git(['add', path], cwd)
  1570. self.git(['commit', '-m', msg, path], cwd)
  1571. def fetch(self, uri=None):
  1572. if uri is None:
  1573. uris = self.d.getVar('SRC_URI').split()
  1574. uri = uris[0]
  1575. d = self.d
  1576. else:
  1577. d = self.d.createCopy()
  1578. d.setVar('SRC_URI', uri)
  1579. uri = d.expand(uri)
  1580. uris = [uri]
  1581. fetcher = bb.fetch2.Fetch(uris, d)
  1582. fetcher.download()
  1583. ud = fetcher.ud[uri]
  1584. return fetcher, ud
  1585. def fetch_and_unpack(self, uri=None):
  1586. fetcher, ud = self.fetch(uri)
  1587. fetcher.unpack(self.d.getVar('WORKDIR'))
  1588. assert os.path.exists(self.d.getVar('S'))
  1589. return fetcher, ud
  1590. def fetch_shallow(self, uri=None, disabled=False, keepclone=False):
  1591. """Fetch a uri, generating a shallow tarball, then unpack using it"""
  1592. fetcher, ud = self.fetch_and_unpack(uri)
  1593. # Confirm that the unpacked repo is unshallow
  1594. if not disabled:
  1595. assert os.path.exists(os.path.join(self.dldir, ud.mirrortarballs[0]))
  1596. # fetch and unpack, from the shallow tarball
  1597. bb.utils.remove(self.gitdir, recurse=True)
  1598. if os.path.exists(ud.clonedir):
  1599. bb.process.run('chmod u+w -R "%s"' % ud.clonedir)
  1600. bb.utils.remove(ud.clonedir, recurse=True)
  1601. bb.utils.remove(ud.clonedir.replace('gitsource', 'gitsubmodule'), recurse=True)
  1602. # confirm that the unpacked repo is used when no git clone or git
  1603. # mirror tarball is available
  1604. fetcher, ud = self.fetch_and_unpack(uri)
  1605. if not disabled:
  1606. assert os.path.exists(os.path.join(self.gitdir, '.git', 'shallow')), 'Unpacked git repository at %s is not shallow' % self.gitdir
  1607. else:
  1608. assert not os.path.exists(os.path.join(self.gitdir, '.git', 'shallow')), 'Unpacked git repository at %s is shallow' % self.gitdir
  1609. return fetcher, ud
  1610. def test_shallow_disabled(self):
  1611. self.add_empty_file('a')
  1612. self.add_empty_file('b')
  1613. self.assertRevCount(2, cwd=self.srcdir)
  1614. self.d.setVar('BB_GIT_SHALLOW', '0')
  1615. self.fetch_shallow(disabled=True)
  1616. self.assertRevCount(2)
  1617. def test_shallow_nobranch(self):
  1618. self.add_empty_file('a')
  1619. self.add_empty_file('b')
  1620. self.assertRevCount(2, cwd=self.srcdir)
  1621. srcrev = self.git('rev-parse HEAD', cwd=self.srcdir).strip()
  1622. self.d.setVar('SRCREV', srcrev)
  1623. uri = self.d.getVar('SRC_URI').split()[0]
  1624. uri = '%s;nobranch=1;bare=1' % uri
  1625. self.fetch_shallow(uri)
  1626. self.assertRevCount(1)
  1627. # shallow refs are used to ensure the srcrev sticks around when we
  1628. # have no other branches referencing it
  1629. self.assertRefs(['refs/shallow/default'])
  1630. def test_shallow_default_depth_1(self):
  1631. # Create initial git repo
  1632. self.add_empty_file('a')
  1633. self.add_empty_file('b')
  1634. self.assertRevCount(2, cwd=self.srcdir)
  1635. self.fetch_shallow()
  1636. self.assertRevCount(1)
  1637. def test_shallow_depth_0_disables(self):
  1638. self.add_empty_file('a')
  1639. self.add_empty_file('b')
  1640. self.assertRevCount(2, cwd=self.srcdir)
  1641. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
  1642. self.fetch_shallow(disabled=True)
  1643. self.assertRevCount(2)
  1644. def test_shallow_depth_default_override(self):
  1645. self.add_empty_file('a')
  1646. self.add_empty_file('b')
  1647. self.assertRevCount(2, cwd=self.srcdir)
  1648. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '2')
  1649. self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '1')
  1650. self.fetch_shallow()
  1651. self.assertRevCount(1)
  1652. def test_shallow_depth_default_override_disable(self):
  1653. self.add_empty_file('a')
  1654. self.add_empty_file('b')
  1655. self.add_empty_file('c')
  1656. self.assertRevCount(3, cwd=self.srcdir)
  1657. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
  1658. self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '2')
  1659. self.fetch_shallow()
  1660. self.assertRevCount(2)
  1661. def test_current_shallow_out_of_date_clone(self):
  1662. # Create initial git repo
  1663. self.add_empty_file('a')
  1664. self.add_empty_file('b')
  1665. self.add_empty_file('c')
  1666. self.assertRevCount(3, cwd=self.srcdir)
  1667. # Clone without tarball
  1668. self.d.setVar('BB_GIT_SHALLOW', '0')
  1669. fetcher, ud = self.fetch()
  1670. # Clone and generate mirror tarball
  1671. self.d.setVar('BB_GIT_SHALLOW', '1')
  1672. fetcher, ud = self.fetch()
  1673. # Ensure we have a current mirror tarball, but an out of date clone
  1674. self.git('update-ref refs/heads/master refs/heads/master~1', cwd=ud.clonedir)
  1675. self.assertRevCount(2, cwd=ud.clonedir)
  1676. # Fetch and unpack, from the current tarball, not the out of date clone
  1677. bb.utils.remove(self.gitdir, recurse=True)
  1678. fetcher, ud = self.fetch()
  1679. fetcher.unpack(self.d.getVar('WORKDIR'))
  1680. self.assertRevCount(1)
  1681. assert os.path.exists(os.path.join(self.d.getVar('WORKDIR'), 'git', 'c'))
  1682. def test_shallow_single_branch_no_merge(self):
  1683. self.add_empty_file('a')
  1684. self.add_empty_file('b')
  1685. self.assertRevCount(2, cwd=self.srcdir)
  1686. self.fetch_shallow()
  1687. self.assertRevCount(1)
  1688. assert os.path.exists(os.path.join(self.gitdir, 'a'))
  1689. assert os.path.exists(os.path.join(self.gitdir, 'b'))
  1690. def test_shallow_no_dangling(self):
  1691. self.add_empty_file('a')
  1692. self.add_empty_file('b')
  1693. self.assertRevCount(2, cwd=self.srcdir)
  1694. self.fetch_shallow()
  1695. self.assertRevCount(1)
  1696. assert not self.git('fsck --dangling')
  1697. def test_shallow_srcrev_branch_truncation(self):
  1698. self.add_empty_file('a')
  1699. self.add_empty_file('b')
  1700. b_commit = self.git('rev-parse HEAD', cwd=self.srcdir).rstrip()
  1701. self.add_empty_file('c')
  1702. self.assertRevCount(3, cwd=self.srcdir)
  1703. self.d.setVar('SRCREV', b_commit)
  1704. self.fetch_shallow()
  1705. # The 'c' commit was removed entirely, and 'a' was removed from history
  1706. self.assertRevCount(1, ['--all'])
  1707. self.assertEqual(self.git('rev-parse HEAD').strip(), b_commit)
  1708. assert os.path.exists(os.path.join(self.gitdir, 'a'))
  1709. assert os.path.exists(os.path.join(self.gitdir, 'b'))
  1710. assert not os.path.exists(os.path.join(self.gitdir, 'c'))
  1711. def test_shallow_ref_pruning(self):
  1712. self.add_empty_file('a')
  1713. self.add_empty_file('b')
  1714. self.git('branch a_branch', cwd=self.srcdir)
  1715. self.assertRefs(['master', 'a_branch'], cwd=self.srcdir)
  1716. self.assertRevCount(2, cwd=self.srcdir)
  1717. self.fetch_shallow()
  1718. self.assertRefs(['master', 'origin/master'])
  1719. self.assertRevCount(1)
  1720. def test_shallow_submodules(self):
  1721. self.add_empty_file('a')
  1722. self.add_empty_file('b')
  1723. smdir = os.path.join(self.tempdir, 'gitsubmodule')
  1724. bb.utils.mkdirhier(smdir)
  1725. self.git_init(cwd=smdir)
  1726. # Make this look like it was cloned from a remote...
  1727. self.git('config --add remote.origin.url "%s"' % smdir, cwd=smdir)
  1728. self.git('config --add remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"', cwd=smdir)
  1729. self.add_empty_file('asub', cwd=smdir)
  1730. self.add_empty_file('bsub', cwd=smdir)
  1731. self.git('submodule init', cwd=self.srcdir)
  1732. self.git('-c protocol.file.allow=always submodule add file://%s' % smdir, cwd=self.srcdir)
  1733. self.git('submodule update', cwd=self.srcdir)
  1734. self.git('commit -m submodule -a', cwd=self.srcdir)
  1735. uri = 'gitsm://%s;protocol=file;subdir=${S};branch=master' % self.srcdir
  1736. fetcher, ud = self.fetch_shallow(uri)
  1737. # Verify the main repository is shallow
  1738. self.assertRevCount(1)
  1739. # Verify the gitsubmodule directory is present
  1740. assert os.listdir(os.path.join(self.gitdir, 'gitsubmodule'))
  1741. # Verify the submodule is also shallow
  1742. self.assertRevCount(1, cwd=os.path.join(self.gitdir, 'gitsubmodule'))
  1743. def test_shallow_submodule_mirrors(self):
  1744. self.add_empty_file('a')
  1745. self.add_empty_file('b')
  1746. smdir = os.path.join(self.tempdir, 'gitsubmodule')
  1747. bb.utils.mkdirhier(smdir)
  1748. self.git_init(cwd=smdir)
  1749. # Make this look like it was cloned from a remote...
  1750. self.git('config --add remote.origin.url "%s"' % smdir, cwd=smdir)
  1751. self.git('config --add remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"', cwd=smdir)
  1752. self.add_empty_file('asub', cwd=smdir)
  1753. self.add_empty_file('bsub', cwd=smdir)
  1754. self.git('submodule init', cwd=self.srcdir)
  1755. self.git('-c protocol.file.allow=always submodule add file://%s' % smdir, cwd=self.srcdir)
  1756. self.git('submodule update', cwd=self.srcdir)
  1757. self.git('commit -m submodule -a', cwd=self.srcdir)
  1758. uri = 'gitsm://%s;protocol=file;subdir=${S};branch=master' % self.srcdir
  1759. # Fetch once to generate the shallow tarball
  1760. fetcher, ud = self.fetch(uri)
  1761. # Set up the mirror
  1762. mirrordir = os.path.join(self.tempdir, 'mirror')
  1763. bb.utils.rename(self.dldir, mirrordir)
  1764. self.d.setVar('PREMIRRORS', 'gitsm://.*/.* file://%s/' % mirrordir)
  1765. # Fetch from the mirror
  1766. bb.utils.remove(self.dldir, recurse=True)
  1767. bb.utils.remove(self.gitdir, recurse=True)
  1768. self.fetch_and_unpack(uri)
  1769. # Verify the main repository is shallow
  1770. self.assertRevCount(1)
  1771. # Verify the gitsubmodule directory is present
  1772. assert os.listdir(os.path.join(self.gitdir, 'gitsubmodule'))
  1773. # Verify the submodule is also shallow
  1774. self.assertRevCount(1, cwd=os.path.join(self.gitdir, 'gitsubmodule'))
  1775. if any(os.path.exists(os.path.join(p, 'git-annex')) for p in os.environ.get('PATH').split(':')):
  1776. def test_shallow_annex(self):
  1777. self.add_empty_file('a')
  1778. self.add_empty_file('b')
  1779. self.git('annex init', cwd=self.srcdir)
  1780. open(os.path.join(self.srcdir, 'c'), 'w').close()
  1781. self.git('annex add c', cwd=self.srcdir)
  1782. self.git('commit --author "Foo Bar <foo@bar>" -m annex-c -a', cwd=self.srcdir)
  1783. bb.process.run('chmod u+w -R %s' % self.srcdir)
  1784. uri = 'gitannex://%s;protocol=file;subdir=${S};branch=master' % self.srcdir
  1785. fetcher, ud = self.fetch_shallow(uri)
  1786. self.assertRevCount(1)
  1787. assert './.git/annex/' in bb.process.run('tar -tzf %s' % os.path.join(self.dldir, ud.mirrortarballs[0]))[0]
  1788. assert os.path.exists(os.path.join(self.gitdir, 'c'))
  1789. def test_shallow_clone_preferred_over_shallow(self):
  1790. self.add_empty_file('a')
  1791. self.add_empty_file('b')
  1792. # Fetch once to generate the shallow tarball
  1793. self.d.setVar('BB_GIT_SHALLOW', '0')
  1794. fetcher, ud = self.fetch()
  1795. # Fetch and unpack with both the clonedir and shallow tarball available
  1796. bb.utils.remove(self.gitdir, recurse=True)
  1797. self.d.setVar('BB_GIT_SHALLOW', '1')
  1798. fetcher, ud = self.fetch_and_unpack()
  1799. # The unpacked tree should *not* be shallow
  1800. self.assertRevCount(2)
  1801. assert not os.path.exists(os.path.join(self.gitdir, '.git', 'shallow'))
  1802. def test_shallow_mirrors(self):
  1803. self.add_empty_file('a')
  1804. self.add_empty_file('b')
  1805. # Fetch once to generate the shallow tarball
  1806. fetcher, ud = self.fetch()
  1807. mirrortarball = ud.mirrortarballs[0]
  1808. assert os.path.exists(os.path.join(self.dldir, mirrortarball))
  1809. # Set up the mirror
  1810. mirrordir = os.path.join(self.tempdir, 'mirror')
  1811. bb.utils.mkdirhier(mirrordir)
  1812. self.d.setVar('PREMIRRORS', 'git://.*/.* file://%s/' % mirrordir)
  1813. bb.utils.rename(os.path.join(self.dldir, mirrortarball),
  1814. os.path.join(mirrordir, mirrortarball))
  1815. # Fetch from the mirror
  1816. bb.utils.remove(self.dldir, recurse=True)
  1817. bb.utils.remove(self.gitdir, recurse=True)
  1818. self.fetch_and_unpack()
  1819. self.assertRevCount(1)
  1820. def test_shallow_invalid_depth(self):
  1821. self.add_empty_file('a')
  1822. self.add_empty_file('b')
  1823. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '-12')
  1824. with self.assertRaises(bb.fetch2.FetchError):
  1825. self.fetch()
  1826. def test_shallow_invalid_depth_default(self):
  1827. self.add_empty_file('a')
  1828. self.add_empty_file('b')
  1829. self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '-12')
  1830. with self.assertRaises(bb.fetch2.FetchError):
  1831. self.fetch()
  1832. def test_shallow_extra_refs(self):
  1833. self.add_empty_file('a')
  1834. self.add_empty_file('b')
  1835. self.git('branch a_branch', cwd=self.srcdir)
  1836. self.assertRefs(['master', 'a_branch'], cwd=self.srcdir)
  1837. self.assertRevCount(2, cwd=self.srcdir)
  1838. self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/heads/a_branch')
  1839. self.fetch_shallow()
  1840. self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
  1841. self.assertRevCount(1)
  1842. def test_shallow_extra_refs_wildcard(self):
  1843. self.add_empty_file('a')
  1844. self.add_empty_file('b')
  1845. self.git('branch a_branch', cwd=self.srcdir)
  1846. self.git('tag v1.0', cwd=self.srcdir)
  1847. self.assertRefs(['master', 'a_branch', 'v1.0'], cwd=self.srcdir)
  1848. self.assertRevCount(2, cwd=self.srcdir)
  1849. self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/tags/*')
  1850. self.fetch_shallow()
  1851. self.assertRefs(['master', 'origin/master', 'v1.0'])
  1852. self.assertRevCount(1)
  1853. def test_shallow_missing_extra_refs(self):
  1854. self.add_empty_file('a')
  1855. self.add_empty_file('b')
  1856. self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/heads/foo')
  1857. with self.assertRaises(bb.fetch2.FetchError):
  1858. self.fetch()
  1859. def test_shallow_missing_extra_refs_wildcard(self):
  1860. self.add_empty_file('a')
  1861. self.add_empty_file('b')
  1862. self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/tags/*')
  1863. self.fetch()
  1864. def test_shallow_remove_revs(self):
  1865. # Create initial git repo
  1866. self.add_empty_file('a')
  1867. self.add_empty_file('b')
  1868. self.git('checkout -b a_branch', cwd=self.srcdir)
  1869. self.add_empty_file('c')
  1870. self.add_empty_file('d')
  1871. self.git('checkout master', cwd=self.srcdir)
  1872. self.git('tag v0.0 a_branch', cwd=self.srcdir)
  1873. self.add_empty_file('e')
  1874. self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir)
  1875. self.git('branch -d a_branch', cwd=self.srcdir)
  1876. self.add_empty_file('f')
  1877. self.assertRevCount(7, cwd=self.srcdir)
  1878. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
  1879. self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
  1880. self.fetch_shallow()
  1881. self.assertRevCount(2)
  1882. def test_shallow_invalid_revs(self):
  1883. self.add_empty_file('a')
  1884. self.add_empty_file('b')
  1885. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
  1886. self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
  1887. with self.assertRaises(bb.fetch2.FetchError):
  1888. self.fetch()
  1889. def test_shallow_fetch_missing_revs(self):
  1890. self.add_empty_file('a')
  1891. self.add_empty_file('b')
  1892. fetcher, ud = self.fetch(self.d.getVar('SRC_URI'))
  1893. self.git('tag v0.0 master', cwd=self.srcdir)
  1894. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
  1895. self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
  1896. with self.assertRaises(bb.fetch2.FetchError), self.assertLogs("BitBake.Fetcher", level="ERROR") as cm:
  1897. self.fetch_shallow()
  1898. self.assertIn("fatal: no commits selected for shallow requests", cm.output[0])
  1899. def test_shallow_fetch_missing_revs_fails(self):
  1900. self.add_empty_file('a')
  1901. self.add_empty_file('b')
  1902. fetcher, ud = self.fetch(self.d.getVar('SRC_URI'))
  1903. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
  1904. self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
  1905. with self.assertRaises(bb.fetch2.FetchError), self.assertLogs("BitBake.Fetcher", level="ERROR") as cm:
  1906. self.fetch_shallow()
  1907. self.assertIn("Unable to find revision v0.0 even from upstream", cm.output[0])
  1908. @skipIfNoNetwork()
  1909. def test_bitbake(self):
  1910. self.git('remote add --mirror=fetch origin https://github.com/openembedded/bitbake', cwd=self.srcdir)
  1911. self.git('config core.bare true', cwd=self.srcdir)
  1912. self.git('fetch', cwd=self.srcdir)
  1913. self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
  1914. # Note that the 1.10.0 tag is annotated, so this also tests
  1915. # reference of an annotated vs unannotated tag
  1916. self.d.setVar('BB_GIT_SHALLOW_REVS', '1.10.0')
  1917. self.fetch_shallow()
  1918. # Confirm that the history of 1.10.0 was removed
  1919. orig_revs = len(self.git('rev-list master', cwd=self.srcdir).splitlines())
  1920. revs = len(self.git('rev-list master').splitlines())
  1921. self.assertNotEqual(orig_revs, revs)
  1922. self.assertRefs(['master', 'origin/master'])
  1923. self.assertRevCount(orig_revs - 1760)
  1924. def test_that_unpack_throws_an_error_when_the_git_clone_nor_shallow_tarball_exist(self):
  1925. self.add_empty_file('a')
  1926. fetcher, ud = self.fetch()
  1927. bb.utils.remove(self.gitdir, recurse=True)
  1928. bb.utils.remove(self.dldir, recurse=True)
  1929. with self.assertRaises(bb.fetch2.UnpackError) as context:
  1930. fetcher.unpack(self.d.getVar('WORKDIR'))
  1931. self.assertIn("No up to date source found", context.exception.msg)
  1932. self.assertIn("clone directory not available or not up to date", context.exception.msg)
  1933. def test_shallow_check_is_shallow(self):
  1934. self.add_empty_file('a')
  1935. self.add_empty_file('b')
  1936. # Fetch and unpack without the clonedir and *only* shallow tarball available
  1937. bb.utils.remove(self.gitdir, recurse=True)
  1938. fetcher, ud = self.fetch_and_unpack()
  1939. # The unpacked tree *should* be shallow
  1940. self.assertRevCount(1)
  1941. assert os.path.exists(os.path.join(self.gitdir, '.git', 'shallow'))
  1942. class GitLfsTest(FetcherTest):
  1943. def skipIfNoGitLFS():
  1944. import shutil
  1945. if not shutil.which('git-lfs'):
  1946. return unittest.skip('git-lfs not installed')
  1947. return lambda f: f
  1948. def setUp(self):
  1949. FetcherTest.setUp(self)
  1950. self.gitdir = os.path.join(self.tempdir, 'git')
  1951. self.srcdir = os.path.join(self.tempdir, 'gitsource')
  1952. self.d.setVar('WORKDIR', self.tempdir)
  1953. self.d.setVar('S', self.gitdir)
  1954. self.d.delVar('PREMIRRORS')
  1955. self.d.delVar('MIRRORS')
  1956. self.d.setVar('SRCREV', '${AUTOREV}')
  1957. self.d.setVar('AUTOREV', '${@bb.fetch2.get_autorev(d)}')
  1958. self.d.setVar("__BBSRCREV_SEEN", "1")
  1959. bb.utils.mkdirhier(self.srcdir)
  1960. self.git_init(cwd=self.srcdir)
  1961. self.commit_file('.gitattributes', '*.mp3 filter=lfs -text')
  1962. def commit_file(self, filename, content):
  1963. with open(os.path.join(self.srcdir, filename), "w") as f:
  1964. f.write(content)
  1965. self.git(["add", filename], cwd=self.srcdir)
  1966. self.git(["commit", "-m", "Change"], cwd=self.srcdir)
  1967. return self.git(["rev-parse", "HEAD"], cwd=self.srcdir).strip()
  1968. def fetch(self, uri=None, download=True):
  1969. uris = self.d.getVar('SRC_URI').split()
  1970. uri = uris[0]
  1971. d = self.d
  1972. fetcher = bb.fetch2.Fetch(uris, d)
  1973. if download:
  1974. fetcher.download()
  1975. ud = fetcher.ud[uri]
  1976. return fetcher, ud
  1977. def get_real_git_lfs_file(self):
  1978. self.d.setVar('PATH', os.environ.get('PATH'))
  1979. fetcher, ud = self.fetch()
  1980. fetcher.unpack(self.d.getVar('WORKDIR'))
  1981. unpacked_lfs_file = os.path.join(self.d.getVar('WORKDIR'), 'git', "Cat_poster_1.jpg")
  1982. return unpacked_lfs_file
  1983. @skipIfNoGitLFS()
  1984. def test_fetch_lfs_on_srcrev_change(self):
  1985. """Test if fetch downloads missing LFS objects when a different revision within an existing repository is requested"""
  1986. self.git(["lfs", "install", "--local"], cwd=self.srcdir)
  1987. @contextlib.contextmanager
  1988. def hide_upstream_repository():
  1989. """Hide the upstream repository to make sure that git lfs cannot pull from it"""
  1990. temp_name = self.srcdir + ".bak"
  1991. os.rename(self.srcdir, temp_name)
  1992. try:
  1993. yield
  1994. finally:
  1995. os.rename(temp_name, self.srcdir)
  1996. def fetch_and_verify(revision, filename, content):
  1997. self.d.setVar('SRCREV', revision)
  1998. fetcher, ud = self.fetch()
  1999. with hide_upstream_repository():
  2000. workdir = self.d.getVar('WORKDIR')
  2001. fetcher.unpack(workdir)
  2002. with open(os.path.join(workdir, "git", filename)) as f:
  2003. self.assertEqual(f.read(), content)
  2004. commit_1 = self.commit_file("a.mp3", "version 1")
  2005. commit_2 = self.commit_file("a.mp3", "version 2")
  2006. self.d.setVar('SRC_URI', "git://%s;protocol=file;lfs=1;branch=master" % self.srcdir)
  2007. # Seed the local download folder by fetching the latest commit and verifying that the LFS contents are
  2008. # available even when the upstream repository disappears.
  2009. fetch_and_verify(commit_2, "a.mp3", "version 2")
  2010. # Verify that even when an older revision is fetched, the needed LFS objects are fetched into the download
  2011. # folder.
  2012. fetch_and_verify(commit_1, "a.mp3", "version 1")
  2013. @skipIfNoGitLFS()
  2014. @skipIfNoNetwork()
  2015. def test_real_git_lfs_repo_succeeds_without_lfs_param(self):
  2016. self.d.setVar('SRC_URI', "git://gitlab.com/gitlab-examples/lfs.git;protocol=https;branch=master")
  2017. f = self.get_real_git_lfs_file()
  2018. self.assertTrue(os.path.exists(f))
  2019. self.assertEqual("c0baab607a97839c9a328b4310713307", bb.utils.md5_file(f))
  2020. @skipIfNoGitLFS()
  2021. @skipIfNoNetwork()
  2022. def test_real_git_lfs_repo_succeeds(self):
  2023. self.d.setVar('SRC_URI', "git://gitlab.com/gitlab-examples/lfs.git;protocol=https;branch=master;lfs=1")
  2024. f = self.get_real_git_lfs_file()
  2025. self.assertTrue(os.path.exists(f))
  2026. self.assertEqual("c0baab607a97839c9a328b4310713307", bb.utils.md5_file(f))
  2027. @skipIfNoGitLFS()
  2028. @skipIfNoNetwork()
  2029. def test_real_git_lfs_repo_skips(self):
  2030. self.d.setVar('SRC_URI', "git://gitlab.com/gitlab-examples/lfs.git;protocol=https;branch=master;lfs=0")
  2031. f = self.get_real_git_lfs_file()
  2032. # This is the actual non-smudged placeholder file on the repo if git-lfs does not run
  2033. lfs_file = (
  2034. 'version https://git-lfs.github.com/spec/v1\n'
  2035. 'oid sha256:34be66b1a39a1955b46a12588df9d5f6fc1da790e05cf01f3c7422f4bbbdc26b\n'
  2036. 'size 11423554\n'
  2037. )
  2038. with open(f) as fh:
  2039. self.assertEqual(lfs_file, fh.read())
  2040. @skipIfNoGitLFS()
  2041. def test_lfs_enabled(self):
  2042. import shutil
  2043. uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir
  2044. self.d.setVar('SRC_URI', uri)
  2045. # With git-lfs installed, test that we can fetch and unpack
  2046. fetcher, ud = self.fetch()
  2047. shutil.rmtree(self.gitdir, ignore_errors=True)
  2048. fetcher.unpack(self.d.getVar('WORKDIR'))
  2049. @skipIfNoGitLFS()
  2050. def test_lfs_disabled(self):
  2051. import shutil
  2052. uri = 'git://%s;protocol=file;lfs=0;branch=master' % self.srcdir
  2053. self.d.setVar('SRC_URI', uri)
  2054. # Verify that the fetcher can survive even if the source
  2055. # repository has Git LFS usage configured.
  2056. fetcher, ud = self.fetch()
  2057. fetcher.unpack(self.d.getVar('WORKDIR'))
  2058. def test_lfs_enabled_not_installed(self):
  2059. import shutil
  2060. uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir
  2061. self.d.setVar('SRC_URI', uri)
  2062. # Careful: suppress initial attempt at downloading
  2063. fetcher, ud = self.fetch(uri=None, download=False)
  2064. # Artificially assert that git-lfs is not installed, so
  2065. # we can verify a failure to unpack in it's absence.
  2066. old_find_git_lfs = ud.method._find_git_lfs
  2067. try:
  2068. # If git-lfs cannot be found, the unpack should throw an error
  2069. with self.assertRaises(bb.fetch2.FetchError):
  2070. fetcher.download()
  2071. ud.method._find_git_lfs = lambda d: False
  2072. shutil.rmtree(self.gitdir, ignore_errors=True)
  2073. fetcher.unpack(self.d.getVar('WORKDIR'))
  2074. finally:
  2075. ud.method._find_git_lfs = old_find_git_lfs
  2076. def test_lfs_disabled_not_installed(self):
  2077. import shutil
  2078. uri = 'git://%s;protocol=file;lfs=0;branch=master' % self.srcdir
  2079. self.d.setVar('SRC_URI', uri)
  2080. # Careful: suppress initial attempt at downloading
  2081. fetcher, ud = self.fetch(uri=None, download=False)
  2082. # Artificially assert that git-lfs is not installed, so
  2083. # we can verify a failure to unpack in it's absence.
  2084. old_find_git_lfs = ud.method._find_git_lfs
  2085. try:
  2086. # Even if git-lfs cannot be found, the unpack should be successful
  2087. fetcher.download()
  2088. ud.method._find_git_lfs = lambda d: False
  2089. shutil.rmtree(self.gitdir, ignore_errors=True)
  2090. fetcher.unpack(self.d.getVar('WORKDIR'))
  2091. finally:
  2092. ud.method._find_git_lfs = old_find_git_lfs
  2093. class GitURLWithSpacesTest(FetcherTest):
  2094. test_git_urls = {
  2095. "git://tfs-example.org:22/tfs/example%20path/example.git;branch=master" : {
  2096. 'url': 'git://tfs-example.org:22/tfs/example%20path/example.git;branch=master',
  2097. 'repo_url': 'git://tfs-example.org:22/tfs/example%20path/example.git',
  2098. 'gitsrcname': 'tfs-example.org.22.tfs.example_path.example.git',
  2099. 'path': '/tfs/example path/example.git'
  2100. },
  2101. "git://tfs-example.org:22/tfs/example%20path/example%20repo.git;branch=master" : {
  2102. 'url': 'git://tfs-example.org:22/tfs/example%20path/example%20repo.git;branch=master',
  2103. 'repo_url': 'git://tfs-example.org:22/tfs/example%20path/example%20repo.git',
  2104. 'gitsrcname': 'tfs-example.org.22.tfs.example_path.example_repo.git',
  2105. 'path': '/tfs/example path/example repo.git'
  2106. }
  2107. }
  2108. def test_urls(self):
  2109. # Set fake SRCREV to stop git fetcher from trying to contact non-existent git repo
  2110. self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
  2111. for test_git_url, ref in self.test_git_urls.items():
  2112. fetcher = bb.fetch.Fetch([test_git_url], self.d)
  2113. ud = fetcher.ud[fetcher.urls[0]]
  2114. self.assertEqual(ud.url, ref['url'])
  2115. self.assertEqual(ud.path, ref['path'])
  2116. self.assertEqual(ud.localfile, os.path.join(self.dldir, "git2", ref['gitsrcname']))
  2117. self.assertEqual(ud.localpath, os.path.join(self.dldir, "git2", ref['gitsrcname']))
  2118. self.assertEqual(ud.lockfile, os.path.join(self.dldir, "git2", ref['gitsrcname'] + '.lock'))
  2119. self.assertEqual(ud.clonedir, os.path.join(self.dldir, "git2", ref['gitsrcname']))
  2120. self.assertEqual(ud.fullmirror, os.path.join(self.dldir, "git2_" + ref['gitsrcname'] + '.tar.gz'))
  2121. self.assertEqual(ud.method._get_repo_url(ud), ref['repo_url'])
  2122. class CrateTest(FetcherTest):
  2123. @skipIfNoNetwork()
  2124. def test_crate_url(self):
  2125. uri = "crate://crates.io/glob/0.2.11"
  2126. self.d.setVar('SRC_URI', uri)
  2127. uris = self.d.getVar('SRC_URI').split()
  2128. d = self.d
  2129. fetcher = bb.fetch2.Fetch(uris, self.d)
  2130. ud = fetcher.ud[fetcher.urls[0]]
  2131. self.assertIn("name", ud.parm)
  2132. self.assertEqual(ud.parm["name"], "glob-0.2.11")
  2133. self.assertIn("downloadfilename", ud.parm)
  2134. self.assertEqual(ud.parm["downloadfilename"], "glob-0.2.11.crate")
  2135. fetcher.download()
  2136. fetcher.unpack(self.tempdir)
  2137. self.assertEqual(sorted(os.listdir(self.tempdir)), ['cargo_home', 'download' , 'unpacked'])
  2138. self.assertEqual(sorted(os.listdir(self.tempdir + "/download")), ['glob-0.2.11.crate', 'glob-0.2.11.crate.done'])
  2139. self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/glob-0.2.11/.cargo-checksum.json"))
  2140. self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/glob-0.2.11/src/lib.rs"))
  2141. @skipIfNoNetwork()
  2142. def test_crate_url_matching_recipe(self):
  2143. self.d.setVar('BP', 'glob-0.2.11')
  2144. uri = "crate://crates.io/glob/0.2.11"
  2145. self.d.setVar('SRC_URI', uri)
  2146. uris = self.d.getVar('SRC_URI').split()
  2147. d = self.d
  2148. fetcher = bb.fetch2.Fetch(uris, self.d)
  2149. ud = fetcher.ud[fetcher.urls[0]]
  2150. self.assertIn("name", ud.parm)
  2151. self.assertEqual(ud.parm["name"], "glob-0.2.11")
  2152. self.assertIn("downloadfilename", ud.parm)
  2153. self.assertEqual(ud.parm["downloadfilename"], "glob-0.2.11.crate")
  2154. fetcher.download()
  2155. fetcher.unpack(self.tempdir)
  2156. self.assertEqual(sorted(os.listdir(self.tempdir)), ['download', 'glob-0.2.11', 'unpacked'])
  2157. self.assertEqual(sorted(os.listdir(self.tempdir + "/download")), ['glob-0.2.11.crate', 'glob-0.2.11.crate.done'])
  2158. self.assertTrue(os.path.exists(self.tempdir + "/glob-0.2.11/src/lib.rs"))
  2159. @skipIfNoNetwork()
  2160. def test_crate_url_params(self):
  2161. uri = "crate://crates.io/aho-corasick/0.7.20;name=aho-corasick-renamed"
  2162. self.d.setVar('SRC_URI', uri)
  2163. uris = self.d.getVar('SRC_URI').split()
  2164. d = self.d
  2165. fetcher = bb.fetch2.Fetch(uris, self.d)
  2166. ud = fetcher.ud[fetcher.urls[0]]
  2167. self.assertIn("name", ud.parm)
  2168. self.assertEqual(ud.parm["name"], "aho-corasick-renamed")
  2169. self.assertIn("downloadfilename", ud.parm)
  2170. self.assertEqual(ud.parm["downloadfilename"], "aho-corasick-0.7.20.crate")
  2171. fetcher.download()
  2172. fetcher.unpack(self.tempdir)
  2173. self.assertEqual(sorted(os.listdir(self.tempdir)), ['cargo_home', 'download' , 'unpacked'])
  2174. self.assertEqual(sorted(os.listdir(self.tempdir + "/download")), ['aho-corasick-0.7.20.crate', 'aho-corasick-0.7.20.crate.done'])
  2175. self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/aho-corasick-0.7.20/.cargo-checksum.json"))
  2176. self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/aho-corasick-0.7.20/src/lib.rs"))
  2177. @skipIfNoNetwork()
  2178. def test_crate_url_multi(self):
  2179. uri = "crate://crates.io/glob/0.2.11 crate://crates.io/time/0.1.35"
  2180. self.d.setVar('SRC_URI', uri)
  2181. uris = self.d.getVar('SRC_URI').split()
  2182. d = self.d
  2183. fetcher = bb.fetch2.Fetch(uris, self.d)
  2184. ud = fetcher.ud[fetcher.urls[0]]
  2185. self.assertIn("name", ud.parm)
  2186. self.assertEqual(ud.parm["name"], "glob-0.2.11")
  2187. self.assertIn("downloadfilename", ud.parm)
  2188. self.assertEqual(ud.parm["downloadfilename"], "glob-0.2.11.crate")
  2189. ud = fetcher.ud[fetcher.urls[1]]
  2190. self.assertIn("name", ud.parm)
  2191. self.assertEqual(ud.parm["name"], "time-0.1.35")
  2192. self.assertIn("downloadfilename", ud.parm)
  2193. self.assertEqual(ud.parm["downloadfilename"], "time-0.1.35.crate")
  2194. fetcher.download()
  2195. fetcher.unpack(self.tempdir)
  2196. self.assertEqual(sorted(os.listdir(self.tempdir)), ['cargo_home', 'download' , 'unpacked'])
  2197. self.assertEqual(sorted(os.listdir(self.tempdir + "/download")), ['glob-0.2.11.crate', 'glob-0.2.11.crate.done', 'time-0.1.35.crate', 'time-0.1.35.crate.done'])
  2198. self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/glob-0.2.11/.cargo-checksum.json"))
  2199. self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/glob-0.2.11/src/lib.rs"))
  2200. self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/time-0.1.35/.cargo-checksum.json"))
  2201. self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/time-0.1.35/src/lib.rs"))
  2202. @skipIfNoNetwork()
  2203. def test_crate_incorrect_cksum(self):
  2204. uri = "crate://crates.io/aho-corasick/0.7.20"
  2205. self.d.setVar('SRC_URI', uri)
  2206. self.d.setVarFlag("SRC_URI", "aho-corasick-0.7.20.sha256sum", hashlib.sha256("Invalid".encode("utf-8")).hexdigest())
  2207. uris = self.d.getVar('SRC_URI').split()
  2208. fetcher = bb.fetch2.Fetch(uris, self.d)
  2209. with self.assertRaisesRegex(bb.fetch2.FetchError, "Fetcher failure for URL"):
  2210. fetcher.download()
  2211. class NPMTest(FetcherTest):
  2212. def skipIfNoNpm():
  2213. import shutil
  2214. if not shutil.which('npm'):
  2215. return unittest.skip('npm not installed')
  2216. return lambda f: f
  2217. @skipIfNoNpm()
  2218. @skipIfNoNetwork()
  2219. def test_npm(self):
  2220. urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
  2221. fetcher = bb.fetch.Fetch(urls, self.d)
  2222. ud = fetcher.ud[fetcher.urls[0]]
  2223. fetcher.download()
  2224. self.assertTrue(os.path.exists(ud.localpath))
  2225. self.assertTrue(os.path.exists(ud.localpath + '.done'))
  2226. self.assertTrue(os.path.exists(ud.resolvefile))
  2227. fetcher.unpack(self.unpackdir)
  2228. unpackdir = os.path.join(self.unpackdir, 'npm')
  2229. self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
  2230. @skipIfNoNpm()
  2231. @skipIfNoNetwork()
  2232. def test_npm_bad_checksum(self):
  2233. urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
  2234. # Fetch once to get a tarball
  2235. fetcher = bb.fetch.Fetch(urls, self.d)
  2236. ud = fetcher.ud[fetcher.urls[0]]
  2237. fetcher.download()
  2238. self.assertTrue(os.path.exists(ud.localpath))
  2239. # Modify the tarball
  2240. bad = b'bad checksum'
  2241. with open(ud.localpath, 'wb') as f:
  2242. f.write(bad)
  2243. # Verify that the tarball is fetched again
  2244. fetcher.download()
  2245. badsum = hashlib.sha512(bad).hexdigest()
  2246. self.assertTrue(os.path.exists(ud.localpath + '_bad-checksum_' + badsum))
  2247. self.assertTrue(os.path.exists(ud.localpath))
  2248. @skipIfNoNpm()
  2249. @skipIfNoNetwork()
  2250. def test_npm_premirrors(self):
  2251. urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
  2252. # Fetch once to get a tarball
  2253. fetcher = bb.fetch.Fetch(urls, self.d)
  2254. ud = fetcher.ud[fetcher.urls[0]]
  2255. fetcher.download()
  2256. self.assertTrue(os.path.exists(ud.localpath))
  2257. # Setup the mirror by renaming the download directory
  2258. mirrordir = os.path.join(self.tempdir, 'mirror')
  2259. bb.utils.rename(self.dldir, mirrordir)
  2260. os.mkdir(self.dldir)
  2261. # Configure the premirror to be used
  2262. self.d.setVar('PREMIRRORS', 'https?$://.*/.* file://%s/npm2' % mirrordir)
  2263. self.d.setVar('BB_FETCH_PREMIRRORONLY', '1')
  2264. # Fetch again
  2265. self.assertFalse(os.path.exists(ud.localpath))
  2266. # The npm fetcher doesn't handle that the .resolved file disappears
  2267. # while the fetcher object exists, which it does when we rename the
  2268. # download directory to "mirror" above. Thus we need a new fetcher to go
  2269. # with the now empty download directory.
  2270. fetcher = bb.fetch.Fetch(urls, self.d)
  2271. ud = fetcher.ud[fetcher.urls[0]]
  2272. fetcher.download()
  2273. self.assertTrue(os.path.exists(ud.localpath))
  2274. @skipIfNoNpm()
  2275. @skipIfNoNetwork()
  2276. def test_npm_premirrors_with_specified_filename(self):
  2277. urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
  2278. # Fetch once to get a tarball
  2279. fetcher = bb.fetch.Fetch(urls, self.d)
  2280. ud = fetcher.ud[fetcher.urls[0]]
  2281. fetcher.download()
  2282. self.assertTrue(os.path.exists(ud.localpath))
  2283. # Setup the mirror
  2284. mirrordir = os.path.join(self.tempdir, 'mirror')
  2285. bb.utils.mkdirhier(mirrordir)
  2286. mirrorfilename = os.path.join(mirrordir, os.path.basename(ud.localpath))
  2287. os.replace(ud.localpath, mirrorfilename)
  2288. self.d.setVar('PREMIRRORS', 'https?$://.*/.* file://%s' % mirrorfilename)
  2289. self.d.setVar('BB_FETCH_PREMIRRORONLY', '1')
  2290. # Fetch again
  2291. self.assertFalse(os.path.exists(ud.localpath))
  2292. fetcher.download()
  2293. self.assertTrue(os.path.exists(ud.localpath))
  2294. @skipIfNoNpm()
  2295. @skipIfNoNetwork()
  2296. def test_npm_mirrors(self):
  2297. # Fetch once to get a tarball
  2298. urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
  2299. fetcher = bb.fetch.Fetch(urls, self.d)
  2300. ud = fetcher.ud[fetcher.urls[0]]
  2301. fetcher.download()
  2302. self.assertTrue(os.path.exists(ud.localpath))
  2303. # Setup the mirror
  2304. mirrordir = os.path.join(self.tempdir, 'mirror')
  2305. bb.utils.mkdirhier(mirrordir)
  2306. os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath)))
  2307. self.d.setVar('MIRRORS', 'https?$://.*/.* file://%s/' % mirrordir)
  2308. # Update the resolved url to an invalid url
  2309. with open(ud.resolvefile, 'r') as f:
  2310. url = f.read()
  2311. uri = URI(url)
  2312. uri.path = '/invalid'
  2313. with open(ud.resolvefile, 'w') as f:
  2314. f.write(str(uri))
  2315. # Fetch again
  2316. self.assertFalse(os.path.exists(ud.localpath))
  2317. fetcher.download()
  2318. self.assertTrue(os.path.exists(ud.localpath))
  2319. @skipIfNoNpm()
  2320. @skipIfNoNetwork()
  2321. def test_npm_destsuffix_downloadfilename(self):
  2322. urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0;destsuffix=foo/bar;downloadfilename=foo-bar.tgz']
  2323. fetcher = bb.fetch.Fetch(urls, self.d)
  2324. fetcher.download()
  2325. self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'foo-bar.tgz')))
  2326. fetcher.unpack(self.unpackdir)
  2327. unpackdir = os.path.join(self.unpackdir, 'foo', 'bar')
  2328. self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
  2329. def test_npm_no_network_no_tarball(self):
  2330. urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
  2331. self.d.setVar('BB_NO_NETWORK', '1')
  2332. fetcher = bb.fetch.Fetch(urls, self.d)
  2333. with self.assertRaises(bb.fetch2.NetworkAccess):
  2334. fetcher.download()
  2335. @skipIfNoNpm()
  2336. @skipIfNoNetwork()
  2337. def test_npm_no_network_with_tarball(self):
  2338. urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
  2339. # Fetch once to get a tarball
  2340. fetcher = bb.fetch.Fetch(urls, self.d)
  2341. fetcher.download()
  2342. # Disable network access
  2343. self.d.setVar('BB_NO_NETWORK', '1')
  2344. # Fetch again
  2345. fetcher.download()
  2346. fetcher.unpack(self.unpackdir)
  2347. unpackdir = os.path.join(self.unpackdir, 'npm')
  2348. self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
  2349. @skipIfNoNpm()
  2350. @skipIfNoNetwork()
  2351. def test_npm_registry_alternate(self):
  2352. urls = ['npm://skimdb.npmjs.com;package=@savoirfairelinux/node-server-example;version=1.0.0']
  2353. fetcher = bb.fetch.Fetch(urls, self.d)
  2354. fetcher.download()
  2355. fetcher.unpack(self.unpackdir)
  2356. unpackdir = os.path.join(self.unpackdir, 'npm')
  2357. self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
  2358. @skipIfNoNpm()
  2359. @skipIfNoNetwork()
  2360. def test_npm_version_latest(self):
  2361. url = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=latest']
  2362. fetcher = bb.fetch.Fetch(url, self.d)
  2363. fetcher.download()
  2364. fetcher.unpack(self.unpackdir)
  2365. unpackdir = os.path.join(self.unpackdir, 'npm')
  2366. self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
  2367. @skipIfNoNpm()
  2368. @skipIfNoNetwork()
  2369. def test_npm_registry_invalid(self):
  2370. urls = ['npm://registry.invalid.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
  2371. fetcher = bb.fetch.Fetch(urls, self.d)
  2372. with self.assertRaises(bb.fetch2.FetchError):
  2373. fetcher.download()
  2374. @skipIfNoNpm()
  2375. @skipIfNoNetwork()
  2376. def test_npm_package_invalid(self):
  2377. urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/invalid;version=1.0.0']
  2378. fetcher = bb.fetch.Fetch(urls, self.d)
  2379. with self.assertRaises(bb.fetch2.FetchError):
  2380. fetcher.download()
  2381. @skipIfNoNpm()
  2382. @skipIfNoNetwork()
  2383. def test_npm_version_invalid(self):
  2384. urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=invalid']
  2385. with self.assertRaises(bb.fetch2.ParameterError):
  2386. fetcher = bb.fetch.Fetch(urls, self.d)
  2387. @skipIfNoNpm()
  2388. @skipIfNoNetwork()
  2389. def test_npm_registry_none(self):
  2390. urls = ['npm://;package=@savoirfairelinux/node-server-example;version=1.0.0']
  2391. with self.assertRaises(bb.fetch2.MalformedUrl):
  2392. fetcher = bb.fetch.Fetch(urls, self.d)
  2393. @skipIfNoNpm()
  2394. @skipIfNoNetwork()
  2395. def test_npm_package_none(self):
  2396. urls = ['npm://registry.npmjs.org;version=1.0.0']
  2397. with self.assertRaises(bb.fetch2.MissingParameterError):
  2398. fetcher = bb.fetch.Fetch(urls, self.d)
  2399. @skipIfNoNpm()
  2400. @skipIfNoNetwork()
  2401. def test_npm_version_none(self):
  2402. urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example']
  2403. with self.assertRaises(bb.fetch2.MissingParameterError):
  2404. fetcher = bb.fetch.Fetch(urls, self.d)
  2405. def create_shrinkwrap_file(self, data):
  2406. import json
  2407. datadir = os.path.join(self.tempdir, 'data')
  2408. swfile = os.path.join(datadir, 'npm-shrinkwrap.json')
  2409. bb.utils.mkdirhier(datadir)
  2410. with open(swfile, 'w') as f:
  2411. json.dump(data, f)
  2412. return swfile
  2413. @skipIfNoNetwork()
  2414. def test_npmsw(self):
  2415. swfile = self.create_shrinkwrap_file({
  2416. 'packages': {
  2417. 'node_modules/array-flatten': {
  2418. 'version': '1.1.1',
  2419. 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
  2420. 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=',
  2421. 'dependencies': {
  2422. 'content-type': "1.0.4"
  2423. }
  2424. },
  2425. 'node_modules/array-flatten/node_modules/content-type': {
  2426. 'version': '1.0.4',
  2427. 'resolved': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz',
  2428. 'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==',
  2429. 'dependencies': {
  2430. 'cookie': 'git+https://github.com/jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09'
  2431. }
  2432. },
  2433. 'node_modules/array-flatten/node_modules/content-type/node_modules/cookie': {
  2434. 'resolved': 'git+https://github.com/jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09'
  2435. }
  2436. }
  2437. })
  2438. fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
  2439. fetcher.download()
  2440. self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')))
  2441. self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz')))
  2442. self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'github.com.jshttp.cookie.git')))
  2443. fetcher.unpack(self.unpackdir)
  2444. self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'npm-shrinkwrap.json')))
  2445. self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'node_modules', 'array-flatten', 'package.json')))
  2446. self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'node_modules', 'array-flatten', 'node_modules', 'content-type', 'package.json')))
  2447. self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'node_modules', 'array-flatten', 'node_modules', 'content-type', 'node_modules', 'cookie', 'package.json')))
  2448. @skipIfNoNetwork()
  2449. def test_npmsw_git(self):
  2450. swfile = self.create_shrinkwrap_file({
  2451. 'packages': {
  2452. 'node_modules/cookie': {
  2453. 'resolved': 'git+https://github.com/jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09'
  2454. }
  2455. }
  2456. })
  2457. fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
  2458. fetcher.download()
  2459. self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'github.com.jshttp.cookie.git')))
  2460. @skipIfNoNetwork()
  2461. def test_npmsw_dev(self):
  2462. swfile = self.create_shrinkwrap_file({
  2463. 'packages': {
  2464. 'node_modules/array-flatten': {
  2465. 'version': '1.1.1',
  2466. 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
  2467. 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
  2468. },
  2469. 'node_modules/content-type': {
  2470. 'version': '1.0.4',
  2471. 'resolved': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz',
  2472. 'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==',
  2473. 'dev': True
  2474. }
  2475. }
  2476. })
  2477. # Fetch with dev disabled
  2478. fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
  2479. fetcher.download()
  2480. self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')))
  2481. self.assertFalse(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz')))
  2482. # Fetch with dev enabled
  2483. fetcher = bb.fetch.Fetch(['npmsw://' + swfile + ';dev=1'], self.d)
  2484. fetcher.download()
  2485. self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')))
  2486. self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz')))
  2487. @skipIfNoNetwork()
  2488. def test_npmsw_destsuffix(self):
  2489. swfile = self.create_shrinkwrap_file({
  2490. 'packages': {
  2491. 'node_modules/array-flatten': {
  2492. 'version': '1.1.1',
  2493. 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
  2494. 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
  2495. }
  2496. }
  2497. })
  2498. fetcher = bb.fetch.Fetch(['npmsw://' + swfile + ';destsuffix=foo/bar'], self.d)
  2499. fetcher.download()
  2500. fetcher.unpack(self.unpackdir)
  2501. self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'foo', 'bar', 'node_modules', 'array-flatten', 'package.json')))
  2502. def test_npmsw_no_network_no_tarball(self):
  2503. swfile = self.create_shrinkwrap_file({
  2504. 'packages': {
  2505. 'node_modules/array-flatten': {
  2506. 'version': '1.1.1',
  2507. 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
  2508. 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
  2509. }
  2510. }
  2511. })
  2512. self.d.setVar('BB_NO_NETWORK', '1')
  2513. fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
  2514. with self.assertRaises(bb.fetch2.NetworkAccess):
  2515. fetcher.download()
  2516. @skipIfNoNpm()
  2517. @skipIfNoNetwork()
  2518. def test_npmsw_no_network_with_tarball(self):
  2519. # Fetch once to get a tarball
  2520. fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d)
  2521. fetcher.download()
  2522. # Disable network access
  2523. self.d.setVar('BB_NO_NETWORK', '1')
  2524. # Fetch again
  2525. swfile = self.create_shrinkwrap_file({
  2526. 'packages': {
  2527. 'node_modules/array-flatten': {
  2528. 'version': '1.1.1',
  2529. 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
  2530. 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
  2531. }
  2532. }
  2533. })
  2534. fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
  2535. fetcher.download()
  2536. fetcher.unpack(self.unpackdir)
  2537. self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'node_modules', 'array-flatten', 'package.json')))
  2538. @skipIfNoNetwork()
  2539. def test_npmsw_npm_reusability(self):
  2540. # Fetch once with npmsw
  2541. swfile = self.create_shrinkwrap_file({
  2542. 'packages': {
  2543. 'node_modules/array-flatten': {
  2544. 'version': '1.1.1',
  2545. 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
  2546. 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
  2547. }
  2548. }
  2549. })
  2550. fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
  2551. fetcher.download()
  2552. # Disable network access
  2553. self.d.setVar('BB_NO_NETWORK', '1')
  2554. # Fetch again with npm
  2555. fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d)
  2556. fetcher.download()
  2557. fetcher.unpack(self.unpackdir)
  2558. self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'npm', 'package.json')))
  2559. @skipIfNoNetwork()
  2560. def test_npmsw_bad_checksum(self):
  2561. # Try to fetch with bad checksum
  2562. swfile = self.create_shrinkwrap_file({
  2563. 'packages': {
  2564. 'node_modules/array-flatten': {
  2565. 'version': '1.1.1',
  2566. 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
  2567. 'integrity': 'sha1-gfNEp2hqgLTFKT6P3AsBYMgsBqg='
  2568. }
  2569. }
  2570. })
  2571. fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
  2572. with self.assertRaises(bb.fetch2.FetchError):
  2573. fetcher.download()
  2574. # Fetch correctly to get a tarball
  2575. swfile = self.create_shrinkwrap_file({
  2576. 'packages': {
  2577. 'node_modules/array-flatten': {
  2578. 'version': '1.1.1',
  2579. 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
  2580. 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
  2581. }
  2582. }
  2583. })
  2584. fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
  2585. fetcher.download()
  2586. localpath = os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')
  2587. self.assertTrue(os.path.exists(localpath))
  2588. # Modify the tarball
  2589. bad = b'bad checksum'
  2590. with open(localpath, 'wb') as f:
  2591. f.write(bad)
  2592. # Verify that the tarball is fetched again
  2593. fetcher.download()
  2594. badsum = hashlib.sha1(bad).hexdigest()
  2595. self.assertTrue(os.path.exists(localpath + '_bad-checksum_' + badsum))
  2596. self.assertTrue(os.path.exists(localpath))
  2597. @skipIfNoNpm()
  2598. @skipIfNoNetwork()
  2599. def test_npmsw_premirrors(self):
  2600. # Fetch once to get a tarball
  2601. fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d)
  2602. ud = fetcher.ud[fetcher.urls[0]]
  2603. fetcher.download()
  2604. self.assertTrue(os.path.exists(ud.localpath))
  2605. # Setup the mirror
  2606. mirrordir = os.path.join(self.tempdir, 'mirror')
  2607. bb.utils.mkdirhier(mirrordir)
  2608. os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath)))
  2609. self.d.setVar('PREMIRRORS', 'https?$://.*/.* file://%s/' % mirrordir)
  2610. self.d.setVar('BB_FETCH_PREMIRRORONLY', '1')
  2611. # Fetch again
  2612. self.assertFalse(os.path.exists(ud.localpath))
  2613. swfile = self.create_shrinkwrap_file({
  2614. 'packages': {
  2615. 'node_modules/array-flatten': {
  2616. 'version': '1.1.1',
  2617. 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
  2618. 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
  2619. }
  2620. }
  2621. })
  2622. fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
  2623. fetcher.download()
  2624. self.assertTrue(os.path.exists(ud.localpath))
  2625. @skipIfNoNpm()
  2626. @skipIfNoNetwork()
  2627. def test_npmsw_mirrors(self):
  2628. # Fetch once to get a tarball
  2629. fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d)
  2630. ud = fetcher.ud[fetcher.urls[0]]
  2631. fetcher.download()
  2632. self.assertTrue(os.path.exists(ud.localpath))
  2633. # Setup the mirror
  2634. mirrordir = os.path.join(self.tempdir, 'mirror')
  2635. bb.utils.mkdirhier(mirrordir)
  2636. os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath)))
  2637. self.d.setVar('MIRRORS', 'https?$://.*/.* file://%s/' % mirrordir)
  2638. # Fetch again with invalid url
  2639. self.assertFalse(os.path.exists(ud.localpath))
  2640. swfile = self.create_shrinkwrap_file({
  2641. 'packages': {
  2642. 'node_modules/array-flatten': {
  2643. 'version': '1.1.1',
  2644. 'resolved': 'https://invalid',
  2645. 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
  2646. }
  2647. }
  2648. })
  2649. fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
  2650. fetcher.download()
  2651. self.assertTrue(os.path.exists(ud.localpath))
  2652. @skipIfNoNetwork()
  2653. def test_npmsw_bundled(self):
  2654. swfile = self.create_shrinkwrap_file({
  2655. 'packages': {
  2656. 'node_modules/array-flatten': {
  2657. 'version': '1.1.1',
  2658. 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
  2659. 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
  2660. },
  2661. 'node_modules/content-type': {
  2662. 'version': '1.0.4',
  2663. 'resolved': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz',
  2664. 'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==',
  2665. 'inBundle': True
  2666. }
  2667. }
  2668. })
  2669. fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
  2670. fetcher.download()
  2671. self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')))
  2672. self.assertFalse(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz')))
  2673. class GitSharedTest(FetcherTest):
  2674. def setUp(self):
  2675. super(GitSharedTest, self).setUp()
  2676. self.recipe_url = "git://git.openembedded.org/bitbake;branch=master;protocol=https"
  2677. self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
  2678. self.d.setVar("__BBSRCREV_SEEN", "1")
  2679. @skipIfNoNetwork()
  2680. def test_shared_unpack(self):
  2681. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  2682. fetcher.download()
  2683. fetcher.unpack(self.unpackdir)
  2684. alt = os.path.join(self.unpackdir, 'git/.git/objects/info/alternates')
  2685. self.assertTrue(os.path.exists(alt))
  2686. @skipIfNoNetwork()
  2687. def test_noshared_unpack(self):
  2688. self.d.setVar('BB_GIT_NOSHARED', '1')
  2689. self.unpackdir += '_noshared'
  2690. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  2691. fetcher.download()
  2692. fetcher.unpack(self.unpackdir)
  2693. alt = os.path.join(self.unpackdir, 'git/.git/objects/info/alternates')
  2694. self.assertFalse(os.path.exists(alt))
  2695. class GitTagVerificationTests(FetcherTest):
  2696. @skipIfNoNetwork()
  2697. def test_tag_rev_match(self):
  2698. # Test a url with rev= and tag= set works
  2699. fetcher = bb.fetch.Fetch(["git://git.openembedded.org/bitbake;branch=2.12;protocol=https;rev=5b4e20377eea8d428edf1aeb2187c18f82ca6757;tag=2.12.0"], self.d)
  2700. fetcher.download()
  2701. fetcher.unpack(self.unpackdir)
  2702. @skipIfNoNetwork()
  2703. def test_tag_rev_match2(self):
  2704. # Test a url with SRCREV and tag= set works
  2705. self.d.setVar('SRCREV', '5b4e20377eea8d428edf1aeb2187c18f82ca6757')
  2706. fetcher = bb.fetch.Fetch(["git://git.openembedded.org/bitbake;branch=2.12;protocol=https;tag=2.12.0"], self.d)
  2707. fetcher.download()
  2708. fetcher.unpack(self.unpackdir)
  2709. @skipIfNoNetwork()
  2710. def test_tag_rev_match3(self):
  2711. # Test a url with SRCREV, rev= and tag= set works
  2712. self.d.setVar('SRCREV', '5b4e20377eea8d428edf1aeb2187c18f82ca6757')
  2713. fetcher = bb.fetch.Fetch(["git://git.openembedded.org/bitbake;branch=2.12;protocol=https;rev=5b4e20377eea8d428edf1aeb2187c18f82ca6757;tag=2.12.0"], self.d)
  2714. fetcher.download()
  2715. fetcher.unpack(self.unpackdir)
  2716. @skipIfNoNetwork()
  2717. def test_tag_rev_match4(self):
  2718. # Test a url with SRCREV and rev= mismatching errors
  2719. self.d.setVar('SRCREV', 'bade540fc31a1c26839efd2c7785a751ce24ebfb')
  2720. with self.assertRaises(bb.fetch2.FetchError):
  2721. fetcher = bb.fetch.Fetch(["git://git.openembedded.org/bitbake;branch=2.12;protocol=https;rev=5b4e20377eea8d428edf1aeb2187c18f82ca6757;tag=2.12.0"], self.d)
  2722. @skipIfNoNetwork()
  2723. def test_tag_rev_match5(self):
  2724. # Test a url with SRCREV, rev= and tag= set works when using shallow clones
  2725. self.d.setVar('BB_GIT_SHALLOW', '1')
  2726. self.d.setVar('SRCREV', '5b4e20377eea8d428edf1aeb2187c18f82ca6757')
  2727. fetcher = bb.fetch.Fetch(["git://git.openembedded.org/bitbake;branch=2.12;protocol=https;rev=5b4e20377eea8d428edf1aeb2187c18f82ca6757;tag=2.12.0"], self.d)
  2728. fetcher.download()
  2729. fetcher.unpack(self.unpackdir)
  2730. @skipIfNoNetwork()
  2731. def test_tag_rev_match6(self):
  2732. # Test a url with SRCREV, rev= and a mismatched tag= when using shallow clones
  2733. self.d.setVar('BB_GIT_SHALLOW', '1')
  2734. fetcher = bb.fetch.Fetch(["git://git.openembedded.org/bitbake;branch=2.12;protocol=https;rev=5b4e20377eea8d428edf1aeb2187c18f82ca6757;tag=2.8.0"], self.d)
  2735. fetcher.download()
  2736. with self.assertRaises(bb.fetch2.FetchError):
  2737. fetcher.unpack(self.unpackdir)
  2738. @skipIfNoNetwork()
  2739. def test_tag_rev_match7(self):
  2740. # Test a url with SRCREV, rev= and a mismatched tag=
  2741. self.d.setVar('SRCREV', '5b4e20377eea8d428edf1aeb2187c18f82ca6757')
  2742. fetcher = bb.fetch.Fetch(["git://git.openembedded.org/bitbake;branch=2.12;protocol=https;rev=5b4e20377eea8d428edf1aeb2187c18f82ca6757;tag=2.8.0"], self.d)
  2743. fetcher.download()
  2744. with self.assertRaises(bb.fetch2.FetchError):
  2745. fetcher.unpack(self.unpackdir)
  2746. class FetchPremirroronlyLocalTest(FetcherTest):
  2747. def setUp(self):
  2748. super(FetchPremirroronlyLocalTest, self).setUp()
  2749. self.mirrordir = os.path.join(self.tempdir, "mirrors")
  2750. os.mkdir(self.mirrordir)
  2751. self.reponame = "bitbake"
  2752. self.gitdir = os.path.join(self.tempdir, "git", self.reponame)
  2753. self.recipe_url = "git://git.fake.repo/bitbake;branch=master;protocol=https"
  2754. self.d.setVar("BB_FETCH_PREMIRRORONLY", "1")
  2755. self.d.setVar("BB_NO_NETWORK", "1")
  2756. self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n")
  2757. self.mirrorname = "git2_git.fake.repo.bitbake.tar.gz"
  2758. self.mirrorfile = os.path.join(self.mirrordir, self.mirrorname)
  2759. self.testfilename = "bitbake-fetch.test"
  2760. def make_git_repo(self):
  2761. recipeurl = "git:/git.fake.repo/bitbake"
  2762. os.makedirs(self.gitdir)
  2763. self.git_init(cwd=self.gitdir)
  2764. for i in range(0):
  2765. self.git_new_commit()
  2766. bb.process.run('tar -czvf {} .'.format(os.path.join(self.mirrordir, self.mirrorname)), cwd = self.gitdir)
  2767. def git_new_commit(self):
  2768. import random
  2769. os.unlink(os.path.join(self.mirrordir, self.mirrorname))
  2770. branch = self.git("branch --show-current", self.gitdir).split()
  2771. with open(os.path.join(self.gitdir, self.testfilename), "w") as testfile:
  2772. testfile.write("File {} from branch {}; Useless random data {}".format(self.testfilename, branch, random.random()))
  2773. self.git("add {}".format(self.testfilename), self.gitdir)
  2774. self.git("commit -a -m \"This random commit {} in branch {}. I'm useless.\"".format(random.random(), branch), self.gitdir)
  2775. bb.process.run('tar -czvf {} .'.format(os.path.join(self.mirrordir, self.mirrorname)), cwd = self.gitdir)
  2776. return self.git("rev-parse HEAD", self.gitdir).strip()
  2777. def git_new_branch(self, name):
  2778. self.git_new_commit()
  2779. head = self.git("rev-parse HEAD", self.gitdir).strip()
  2780. self.git("checkout -b {}".format(name), self.gitdir)
  2781. newrev = self.git_new_commit()
  2782. self.git("checkout {}".format(head), self.gitdir)
  2783. return newrev
  2784. def test_mirror_multiple_fetches(self):
  2785. self.make_git_repo()
  2786. self.d.setVar("SRCREV", self.git_new_commit())
  2787. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  2788. fetcher.download()
  2789. fetcher.unpack(self.unpackdir)
  2790. ## New commit in premirror. it's not in the download_dir
  2791. self.d.setVar("SRCREV", self.git_new_commit())
  2792. fetcher2 = bb.fetch.Fetch([self.recipe_url], self.d)
  2793. fetcher2.download()
  2794. fetcher2.unpack(self.unpackdir)
  2795. ## New commit in premirror. it's not in the download_dir
  2796. self.d.setVar("SRCREV", self.git_new_commit())
  2797. fetcher3 = bb.fetch.Fetch([self.recipe_url], self.d)
  2798. fetcher3.download()
  2799. fetcher3.unpack(self.unpackdir)
  2800. def test_mirror_commit_nonexistent(self):
  2801. self.make_git_repo()
  2802. self.d.setVar("SRCREV", "0"*40)
  2803. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  2804. with self.assertRaises(bb.fetch2.NetworkAccess):
  2805. fetcher.download()
  2806. def test_mirror_commit_exists(self):
  2807. self.make_git_repo()
  2808. self.d.setVar("SRCREV", self.git_new_commit())
  2809. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  2810. fetcher.download()
  2811. fetcher.unpack(self.unpackdir)
  2812. def test_mirror_tarball_nonexistent(self):
  2813. self.d.setVar("SRCREV", "0"*40)
  2814. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  2815. with self.assertRaises(bb.fetch2.NetworkAccess):
  2816. fetcher.download()
  2817. class FetchPremirroronlyNetworkTest(FetcherTest):
  2818. def setUp(self):
  2819. super(FetchPremirroronlyNetworkTest, self).setUp()
  2820. self.mirrordir = os.path.join(self.tempdir, "mirrors")
  2821. os.mkdir(self.mirrordir)
  2822. self.reponame = "fstests"
  2823. self.clonedir = os.path.join(self.tempdir, "git")
  2824. self.gitdir = os.path.join(self.tempdir, "git", "{}.git".format(self.reponame))
  2825. self.recipe_url = "git://git.yoctoproject.org/fstests;protocol=https;branch=master"
  2826. self.d.setVar("BB_FETCH_PREMIRRORONLY", "1")
  2827. self.d.setVar("BB_NO_NETWORK", "0")
  2828. self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n")
  2829. def make_git_repo(self):
  2830. import shutil
  2831. self.mirrorname = "git2_git.yoctoproject.org.fstests.tar.gz"
  2832. os.makedirs(self.clonedir)
  2833. self.git("clone --bare --shallow-since=\"01.01.2013\" {}".format(self.recipe_url), self.clonedir)
  2834. bb.process.run('tar -czvf {} .'.format(os.path.join(self.mirrordir, self.mirrorname)), cwd = self.gitdir)
  2835. shutil.rmtree(self.clonedir)
  2836. @skipIfNoNetwork()
  2837. def test_mirror_tarball_updated(self):
  2838. self.make_git_repo()
  2839. ## Upstream commit is in the mirror
  2840. self.d.setVar("SRCREV", "49d65d53c2bf558ae6e9185af0f3af7b79d255ec")
  2841. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  2842. fetcher.download()
  2843. @skipIfNoNetwork()
  2844. def test_mirror_tarball_outdated(self):
  2845. self.make_git_repo()
  2846. ## Upstream commit not in the mirror
  2847. self.d.setVar("SRCREV", "15413486df1f5a5b5af699b6f3ba5f0984e52a9f")
  2848. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  2849. with self.assertRaises(bb.fetch2.NetworkAccess):
  2850. fetcher.download()
  2851. class FetchPremirroronlyMercurialTest(FetcherTest):
  2852. """ Test for premirrors with mercurial repos
  2853. the test covers also basic hg:// clone (see fetch_and_create_tarball
  2854. """
  2855. def skipIfNoHg():
  2856. import shutil
  2857. if not shutil.which('hg'):
  2858. return unittest.skip('Mercurial not installed')
  2859. return lambda f: f
  2860. def setUp(self):
  2861. super(FetchPremirroronlyMercurialTest, self).setUp()
  2862. self.mirrordir = os.path.join(self.tempdir, "mirrors")
  2863. os.mkdir(self.mirrordir)
  2864. self.reponame = "libgnt"
  2865. self.clonedir = os.path.join(self.tempdir, "hg")
  2866. self.recipe_url = "hg://keep.imfreedom.org/libgnt;module=libgnt"
  2867. self.d.setVar("SRCREV", "53e8b422faaf")
  2868. self.mirrorname = "hg_libgnt_keep.imfreedom.org_.libgnt.tar.gz"
  2869. def fetch_and_create_tarball(self):
  2870. """
  2871. Ask bitbake to download repo and prepare mirror tarball for us
  2872. """
  2873. self.d.setVar("BB_GENERATE_MIRROR_TARBALLS", "1")
  2874. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  2875. fetcher.download()
  2876. mirrorfile = os.path.join(self.d.getVar("DL_DIR"), self.mirrorname)
  2877. self.assertTrue(os.path.exists(mirrorfile), "Mirror tarball {} has not been created".format(mirrorfile))
  2878. ## moving tarball to mirror directory
  2879. os.rename(mirrorfile, os.path.join(self.mirrordir, self.mirrorname))
  2880. self.d.setVar("BB_GENERATE_MIRROR_TARBALLS", "0")
  2881. @skipIfNoNetwork()
  2882. @skipIfNoHg()
  2883. def test_premirror_mercurial(self):
  2884. self.fetch_and_create_tarball()
  2885. self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n")
  2886. self.d.setVar("BB_FETCH_PREMIRRORONLY", "1")
  2887. self.d.setVar("BB_NO_NETWORK", "1")
  2888. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  2889. fetcher.download()
  2890. class FetchPremirroronlyBrokenTarball(FetcherTest):
  2891. def setUp(self):
  2892. super(FetchPremirroronlyBrokenTarball, self).setUp()
  2893. self.mirrordir = os.path.join(self.tempdir, "mirrors")
  2894. os.mkdir(self.mirrordir)
  2895. self.reponame = "bitbake"
  2896. self.gitdir = os.path.join(self.tempdir, "git", self.reponame)
  2897. self.recipe_url = "git://git.fake.repo/bitbake;protocol=https;branch=master"
  2898. self.d.setVar("BB_FETCH_PREMIRRORONLY", "1")
  2899. self.d.setVar("BB_NO_NETWORK", "1")
  2900. self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n")
  2901. self.mirrorname = "git2_git.fake.repo.bitbake.tar.gz"
  2902. with open(os.path.join(self.mirrordir, self.mirrorname), 'w') as targz:
  2903. targz.write("This is not tar.gz file!")
  2904. def test_mirror_broken_download(self):
  2905. import sys
  2906. self.d.setVar("SRCREV", "0"*40)
  2907. fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
  2908. with self.assertRaises(bb.fetch2.FetchError), self.assertLogs() as logs:
  2909. fetcher.download()
  2910. output = "".join(logs.output)
  2911. self.assertFalse(" not a git repository (or any parent up to mount point /)" in output)
  2912. class GoModTest(FetcherTest):
  2913. @skipIfNoNetwork()
  2914. def test_gomod_url(self):
  2915. urls = ['gomod://github.com/Azure/azure-sdk-for-go/sdk/storage/azblob;version=v1.0.0;'
  2916. 'sha256sum=9bb69aea32f1d59711701f9562d66432c9c0374205e5009d1d1a62f03fb4fdad']
  2917. fetcher = bb.fetch2.Fetch(urls, self.d)
  2918. ud = fetcher.ud[urls[0]]
  2919. self.assertEqual(ud.url, 'https://proxy.golang.org/github.com/%21azure/azure-sdk-for-go/sdk/storage/azblob/%40v/v1.0.0.zip')
  2920. self.assertEqual(ud.parm['downloadfilename'], 'github.com.Azure.azure-sdk-for-go.sdk.storage.azblob@v1.0.0.zip')
  2921. self.assertEqual(ud.parm['name'], 'github.com/Azure/azure-sdk-for-go/sdk/storage/azblob@v1.0.0')
  2922. fetcher.download()
  2923. fetcher.unpack(self.unpackdir)
  2924. downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
  2925. self.assertTrue(os.path.exists(os.path.join(downloaddir, 'github.com/!azure/azure-sdk-for-go/sdk/storage/azblob/@v/v1.0.0.zip')))
  2926. self.assertTrue(os.path.exists(os.path.join(downloaddir, 'github.com/!azure/azure-sdk-for-go/sdk/storage/azblob/@v/v1.0.0.mod')))
  2927. self.assertEqual(bb.utils.sha256_file(os.path.join(downloaddir, 'github.com/!azure/azure-sdk-for-go/sdk/storage/azblob/@v/v1.0.0.mod')),
  2928. '7873b8544842329b4f385a3aa6cf82cc2bc8defb41a04fa5291c35fd5900e873')
  2929. @skipIfNoNetwork()
  2930. def test_gomod_url_go_mod_only(self):
  2931. urls = ['gomod://github.com/Azure/azure-sdk-for-go/sdk/storage/azblob;version=v1.0.0;mod=1;'
  2932. 'sha256sum=7873b8544842329b4f385a3aa6cf82cc2bc8defb41a04fa5291c35fd5900e873']
  2933. fetcher = bb.fetch2.Fetch(urls, self.d)
  2934. ud = fetcher.ud[urls[0]]
  2935. self.assertEqual(ud.url, 'https://proxy.golang.org/github.com/%21azure/azure-sdk-for-go/sdk/storage/azblob/%40v/v1.0.0.mod')
  2936. self.assertEqual(ud.parm['downloadfilename'], 'github.com.Azure.azure-sdk-for-go.sdk.storage.azblob@v1.0.0.mod')
  2937. self.assertEqual(ud.parm['name'], 'github.com/Azure/azure-sdk-for-go/sdk/storage/azblob@v1.0.0')
  2938. fetcher.download()
  2939. fetcher.unpack(self.unpackdir)
  2940. downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
  2941. self.assertTrue(os.path.exists(os.path.join(downloaddir, 'github.com/!azure/azure-sdk-for-go/sdk/storage/azblob/@v/v1.0.0.mod')))
  2942. @skipIfNoNetwork()
  2943. def test_gomod_url_sha256sum_varflag(self):
  2944. urls = ['gomod://gopkg.in/ini.v1;version=v1.67.0']
  2945. self.d.setVarFlag('SRC_URI', 'gopkg.in/ini.v1@v1.67.0.sha256sum', 'bd845dfc762a87a56e5a32a07770dc83e86976db7705d7f89c5dbafdc60b06c6')
  2946. fetcher = bb.fetch2.Fetch(urls, self.d)
  2947. ud = fetcher.ud[urls[0]]
  2948. self.assertEqual(ud.url, 'https://proxy.golang.org/gopkg.in/ini.v1/%40v/v1.67.0.zip')
  2949. self.assertEqual(ud.parm['downloadfilename'], 'gopkg.in.ini.v1@v1.67.0.zip')
  2950. self.assertEqual(ud.parm['name'], 'gopkg.in/ini.v1@v1.67.0')
  2951. fetcher.download()
  2952. fetcher.unpack(self.unpackdir)
  2953. downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
  2954. self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.zip')))
  2955. self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.mod')))
  2956. self.assertEqual(bb.utils.sha256_file(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.mod')),
  2957. '13aedd85db8e555104108e0e613bb7e4d1242af7f27c15423dd9ab63b60b72a1')
  2958. @skipIfNoNetwork()
  2959. def test_gomod_url_no_go_mod_in_module(self):
  2960. urls = ['gomod://gopkg.in/ini.v1;version=v1.67.0;'
  2961. 'sha256sum=bd845dfc762a87a56e5a32a07770dc83e86976db7705d7f89c5dbafdc60b06c6']
  2962. fetcher = bb.fetch2.Fetch(urls, self.d)
  2963. ud = fetcher.ud[urls[0]]
  2964. self.assertEqual(ud.url, 'https://proxy.golang.org/gopkg.in/ini.v1/%40v/v1.67.0.zip')
  2965. self.assertEqual(ud.parm['downloadfilename'], 'gopkg.in.ini.v1@v1.67.0.zip')
  2966. self.assertEqual(ud.parm['name'], 'gopkg.in/ini.v1@v1.67.0')
  2967. fetcher.download()
  2968. fetcher.unpack(self.unpackdir)
  2969. downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
  2970. self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.zip')))
  2971. self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.mod')))
  2972. self.assertEqual(bb.utils.sha256_file(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.mod')),
  2973. '13aedd85db8e555104108e0e613bb7e4d1242af7f27c15423dd9ab63b60b72a1')
  2974. @skipIfNoNetwork()
  2975. def test_gomod_url_host_only(self):
  2976. urls = ['gomod://go.opencensus.io;version=v0.24.0;'
  2977. 'sha256sum=203a767d7f8e7c1ebe5588220ad168d1e15b14ae70a636de7ca9a4a88a7e0d0c']
  2978. fetcher = bb.fetch2.Fetch(urls, self.d)
  2979. ud = fetcher.ud[urls[0]]
  2980. self.assertEqual(ud.url, 'https://proxy.golang.org/go.opencensus.io/%40v/v0.24.0.zip')
  2981. self.assertEqual(ud.parm['downloadfilename'], 'go.opencensus.io@v0.24.0.zip')
  2982. self.assertEqual(ud.parm['name'], 'go.opencensus.io@v0.24.0')
  2983. fetcher.download()
  2984. fetcher.unpack(self.unpackdir)
  2985. downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
  2986. self.assertTrue(os.path.exists(os.path.join(downloaddir, 'go.opencensus.io/@v/v0.24.0.zip')))
  2987. self.assertTrue(os.path.exists(os.path.join(downloaddir, 'go.opencensus.io/@v/v0.24.0.mod')))
  2988. self.assertEqual(bb.utils.sha256_file(os.path.join(downloaddir, 'go.opencensus.io/@v/v0.24.0.mod')),
  2989. '0dc9ccc660ad21cebaffd548f2cc6efa27891c68b4fbc1f8a3893b00f1acec96')
  2990. class GoModGitTest(FetcherTest):
  2991. @skipIfNoNetwork()
  2992. def test_gomodgit_url_repo(self):
  2993. urls = ['gomodgit://golang.org/x/net;version=v0.9.0;'
  2994. 'repo=go.googlesource.com/net;'
  2995. 'srcrev=694cff8668bac64e0864b552bffc280cd27f21b1']
  2996. fetcher = bb.fetch2.Fetch(urls, self.d)
  2997. ud = fetcher.ud[urls[0]]
  2998. self.assertEqual(ud.host, 'go.googlesource.com')
  2999. self.assertEqual(ud.path, '/net')
  3000. self.assertEqual(ud.name, 'golang.org/x/net@v0.9.0')
  3001. self.assertEqual(self.d.getVar('SRCREV_golang.org/x/net@v0.9.0'), '694cff8668bac64e0864b552bffc280cd27f21b1')
  3002. fetcher.download()
  3003. self.assertTrue(os.path.exists(ud.localpath))
  3004. fetcher.unpack(self.unpackdir)
  3005. vcsdir = os.path.join(self.unpackdir, 'pkg/mod/cache/vcs')
  3006. self.assertTrue(os.path.exists(os.path.join(vcsdir, 'ed42bd05533fd84ae290a5d33ebd3695a0a2b06131beebd5450825bee8603aca')))
  3007. downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
  3008. self.assertTrue(os.path.exists(os.path.join(downloaddir, 'golang.org/x/net/@v/v0.9.0.zip')))
  3009. self.assertTrue(os.path.exists(os.path.join(downloaddir, 'golang.org/x/net/@v/v0.9.0.mod')))
  3010. self.assertEqual(bb.utils.sha256_file(os.path.join(downloaddir, 'golang.org/x/net/@v/v0.9.0.mod')),
  3011. 'c5d6851ede50ec1c001afb763040194b68961bf06997e2605e8bf06dcd2aeb2e')
  3012. @skipIfNoNetwork()
  3013. def test_gomodgit_url_subdir(self):
  3014. urls = ['gomodgit://github.com/Azure/azure-sdk-for-go/sdk/storage/azblob;version=v1.0.0;'
  3015. 'repo=github.com/Azure/azure-sdk-for-go;subdir=sdk/storage/azblob;'
  3016. 'srcrev=ec928e0ed34db682b3f783d3739d1c538142e0c3']
  3017. fetcher = bb.fetch2.Fetch(urls, self.d)
  3018. ud = fetcher.ud[urls[0]]
  3019. self.assertEqual(ud.host, 'github.com')
  3020. self.assertEqual(ud.path, '/Azure/azure-sdk-for-go')
  3021. self.assertEqual(ud.parm['subpath'], 'sdk/storage/azblob')
  3022. self.assertEqual(ud.name, 'github.com/Azure/azure-sdk-for-go/sdk/storage/azblob@v1.0.0')
  3023. self.assertEqual(self.d.getVar('SRCREV_github.com/Azure/azure-sdk-for-go/sdk/storage/azblob@v1.0.0'), 'ec928e0ed34db682b3f783d3739d1c538142e0c3')
  3024. fetcher.download()
  3025. self.assertTrue(os.path.exists(ud.localpath))
  3026. fetcher.unpack(self.unpackdir)
  3027. vcsdir = os.path.join(self.unpackdir, 'pkg/mod/cache/vcs')
  3028. self.assertTrue(os.path.exists(os.path.join(vcsdir, 'd31d6145676ed3066ce573a8198f326dea5be45a43b3d8f41ce7787fd71d66b3')))
  3029. downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
  3030. self.assertTrue(os.path.exists(os.path.join(downloaddir, 'github.com/!azure/azure-sdk-for-go/sdk/storage/azblob/@v/v1.0.0.zip')))
  3031. self.assertTrue(os.path.exists(os.path.join(downloaddir, 'github.com/!azure/azure-sdk-for-go/sdk/storage/azblob/@v/v1.0.0.mod')))
  3032. self.assertEqual(bb.utils.sha256_file(os.path.join(downloaddir, 'github.com/!azure/azure-sdk-for-go/sdk/storage/azblob/@v/v1.0.0.mod')),
  3033. '7873b8544842329b4f385a3aa6cf82cc2bc8defb41a04fa5291c35fd5900e873')
  3034. @skipIfNoNetwork()
  3035. def test_gomodgit_url_srcrev_var(self):
  3036. urls = ['gomodgit://gopkg.in/ini.v1;version=v1.67.0']
  3037. self.d.setVar('SRCREV_gopkg.in/ini.v1@v1.67.0', 'b2f570e5b5b844226bbefe6fb521d891f529a951')
  3038. fetcher = bb.fetch2.Fetch(urls, self.d)
  3039. ud = fetcher.ud[urls[0]]
  3040. self.assertEqual(ud.host, 'gopkg.in')
  3041. self.assertEqual(ud.path, '/ini.v1')
  3042. self.assertEqual(ud.name, 'gopkg.in/ini.v1@v1.67.0')
  3043. self.assertEqual(ud.parm['srcrev'], 'b2f570e5b5b844226bbefe6fb521d891f529a951')
  3044. fetcher.download()
  3045. fetcher.unpack(self.unpackdir)
  3046. vcsdir = os.path.join(self.unpackdir, 'pkg/mod/cache/vcs')
  3047. self.assertTrue(os.path.exists(os.path.join(vcsdir, 'b7879a4be9ba8598851b8278b14c4f71a8316be64913298d1639cce6bde59bc3')))
  3048. downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
  3049. self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.zip')))
  3050. self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.mod')))
  3051. self.assertEqual(bb.utils.sha256_file(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.mod')),
  3052. '13aedd85db8e555104108e0e613bb7e4d1242af7f27c15423dd9ab63b60b72a1')
  3053. @skipIfNoNetwork()
  3054. def test_gomodgit_url_no_go_mod_in_module(self):
  3055. urls = ['gomodgit://gopkg.in/ini.v1;version=v1.67.0;'
  3056. 'srcrev=b2f570e5b5b844226bbefe6fb521d891f529a951']
  3057. fetcher = bb.fetch2.Fetch(urls, self.d)
  3058. ud = fetcher.ud[urls[0]]
  3059. self.assertEqual(ud.host, 'gopkg.in')
  3060. self.assertEqual(ud.path, '/ini.v1')
  3061. self.assertEqual(ud.name, 'gopkg.in/ini.v1@v1.67.0')
  3062. self.assertEqual(self.d.getVar('SRCREV_gopkg.in/ini.v1@v1.67.0'), 'b2f570e5b5b844226bbefe6fb521d891f529a951')
  3063. fetcher.download()
  3064. fetcher.unpack(self.unpackdir)
  3065. vcsdir = os.path.join(self.unpackdir, 'pkg/mod/cache/vcs')
  3066. self.assertTrue(os.path.exists(os.path.join(vcsdir, 'b7879a4be9ba8598851b8278b14c4f71a8316be64913298d1639cce6bde59bc3')))
  3067. downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
  3068. self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.zip')))
  3069. self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.mod')))
  3070. self.assertEqual(bb.utils.sha256_file(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.mod')),
  3071. '13aedd85db8e555104108e0e613bb7e4d1242af7f27c15423dd9ab63b60b72a1')
  3072. @skipIfNoNetwork()
  3073. def test_gomodgit_url_host_only(self):
  3074. urls = ['gomodgit://go.opencensus.io;version=v0.24.0;'
  3075. 'repo=github.com/census-instrumentation/opencensus-go;'
  3076. 'srcrev=b1a01ee95db0e690d91d7193d037447816fae4c5']
  3077. fetcher = bb.fetch2.Fetch(urls, self.d)
  3078. ud = fetcher.ud[urls[0]]
  3079. self.assertEqual(ud.host, 'github.com')
  3080. self.assertEqual(ud.path, '/census-instrumentation/opencensus-go')
  3081. self.assertEqual(ud.name, 'go.opencensus.io@v0.24.0')
  3082. self.assertEqual(self.d.getVar('SRCREV_go.opencensus.io@v0.24.0'), 'b1a01ee95db0e690d91d7193d037447816fae4c5')
  3083. fetcher.download()
  3084. fetcher.unpack(self.unpackdir)
  3085. vcsdir = os.path.join(self.unpackdir, 'pkg/mod/cache/vcs')
  3086. self.assertTrue(os.path.exists(os.path.join(vcsdir, 'aae3ac7b2122ed3345654e6327855e9682f4a5350d63e93dbcfc51c4419df0e1')))
  3087. downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
  3088. self.assertTrue(os.path.exists(os.path.join(downloaddir, 'go.opencensus.io/@v/v0.24.0.zip')))
  3089. self.assertTrue(os.path.exists(os.path.join(downloaddir, 'go.opencensus.io/@v/v0.24.0.mod')))
  3090. self.assertEqual(bb.utils.sha256_file(os.path.join(downloaddir, 'go.opencensus.io/@v/v0.24.0.mod')),
  3091. '0dc9ccc660ad21cebaffd548f2cc6efa27891c68b4fbc1f8a3893b00f1acec96')