blob: c7a23407c1d1ec089680e134aa1e336c081e1568 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#
2# BitBake Tests for the Fetcher (fetch2/)
3#
4# Copyright (C) 2012 Richard Purdie
5#
Brad Bishopc342db32019-05-15 21:57:59 -04006# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007#
8
9import unittest
Brad Bishop316dfdd2018-06-25 12:45:53 -040010import hashlib
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011import tempfile
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012import collections
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013import os
Patrick Williams92b42cb2022-09-03 06:53:57 -050014import signal
Andrew Geissler9aee5002022-03-30 16:27:02 +000015import tarfile
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016from bb.fetch2 import URI
17from bb.fetch2 import FetchMethod
18import bb
Andrew Geissler82c905d2020-04-13 13:39:40 -050019from bb.tests.support.httpserver import HTTPService
Patrick Williamsc124f4f2015-09-15 14:41:29 -050020
Brad Bishopd7bf8c12018-02-25 22:55:05 -050021def skipIfNoNetwork():
22 if os.environ.get("BB_SKIP_NETTESTS") == "yes":
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000023 return unittest.skip("network test")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050024 return lambda f: f
25
Patrick Williams92b42cb2022-09-03 06:53:57 -050026class TestTimeout(Exception):
Andrew Geissler8f840682023-07-21 09:09:43 -050027 # Indicate to pytest that this is not a test suite
28 __test__ = False
Patrick Williams92b42cb2022-09-03 06:53:57 -050029
30class Timeout():
31
32 def __init__(self, seconds):
33 self.seconds = seconds
34
35 def handle_timeout(self, signum, frame):
36 raise TestTimeout("Test failed: timeout reached")
37
38 def __enter__(self):
39 signal.signal(signal.SIGALRM, self.handle_timeout)
40 signal.alarm(self.seconds)
41
42 def __exit__(self, exc_type, exc_val, exc_tb):
43 signal.alarm(0)
44
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045class URITest(unittest.TestCase):
46 test_uris = {
47 "http://www.google.com/index.html" : {
48 'uri': 'http://www.google.com/index.html',
49 'scheme': 'http',
50 'hostname': 'www.google.com',
51 'port': None,
52 'hostport': 'www.google.com',
53 'path': '/index.html',
54 'userinfo': '',
55 'username': '',
56 'password': '',
57 'params': {},
58 'query': {},
59 'relative': False
60 },
61 "http://www.google.com/index.html;param1=value1" : {
62 'uri': 'http://www.google.com/index.html;param1=value1',
63 'scheme': 'http',
64 'hostname': 'www.google.com',
65 'port': None,
66 'hostport': 'www.google.com',
67 'path': '/index.html',
68 'userinfo': '',
69 'username': '',
70 'password': '',
71 'params': {
72 'param1': 'value1'
73 },
74 'query': {},
75 'relative': False
76 },
77 "http://www.example.org/index.html?param1=value1" : {
78 'uri': 'http://www.example.org/index.html?param1=value1',
79 'scheme': 'http',
80 'hostname': 'www.example.org',
81 'port': None,
82 'hostport': 'www.example.org',
83 'path': '/index.html',
84 'userinfo': '',
85 'username': '',
86 'password': '',
87 'params': {},
88 'query': {
89 'param1': 'value1'
90 },
91 'relative': False
92 },
93 "http://www.example.org/index.html?qparam1=qvalue1;param2=value2" : {
94 'uri': 'http://www.example.org/index.html?qparam1=qvalue1;param2=value2',
95 'scheme': 'http',
96 'hostname': 'www.example.org',
97 'port': None,
98 'hostport': 'www.example.org',
99 'path': '/index.html',
100 'userinfo': '',
101 'username': '',
102 'password': '',
103 'params': {
104 'param2': 'value2'
105 },
106 'query': {
107 'qparam1': 'qvalue1'
108 },
109 'relative': False
110 },
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600111 # Check that trailing semicolons are handled correctly
112 "http://www.example.org/index.html?qparam1=qvalue1;param2=value2;" : {
113 'uri': 'http://www.example.org/index.html?qparam1=qvalue1;param2=value2',
114 'scheme': 'http',
115 'hostname': 'www.example.org',
116 'port': None,
117 'hostport': 'www.example.org',
118 'path': '/index.html',
119 'userinfo': '',
120 'username': '',
121 'password': '',
122 'params': {
123 'param2': 'value2'
124 },
125 'query': {
126 'qparam1': 'qvalue1'
127 },
128 'relative': False
129 },
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500130 "http://www.example.com:8080/index.html" : {
131 'uri': 'http://www.example.com:8080/index.html',
132 'scheme': 'http',
133 'hostname': 'www.example.com',
134 'port': 8080,
135 'hostport': 'www.example.com:8080',
136 'path': '/index.html',
137 'userinfo': '',
138 'username': '',
139 'password': '',
140 'params': {},
141 'query': {},
142 'relative': False
143 },
144 "cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg" : {
145 'uri': 'cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg',
146 'scheme': 'cvs',
147 'hostname': 'cvs.handhelds.org',
148 'port': None,
149 'hostport': 'cvs.handhelds.org',
150 'path': '/cvs',
151 'userinfo': 'anoncvs',
152 'username': 'anoncvs',
153 'password': '',
154 'params': {
155 'module': 'familiar/dist/ipkg'
156 },
157 'query': {},
158 'relative': False
159 },
160 "cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg": {
161 'uri': 'cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg',
162 'scheme': 'cvs',
163 'hostname': 'cvs.handhelds.org',
164 'port': None,
165 'hostport': 'cvs.handhelds.org',
166 'path': '/cvs',
167 'userinfo': 'anoncvs:anonymous',
168 'username': 'anoncvs',
169 'password': 'anonymous',
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600170 'params': collections.OrderedDict([
171 ('tag', 'V0-99-81'),
172 ('module', 'familiar/dist/ipkg')
173 ]),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500174 'query': {},
175 'relative': False
176 },
177 "file://example.diff": { # NOTE: Not RFC compliant!
178 'uri': 'file:example.diff',
179 'scheme': 'file',
180 'hostname': '',
181 'port': None,
182 'hostport': '',
183 'path': 'example.diff',
184 'userinfo': '',
185 'username': '',
186 'password': '',
187 'params': {},
188 'query': {},
189 'relative': True
190 },
191 "file:example.diff": { # NOTE: RFC compliant version of the former
192 'uri': 'file:example.diff',
193 'scheme': 'file',
194 'hostname': '',
195 'port': None,
196 'hostport': '',
197 'path': 'example.diff',
198 'userinfo': '',
199 'userinfo': '',
200 'username': '',
201 'password': '',
202 'params': {},
203 'query': {},
204 'relative': True
205 },
206 "file:///tmp/example.diff": {
207 'uri': 'file:///tmp/example.diff',
208 'scheme': 'file',
209 'hostname': '',
210 'port': None,
211 'hostport': '',
212 'path': '/tmp/example.diff',
213 'userinfo': '',
214 'userinfo': '',
215 'username': '',
216 'password': '',
217 'params': {},
218 'query': {},
219 'relative': False
220 },
221 "git:///path/example.git": {
222 'uri': 'git:///path/example.git',
223 'scheme': 'git',
224 'hostname': '',
225 'port': None,
226 'hostport': '',
227 'path': '/path/example.git',
228 'userinfo': '',
229 'userinfo': '',
230 'username': '',
231 'password': '',
232 'params': {},
233 'query': {},
234 'relative': False
235 },
236 "git:path/example.git": {
237 'uri': 'git:path/example.git',
238 'scheme': 'git',
239 'hostname': '',
240 'port': None,
241 'hostport': '',
242 'path': 'path/example.git',
243 'userinfo': '',
244 'userinfo': '',
245 'username': '',
246 'password': '',
247 'params': {},
248 'query': {},
249 'relative': True
250 },
251 "git://example.net/path/example.git": {
252 'uri': 'git://example.net/path/example.git',
253 'scheme': 'git',
254 'hostname': 'example.net',
255 'port': None,
256 'hostport': 'example.net',
257 'path': '/path/example.git',
258 'userinfo': '',
259 'userinfo': '',
260 'username': '',
261 'password': '',
262 'params': {},
263 'query': {},
264 'relative': False
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500265 },
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500266 "git://tfs-example.org:22/tfs/example%20path/example.git": {
267 'uri': 'git://tfs-example.org:22/tfs/example%20path/example.git',
268 'scheme': 'git',
269 'hostname': 'tfs-example.org',
270 'port': 22,
271 'hostport': 'tfs-example.org:22',
272 'path': '/tfs/example path/example.git',
273 'userinfo': '',
274 'userinfo': '',
275 'username': '',
276 'password': '',
277 'params': {},
278 'query': {},
279 'relative': False
280 },
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500281 "http://somesite.net;someparam=1": {
282 'uri': 'http://somesite.net;someparam=1',
283 'scheme': 'http',
284 'hostname': 'somesite.net',
285 'port': None,
286 'hostport': 'somesite.net',
287 'path': '',
288 'userinfo': '',
289 'userinfo': '',
290 'username': '',
291 'password': '',
292 'params': {"someparam" : "1"},
293 'query': {},
294 'relative': False
295 },
296 "file://somelocation;someparam=1": {
297 'uri': 'file:somelocation;someparam=1',
298 'scheme': 'file',
299 'hostname': '',
300 'port': None,
301 'hostport': '',
302 'path': 'somelocation',
303 'userinfo': '',
304 'userinfo': '',
305 'username': '',
306 'password': '',
307 'params': {"someparam" : "1"},
308 'query': {},
309 'relative': True
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500310 }
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500311
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500312 }
313
314 def test_uri(self):
315 for test_uri, ref in self.test_uris.items():
316 uri = URI(test_uri)
317
318 self.assertEqual(str(uri), ref['uri'])
319
320 # expected attributes
321 self.assertEqual(uri.scheme, ref['scheme'])
322
323 self.assertEqual(uri.userinfo, ref['userinfo'])
324 self.assertEqual(uri.username, ref['username'])
325 self.assertEqual(uri.password, ref['password'])
326
327 self.assertEqual(uri.hostname, ref['hostname'])
328 self.assertEqual(uri.port, ref['port'])
329 self.assertEqual(uri.hostport, ref['hostport'])
330
331 self.assertEqual(uri.path, ref['path'])
332 self.assertEqual(uri.params, ref['params'])
333
334 self.assertEqual(uri.relative, ref['relative'])
335
336 def test_dict(self):
337 for test in self.test_uris.values():
338 uri = URI()
339
340 self.assertEqual(uri.scheme, '')
341 self.assertEqual(uri.userinfo, '')
342 self.assertEqual(uri.username, '')
343 self.assertEqual(uri.password, '')
344 self.assertEqual(uri.hostname, '')
345 self.assertEqual(uri.port, None)
346 self.assertEqual(uri.path, '')
347 self.assertEqual(uri.params, {})
348
349
350 uri.scheme = test['scheme']
351 self.assertEqual(uri.scheme, test['scheme'])
352
353 uri.userinfo = test['userinfo']
354 self.assertEqual(uri.userinfo, test['userinfo'])
355 self.assertEqual(uri.username, test['username'])
356 self.assertEqual(uri.password, test['password'])
357
358 # make sure changing the values doesn't do anything unexpected
359 uri.username = 'changeme'
360 self.assertEqual(uri.username, 'changeme')
361 self.assertEqual(uri.password, test['password'])
362 uri.password = 'insecure'
363 self.assertEqual(uri.username, 'changeme')
364 self.assertEqual(uri.password, 'insecure')
365
366 # reset back after our trickery
367 uri.userinfo = test['userinfo']
368 self.assertEqual(uri.userinfo, test['userinfo'])
369 self.assertEqual(uri.username, test['username'])
370 self.assertEqual(uri.password, test['password'])
371
372 uri.hostname = test['hostname']
373 self.assertEqual(uri.hostname, test['hostname'])
374 self.assertEqual(uri.hostport, test['hostname'])
375
376 uri.port = test['port']
377 self.assertEqual(uri.port, test['port'])
378 self.assertEqual(uri.hostport, test['hostport'])
379
380 uri.path = test['path']
381 self.assertEqual(uri.path, test['path'])
382
383 uri.params = test['params']
384 self.assertEqual(uri.params, test['params'])
385
386 uri.query = test['query']
387 self.assertEqual(uri.query, test['query'])
388
389 self.assertEqual(str(uri), test['uri'])
390
391 uri.params = {}
392 self.assertEqual(uri.params, {})
393 self.assertEqual(str(uri), (str(uri).split(";"))[0])
394
395class FetcherTest(unittest.TestCase):
396
397 def setUp(self):
398 self.origdir = os.getcwd()
399 self.d = bb.data.init()
Andrew Geisslereff27472021-10-29 15:35:00 -0500400 self.tempdir = tempfile.mkdtemp(prefix="bitbake-fetch-")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500401 self.dldir = os.path.join(self.tempdir, "download")
402 os.mkdir(self.dldir)
403 self.d.setVar("DL_DIR", self.dldir)
404 self.unpackdir = os.path.join(self.tempdir, "unpacked")
405 os.mkdir(self.unpackdir)
406 persistdir = os.path.join(self.tempdir, "persistdata")
407 self.d.setVar("PERSISTENT_DIR", persistdir)
408
409 def tearDown(self):
410 os.chdir(self.origdir)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600411 if os.environ.get("BB_TMPDIR_NOCLEAN") == "yes":
412 print("Not cleaning up %s. Please remove manually." % self.tempdir)
413 else:
Andrew Geisslerc926e172021-05-07 16:11:35 -0500414 bb.process.run('chmod u+rw -R %s' % self.tempdir)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600415 bb.utils.prunedir(self.tempdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500416
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000417 def git(self, cmd, cwd=None):
418 if isinstance(cmd, str):
419 cmd = 'git ' + cmd
420 else:
421 cmd = ['git'] + cmd
422 if cwd is None:
423 cwd = self.gitdir
424 return bb.process.run(cmd, cwd=cwd)[0]
425
426 def git_init(self, cwd=None):
427 self.git('init', cwd=cwd)
Patrick Williamse760df82023-05-26 11:10:49 -0500428 # Explicitly set initial branch to master as
429 # a common setup is to use other default
430 # branch than master.
431 self.git(['checkout', '-b', 'master'], cwd=cwd)
Andrew Geissler8f840682023-07-21 09:09:43 -0500432
433 try:
434 self.git(['config', 'user.email'], cwd=cwd)
435 except bb.process.ExecutionError:
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000436 self.git(['config', 'user.email', 'you@example.com'], cwd=cwd)
Andrew Geissler8f840682023-07-21 09:09:43 -0500437
438 try:
439 self.git(['config', 'user.name'], cwd=cwd)
440 except bb.process.ExecutionError:
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000441 self.git(['config', 'user.name', 'Your Name'], cwd=cwd)
442
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500443class MirrorUriTest(FetcherTest):
444
445 replaceuris = {
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000446 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "http://somewhere.org/somedir/")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500447 : "http://somewhere.org/somedir/git2_git.invalid.infradead.org.mtd-utils.git.tar.gz",
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000448 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http")
449 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
450 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http")
451 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
452 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/\\2;protocol=http")
453 : "git://somewhere.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500454 ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890", "git://someserver.org/bitbake", "git://git.openembedded.org/bitbake")
455 : "git://git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890",
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000456 ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500457 : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000458 ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache/")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500459 : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000460 ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org/somedir3")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500461 : "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz",
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000462 ("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")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500463 : "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz",
464 ("http://www.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", "http://www.apache.org/dist", "http://archive.apache.org/dist")
465 : "http://archive.apache.org/dist/subversion/subversion-1.7.1.tar.bz2",
466 ("http://www.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", "http://.*/.*", "file:///somepath/downloads/")
467 : "file:///somepath/downloads/subversion-1.7.1.tar.bz2",
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000468 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http")
469 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
470 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http")
471 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
472 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/MIRRORNAME;protocol=http")
473 : "git://somewhere.org/somedir/git.invalid.infradead.org.foo.mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800474 ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org")
475 : "http://somewhere2.org/somefile_1.2.3.tar.gz",
476 ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org/")
477 : "http://somewhere2.org/somefile_1.2.3.tar.gz",
478 ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master", "git://someserver.org/bitbake;branch=master", "git://git.openembedded.org/bitbake;protocol=http")
479 : "git://git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master;protocol=http",
Andrew Geissler595f6302022-01-24 19:11:47 +0000480 ("git://user1@someserver.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master", "git://someserver.org/bitbake;branch=master", "git://user2@git.openembedded.org/bitbake;protocol=http")
481 : "git://user2@git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master;protocol=http",
482 ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890;protocol=git;branch=master", "git://someserver.org/bitbake", "git://someotherserver.org/bitbake;protocol=https")
483 : "git://someotherserver.org/bitbake;tag=1234567890123456789012345678901234567890;protocol=https;branch=master",
Andrew Geissler595f6302022-01-24 19:11:47 +0000484 ("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",
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000485 ("https://somewhere.org/example/1.0.0/example;downloadfilename=some-example-1.0.0.tgz", "https://.*/.*", "file:///mirror/PATH")
486 : "file:///mirror/example/1.0.0/some-example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz",
487 ("https://somewhere.org/example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz", "https://.*/.*", "file:///mirror/some-example-1.0.0.tgz")
488 : "file:///mirror/some-example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz",
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500489
490 #Renaming files doesn't work
491 #("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"
492 #("file://sstate-xyz.tgz", "file://.*/.*", "file:///somewhere/1234/sstate-cache") : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
493 }
494
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000495 mirrorvar = "http://.*/.* file:///somepath/downloads/ " \
496 "git://someserver.org/bitbake git://git.openembedded.org/bitbake " \
497 "https://.*/.* file:///someotherpath/downloads/ " \
498 "http://.*/.* file:///someotherpath/downloads/"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500499
500 def test_urireplace(self):
Andrew Geissler615f2f12022-07-15 14:00:58 -0500501 self.d.setVar("FILESPATH", ".")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500502 for k, v in self.replaceuris.items():
503 ud = bb.fetch.FetchData(k[0], self.d)
504 ud.setup_localpath(self.d)
505 mirrors = bb.fetch2.mirror_from_string("%s %s" % (k[1], k[2]))
506 newuris, uds = bb.fetch2.build_mirroruris(ud, mirrors, self.d)
507 self.assertEqual([v], newuris)
508
509 def test_urilist1(self):
510 fetcher = bb.fetch.FetchData("http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
511 mirrors = bb.fetch2.mirror_from_string(self.mirrorvar)
512 uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
513 self.assertEqual(uris, ['file:///somepath/downloads/bitbake-1.0.tar.gz', 'file:///someotherpath/downloads/bitbake-1.0.tar.gz'])
514
515 def test_urilist2(self):
516 # Catch https:// -> files:// bug
517 fetcher = bb.fetch.FetchData("https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
518 mirrors = bb.fetch2.mirror_from_string(self.mirrorvar)
519 uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
520 self.assertEqual(uris, ['file:///someotherpath/downloads/bitbake-1.0.tar.gz'])
521
522 def test_mirror_of_mirror(self):
523 # Test if mirror of a mirror works
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000524 mirrorvar = self.mirrorvar + " http://.*/.* http://otherdownloads.yoctoproject.org/downloads/"
525 mirrorvar = mirrorvar + " http://otherdownloads.yoctoproject.org/.* http://downloads2.yoctoproject.org/downloads/"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500526 fetcher = bb.fetch.FetchData("http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
527 mirrors = bb.fetch2.mirror_from_string(mirrorvar)
528 uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
529 self.assertEqual(uris, ['file:///somepath/downloads/bitbake-1.0.tar.gz',
530 'file:///someotherpath/downloads/bitbake-1.0.tar.gz',
531 'http://otherdownloads.yoctoproject.org/downloads/bitbake-1.0.tar.gz',
532 'http://downloads2.yoctoproject.org/downloads/bitbake-1.0.tar.gz'])
533
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000534 recmirrorvar = "https://.*/[^/]* http://AAAA/A/A/A/ " \
535 "https://.*/[^/]* https://BBBB/B/B/B/"
Patrick Williamsd7e96312015-09-22 08:09:05 -0500536
537 def test_recursive(self):
538 fetcher = bb.fetch.FetchData("https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
539 mirrors = bb.fetch2.mirror_from_string(self.recmirrorvar)
540 uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
541 self.assertEqual(uris, ['http://AAAA/A/A/A/bitbake/bitbake-1.0.tar.gz',
542 'https://BBBB/B/B/B/bitbake/bitbake-1.0.tar.gz',
543 'http://AAAA/A/A/A/B/B/bitbake/bitbake-1.0.tar.gz'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500544
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800545
546class GitDownloadDirectoryNamingTest(FetcherTest):
547 def setUp(self):
548 super(GitDownloadDirectoryNamingTest, self).setUp()
Andrew Geissler028142b2023-05-05 11:29:21 -0500549 self.recipe_url = "git://git.openembedded.org/bitbake;branch=master;protocol=https"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800550 self.recipe_dir = "git.openembedded.org.bitbake"
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000551 self.mirror_url = "git://github.com/openembedded/bitbake.git;protocol=https;branch=master"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800552 self.mirror_dir = "github.com.openembedded.bitbake.git"
553
554 self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
555
556 def setup_mirror_rewrite(self):
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000557 self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800558
559 @skipIfNoNetwork()
560 def test_that_directory_is_named_after_recipe_url_when_no_mirroring_is_used(self):
561 self.setup_mirror_rewrite()
562 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
563
564 fetcher.download()
565
566 dir = os.listdir(self.dldir + "/git2")
567 self.assertIn(self.recipe_dir, dir)
568
569 @skipIfNoNetwork()
570 def test_that_directory_exists_for_mirrored_url_and_recipe_url_when_mirroring_is_used(self):
571 self.setup_mirror_rewrite()
572 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
573
574 fetcher.download()
575
576 dir = os.listdir(self.dldir + "/git2")
577 self.assertIn(self.mirror_dir, dir)
578 self.assertIn(self.recipe_dir, dir)
579
580 @skipIfNoNetwork()
581 def test_that_recipe_directory_and_mirrored_directory_exists_when_mirroring_is_used_and_the_mirrored_directory_already_exists(self):
582 self.setup_mirror_rewrite()
583 fetcher = bb.fetch.Fetch([self.mirror_url], self.d)
584 fetcher.download()
585 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
586
587 fetcher.download()
588
589 dir = os.listdir(self.dldir + "/git2")
590 self.assertIn(self.mirror_dir, dir)
591 self.assertIn(self.recipe_dir, dir)
592
593
594class TarballNamingTest(FetcherTest):
595 def setUp(self):
596 super(TarballNamingTest, self).setUp()
Andrew Geissler028142b2023-05-05 11:29:21 -0500597 self.recipe_url = "git://git.openembedded.org/bitbake;branch=master;protocol=https"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800598 self.recipe_tarball = "git2_git.openembedded.org.bitbake.tar.gz"
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000599 self.mirror_url = "git://github.com/openembedded/bitbake.git;protocol=https;branch=master"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800600 self.mirror_tarball = "git2_github.com.openembedded.bitbake.git.tar.gz"
601
602 self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '1')
603 self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
604
605 def setup_mirror_rewrite(self):
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000606 self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800607
608 @skipIfNoNetwork()
609 def test_that_the_recipe_tarball_is_created_when_no_mirroring_is_used(self):
610 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
611
612 fetcher.download()
613
614 dir = os.listdir(self.dldir)
615 self.assertIn(self.recipe_tarball, dir)
616
617 @skipIfNoNetwork()
618 def test_that_the_mirror_tarball_is_created_when_mirroring_is_used(self):
619 self.setup_mirror_rewrite()
620 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
621
622 fetcher.download()
623
624 dir = os.listdir(self.dldir)
625 self.assertIn(self.mirror_tarball, dir)
626
627
628class GitShallowTarballNamingTest(FetcherTest):
629 def setUp(self):
630 super(GitShallowTarballNamingTest, self).setUp()
Andrew Geissler028142b2023-05-05 11:29:21 -0500631 self.recipe_url = "git://git.openembedded.org/bitbake;branch=master;protocol=https"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800632 self.recipe_tarball = "gitshallow_git.openembedded.org.bitbake_82ea737-1_master.tar.gz"
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000633 self.mirror_url = "git://github.com/openembedded/bitbake.git;protocol=https;branch=master"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800634 self.mirror_tarball = "gitshallow_github.com.openembedded.bitbake.git_82ea737-1_master.tar.gz"
635
636 self.d.setVar('BB_GIT_SHALLOW', '1')
637 self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1')
638 self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
639
640 def setup_mirror_rewrite(self):
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000641 self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800642
643 @skipIfNoNetwork()
644 def test_that_the_tarball_is_named_after_recipe_url_when_no_mirroring_is_used(self):
645 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
646
647 fetcher.download()
648
649 dir = os.listdir(self.dldir)
650 self.assertIn(self.recipe_tarball, dir)
651
652 @skipIfNoNetwork()
653 def test_that_the_mirror_tarball_is_created_when_mirroring_is_used(self):
654 self.setup_mirror_rewrite()
655 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
656
657 fetcher.download()
658
659 dir = os.listdir(self.dldir)
660 self.assertIn(self.mirror_tarball, dir)
661
662
Andrew Geissler9aee5002022-03-30 16:27:02 +0000663class CleanTarballTest(FetcherTest):
664 def setUp(self):
665 super(CleanTarballTest, self).setUp()
Andrew Geissler028142b2023-05-05 11:29:21 -0500666 self.recipe_url = "git://git.openembedded.org/bitbake;protocol=https"
Andrew Geissler9aee5002022-03-30 16:27:02 +0000667 self.recipe_tarball = "git2_git.openembedded.org.bitbake.tar.gz"
668
669 self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '1')
670 self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
671
672 @skipIfNoNetwork()
673 def test_that_the_tarball_contents_does_not_leak_info(self):
674 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
675
676 fetcher.download()
677
678 fetcher.unpack(self.unpackdir)
679 mtime = bb.process.run('git log --all -1 --format=%ct',
680 cwd=os.path.join(self.unpackdir, 'git'))
681 self.assertEqual(len(mtime), 2)
682 mtime = int(mtime[0])
683
684 archive = tarfile.open(os.path.join(self.dldir, self.recipe_tarball))
685 self.assertNotEqual(len(archive.members), 0)
686 for member in archive.members:
Andrew Geissler20137392023-10-12 04:59:14 -0600687 if member.name == ".":
688 continue
689 self.assertEqual(member.uname, 'oe', "user name for %s differs" % member.name)
690 self.assertEqual(member.uid, 0, "uid for %s differs" % member.name)
691 self.assertEqual(member.gname, 'oe', "group name for %s differs" % member.name)
692 self.assertEqual(member.gid, 0, "gid for %s differs" % member.name)
693 self.assertEqual(member.mtime, mtime, "mtime for %s differs" % member.name)
Andrew Geissler9aee5002022-03-30 16:27:02 +0000694
695
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500696class FetcherLocalTest(FetcherTest):
697 def setUp(self):
698 def touch(fn):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600699 with open(fn, 'a'):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500700 os.utime(fn, None)
701
702 super(FetcherLocalTest, self).setUp()
703 self.localsrcdir = os.path.join(self.tempdir, 'localsrc')
704 os.makedirs(self.localsrcdir)
705 touch(os.path.join(self.localsrcdir, 'a'))
706 touch(os.path.join(self.localsrcdir, 'b'))
707 os.makedirs(os.path.join(self.localsrcdir, 'dir'))
708 touch(os.path.join(self.localsrcdir, 'dir', 'c'))
709 touch(os.path.join(self.localsrcdir, 'dir', 'd'))
710 os.makedirs(os.path.join(self.localsrcdir, 'dir', 'subdir'))
711 touch(os.path.join(self.localsrcdir, 'dir', 'subdir', 'e'))
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500712 touch(os.path.join(self.localsrcdir, r'backslash\x2dsystemd-unit.device'))
Andrew Geissler595f6302022-01-24 19:11:47 +0000713 bb.process.run('tar cf archive.tar -C dir .', cwd=self.localsrcdir)
714 bb.process.run('tar czf archive.tar.gz -C dir .', cwd=self.localsrcdir)
715 bb.process.run('tar cjf archive.tar.bz2 -C dir .', cwd=self.localsrcdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500716 self.d.setVar("FILESPATH", self.localsrcdir)
717
718 def fetchUnpack(self, uris):
719 fetcher = bb.fetch.Fetch(uris, self.d)
720 fetcher.download()
721 fetcher.unpack(self.unpackdir)
722 flst = []
723 for root, dirs, files in os.walk(self.unpackdir):
724 for f in files:
725 flst.append(os.path.relpath(os.path.join(root, f), self.unpackdir))
726 flst.sort()
727 return flst
728
Andrew Geissler615f2f12022-07-15 14:00:58 -0500729 def test_local_checksum_fails_no_file(self):
730 self.d.setVar("SRC_URI", "file://404")
731 with self.assertRaises(bb.BBHandledException):
732 bb.fetch.get_checksum_file_list(self.d)
733
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500734 def test_local(self):
735 tree = self.fetchUnpack(['file://a', 'file://dir/c'])
736 self.assertEqual(tree, ['a', 'dir/c'])
737
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500738 def test_local_backslash(self):
739 tree = self.fetchUnpack([r'file://backslash\x2dsystemd-unit.device'])
740 self.assertEqual(tree, [r'backslash\x2dsystemd-unit.device'])
741
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500742 def test_local_wildcard(self):
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500743 with self.assertRaises(bb.fetch2.ParameterError):
744 tree = self.fetchUnpack(['file://a', 'file://dir/*'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500745
746 def test_local_dir(self):
747 tree = self.fetchUnpack(['file://a', 'file://dir'])
748 self.assertEqual(tree, ['a', 'dir/c', 'dir/d', 'dir/subdir/e'])
749
750 def test_local_subdir(self):
751 tree = self.fetchUnpack(['file://dir/subdir'])
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500752 self.assertEqual(tree, ['dir/subdir/e'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500753
754 def test_local_subdir_file(self):
755 tree = self.fetchUnpack(['file://dir/subdir/e'])
756 self.assertEqual(tree, ['dir/subdir/e'])
757
758 def test_local_subdirparam(self):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500759 tree = self.fetchUnpack(['file://a;subdir=bar', 'file://dir;subdir=foo/moo'])
760 self.assertEqual(tree, ['bar/a', 'foo/moo/dir/c', 'foo/moo/dir/d', 'foo/moo/dir/subdir/e'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500761
762 def test_local_deepsubdirparam(self):
763 tree = self.fetchUnpack(['file://dir/subdir/e;subdir=bar'])
764 self.assertEqual(tree, ['bar/dir/subdir/e'])
765
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600766 def test_local_absolutedir(self):
767 # Unpacking to an absolute path that is a subdirectory of the root
768 # should work
769 tree = self.fetchUnpack(['file://a;subdir=%s' % os.path.join(self.unpackdir, 'bar')])
770
771 # Unpacking to an absolute path outside of the root should fail
772 with self.assertRaises(bb.fetch2.UnpackError):
773 self.fetchUnpack(['file://a;subdir=/bin/sh'])
774
Andrew Geissler595f6302022-01-24 19:11:47 +0000775 def test_local_striplevel(self):
776 tree = self.fetchUnpack(['file://archive.tar;subdir=bar;striplevel=1'])
777 self.assertEqual(tree, ['bar/c', 'bar/d', 'bar/subdir/e'])
778
779 def test_local_striplevel_gzip(self):
780 tree = self.fetchUnpack(['file://archive.tar.gz;subdir=bar;striplevel=1'])
781 self.assertEqual(tree, ['bar/c', 'bar/d', 'bar/subdir/e'])
782
783 def test_local_striplevel_bzip2(self):
784 tree = self.fetchUnpack(['file://archive.tar.bz2;subdir=bar;striplevel=1'])
785 self.assertEqual(tree, ['bar/c', 'bar/d', 'bar/subdir/e'])
786
Andrew Geisslerc926e172021-05-07 16:11:35 -0500787 def dummyGitTest(self, suffix):
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600788 # Create dummy local Git repo
789 src_dir = tempfile.mkdtemp(dir=self.tempdir,
790 prefix='gitfetch_localusehead_')
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000791 self.gitdir = os.path.abspath(src_dir)
792 self.git_init()
793 self.git(['commit', '--allow-empty', '-m', 'Dummy commit'])
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600794 # Use other branch than master
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000795 self.git(['checkout', '-b', 'my-devel'])
796 self.git(['commit', '--allow-empty', '-m', 'Dummy commit 2'])
797 orig_rev = self.git(['rev-parse', 'HEAD']).strip()
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600798
799 # Fetch and check revision
800 self.d.setVar("SRCREV", "AUTOINC")
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500801 self.d.setVar("__BBSRCREV_SEEN", "1")
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000802 url = "git://" + self.gitdir + ";branch=master;protocol=file;" + suffix
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600803 fetcher = bb.fetch.Fetch([url], self.d)
804 fetcher.download()
805 fetcher.unpack(self.unpackdir)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000806 unpack_rev = self.git(['rev-parse', 'HEAD'],
807 cwd=os.path.join(self.unpackdir, 'git')).strip()
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600808 self.assertEqual(orig_rev, unpack_rev)
809
Andrew Geisslerc926e172021-05-07 16:11:35 -0500810 def test_local_gitfetch_usehead(self):
811 self.dummyGitTest("usehead=1")
812
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600813 def test_local_gitfetch_usehead_withname(self):
Andrew Geisslerc926e172021-05-07 16:11:35 -0500814 self.dummyGitTest("usehead=1;name=newName")
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600815
Andrew Geisslerc926e172021-05-07 16:11:35 -0500816 def test_local_gitfetch_shared(self):
817 self.dummyGitTest("usehead=1;name=sharedName")
818 alt = os.path.join(self.unpackdir, 'git/.git/objects/info/alternates')
819 self.assertTrue(os.path.exists(alt))
820
821 def test_local_gitfetch_noshared(self):
822 self.d.setVar('BB_GIT_NOSHARED', '1')
823 self.unpackdir += '_noshared'
824 self.dummyGitTest("usehead=1;name=noSharedName")
825 alt = os.path.join(self.unpackdir, 'git/.git/objects/info/alternates')
826 self.assertFalse(os.path.exists(alt))
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600827
Brad Bishop316dfdd2018-06-25 12:45:53 -0400828class FetcherNoNetworkTest(FetcherTest):
829 def setUp(self):
830 super().setUp()
831 # all test cases are based on not having network
832 self.d.setVar("BB_NO_NETWORK", "1")
833
834 def test_missing(self):
835 string = "this is a test file\n".encode("utf-8")
836 self.d.setVarFlag("SRC_URI", "md5sum", hashlib.md5(string).hexdigest())
837 self.d.setVarFlag("SRC_URI", "sha256sum", hashlib.sha256(string).hexdigest())
838
839 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
840 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
841 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/test-file.tar.gz"], self.d)
842 with self.assertRaises(bb.fetch2.NetworkAccess):
843 fetcher.download()
844
845 def test_valid_missing_donestamp(self):
846 # create the file in the download directory with correct hash
847 string = "this is a test file\n".encode("utf-8")
848 with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb") as f:
849 f.write(string)
850
851 self.d.setVarFlag("SRC_URI", "md5sum", hashlib.md5(string).hexdigest())
852 self.d.setVarFlag("SRC_URI", "sha256sum", hashlib.sha256(string).hexdigest())
853
854 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
855 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
856 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/test-file.tar.gz"], self.d)
857 fetcher.download()
858 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
859
860 def test_invalid_missing_donestamp(self):
861 # create an invalid file in the download directory with incorrect hash
862 string = "this is a test file\n".encode("utf-8")
863 with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb"):
864 pass
865
866 self.d.setVarFlag("SRC_URI", "md5sum", hashlib.md5(string).hexdigest())
867 self.d.setVarFlag("SRC_URI", "sha256sum", hashlib.sha256(string).hexdigest())
868
869 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
870 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
871 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/test-file.tar.gz"], self.d)
872 with self.assertRaises(bb.fetch2.NetworkAccess):
873 fetcher.download()
874 # the existing file should not exist or should have be moved to "bad-checksum"
875 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
876
877 def test_nochecksums_missing(self):
878 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
879 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
880 # ssh fetch does not support checksums
881 fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d)
882 # attempts to download with missing donestamp
883 with self.assertRaises(bb.fetch2.NetworkAccess):
884 fetcher.download()
885
886 def test_nochecksums_missing_donestamp(self):
887 # create a file in the download directory
888 with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb"):
889 pass
890
891 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
892 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
893 # ssh fetch does not support checksums
894 fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d)
895 # attempts to download with missing donestamp
896 with self.assertRaises(bb.fetch2.NetworkAccess):
897 fetcher.download()
898
899 def test_nochecksums_has_donestamp(self):
900 # create a file in the download directory with the donestamp
901 with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb"):
902 pass
903 with open(os.path.join(self.dldir, "test-file.tar.gz.done"), "wb"):
904 pass
905
906 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
907 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
908 # ssh fetch does not support checksums
909 fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d)
910 # should not fetch
911 fetcher.download()
912 # both files should still exist
913 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
914 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
915
916 def test_nochecksums_missing_has_donestamp(self):
917 # create a file in the download directory with the donestamp
918 with open(os.path.join(self.dldir, "test-file.tar.gz.done"), "wb"):
919 pass
920
921 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
922 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
923 # ssh fetch does not support checksums
924 fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d)
925 with self.assertRaises(bb.fetch2.NetworkAccess):
926 fetcher.download()
927 # both files should still exist
928 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
929 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
930
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500931class FetcherNetworkTest(FetcherTest):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500932 @skipIfNoNetwork()
933 def test_fetch(self):
Andrew Geisslereff27472021-10-29 15:35:00 -0500934 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)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500935 fetcher.download()
936 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
937 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.1.tar.gz"), 57892)
938 self.d.setVar("BB_NO_NETWORK", "1")
Andrew Geisslereff27472021-10-29 15:35:00 -0500939 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)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500940 fetcher.download()
941 fetcher.unpack(self.unpackdir)
942 self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.0/")), 9)
943 self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.1/")), 9)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500944
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500945 @skipIfNoNetwork()
946 def test_fetch_mirror(self):
Andrew Geisslereff27472021-10-29 15:35:00 -0500947 self.d.setVar("MIRRORS", "http://.*/.* https://downloads.yoctoproject.org/releases/bitbake")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500948 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
949 fetcher.download()
950 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
951
952 @skipIfNoNetwork()
953 def test_fetch_mirror_of_mirror(self):
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000954 self.d.setVar("MIRRORS", "http://.*/.* http://invalid2.yoctoproject.org/ http://invalid2.yoctoproject.org/.* https://downloads.yoctoproject.org/releases/bitbake")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500955 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
956 fetcher.download()
957 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
958
959 @skipIfNoNetwork()
960 def test_fetch_file_mirror_of_mirror(self):
Andrew Geissler615f2f12022-07-15 14:00:58 -0500961 self.d.setVar("FILESPATH", ".")
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000962 self.d.setVar("MIRRORS", "http://.*/.* file:///some1where/ file:///some1where/.* file://some2where/ file://some2where/.* https://downloads.yoctoproject.org/releases/bitbake")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500963 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
964 os.mkdir(self.dldir + "/some2where")
965 fetcher.download()
966 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
967
968 @skipIfNoNetwork()
969 def test_fetch_premirror(self):
Andrew Geisslereff27472021-10-29 15:35:00 -0500970 self.d.setVar("PREMIRRORS", "http://.*/.* https://downloads.yoctoproject.org/releases/bitbake")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500971 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
972 fetcher.download()
973 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
974
975 @skipIfNoNetwork()
Andrew Geissler5199d832021-09-24 16:47:35 -0500976 def test_fetch_specify_downloadfilename(self):
Andrew Geisslereff27472021-10-29 15:35:00 -0500977 fetcher = bb.fetch.Fetch(["https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz;downloadfilename=bitbake-v1.0.0.tar.gz"], self.d)
Andrew Geissler5199d832021-09-24 16:47:35 -0500978 fetcher.download()
979 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-v1.0.0.tar.gz"), 57749)
980
981 @skipIfNoNetwork()
982 def test_fetch_premirror_specify_downloadfilename_regex_uri(self):
Andrew Geisslereff27472021-10-29 15:35:00 -0500983 self.d.setVar("PREMIRRORS", "http://.*/.* https://downloads.yoctoproject.org/releases/bitbake/")
Andrew Geissler595f6302022-01-24 19:11:47 +0000984 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/1.0.tar.gz;downloadfilename=bitbake-1.0.tar.gz"], self.d)
Andrew Geissler5199d832021-09-24 16:47:35 -0500985 fetcher.download()
Andrew Geissler595f6302022-01-24 19:11:47 +0000986 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
Andrew Geissler5199d832021-09-24 16:47:35 -0500987
988 @skipIfNoNetwork()
989 # BZ13039
990 def test_fetch_premirror_specify_downloadfilename_specific_uri(self):
Andrew Geisslereff27472021-10-29 15:35:00 -0500991 self.d.setVar("PREMIRRORS", "http://invalid.yoctoproject.org/releases/bitbake https://downloads.yoctoproject.org/releases/bitbake")
Andrew Geissler595f6302022-01-24 19:11:47 +0000992 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/1.0.tar.gz;downloadfilename=bitbake-1.0.tar.gz"], self.d)
Andrew Geissler5199d832021-09-24 16:47:35 -0500993 fetcher.download()
Andrew Geissler595f6302022-01-24 19:11:47 +0000994 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
995
996 @skipIfNoNetwork()
997 def test_fetch_premirror_use_downloadfilename_to_fetch(self):
998 # Ensure downloadfilename is used when fetching from premirror.
999 self.d.setVar("PREMIRRORS", "http://.*/.* https://downloads.yoctoproject.org/releases/bitbake")
1000 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.1.tar.gz;downloadfilename=bitbake-1.0.tar.gz"], self.d)
1001 fetcher.download()
1002 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
Andrew Geissler5199d832021-09-24 16:47:35 -05001003
1004 @skipIfNoNetwork()
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001005 def gitfetcher(self, url1, url2):
1006 def checkrevision(self, fetcher):
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001007 fetcher.unpack(self.unpackdir)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001008 revision = self.git(['rev-parse', 'HEAD'],
1009 cwd=os.path.join(self.unpackdir, 'git')).strip()
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001010 self.assertEqual(revision, "270a05b0b4ba0959fe0624d2a4885d7b70426da5")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001011
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001012 self.d.setVar("BB_GENERATE_MIRROR_TARBALLS", "1")
1013 self.d.setVar("SRCREV", "270a05b0b4ba0959fe0624d2a4885d7b70426da5")
1014 fetcher = bb.fetch.Fetch([url1], self.d)
1015 fetcher.download()
1016 checkrevision(self, fetcher)
1017 # Wipe out the dldir clone and the unpacked source, turn off the network and check mirror tarball works
1018 bb.utils.prunedir(self.dldir + "/git2/")
1019 bb.utils.prunedir(self.unpackdir)
1020 self.d.setVar("BB_NO_NETWORK", "1")
1021 fetcher = bb.fetch.Fetch([url2], self.d)
1022 fetcher.download()
1023 checkrevision(self, fetcher)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001024
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001025 @skipIfNoNetwork()
1026 def test_gitfetch(self):
Andrew Geissler028142b2023-05-05 11:29:21 -05001027 url1 = url2 = "git://git.openembedded.org/bitbake;branch=master;protocol=https"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001028 self.gitfetcher(url1, url2)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001029
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001030 @skipIfNoNetwork()
1031 def test_gitfetch_goodsrcrev(self):
1032 # SRCREV is set but matches rev= parameter
Andrew Geissler028142b2023-05-05 11:29:21 -05001033 url1 = url2 = "git://git.openembedded.org/bitbake;rev=270a05b0b4ba0959fe0624d2a4885d7b70426da5;branch=master;protocol=https"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001034 self.gitfetcher(url1, url2)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001035
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001036 @skipIfNoNetwork()
1037 def test_gitfetch_badsrcrev(self):
1038 # SRCREV is set but does not match rev= parameter
Andrew Geissler028142b2023-05-05 11:29:21 -05001039 url1 = url2 = "git://git.openembedded.org/bitbake;rev=dead05b0b4ba0959fe0624d2a4885d7b70426da5;branch=master;protocol=https"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001040 self.assertRaises(bb.fetch.FetchError, self.gitfetcher, url1, url2)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001041
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001042 @skipIfNoNetwork()
1043 def test_gitfetch_tagandrev(self):
1044 # SRCREV is set but does not match rev= parameter
Andrew Geissler028142b2023-05-05 11:29:21 -05001045 url1 = url2 = "git://git.openembedded.org/bitbake;rev=270a05b0b4ba0959fe0624d2a4885d7b70426da5;tag=270a05b0b4ba0959fe0624d2a4885d7b70426da5;protocol=https"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001046 self.assertRaises(bb.fetch.FetchError, self.gitfetcher, url1, url2)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001047
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001048 @skipIfNoNetwork()
Andrew Geisslerd1e89492021-02-12 15:35:20 -06001049 def test_gitfetch_usehead(self):
1050 # Since self.gitfetcher() sets SRCREV we expect this to override
1051 # `usehead=1' and instead fetch the specified SRCREV. See
1052 # test_local_gitfetch_usehead() for a positive use of the usehead
1053 # feature.
Andrew Geissler028142b2023-05-05 11:29:21 -05001054 url = "git://git.openembedded.org/bitbake;usehead=1;branch=master;protocol=https"
Andrew Geisslerd1e89492021-02-12 15:35:20 -06001055 self.assertRaises(bb.fetch.ParameterError, self.gitfetcher, url, url)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001056
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001057 @skipIfNoNetwork()
Andrew Geisslerd1e89492021-02-12 15:35:20 -06001058 def test_gitfetch_usehead_withname(self):
1059 # Since self.gitfetcher() sets SRCREV we expect this to override
1060 # `usehead=1' and instead fetch the specified SRCREV. See
1061 # test_local_gitfetch_usehead() for a positive use of the usehead
1062 # feature.
Andrew Geissler028142b2023-05-05 11:29:21 -05001063 url = "git://git.openembedded.org/bitbake;usehead=1;name=newName;branch=master;protocol=https"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001064 self.assertRaises(bb.fetch.ParameterError, self.gitfetcher, url, url)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001065
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001066 @skipIfNoNetwork()
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001067 def test_gitfetch_finds_local_tarball_for_mirrored_url_when_previous_downloaded_by_the_recipe_url(self):
Andrew Geissler028142b2023-05-05 11:29:21 -05001068 recipeurl = "git://git.openembedded.org/bitbake;branch=master;protocol=https"
1069 mirrorurl = "git://someserver.org/bitbake;branch=master;protocol=https"
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001070 self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake")
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001071 self.gitfetcher(recipeurl, mirrorurl)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001072
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001073 @skipIfNoNetwork()
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001074 def test_gitfetch_finds_local_tarball_when_previous_downloaded_from_a_premirror(self):
Andrew Geissler028142b2023-05-05 11:29:21 -05001075 recipeurl = "git://someserver.org/bitbake;branch=master;protocol=https"
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001076 self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake")
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001077 self.gitfetcher(recipeurl, recipeurl)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001078
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001079 @skipIfNoNetwork()
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001080 def test_gitfetch_finds_local_repository_when_premirror_rewrites_the_recipe_url(self):
Andrew Geissler028142b2023-05-05 11:29:21 -05001081 realurl = "https://git.openembedded.org/bitbake"
1082 recipeurl = "git://someserver.org/bitbake;protocol=https"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001083 self.sourcedir = self.unpackdir.replace("unpacked", "sourcemirror.git")
1084 os.chdir(self.tempdir)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001085 self.git(['clone', realurl, self.sourcedir], cwd=self.tempdir)
1086 self.d.setVar("PREMIRRORS", "%s git://%s;protocol=file" % (recipeurl, self.sourcedir))
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001087 self.gitfetcher(recipeurl, recipeurl)
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001088
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001089 @skipIfNoNetwork()
1090 def test_git_submodule(self):
Brad Bishopf8caae32019-03-25 13:13:56 -04001091 # URL with ssh submodules
Andrew Geissler028142b2023-05-05 11:29:21 -05001092 url = "gitsm://git.yoctoproject.org/git-submodule-test;branch=ssh-gitsm-tests;rev=049da4a6cb198d7c0302e9e8b243a1443cb809a7;branch=master;protocol=https"
Brad Bishopf8caae32019-03-25 13:13:56 -04001093 # Original URL (comment this if you have ssh access to git.yoctoproject.org)
Andrew Geissler028142b2023-05-05 11:29:21 -05001094 url = "gitsm://git.yoctoproject.org/git-submodule-test;branch=master;rev=a2885dd7d25380d23627e7544b7bbb55014b16ee;branch=master;protocol=https"
Brad Bishopf8caae32019-03-25 13:13:56 -04001095 fetcher = bb.fetch.Fetch([url], self.d)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001096 fetcher.download()
1097 # Previous cwd has been deleted
1098 os.chdir(os.path.dirname(self.unpackdir))
1099 fetcher.unpack(self.unpackdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001100
Brad Bishopf8caae32019-03-25 13:13:56 -04001101 repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
1102 self.assertTrue(os.path.exists(repo_path), msg='Unpacked repository missing')
1103 self.assertTrue(os.path.exists(os.path.join(repo_path, 'bitbake')), msg='bitbake submodule missing')
1104 self.assertFalse(os.path.exists(os.path.join(repo_path, 'na')), msg='uninitialized submodule present')
1105
1106 # Only when we're running the extended test with a submodule's submodule, can we check this.
1107 if os.path.exists(os.path.join(repo_path, 'bitbake-gitsm-test1')):
1108 self.assertTrue(os.path.exists(os.path.join(repo_path, 'bitbake-gitsm-test1', 'bitbake')), msg='submodule of submodule missing')
1109
Brad Bishop96ff1982019-08-19 13:50:42 -04001110 @skipIfNoNetwork()
Brad Bishopf8caae32019-03-25 13:13:56 -04001111 def test_git_submodule_dbus_broker(self):
1112 # The following external repositories have show failures in fetch and unpack operations
1113 # We want to avoid regressions!
Andrew Geissler595f6302022-01-24 19:11:47 +00001114 url = "gitsm://github.com/bus1/dbus-broker;protocol=https;rev=fc874afa0992d0c75ec25acb43d344679f0ee7d2;branch=main"
Brad Bishopf8caae32019-03-25 13:13:56 -04001115 fetcher = bb.fetch.Fetch([url], self.d)
1116 fetcher.download()
1117 # Previous cwd has been deleted
1118 os.chdir(os.path.dirname(self.unpackdir))
1119 fetcher.unpack(self.unpackdir)
1120
1121 repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
1122 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-dvar/config')), msg='Missing submodule config "subprojects/c-dvar"')
1123 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-list/config')), msg='Missing submodule config "subprojects/c-list"')
1124 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-rbtree/config')), msg='Missing submodule config "subprojects/c-rbtree"')
1125 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-sundry/config')), msg='Missing submodule config "subprojects/c-sundry"')
1126 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-utf8/config')), msg='Missing submodule config "subprojects/c-utf8"')
1127
Brad Bishop96ff1982019-08-19 13:50:42 -04001128 @skipIfNoNetwork()
Brad Bishopf8caae32019-03-25 13:13:56 -04001129 def test_git_submodule_CLI11(self):
Andrew Geissler595f6302022-01-24 19:11:47 +00001130 url = "gitsm://github.com/CLIUtils/CLI11;protocol=https;rev=bd4dc911847d0cde7a6b41dfa626a85aab213baf;branch=main"
Brad Bishopf8caae32019-03-25 13:13:56 -04001131 fetcher = bb.fetch.Fetch([url], self.d)
1132 fetcher.download()
1133 # Previous cwd has been deleted
1134 os.chdir(os.path.dirname(self.unpackdir))
1135 fetcher.unpack(self.unpackdir)
1136
1137 repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
1138 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/googletest/config')), msg='Missing submodule config "extern/googletest"')
1139 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/json/config')), msg='Missing submodule config "extern/json"')
1140 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/sanitizers/config')), msg='Missing submodule config "extern/sanitizers"')
1141
Brad Bishop96ff1982019-08-19 13:50:42 -04001142 @skipIfNoNetwork()
Brad Bishop19323692019-04-05 15:28:33 -04001143 def test_git_submodule_update_CLI11(self):
1144 """ Prevent regression on update detection not finding missing submodule, or modules without needed commits """
Andrew Geissler595f6302022-01-24 19:11:47 +00001145 url = "gitsm://github.com/CLIUtils/CLI11;protocol=https;rev=cf6a99fa69aaefe477cc52e3ef4a7d2d7fa40714;branch=main"
Brad Bishop19323692019-04-05 15:28:33 -04001146 fetcher = bb.fetch.Fetch([url], self.d)
1147 fetcher.download()
1148
1149 # CLI11 that pulls in a newer nlohmann-json
Andrew Geissler595f6302022-01-24 19:11:47 +00001150 url = "gitsm://github.com/CLIUtils/CLI11;protocol=https;rev=49ac989a9527ee9bb496de9ded7b4872c2e0e5ca;branch=main"
Brad Bishop19323692019-04-05 15:28:33 -04001151 fetcher = bb.fetch.Fetch([url], self.d)
1152 fetcher.download()
1153 # Previous cwd has been deleted
1154 os.chdir(os.path.dirname(self.unpackdir))
1155 fetcher.unpack(self.unpackdir)
1156
1157 repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
1158 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/googletest/config')), msg='Missing submodule config "extern/googletest"')
1159 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/json/config')), msg='Missing submodule config "extern/json"')
1160 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/sanitizers/config')), msg='Missing submodule config "extern/sanitizers"')
1161
Brad Bishop96ff1982019-08-19 13:50:42 -04001162 @skipIfNoNetwork()
Brad Bishopf8caae32019-03-25 13:13:56 -04001163 def test_git_submodule_aktualizr(self):
Andrew Geissler595f6302022-01-24 19:11:47 +00001164 url = "gitsm://github.com/advancedtelematic/aktualizr;branch=master;protocol=https;rev=d00d1a04cc2366d1a5f143b84b9f507f8bd32c44"
Brad Bishopf8caae32019-03-25 13:13:56 -04001165 fetcher = bb.fetch.Fetch([url], self.d)
1166 fetcher.download()
1167 # Previous cwd has been deleted
1168 os.chdir(os.path.dirname(self.unpackdir))
1169 fetcher.unpack(self.unpackdir)
1170
1171 repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
1172 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"')
1173 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"')
1174 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")
1175 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"')
1176 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/third_party/googletest/config')), msg='Missing submodule config "third_party/googletest/config"')
1177 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"')
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001178
Brad Bishop96ff1982019-08-19 13:50:42 -04001179 @skipIfNoNetwork()
Brad Bishop393846f2019-05-20 12:24:11 -04001180 def test_git_submodule_iotedge(self):
1181 """ Prevent regression on deeply nested submodules not being checked out properly, even though they were fetched. """
1182
1183 # This repository also has submodules where the module (name), path and url do not align
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001184 url = "gitsm://github.com/azure/iotedge.git;protocol=https;rev=d76e0316c6f324345d77c48a83ce836d09392699;branch=main"
Brad Bishop393846f2019-05-20 12:24:11 -04001185 fetcher = bb.fetch.Fetch([url], self.d)
1186 fetcher.download()
1187 # Previous cwd has been deleted
1188 os.chdir(os.path.dirname(self.unpackdir))
1189 fetcher.unpack(self.unpackdir)
1190
1191 repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
1192
1193 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')
1194 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')
1195 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')
1196 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')
1197 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')
1198 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')
1199 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')
1200 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')
1201 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')
1202 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')
1203 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')
1204 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')
1205 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')
1206
Patrick Williams92b42cb2022-09-03 06:53:57 -05001207 @skipIfNoNetwork()
1208 def test_git_submodule_reference_to_parent(self):
1209 self.recipe_url = "gitsm://github.com/gflags/gflags.git;protocol=https;branch=master"
1210 self.d.setVar("SRCREV", "14e1138441bbbb584160cb1c0a0426ec1bac35f1")
1211 with Timeout(60):
1212 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
1213 with self.assertRaises(bb.fetch2.FetchError):
1214 fetcher.download()
1215
Brad Bishop15ae2502019-06-18 21:44:24 -04001216class SVNTest(FetcherTest):
1217 def skipIfNoSvn():
1218 import shutil
1219 if not shutil.which("svn"):
1220 return unittest.skip("svn not installed, tests being skipped")
1221
1222 if not shutil.which("svnadmin"):
1223 return unittest.skip("svnadmin not installed, tests being skipped")
1224
1225 return lambda f: f
1226
1227 @skipIfNoSvn()
1228 def setUp(self):
1229 """ Create a local repository """
1230
1231 super(SVNTest, self).setUp()
1232
1233 # Create something we can fetch
1234 src_dir = tempfile.mkdtemp(dir=self.tempdir,
1235 prefix='svnfetch_srcdir_')
1236 src_dir = os.path.abspath(src_dir)
1237 bb.process.run("echo readme > README.md", cwd=src_dir)
1238
1239 # Store it in a local SVN repository
1240 repo_dir = tempfile.mkdtemp(dir=self.tempdir,
1241 prefix='svnfetch_localrepo_')
1242 repo_dir = os.path.abspath(repo_dir)
1243 bb.process.run("svnadmin create project", cwd=repo_dir)
1244
1245 self.repo_url = "file://%s/project" % repo_dir
1246 bb.process.run("svn import --non-interactive -m 'Initial import' %s %s/trunk" % (src_dir, self.repo_url),
1247 cwd=repo_dir)
1248
1249 bb.process.run("svn co %s svnfetch_co" % self.repo_url, cwd=self.tempdir)
1250 # Github will emulate SVN. Use this to check if we're downloding...
Andrew Geissler595f6302022-01-24 19:11:47 +00001251 bb.process.run("svn propset svn:externals 'bitbake https://github.com/PhilipHazel/pcre2.git' .",
Brad Bishop15ae2502019-06-18 21:44:24 -04001252 cwd=os.path.join(self.tempdir, 'svnfetch_co', 'trunk'))
1253 bb.process.run("svn commit --non-interactive -m 'Add external'",
1254 cwd=os.path.join(self.tempdir, 'svnfetch_co', 'trunk'))
1255
1256 self.src_dir = src_dir
1257 self.repo_dir = repo_dir
1258
1259 @skipIfNoSvn()
1260 def tearDown(self):
1261 os.chdir(self.origdir)
1262 if os.environ.get("BB_TMPDIR_NOCLEAN") == "yes":
1263 print("Not cleaning up %s. Please remove manually." % self.tempdir)
1264 else:
1265 bb.utils.prunedir(self.tempdir)
1266
1267 @skipIfNoSvn()
1268 @skipIfNoNetwork()
1269 def test_noexternal_svn(self):
1270 # Always match the rev count from setUp (currently rev 2)
1271 url = "svn://%s;module=trunk;protocol=file;rev=2" % self.repo_url.replace('file://', '')
1272 fetcher = bb.fetch.Fetch([url], self.d)
1273 fetcher.download()
1274 os.chdir(os.path.dirname(self.unpackdir))
1275 fetcher.unpack(self.unpackdir)
1276
1277 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk')), msg="Missing trunk")
1278 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk', 'README.md')), msg="Missing contents")
1279 self.assertFalse(os.path.exists(os.path.join(self.unpackdir, 'trunk/bitbake/trunk')), msg="External dir should NOT exist")
1280 self.assertFalse(os.path.exists(os.path.join(self.unpackdir, 'trunk/bitbake/trunk', 'README')), msg="External README should NOT exit")
1281
1282 @skipIfNoSvn()
1283 def test_external_svn(self):
1284 # Always match the rev count from setUp (currently rev 2)
1285 url = "svn://%s;module=trunk;protocol=file;externals=allowed;rev=2" % self.repo_url.replace('file://', '')
1286 fetcher = bb.fetch.Fetch([url], self.d)
1287 fetcher.download()
1288 os.chdir(os.path.dirname(self.unpackdir))
1289 fetcher.unpack(self.unpackdir)
1290
1291 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk')), msg="Missing trunk")
1292 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk', 'README.md')), msg="Missing contents")
1293 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk/bitbake/trunk')), msg="External dir should exist")
1294 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk/bitbake/trunk', 'README')), msg="External README should exit")
1295
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001296class TrustedNetworksTest(FetcherTest):
1297 def test_trusted_network(self):
1298 # Ensure trusted_network returns False when the host IS in the list.
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001299 url = "git://Someserver.org/foo;rev=1;branch=master"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001300 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org someserver.org server2.org server3.org")
1301 self.assertTrue(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001302
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001303 def test_wild_trusted_network(self):
1304 # Ensure trusted_network returns true when the *.host IS in the list.
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001305 url = "git://Someserver.org/foo;rev=1;branch=master"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001306 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
1307 self.assertTrue(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001308
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001309 def test_prefix_wild_trusted_network(self):
1310 # Ensure trusted_network returns true when the prefix matches *.host.
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001311 url = "git://git.Someserver.org/foo;rev=1;branch=master"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001312 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
1313 self.assertTrue(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001314
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001315 def test_two_prefix_wild_trusted_network(self):
1316 # Ensure trusted_network returns true when the prefix matches *.host.
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001317 url = "git://something.git.Someserver.org/foo;rev=1;branch=master"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001318 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
1319 self.assertTrue(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001320
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001321 def test_port_trusted_network(self):
1322 # Ensure trusted_network returns True, even if the url specifies a port.
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001323 url = "git://someserver.org:8080/foo;rev=1;branch=master"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001324 self.d.setVar("BB_ALLOWED_NETWORKS", "someserver.org")
1325 self.assertTrue(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001326
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001327 def test_untrusted_network(self):
1328 # Ensure trusted_network returns False when the host is NOT in the list.
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001329 url = "git://someserver.org/foo;rev=1;branch=master"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001330 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org server2.org server3.org")
1331 self.assertFalse(bb.fetch.trusted_network(self.d, url))
1332
1333 def test_wild_untrusted_network(self):
1334 # Ensure trusted_network returns False when the host is NOT in the list.
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001335 url = "git://*.someserver.org/foo;rev=1;branch=master"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001336 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org server2.org server3.org")
1337 self.assertFalse(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001338
1339class URLHandle(unittest.TestCase):
1340
1341 datatable = {
1342 "http://www.google.com/index.html" : ('http', 'www.google.com', '/index.html', '', '', {}),
1343 "cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg" : ('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', '', {'module': 'familiar/dist/ipkg'}),
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001344 "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')])),
Andrew Geissler028142b2023-05-05 11:29:21 -05001345 "git://git.openembedded.org/bitbake;branch=@foo;protocol=https" : ('git', 'git.openembedded.org', '/bitbake', '', '', {'branch': '@foo', 'protocol' : 'https'}),
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001346 "file://somelocation;someparam=1": ('file', '', 'somelocation', '', '', {'someparam': '1'}),
Patrick Williams2a254922023-08-11 09:48:11 -05001347 "https://somesite.com/somerepo.git;user=anyUser:idtoken=1234" : ('https', 'somesite.com', '/somerepo.git', '', '', {'user': 'anyUser:idtoken=1234'}),
Andrew Geissler028142b2023-05-05 11:29:21 -05001348 r'git://s.o-me_ONE:!#$%^&*()-_={}[]\|:?,.<>~`@git.openembedded.org/bitbake;branch=main;protocol=https': ('git', 'git.openembedded.org', '/bitbake', 's.o-me_ONE', r'!#$%^&*()-_={}[]\|:?,.<>~`', {'branch': 'main', 'protocol' : 'https'}),
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001349 }
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001350 # we require a pathname to encodeurl but users can still pass such urls to
1351 # decodeurl and we need to handle them
1352 decodedata = datatable.copy()
1353 decodedata.update({
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001354 "http://somesite.net;someparam=1": ('http', 'somesite.net', '/', '', '', {'someparam': '1'}),
Patrick Williams2390b1b2022-11-03 13:47:49 -05001355 "npmsw://some.registry.url;package=@pkg;version=latest": ('npmsw', 'some.registry.url', '/', '', '', {'package': '@pkg', 'version': 'latest'}),
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001356 })
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001357
1358 def test_decodeurl(self):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001359 for k, v in self.decodedata.items():
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001360 result = bb.fetch.decodeurl(k)
1361 self.assertEqual(result, v)
1362
1363 def test_encodeurl(self):
1364 for k, v in self.datatable.items():
1365 result = bb.fetch.encodeurl(v)
1366 self.assertEqual(result, k)
1367
1368class FetchLatestVersionTest(FetcherTest):
1369
1370 test_git_uris = {
1371 # version pattern "X.Y.Z"
Andrew Geissler595f6302022-01-24 19:11:47 +00001372 ("mx-1.0", "git://github.com/clutter-project/mx.git;branch=mx-1.4;protocol=https", "9b1db6b8060bd00b121a692f942404a24ae2960f", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001373 : "1.99.4",
1374 # version pattern "vX.Y"
Andrew Geisslerd25ed322020-06-27 00:28:28 -05001375 # mirror of git.infradead.org since network issues interfered with testing
Andrew Geissler028142b2023-05-05 11:29:21 -05001376 ("mtd-utils", "git://git.yoctoproject.org/mtd-utils.git;branch=master;protocol=https", "ca39eb1d98e736109c64ff9c1aa2a6ecca222d8f", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001377 : "1.5.0",
1378 # version pattern "pkg_name-X.Y"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001379 # mirror of git://anongit.freedesktop.org/git/xorg/proto/presentproto since network issues interfered with testing
Andrew Geissler028142b2023-05-05 11:29:21 -05001380 ("presentproto", "git://git.yoctoproject.org/bbfetchtests-presentproto;branch=master;protocol=https", "24f3a56e541b0a9e6c6ee76081f441221a120ef9", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001381 : "1.0",
1382 # version pattern "pkg_name-vX.Y.Z"
Andrew Geissler028142b2023-05-05 11:29:21 -05001383 ("dtc", "git://git.yoctoproject.org/bbfetchtests-dtc.git;branch=master;protocol=https", "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001384 : "1.4.0",
1385 # combination version pattern
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001386 ("sysprof", "git://gitlab.gnome.org/GNOME/sysprof.git;protocol=https;branch=master", "cd44ee6644c3641507fb53b8a2a69137f2971219", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001387 : "1.2.0",
1388 ("u-boot-mkimage", "git://git.denx.de/u-boot.git;branch=master;protocol=git", "62c175fbb8a0f9a926c88294ea9f7e88eb898f6c", "")
1389 : "2014.01",
1390 # version pattern "yyyymmdd"
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001391 ("mobile-broadband-provider-info", "git://gitlab.gnome.org/GNOME/mobile-broadband-provider-info.git;protocol=https;branch=master", "4ed19e11c2975105b71b956440acdb25d46a347d", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001392 : "20120614",
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001393 # packages with a valid UPSTREAM_CHECK_GITTAGREGEX
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001394 # mirror of git://anongit.freedesktop.org/xorg/driver/xf86-video-omap since network issues interfered with testing
Andrew Geissler028142b2023-05-05 11:29:21 -05001395 ("xf86-video-omap", "git://git.yoctoproject.org/bbfetchtests-xf86-video-omap;branch=master;protocol=https", "ae0394e687f1a77e966cf72f895da91840dffb8f", r"(?P<pver>(\d+\.(\d\.?)*))")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001396 : "0.4.3",
Andrew Geissler028142b2023-05-05 11:29:21 -05001397 ("build-appliance-image", "git://git.yoctoproject.org/poky;branch=master;protocol=https", "b37dd451a52622d5b570183a81583cc34c2ff555", r"(?P<pver>(([0-9][\.|_]?)+[0-9]))")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001398 : "11.0.0",
Andrew Geissler595f6302022-01-24 19:11:47 +00001399 ("chkconfig-alternatives-native", "git://github.com/kergoth/chkconfig;branch=sysroot;protocol=https", "cd437ecbd8986c894442f8fce1e0061e20f04dee", r"chkconfig\-(?P<pver>((\d+[\.\-_]*)+))")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001400 : "1.3.59",
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001401 ("remake", "git://github.com/rocky/remake.git;protocol=https;branch=master", "f05508e521987c8494c92d9c2871aec46307d51d", r"(?P<pver>(\d+\.(\d+\.)*\d*(\+dbg\d+(\.\d+)*)*))")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001402 : "3.82+dbg0.9",
1403 }
1404
1405 test_wget_uris = {
Andrew Geissler82c905d2020-04-13 13:39:40 -05001406 #
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001407 # packages with versions inside directory name
Andrew Geissler82c905d2020-04-13 13:39:40 -05001408 #
1409 # http://kernel.org/pub/linux/utils/util-linux/v2.23/util-linux-2.24.2.tar.bz2
1410 ("util-linux", "/pub/linux/utils/util-linux/v2.23/util-linux-2.24.2.tar.bz2", "", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001411 : "2.24.2",
Andrew Geissler82c905d2020-04-13 13:39:40 -05001412 # http://www.abisource.com/downloads/enchant/1.6.0/enchant-1.6.0.tar.gz
1413 ("enchant", "/downloads/enchant/1.6.0/enchant-1.6.0.tar.gz", "", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001414 : "1.6.0",
Andrew Geissler82c905d2020-04-13 13:39:40 -05001415 # http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz
1416 ("cmake", "/files/v2.8/cmake-2.8.12.1.tar.gz", "", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001417 : "2.8.12.1",
Andrew Geissler517393d2023-01-13 08:55:19 -06001418 # https://download.gnome.org/sources/libxml2/2.9/libxml2-2.9.14.tar.xz
1419 ("libxml2", "/software/libxml2/2.9/libxml2-2.9.14.tar.xz", "", "")
1420 : "2.10.3",
Andrew Geissler82c905d2020-04-13 13:39:40 -05001421 #
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001422 # packages with versions only in current directory
Andrew Geissler82c905d2020-04-13 13:39:40 -05001423 #
Andrew Geisslereff27472021-10-29 15:35:00 -05001424 # https://downloads.yoctoproject.org/releases/eglibc/eglibc-2.18-svnr23787.tar.bz2
Andrew Geissler82c905d2020-04-13 13:39:40 -05001425 ("eglic", "/releases/eglibc/eglibc-2.18-svnr23787.tar.bz2", "", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001426 : "2.19",
Andrew Geisslereff27472021-10-29 15:35:00 -05001427 # https://downloads.yoctoproject.org/releases/gnu-config/gnu-config-20120814.tar.bz2
Andrew Geissler82c905d2020-04-13 13:39:40 -05001428 ("gnu-config", "/releases/gnu-config/gnu-config-20120814.tar.bz2", "", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001429 : "20120814",
Andrew Geissler82c905d2020-04-13 13:39:40 -05001430 #
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001431 # packages with "99" in the name of possible version
Andrew Geissler82c905d2020-04-13 13:39:40 -05001432 #
1433 # http://freedesktop.org/software/pulseaudio/releases/pulseaudio-4.0.tar.xz
1434 ("pulseaudio", "/software/pulseaudio/releases/pulseaudio-4.0.tar.xz", "", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001435 : "5.0",
Andrew Geissler82c905d2020-04-13 13:39:40 -05001436 # http://xorg.freedesktop.org/releases/individual/xserver/xorg-server-1.15.1.tar.bz2
1437 ("xserver-xorg", "/releases/individual/xserver/xorg-server-1.15.1.tar.bz2", "", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001438 : "1.15.1",
Andrew Geissler82c905d2020-04-13 13:39:40 -05001439 #
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001440 # packages with valid UPSTREAM_CHECK_URI and UPSTREAM_CHECK_REGEX
Andrew Geissler82c905d2020-04-13 13:39:40 -05001441 #
1442 # http://www.cups.org/software/1.7.2/cups-1.7.2-source.tar.bz2
1443 # https://github.com/apple/cups/releases
Andrew Geissler5199d832021-09-24 16:47:35 -05001444 ("cups", "/software/1.7.2/cups-1.7.2-source.tar.bz2", "/apple/cups/releases", r"(?P<name>cups\-)(?P<pver>((\d+[\.\-_]*)+))\-source\.tar\.gz")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001445 : "2.0.0",
Andrew Geissler82c905d2020-04-13 13:39:40 -05001446 # http://download.oracle.com/berkeley-db/db-5.3.21.tar.gz
1447 # http://ftp.debian.org/debian/pool/main/d/db5.3/
Andrew Geissler5199d832021-09-24 16:47:35 -05001448 ("db", "/berkeley-db/db-5.3.21.tar.gz", "/debian/pool/main/d/db5.3/", r"(?P<name>db5\.3_)(?P<pver>\d+(\.\d+)+).+\.orig\.tar\.xz")
Brad Bishop79641f22019-09-10 07:20:22 -04001449 : "5.3.10",
Andrew Geissler595f6302022-01-24 19:11:47 +00001450 #
1451 # packages where the tarball compression changed in the new version
1452 #
1453 # http://ftp.debian.org/debian/pool/main/m/minicom/minicom_2.7.1.orig.tar.gz
1454 ("minicom", "/debian/pool/main/m/minicom/minicom_2.7.1.orig.tar.gz", "", "")
1455 : "2.8",
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001456 }
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001457
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001458 @skipIfNoNetwork()
1459 def test_git_latest_versionstring(self):
1460 for k, v in self.test_git_uris.items():
1461 self.d.setVar("PN", k[0])
1462 self.d.setVar("SRCREV", k[2])
1463 self.d.setVar("UPSTREAM_CHECK_GITTAGREGEX", k[3])
1464 ud = bb.fetch2.FetchData(k[1], self.d)
1465 pupver= ud.method.latest_versionstring(ud, self.d)
1466 verstring = pupver[0]
Brad Bishop316dfdd2018-06-25 12:45:53 -04001467 self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0])
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001468 r = bb.utils.vercmp_string(v, verstring)
1469 self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring))
1470
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001471 def test_wget_latest_versionstring(self):
Andrew Geissler82c905d2020-04-13 13:39:40 -05001472 testdata = os.path.dirname(os.path.abspath(__file__)) + "/fetch-testdata"
1473 server = HTTPService(testdata)
1474 server.start()
1475 port = server.port
1476 try:
1477 for k, v in self.test_wget_uris.items():
1478 self.d.setVar("PN", k[0])
1479 checkuri = ""
1480 if k[2]:
1481 checkuri = "http://localhost:%s/" % port + k[2]
1482 self.d.setVar("UPSTREAM_CHECK_URI", checkuri)
1483 self.d.setVar("UPSTREAM_CHECK_REGEX", k[3])
1484 url = "http://localhost:%s/" % port + k[1]
1485 ud = bb.fetch2.FetchData(url, self.d)
1486 pupver = ud.method.latest_versionstring(ud, self.d)
1487 verstring = pupver[0]
1488 self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0])
1489 r = bb.utils.vercmp_string(v, verstring)
1490 self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring))
1491 finally:
1492 server.stop()
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001493
1494
1495class FetchCheckStatusTest(FetcherTest):
Andrew Geisslereff27472021-10-29 15:35:00 -05001496 test_wget_uris = ["https://downloads.yoctoproject.org/releases/sato/sato-engine-0.1.tar.gz",
1497 "https://downloads.yoctoproject.org/releases/sato/sato-engine-0.2.tar.gz",
1498 "https://downloads.yoctoproject.org/releases/sato/sato-engine-0.3.tar.gz",
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001499 "https://yoctoproject.org/",
Andrew Geissler95ac1b82021-03-31 14:34:31 -05001500 "https://docs.yoctoproject.org",
Andrew Geisslereff27472021-10-29 15:35:00 -05001501 "https://downloads.yoctoproject.org/releases/opkg/opkg-0.1.7.tar.gz",
1502 "https://downloads.yoctoproject.org/releases/opkg/opkg-0.3.0.tar.gz",
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001503 "ftp://sourceware.org/pub/libffi/libffi-1.20.tar.gz",
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001504 # GitHub releases are hosted on Amazon S3, which doesn't support HEAD
1505 "https://github.com/kergoth/tslib/releases/download/1.1/tslib-1.1.tar.xz"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001506 ]
1507
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001508 @skipIfNoNetwork()
1509 def test_wget_checkstatus(self):
1510 fetch = bb.fetch2.Fetch(self.test_wget_uris, self.d)
1511 for u in self.test_wget_uris:
1512 with self.subTest(url=u):
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001513 ud = fetch.ud[u]
1514 m = ud.method
1515 ret = m.checkstatus(fetch, ud, self.d)
1516 self.assertTrue(ret, msg="URI %s, can't check status" % (u))
1517
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001518 @skipIfNoNetwork()
1519 def test_wget_checkstatus_connection_cache(self):
1520 from bb.fetch2 import FetchConnectionCache
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001521
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001522 connection_cache = FetchConnectionCache()
1523 fetch = bb.fetch2.Fetch(self.test_wget_uris, self.d,
1524 connection_cache = connection_cache)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001525
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001526 for u in self.test_wget_uris:
1527 with self.subTest(url=u):
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001528 ud = fetch.ud[u]
1529 m = ud.method
1530 ret = m.checkstatus(fetch, ud, self.d)
1531 self.assertTrue(ret, msg="URI %s, can't check status" % (u))
1532
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001533 connection_cache.close_connections()
1534
1535
1536class GitMakeShallowTest(FetcherTest):
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001537 def setUp(self):
1538 FetcherTest.setUp(self)
1539 self.gitdir = os.path.join(self.tempdir, 'gitshallow')
1540 bb.utils.mkdirhier(self.gitdir)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001541 self.git_init()
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001542
1543 def assertRefs(self, expected_refs):
1544 actual_refs = self.git(['for-each-ref', '--format=%(refname)']).splitlines()
1545 full_expected = self.git(['rev-parse', '--symbolic-full-name'] + expected_refs).splitlines()
1546 self.assertEqual(sorted(full_expected), sorted(actual_refs))
1547
1548 def assertRevCount(self, expected_count, args=None):
1549 if args is None:
1550 args = ['HEAD']
1551 revs = self.git(['rev-list'] + args)
1552 actual_count = len(revs.splitlines())
1553 self.assertEqual(expected_count, actual_count, msg='Object count `%d` is not the expected `%d`' % (actual_count, expected_count))
1554
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001555 def make_shallow(self, args=None):
1556 if args is None:
1557 args = ['HEAD']
Brad Bishop316dfdd2018-06-25 12:45:53 -04001558 return bb.process.run([bb.fetch2.git.Git.make_shallow_path] + args, cwd=self.gitdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001559
1560 def add_empty_file(self, path, msg=None):
1561 if msg is None:
1562 msg = path
1563 open(os.path.join(self.gitdir, path), 'w').close()
1564 self.git(['add', path])
1565 self.git(['commit', '-m', msg, path])
1566
1567 def test_make_shallow_single_branch_no_merge(self):
1568 self.add_empty_file('a')
1569 self.add_empty_file('b')
1570 self.assertRevCount(2)
1571 self.make_shallow()
1572 self.assertRevCount(1)
1573
1574 def test_make_shallow_single_branch_one_merge(self):
1575 self.add_empty_file('a')
1576 self.add_empty_file('b')
1577 self.git('checkout -b a_branch')
1578 self.add_empty_file('c')
1579 self.git('checkout master')
1580 self.add_empty_file('d')
1581 self.git('merge --no-ff --no-edit a_branch')
1582 self.git('branch -d a_branch')
1583 self.add_empty_file('e')
1584 self.assertRevCount(6)
1585 self.make_shallow(['HEAD~2'])
1586 self.assertRevCount(5)
1587
1588 def test_make_shallow_at_merge(self):
1589 self.add_empty_file('a')
1590 self.git('checkout -b a_branch')
1591 self.add_empty_file('b')
1592 self.git('checkout master')
1593 self.git('merge --no-ff --no-edit a_branch')
1594 self.git('branch -d a_branch')
1595 self.assertRevCount(3)
1596 self.make_shallow()
1597 self.assertRevCount(1)
1598
1599 def test_make_shallow_annotated_tag(self):
1600 self.add_empty_file('a')
1601 self.add_empty_file('b')
1602 self.git('tag -a -m a_tag a_tag')
1603 self.assertRevCount(2)
1604 self.make_shallow(['a_tag'])
1605 self.assertRevCount(1)
1606
1607 def test_make_shallow_multi_ref(self):
1608 self.add_empty_file('a')
1609 self.add_empty_file('b')
1610 self.git('checkout -b a_branch')
1611 self.add_empty_file('c')
1612 self.git('checkout master')
1613 self.add_empty_file('d')
1614 self.git('checkout -b a_branch_2')
1615 self.add_empty_file('a_tag')
1616 self.git('tag a_tag')
1617 self.git('checkout master')
1618 self.git('branch -D a_branch_2')
1619 self.add_empty_file('e')
1620 self.assertRevCount(6, ['--all'])
1621 self.make_shallow()
1622 self.assertRevCount(5, ['--all'])
1623
1624 def test_make_shallow_multi_ref_trim(self):
1625 self.add_empty_file('a')
1626 self.git('checkout -b a_branch')
1627 self.add_empty_file('c')
1628 self.git('checkout master')
1629 self.assertRevCount(1)
1630 self.assertRevCount(2, ['--all'])
1631 self.assertRefs(['master', 'a_branch'])
1632 self.make_shallow(['-r', 'master', 'HEAD'])
1633 self.assertRevCount(1, ['--all'])
1634 self.assertRefs(['master'])
1635
1636 def test_make_shallow_noop(self):
1637 self.add_empty_file('a')
1638 self.assertRevCount(1)
1639 self.make_shallow()
1640 self.assertRevCount(1)
1641
1642 @skipIfNoNetwork()
1643 def test_make_shallow_bitbake(self):
1644 self.git('remote add origin https://github.com/openembedded/bitbake')
1645 self.git('fetch --tags origin')
1646 orig_revs = len(self.git('rev-list --all').splitlines())
1647 self.make_shallow(['refs/tags/1.10.0'])
1648 self.assertRevCount(orig_revs - 1746, ['--all'])
1649
1650class GitShallowTest(FetcherTest):
1651 def setUp(self):
1652 FetcherTest.setUp(self)
1653 self.gitdir = os.path.join(self.tempdir, 'git')
1654 self.srcdir = os.path.join(self.tempdir, 'gitsource')
1655
1656 bb.utils.mkdirhier(self.srcdir)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001657 self.git_init(cwd=self.srcdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001658 self.d.setVar('WORKDIR', self.tempdir)
1659 self.d.setVar('S', self.gitdir)
1660 self.d.delVar('PREMIRRORS')
1661 self.d.delVar('MIRRORS')
1662
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001663 uri = 'git://%s;protocol=file;subdir=${S};branch=master' % self.srcdir
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001664 self.d.setVar('SRC_URI', uri)
1665 self.d.setVar('SRCREV', '${AUTOREV}')
1666 self.d.setVar('AUTOREV', '${@bb.fetch2.get_autorev(d)}')
1667
1668 self.d.setVar('BB_GIT_SHALLOW', '1')
1669 self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '0')
1670 self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1')
Andrew Geisslerfc113ea2023-03-31 09:59:46 -05001671 self.d.setVar("__BBSRCREV_SEEN", "1")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001672
1673 def assertRefs(self, expected_refs, cwd=None):
1674 if cwd is None:
1675 cwd = self.gitdir
1676 actual_refs = self.git(['for-each-ref', '--format=%(refname)'], cwd=cwd).splitlines()
1677 full_expected = self.git(['rev-parse', '--symbolic-full-name'] + expected_refs, cwd=cwd).splitlines()
1678 self.assertEqual(sorted(set(full_expected)), sorted(set(actual_refs)))
1679
1680 def assertRevCount(self, expected_count, args=None, cwd=None):
1681 if args is None:
1682 args = ['HEAD']
1683 if cwd is None:
1684 cwd = self.gitdir
1685 revs = self.git(['rev-list'] + args, cwd=cwd)
1686 actual_count = len(revs.splitlines())
1687 self.assertEqual(expected_count, actual_count, msg='Object count `%d` is not the expected `%d`' % (actual_count, expected_count))
1688
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001689 def add_empty_file(self, path, cwd=None, msg=None):
1690 if msg is None:
1691 msg = path
1692 if cwd is None:
1693 cwd = self.srcdir
1694 open(os.path.join(cwd, path), 'w').close()
1695 self.git(['add', path], cwd)
1696 self.git(['commit', '-m', msg, path], cwd)
1697
1698 def fetch(self, uri=None):
1699 if uri is None:
Brad Bishop19323692019-04-05 15:28:33 -04001700 uris = self.d.getVar('SRC_URI').split()
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001701 uri = uris[0]
1702 d = self.d
1703 else:
1704 d = self.d.createCopy()
1705 d.setVar('SRC_URI', uri)
1706 uri = d.expand(uri)
1707 uris = [uri]
1708
1709 fetcher = bb.fetch2.Fetch(uris, d)
1710 fetcher.download()
1711 ud = fetcher.ud[uri]
1712 return fetcher, ud
1713
1714 def fetch_and_unpack(self, uri=None):
1715 fetcher, ud = self.fetch(uri)
1716 fetcher.unpack(self.d.getVar('WORKDIR'))
1717 assert os.path.exists(self.d.getVar('S'))
1718 return fetcher, ud
1719
1720 def fetch_shallow(self, uri=None, disabled=False, keepclone=False):
1721 """Fetch a uri, generating a shallow tarball, then unpack using it"""
1722 fetcher, ud = self.fetch_and_unpack(uri)
1723 assert os.path.exists(ud.clonedir), 'Git clone in DLDIR (%s) does not exist for uri %s' % (ud.clonedir, uri)
1724
1725 # Confirm that the unpacked repo is unshallow
1726 if not disabled:
1727 assert os.path.exists(os.path.join(self.dldir, ud.mirrortarballs[0]))
1728
1729 # fetch and unpack, from the shallow tarball
1730 bb.utils.remove(self.gitdir, recurse=True)
Andrew Geisslerc926e172021-05-07 16:11:35 -05001731 bb.process.run('chmod u+w -R "%s"' % ud.clonedir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001732 bb.utils.remove(ud.clonedir, recurse=True)
Brad Bishopf8caae32019-03-25 13:13:56 -04001733 bb.utils.remove(ud.clonedir.replace('gitsource', 'gitsubmodule'), recurse=True)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001734
1735 # confirm that the unpacked repo is used when no git clone or git
1736 # mirror tarball is available
1737 fetcher, ud = self.fetch_and_unpack(uri)
1738 if not disabled:
1739 assert os.path.exists(os.path.join(self.gitdir, '.git', 'shallow')), 'Unpacked git repository at %s is not shallow' % self.gitdir
1740 else:
1741 assert not os.path.exists(os.path.join(self.gitdir, '.git', 'shallow')), 'Unpacked git repository at %s is shallow' % self.gitdir
1742 return fetcher, ud
1743
1744 def test_shallow_disabled(self):
1745 self.add_empty_file('a')
1746 self.add_empty_file('b')
1747 self.assertRevCount(2, cwd=self.srcdir)
1748
1749 self.d.setVar('BB_GIT_SHALLOW', '0')
1750 self.fetch_shallow(disabled=True)
1751 self.assertRevCount(2)
1752
1753 def test_shallow_nobranch(self):
1754 self.add_empty_file('a')
1755 self.add_empty_file('b')
1756 self.assertRevCount(2, cwd=self.srcdir)
1757
1758 srcrev = self.git('rev-parse HEAD', cwd=self.srcdir).strip()
1759 self.d.setVar('SRCREV', srcrev)
Brad Bishop19323692019-04-05 15:28:33 -04001760 uri = self.d.getVar('SRC_URI').split()[0]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001761 uri = '%s;nobranch=1;bare=1' % uri
1762
1763 self.fetch_shallow(uri)
1764 self.assertRevCount(1)
1765
1766 # shallow refs are used to ensure the srcrev sticks around when we
1767 # have no other branches referencing it
1768 self.assertRefs(['refs/shallow/default'])
1769
1770 def test_shallow_default_depth_1(self):
1771 # Create initial git repo
1772 self.add_empty_file('a')
1773 self.add_empty_file('b')
1774 self.assertRevCount(2, cwd=self.srcdir)
1775
1776 self.fetch_shallow()
1777 self.assertRevCount(1)
1778
1779 def test_shallow_depth_0_disables(self):
1780 self.add_empty_file('a')
1781 self.add_empty_file('b')
1782 self.assertRevCount(2, cwd=self.srcdir)
1783
1784 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
1785 self.fetch_shallow(disabled=True)
1786 self.assertRevCount(2)
1787
1788 def test_shallow_depth_default_override(self):
1789 self.add_empty_file('a')
1790 self.add_empty_file('b')
1791 self.assertRevCount(2, cwd=self.srcdir)
1792
1793 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '2')
1794 self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '1')
1795 self.fetch_shallow()
1796 self.assertRevCount(1)
1797
1798 def test_shallow_depth_default_override_disable(self):
1799 self.add_empty_file('a')
1800 self.add_empty_file('b')
1801 self.add_empty_file('c')
1802 self.assertRevCount(3, cwd=self.srcdir)
1803
1804 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
1805 self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '2')
1806 self.fetch_shallow()
1807 self.assertRevCount(2)
1808
1809 def test_current_shallow_out_of_date_clone(self):
1810 # Create initial git repo
1811 self.add_empty_file('a')
1812 self.add_empty_file('b')
1813 self.add_empty_file('c')
1814 self.assertRevCount(3, cwd=self.srcdir)
1815
1816 # Clone and generate mirror tarball
1817 fetcher, ud = self.fetch()
1818
1819 # Ensure we have a current mirror tarball, but an out of date clone
1820 self.git('update-ref refs/heads/master refs/heads/master~1', cwd=ud.clonedir)
1821 self.assertRevCount(2, cwd=ud.clonedir)
1822
1823 # Fetch and unpack, from the current tarball, not the out of date clone
1824 bb.utils.remove(self.gitdir, recurse=True)
1825 fetcher, ud = self.fetch()
1826 fetcher.unpack(self.d.getVar('WORKDIR'))
1827 self.assertRevCount(1)
1828
1829 def test_shallow_single_branch_no_merge(self):
1830 self.add_empty_file('a')
1831 self.add_empty_file('b')
1832 self.assertRevCount(2, cwd=self.srcdir)
1833
1834 self.fetch_shallow()
1835 self.assertRevCount(1)
1836 assert os.path.exists(os.path.join(self.gitdir, 'a'))
1837 assert os.path.exists(os.path.join(self.gitdir, 'b'))
1838
1839 def test_shallow_no_dangling(self):
1840 self.add_empty_file('a')
1841 self.add_empty_file('b')
1842 self.assertRevCount(2, cwd=self.srcdir)
1843
1844 self.fetch_shallow()
1845 self.assertRevCount(1)
1846 assert not self.git('fsck --dangling')
1847
1848 def test_shallow_srcrev_branch_truncation(self):
1849 self.add_empty_file('a')
1850 self.add_empty_file('b')
1851 b_commit = self.git('rev-parse HEAD', cwd=self.srcdir).rstrip()
1852 self.add_empty_file('c')
1853 self.assertRevCount(3, cwd=self.srcdir)
1854
1855 self.d.setVar('SRCREV', b_commit)
1856 self.fetch_shallow()
1857
1858 # The 'c' commit was removed entirely, and 'a' was removed from history
1859 self.assertRevCount(1, ['--all'])
1860 self.assertEqual(self.git('rev-parse HEAD').strip(), b_commit)
1861 assert os.path.exists(os.path.join(self.gitdir, 'a'))
1862 assert os.path.exists(os.path.join(self.gitdir, 'b'))
1863 assert not os.path.exists(os.path.join(self.gitdir, 'c'))
1864
1865 def test_shallow_ref_pruning(self):
1866 self.add_empty_file('a')
1867 self.add_empty_file('b')
1868 self.git('branch a_branch', cwd=self.srcdir)
1869 self.assertRefs(['master', 'a_branch'], cwd=self.srcdir)
1870 self.assertRevCount(2, cwd=self.srcdir)
1871
1872 self.fetch_shallow()
1873
1874 self.assertRefs(['master', 'origin/master'])
1875 self.assertRevCount(1)
1876
1877 def test_shallow_submodules(self):
1878 self.add_empty_file('a')
1879 self.add_empty_file('b')
1880
1881 smdir = os.path.join(self.tempdir, 'gitsubmodule')
1882 bb.utils.mkdirhier(smdir)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001883 self.git_init(cwd=smdir)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001884 # Make this look like it was cloned from a remote...
1885 self.git('config --add remote.origin.url "%s"' % smdir, cwd=smdir)
1886 self.git('config --add remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"', cwd=smdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001887 self.add_empty_file('asub', cwd=smdir)
Brad Bishopf8caae32019-03-25 13:13:56 -04001888 self.add_empty_file('bsub', cwd=smdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001889
1890 self.git('submodule init', cwd=self.srcdir)
Patrick Williams2390b1b2022-11-03 13:47:49 -05001891 self.git('-c protocol.file.allow=always submodule add file://%s' % smdir, cwd=self.srcdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001892 self.git('submodule update', cwd=self.srcdir)
1893 self.git('commit -m submodule -a', cwd=self.srcdir)
1894
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001895 uri = 'gitsm://%s;protocol=file;subdir=${S};branch=master' % self.srcdir
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001896 fetcher, ud = self.fetch_shallow(uri)
1897
Brad Bishopf8caae32019-03-25 13:13:56 -04001898 # Verify the main repository is shallow
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001899 self.assertRevCount(1)
Brad Bishopf8caae32019-03-25 13:13:56 -04001900
1901 # Verify the gitsubmodule directory is present
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001902 assert os.listdir(os.path.join(self.gitdir, 'gitsubmodule'))
1903
Brad Bishopf8caae32019-03-25 13:13:56 -04001904 # Verify the submodule is also shallow
1905 self.assertRevCount(1, cwd=os.path.join(self.gitdir, 'gitsubmodule'))
1906
Andrew Geissler82c905d2020-04-13 13:39:40 -05001907 def test_shallow_submodule_mirrors(self):
1908 self.add_empty_file('a')
1909 self.add_empty_file('b')
1910
1911 smdir = os.path.join(self.tempdir, 'gitsubmodule')
1912 bb.utils.mkdirhier(smdir)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001913 self.git_init(cwd=smdir)
Andrew Geissler82c905d2020-04-13 13:39:40 -05001914 # Make this look like it was cloned from a remote...
1915 self.git('config --add remote.origin.url "%s"' % smdir, cwd=smdir)
1916 self.git('config --add remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"', cwd=smdir)
1917 self.add_empty_file('asub', cwd=smdir)
1918 self.add_empty_file('bsub', cwd=smdir)
1919
1920 self.git('submodule init', cwd=self.srcdir)
Patrick Williams2390b1b2022-11-03 13:47:49 -05001921 self.git('-c protocol.file.allow=always submodule add file://%s' % smdir, cwd=self.srcdir)
Andrew Geissler82c905d2020-04-13 13:39:40 -05001922 self.git('submodule update', cwd=self.srcdir)
1923 self.git('commit -m submodule -a', cwd=self.srcdir)
1924
1925 uri = 'gitsm://%s;protocol=file;subdir=${S}' % self.srcdir
1926
1927 # Fetch once to generate the shallow tarball
1928 fetcher, ud = self.fetch(uri)
1929
1930 # Set up the mirror
1931 mirrordir = os.path.join(self.tempdir, 'mirror')
Andrew Geisslerc926e172021-05-07 16:11:35 -05001932 bb.utils.rename(self.dldir, mirrordir)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001933 self.d.setVar('PREMIRRORS', 'gitsm://.*/.* file://%s/' % mirrordir)
Andrew Geissler82c905d2020-04-13 13:39:40 -05001934
1935 # Fetch from the mirror
1936 bb.utils.remove(self.dldir, recurse=True)
1937 bb.utils.remove(self.gitdir, recurse=True)
1938 self.fetch_and_unpack(uri)
1939
1940 # Verify the main repository is shallow
1941 self.assertRevCount(1)
1942
1943 # Verify the gitsubmodule directory is present
1944 assert os.listdir(os.path.join(self.gitdir, 'gitsubmodule'))
1945
1946 # Verify the submodule is also shallow
1947 self.assertRevCount(1, cwd=os.path.join(self.gitdir, 'gitsubmodule'))
Brad Bishopf8caae32019-03-25 13:13:56 -04001948
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001949 if any(os.path.exists(os.path.join(p, 'git-annex')) for p in os.environ.get('PATH').split(':')):
1950 def test_shallow_annex(self):
1951 self.add_empty_file('a')
1952 self.add_empty_file('b')
1953 self.git('annex init', cwd=self.srcdir)
1954 open(os.path.join(self.srcdir, 'c'), 'w').close()
1955 self.git('annex add c', cwd=self.srcdir)
Andrew Geisslerc926e172021-05-07 16:11:35 -05001956 self.git('commit --author "Foo Bar <foo@bar>" -m annex-c -a', cwd=self.srcdir)
1957 bb.process.run('chmod u+w -R %s' % self.srcdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001958
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001959 uri = 'gitannex://%s;protocol=file;subdir=${S};branch=master' % self.srcdir
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001960 fetcher, ud = self.fetch_shallow(uri)
1961
1962 self.assertRevCount(1)
1963 assert './.git/annex/' in bb.process.run('tar -tzf %s' % os.path.join(self.dldir, ud.mirrortarballs[0]))[0]
1964 assert os.path.exists(os.path.join(self.gitdir, 'c'))
1965
1966 def test_shallow_multi_one_uri(self):
1967 # Create initial git repo
1968 self.add_empty_file('a')
1969 self.add_empty_file('b')
1970 self.git('checkout -b a_branch', cwd=self.srcdir)
1971 self.add_empty_file('c')
1972 self.add_empty_file('d')
1973 self.git('checkout master', cwd=self.srcdir)
1974 self.git('tag v0.0 a_branch', cwd=self.srcdir)
1975 self.add_empty_file('e')
1976 self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir)
1977 self.add_empty_file('f')
1978 self.assertRevCount(7, cwd=self.srcdir)
1979
Brad Bishop19323692019-04-05 15:28:33 -04001980 uri = self.d.getVar('SRC_URI').split()[0]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001981 uri = '%s;branch=master,a_branch;name=master,a_branch' % uri
1982
1983 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
1984 self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
1985 self.d.setVar('SRCREV_master', '${AUTOREV}')
1986 self.d.setVar('SRCREV_a_branch', '${AUTOREV}')
1987
1988 self.fetch_shallow(uri)
1989
1990 self.assertRevCount(5)
1991 self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
1992
1993 def test_shallow_multi_one_uri_depths(self):
1994 # Create initial git repo
1995 self.add_empty_file('a')
1996 self.add_empty_file('b')
1997 self.git('checkout -b a_branch', cwd=self.srcdir)
1998 self.add_empty_file('c')
1999 self.add_empty_file('d')
2000 self.git('checkout master', cwd=self.srcdir)
2001 self.add_empty_file('e')
2002 self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir)
2003 self.add_empty_file('f')
2004 self.assertRevCount(7, cwd=self.srcdir)
2005
Brad Bishop19323692019-04-05 15:28:33 -04002006 uri = self.d.getVar('SRC_URI').split()[0]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002007 uri = '%s;branch=master,a_branch;name=master,a_branch' % uri
2008
2009 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
2010 self.d.setVar('BB_GIT_SHALLOW_DEPTH_master', '3')
2011 self.d.setVar('BB_GIT_SHALLOW_DEPTH_a_branch', '1')
2012 self.d.setVar('SRCREV_master', '${AUTOREV}')
2013 self.d.setVar('SRCREV_a_branch', '${AUTOREV}')
2014
2015 self.fetch_shallow(uri)
2016
2017 self.assertRevCount(4, ['--all'])
2018 self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
2019
2020 def test_shallow_clone_preferred_over_shallow(self):
2021 self.add_empty_file('a')
2022 self.add_empty_file('b')
2023
2024 # Fetch once to generate the shallow tarball
2025 fetcher, ud = self.fetch()
2026 assert os.path.exists(os.path.join(self.dldir, ud.mirrortarballs[0]))
2027
2028 # Fetch and unpack with both the clonedir and shallow tarball available
2029 bb.utils.remove(self.gitdir, recurse=True)
2030 fetcher, ud = self.fetch_and_unpack()
2031
2032 # The unpacked tree should *not* be shallow
2033 self.assertRevCount(2)
2034 assert not os.path.exists(os.path.join(self.gitdir, '.git', 'shallow'))
2035
2036 def test_shallow_mirrors(self):
2037 self.add_empty_file('a')
2038 self.add_empty_file('b')
2039
2040 # Fetch once to generate the shallow tarball
2041 fetcher, ud = self.fetch()
2042 mirrortarball = ud.mirrortarballs[0]
2043 assert os.path.exists(os.path.join(self.dldir, mirrortarball))
2044
2045 # Set up the mirror
2046 mirrordir = os.path.join(self.tempdir, 'mirror')
2047 bb.utils.mkdirhier(mirrordir)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002048 self.d.setVar('PREMIRRORS', 'git://.*/.* file://%s/' % mirrordir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002049
Andrew Geisslerc926e172021-05-07 16:11:35 -05002050 bb.utils.rename(os.path.join(self.dldir, mirrortarball),
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002051 os.path.join(mirrordir, mirrortarball))
2052
2053 # Fetch from the mirror
2054 bb.utils.remove(self.dldir, recurse=True)
2055 bb.utils.remove(self.gitdir, recurse=True)
2056 self.fetch_and_unpack()
2057 self.assertRevCount(1)
2058
2059 def test_shallow_invalid_depth(self):
2060 self.add_empty_file('a')
2061 self.add_empty_file('b')
2062
2063 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '-12')
2064 with self.assertRaises(bb.fetch2.FetchError):
2065 self.fetch()
2066
2067 def test_shallow_invalid_depth_default(self):
2068 self.add_empty_file('a')
2069 self.add_empty_file('b')
2070
2071 self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '-12')
2072 with self.assertRaises(bb.fetch2.FetchError):
2073 self.fetch()
2074
2075 def test_shallow_extra_refs(self):
2076 self.add_empty_file('a')
2077 self.add_empty_file('b')
2078 self.git('branch a_branch', cwd=self.srcdir)
2079 self.assertRefs(['master', 'a_branch'], cwd=self.srcdir)
2080 self.assertRevCount(2, cwd=self.srcdir)
2081
2082 self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/heads/a_branch')
2083 self.fetch_shallow()
2084
2085 self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
2086 self.assertRevCount(1)
2087
2088 def test_shallow_extra_refs_wildcard(self):
2089 self.add_empty_file('a')
2090 self.add_empty_file('b')
2091 self.git('branch a_branch', cwd=self.srcdir)
2092 self.git('tag v1.0', cwd=self.srcdir)
2093 self.assertRefs(['master', 'a_branch', 'v1.0'], cwd=self.srcdir)
2094 self.assertRevCount(2, cwd=self.srcdir)
2095
2096 self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/tags/*')
2097 self.fetch_shallow()
2098
2099 self.assertRefs(['master', 'origin/master', 'v1.0'])
2100 self.assertRevCount(1)
2101
2102 def test_shallow_missing_extra_refs(self):
2103 self.add_empty_file('a')
2104 self.add_empty_file('b')
2105
2106 self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/heads/foo')
2107 with self.assertRaises(bb.fetch2.FetchError):
2108 self.fetch()
2109
2110 def test_shallow_missing_extra_refs_wildcard(self):
2111 self.add_empty_file('a')
2112 self.add_empty_file('b')
2113
2114 self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/tags/*')
2115 self.fetch()
2116
2117 def test_shallow_remove_revs(self):
2118 # Create initial git repo
2119 self.add_empty_file('a')
2120 self.add_empty_file('b')
2121 self.git('checkout -b a_branch', cwd=self.srcdir)
2122 self.add_empty_file('c')
2123 self.add_empty_file('d')
2124 self.git('checkout master', cwd=self.srcdir)
2125 self.git('tag v0.0 a_branch', cwd=self.srcdir)
2126 self.add_empty_file('e')
2127 self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir)
2128 self.git('branch -d a_branch', cwd=self.srcdir)
2129 self.add_empty_file('f')
2130 self.assertRevCount(7, cwd=self.srcdir)
2131
2132 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
2133 self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
2134
2135 self.fetch_shallow()
2136
2137 self.assertRevCount(5)
2138
2139 def test_shallow_invalid_revs(self):
2140 self.add_empty_file('a')
2141 self.add_empty_file('b')
2142
2143 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
2144 self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
2145
2146 with self.assertRaises(bb.fetch2.FetchError):
2147 self.fetch()
2148
Brad Bishop64c979e2019-11-04 13:55:29 -05002149 def test_shallow_fetch_missing_revs(self):
2150 self.add_empty_file('a')
2151 self.add_empty_file('b')
2152 fetcher, ud = self.fetch(self.d.getVar('SRC_URI'))
2153 self.git('tag v0.0 master', cwd=self.srcdir)
2154 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
2155 self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
2156 self.fetch_shallow()
2157
2158 def test_shallow_fetch_missing_revs_fails(self):
2159 self.add_empty_file('a')
2160 self.add_empty_file('b')
2161 fetcher, ud = self.fetch(self.d.getVar('SRC_URI'))
2162 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
2163 self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
2164
2165 with self.assertRaises(bb.fetch2.FetchError), self.assertLogs("BitBake.Fetcher", level="ERROR") as cm:
2166 self.fetch_shallow()
2167 self.assertIn("Unable to find revision v0.0 even from upstream", cm.output[0])
2168
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002169 @skipIfNoNetwork()
2170 def test_bitbake(self):
Andrew Geissler595f6302022-01-24 19:11:47 +00002171 self.git('remote add --mirror=fetch origin https://github.com/openembedded/bitbake', cwd=self.srcdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002172 self.git('config core.bare true', cwd=self.srcdir)
2173 self.git('fetch', cwd=self.srcdir)
2174
2175 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
2176 # Note that the 1.10.0 tag is annotated, so this also tests
2177 # reference of an annotated vs unannotated tag
2178 self.d.setVar('BB_GIT_SHALLOW_REVS', '1.10.0')
2179
2180 self.fetch_shallow()
2181
2182 # Confirm that the history of 1.10.0 was removed
2183 orig_revs = len(self.git('rev-list master', cwd=self.srcdir).splitlines())
2184 revs = len(self.git('rev-list master').splitlines())
2185 self.assertNotEqual(orig_revs, revs)
2186 self.assertRefs(['master', 'origin/master'])
2187 self.assertRevCount(orig_revs - 1758)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08002188
2189 def test_that_unpack_throws_an_error_when_the_git_clone_nor_shallow_tarball_exist(self):
2190 self.add_empty_file('a')
2191 fetcher, ud = self.fetch()
2192 bb.utils.remove(self.gitdir, recurse=True)
2193 bb.utils.remove(self.dldir, recurse=True)
2194
2195 with self.assertRaises(bb.fetch2.UnpackError) as context:
2196 fetcher.unpack(self.d.getVar('WORKDIR'))
2197
2198 self.assertIn("No up to date source found", context.exception.msg)
2199 self.assertIn("clone directory not available or not up to date", context.exception.msg)
2200
2201 @skipIfNoNetwork()
2202 def test_that_unpack_does_work_when_using_git_shallow_tarball_but_tarball_is_not_available(self):
2203 self.d.setVar('SRCREV', 'e5939ff608b95cdd4d0ab0e1935781ab9a276ac0')
2204 self.d.setVar('BB_GIT_SHALLOW', '1')
2205 self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1')
Andrew Geissler028142b2023-05-05 11:29:21 -05002206 fetcher = bb.fetch.Fetch(["git://git.yoctoproject.org/fstests;branch=master;protocol=https"], self.d)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08002207 fetcher.download()
2208
2209 bb.utils.remove(self.dldir + "/*.tar.gz")
2210 fetcher.unpack(self.unpackdir)
2211
2212 dir = os.listdir(self.unpackdir + "/git/")
2213 self.assertIn("fstests.doap", dir)
Brad Bishop00e122a2019-10-05 11:10:57 -04002214
2215class GitLfsTest(FetcherTest):
Andrew Geissler6aa7eec2023-03-03 12:41:14 -06002216 def skipIfNoGitLFS():
2217 import shutil
2218 if not shutil.which('git-lfs'):
2219 return unittest.skip('git-lfs not installed')
2220 return lambda f: f
2221
Brad Bishop00e122a2019-10-05 11:10:57 -04002222 def setUp(self):
2223 FetcherTest.setUp(self)
2224
2225 self.gitdir = os.path.join(self.tempdir, 'git')
2226 self.srcdir = os.path.join(self.tempdir, 'gitsource')
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002227
Brad Bishop00e122a2019-10-05 11:10:57 -04002228 self.d.setVar('WORKDIR', self.tempdir)
2229 self.d.setVar('S', self.gitdir)
2230 self.d.delVar('PREMIRRORS')
2231 self.d.delVar('MIRRORS')
2232
2233 self.d.setVar('SRCREV', '${AUTOREV}')
2234 self.d.setVar('AUTOREV', '${@bb.fetch2.get_autorev(d)}')
Andrew Geisslerfc113ea2023-03-31 09:59:46 -05002235 self.d.setVar("__BBSRCREV_SEEN", "1")
Brad Bishop00e122a2019-10-05 11:10:57 -04002236
2237 bb.utils.mkdirhier(self.srcdir)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002238 self.git_init(cwd=self.srcdir)
Brad Bishop00e122a2019-10-05 11:10:57 -04002239 with open(os.path.join(self.srcdir, '.gitattributes'), 'wt') as attrs:
2240 attrs.write('*.mp3 filter=lfs -text')
2241 self.git(['add', '.gitattributes'], cwd=self.srcdir)
2242 self.git(['commit', '-m', "attributes", '.gitattributes'], cwd=self.srcdir)
2243
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002244 def fetch(self, uri=None, download=True):
Brad Bishop00e122a2019-10-05 11:10:57 -04002245 uris = self.d.getVar('SRC_URI').split()
2246 uri = uris[0]
2247 d = self.d
2248
2249 fetcher = bb.fetch2.Fetch(uris, d)
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002250 if download:
2251 fetcher.download()
Brad Bishop00e122a2019-10-05 11:10:57 -04002252 ud = fetcher.ud[uri]
2253 return fetcher, ud
2254
Andrew Geissler6aa7eec2023-03-03 12:41:14 -06002255 def get_real_git_lfs_file(self):
2256 self.d.setVar('PATH', os.environ.get('PATH'))
2257 fetcher, ud = self.fetch()
2258 fetcher.unpack(self.d.getVar('WORKDIR'))
2259 unpacked_lfs_file = os.path.join(self.d.getVar('WORKDIR'), 'git', "Cat_poster_1.jpg")
2260 return unpacked_lfs_file
2261
2262 @skipIfNoGitLFS()
2263 @skipIfNoNetwork()
2264 def test_real_git_lfs_repo_succeeds_without_lfs_param(self):
2265 self.d.setVar('SRC_URI', "git://gitlab.com/gitlab-examples/lfs.git;protocol=https;branch=master")
2266 f = self.get_real_git_lfs_file()
2267 self.assertTrue(os.path.exists(f))
2268 self.assertEqual("c0baab607a97839c9a328b4310713307", bb.utils.md5_file(f))
2269
2270 @skipIfNoGitLFS()
2271 @skipIfNoNetwork()
2272 def test_real_git_lfs_repo_succeeds(self):
2273 self.d.setVar('SRC_URI', "git://gitlab.com/gitlab-examples/lfs.git;protocol=https;branch=master;lfs=1")
2274 f = self.get_real_git_lfs_file()
2275 self.assertTrue(os.path.exists(f))
2276 self.assertEqual("c0baab607a97839c9a328b4310713307", bb.utils.md5_file(f))
2277
2278 @skipIfNoGitLFS()
2279 @skipIfNoNetwork()
Patrick Williamsac13d5f2023-11-24 18:59:46 -06002280 def test_real_git_lfs_repo_skips(self):
Andrew Geissler6aa7eec2023-03-03 12:41:14 -06002281 self.d.setVar('SRC_URI', "git://gitlab.com/gitlab-examples/lfs.git;protocol=https;branch=master;lfs=0")
2282 f = self.get_real_git_lfs_file()
2283 # This is the actual non-smudged placeholder file on the repo if git-lfs does not run
2284 lfs_file = (
2285 'version https://git-lfs.github.com/spec/v1\n'
2286 'oid sha256:34be66b1a39a1955b46a12588df9d5f6fc1da790e05cf01f3c7422f4bbbdc26b\n'
2287 'size 11423554\n'
2288 )
2289
2290 with open(f) as fh:
2291 self.assertEqual(lfs_file, fh.read())
2292
Patrick Williamsac13d5f2023-11-24 18:59:46 -06002293 @skipIfNoGitLFS()
Brad Bishop00e122a2019-10-05 11:10:57 -04002294 def test_lfs_enabled(self):
2295 import shutil
2296
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002297 uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir
Brad Bishop00e122a2019-10-05 11:10:57 -04002298 self.d.setVar('SRC_URI', uri)
2299
Patrick Williamsac13d5f2023-11-24 18:59:46 -06002300 # With git-lfs installed, test that we can fetch and unpack
2301 fetcher, ud = self.fetch()
2302 shutil.rmtree(self.gitdir, ignore_errors=True)
2303 fetcher.unpack(self.d.getVar('WORKDIR'))
2304
2305 @skipIfNoGitLFS()
2306 def test_lfs_disabled(self):
2307 import shutil
2308
2309 uri = 'git://%s;protocol=file;lfs=0;branch=master' % self.srcdir
2310 self.d.setVar('SRC_URI', uri)
2311
2312 # Verify that the fetcher can survive even if the source
2313 # repository has Git LFS usage configured.
2314 fetcher, ud = self.fetch()
2315 fetcher.unpack(self.d.getVar('WORKDIR'))
2316
2317 def test_lfs_enabled_not_installed(self):
2318 import shutil
2319
2320 uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir
2321 self.d.setVar('SRC_URI', uri)
2322
2323 # Careful: suppress initial attempt at downloading
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002324 fetcher, ud = self.fetch(uri=None, download=False)
Brad Bishop00e122a2019-10-05 11:10:57 -04002325
Patrick Williamsac13d5f2023-11-24 18:59:46 -06002326 # Artificially assert that git-lfs is not installed, so
2327 # we can verify a failure to unpack in it's absence.
Andrew Geissler6aa7eec2023-03-03 12:41:14 -06002328 old_find_git_lfs = ud.method._find_git_lfs
2329 try:
2330 # If git-lfs cannot be found, the unpack should throw an error
2331 with self.assertRaises(bb.fetch2.FetchError):
2332 fetcher.download()
2333 ud.method._find_git_lfs = lambda d: False
2334 shutil.rmtree(self.gitdir, ignore_errors=True)
2335 fetcher.unpack(self.d.getVar('WORKDIR'))
2336 finally:
2337 ud.method._find_git_lfs = old_find_git_lfs
Brad Bishop00e122a2019-10-05 11:10:57 -04002338
Patrick Williamsac13d5f2023-11-24 18:59:46 -06002339 def test_lfs_disabled_not_installed(self):
Brad Bishop00e122a2019-10-05 11:10:57 -04002340 import shutil
2341
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002342 uri = 'git://%s;protocol=file;lfs=0;branch=master' % self.srcdir
Brad Bishop00e122a2019-10-05 11:10:57 -04002343 self.d.setVar('SRC_URI', uri)
2344
Patrick Williamsac13d5f2023-11-24 18:59:46 -06002345 # Careful: suppress initial attempt at downloading
2346 fetcher, ud = self.fetch(uri=None, download=False)
Brad Bishop00e122a2019-10-05 11:10:57 -04002347
Patrick Williamsac13d5f2023-11-24 18:59:46 -06002348 # Artificially assert that git-lfs is not installed, so
2349 # we can verify a failure to unpack in it's absence.
Andrew Geissler6aa7eec2023-03-03 12:41:14 -06002350 old_find_git_lfs = ud.method._find_git_lfs
2351 try:
Patrick Williamsac13d5f2023-11-24 18:59:46 -06002352 # Even if git-lfs cannot be found, the unpack should be successful
2353 fetcher.download()
Andrew Geissler6aa7eec2023-03-03 12:41:14 -06002354 ud.method._find_git_lfs = lambda d: False
2355 shutil.rmtree(self.gitdir, ignore_errors=True)
2356 fetcher.unpack(self.d.getVar('WORKDIR'))
2357 finally:
2358 ud.method._find_git_lfs = old_find_git_lfs
Andrew Geissler82c905d2020-04-13 13:39:40 -05002359
Andrew Geisslerc3d88e42020-10-02 09:45:00 -05002360class GitURLWithSpacesTest(FetcherTest):
2361 test_git_urls = {
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002362 "git://tfs-example.org:22/tfs/example%20path/example.git;branch=master" : {
2363 'url': 'git://tfs-example.org:22/tfs/example%20path/example.git;branch=master',
Andrew Geisslerc3d88e42020-10-02 09:45:00 -05002364 'gitsrcname': 'tfs-example.org.22.tfs.example_path.example.git',
2365 'path': '/tfs/example path/example.git'
2366 },
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002367 "git://tfs-example.org:22/tfs/example%20path/example%20repo.git;branch=master" : {
2368 'url': 'git://tfs-example.org:22/tfs/example%20path/example%20repo.git;branch=master',
Andrew Geisslerc3d88e42020-10-02 09:45:00 -05002369 'gitsrcname': 'tfs-example.org.22.tfs.example_path.example_repo.git',
2370 'path': '/tfs/example path/example repo.git'
2371 }
2372 }
2373
2374 def test_urls(self):
2375
2376 # Set fake SRCREV to stop git fetcher from trying to contact non-existent git repo
2377 self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
2378
2379 for test_git_url, ref in self.test_git_urls.items():
2380
2381 fetcher = bb.fetch.Fetch([test_git_url], self.d)
2382 ud = fetcher.ud[fetcher.urls[0]]
2383
2384 self.assertEqual(ud.url, ref['url'])
2385 self.assertEqual(ud.path, ref['path'])
2386 self.assertEqual(ud.localfile, os.path.join(self.dldir, "git2", ref['gitsrcname']))
2387 self.assertEqual(ud.localpath, os.path.join(self.dldir, "git2", ref['gitsrcname']))
2388 self.assertEqual(ud.lockfile, os.path.join(self.dldir, "git2", ref['gitsrcname'] + '.lock'))
2389 self.assertEqual(ud.clonedir, os.path.join(self.dldir, "git2", ref['gitsrcname']))
2390 self.assertEqual(ud.fullmirror, os.path.join(self.dldir, "git2_" + ref['gitsrcname'] + '.tar.gz'))
2391
Andrew Geissler595f6302022-01-24 19:11:47 +00002392class CrateTest(FetcherTest):
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002393 @skipIfNoNetwork()
Andrew Geissler595f6302022-01-24 19:11:47 +00002394 def test_crate_url(self):
2395
2396 uri = "crate://crates.io/glob/0.2.11"
2397 self.d.setVar('SRC_URI', uri)
2398
2399 uris = self.d.getVar('SRC_URI').split()
2400 d = self.d
2401
2402 fetcher = bb.fetch2.Fetch(uris, self.d)
Andrew Geisslerfc113ea2023-03-31 09:59:46 -05002403 ud = fetcher.ud[fetcher.urls[0]]
2404
2405 self.assertIn("name", ud.parm)
Patrick Williams8e7b46e2023-05-01 14:19:06 -05002406 self.assertEqual(ud.parm["name"], "glob-0.2.11")
Andrew Geisslerfc113ea2023-03-31 09:59:46 -05002407 self.assertIn("downloadfilename", ud.parm)
2408 self.assertEqual(ud.parm["downloadfilename"], "glob-0.2.11.crate")
2409
Andrew Geissler595f6302022-01-24 19:11:47 +00002410 fetcher.download()
2411 fetcher.unpack(self.tempdir)
2412 self.assertEqual(sorted(os.listdir(self.tempdir)), ['cargo_home', 'download' , 'unpacked'])
2413 self.assertEqual(sorted(os.listdir(self.tempdir + "/download")), ['glob-0.2.11.crate', 'glob-0.2.11.crate.done'])
2414 self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/glob-0.2.11/.cargo-checksum.json"))
2415 self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/glob-0.2.11/src/lib.rs"))
2416
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002417 @skipIfNoNetwork()
Patrick Williamse760df82023-05-26 11:10:49 -05002418 def test_crate_url_matching_recipe(self):
2419
2420 self.d.setVar('BP', 'glob-0.2.11')
2421
2422 uri = "crate://crates.io/glob/0.2.11"
2423 self.d.setVar('SRC_URI', uri)
2424
2425 uris = self.d.getVar('SRC_URI').split()
2426 d = self.d
2427
2428 fetcher = bb.fetch2.Fetch(uris, self.d)
2429 ud = fetcher.ud[fetcher.urls[0]]
2430
2431 self.assertIn("name", ud.parm)
2432 self.assertEqual(ud.parm["name"], "glob-0.2.11")
2433 self.assertIn("downloadfilename", ud.parm)
2434 self.assertEqual(ud.parm["downloadfilename"], "glob-0.2.11.crate")
2435
2436 fetcher.download()
2437 fetcher.unpack(self.tempdir)
2438 self.assertEqual(sorted(os.listdir(self.tempdir)), ['download', 'glob-0.2.11', 'unpacked'])
2439 self.assertEqual(sorted(os.listdir(self.tempdir + "/download")), ['glob-0.2.11.crate', 'glob-0.2.11.crate.done'])
2440 self.assertTrue(os.path.exists(self.tempdir + "/glob-0.2.11/src/lib.rs"))
2441
2442 @skipIfNoNetwork()
Andrew Geisslerfc113ea2023-03-31 09:59:46 -05002443 def test_crate_url_params(self):
2444
2445 uri = "crate://crates.io/aho-corasick/0.7.20;name=aho-corasick-renamed"
2446 self.d.setVar('SRC_URI', uri)
2447
2448 uris = self.d.getVar('SRC_URI').split()
2449 d = self.d
2450
2451 fetcher = bb.fetch2.Fetch(uris, self.d)
2452 ud = fetcher.ud[fetcher.urls[0]]
2453
2454 self.assertIn("name", ud.parm)
2455 self.assertEqual(ud.parm["name"], "aho-corasick-renamed")
2456 self.assertIn("downloadfilename", ud.parm)
2457 self.assertEqual(ud.parm["downloadfilename"], "aho-corasick-0.7.20.crate")
2458
2459 fetcher.download()
2460 fetcher.unpack(self.tempdir)
2461 self.assertEqual(sorted(os.listdir(self.tempdir)), ['cargo_home', 'download' , 'unpacked'])
2462 self.assertEqual(sorted(os.listdir(self.tempdir + "/download")), ['aho-corasick-0.7.20.crate', 'aho-corasick-0.7.20.crate.done'])
2463 self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/aho-corasick-0.7.20/.cargo-checksum.json"))
2464 self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/aho-corasick-0.7.20/src/lib.rs"))
2465
2466 @skipIfNoNetwork()
Andrew Geissler595f6302022-01-24 19:11:47 +00002467 def test_crate_url_multi(self):
2468
2469 uri = "crate://crates.io/glob/0.2.11 crate://crates.io/time/0.1.35"
2470 self.d.setVar('SRC_URI', uri)
2471
2472 uris = self.d.getVar('SRC_URI').split()
2473 d = self.d
2474
2475 fetcher = bb.fetch2.Fetch(uris, self.d)
Andrew Geisslerfc113ea2023-03-31 09:59:46 -05002476 ud = fetcher.ud[fetcher.urls[0]]
2477
2478 self.assertIn("name", ud.parm)
Patrick Williams8e7b46e2023-05-01 14:19:06 -05002479 self.assertEqual(ud.parm["name"], "glob-0.2.11")
Andrew Geisslerfc113ea2023-03-31 09:59:46 -05002480 self.assertIn("downloadfilename", ud.parm)
2481 self.assertEqual(ud.parm["downloadfilename"], "glob-0.2.11.crate")
2482
2483 ud = fetcher.ud[fetcher.urls[1]]
2484 self.assertIn("name", ud.parm)
Patrick Williams8e7b46e2023-05-01 14:19:06 -05002485 self.assertEqual(ud.parm["name"], "time-0.1.35")
Andrew Geisslerfc113ea2023-03-31 09:59:46 -05002486 self.assertIn("downloadfilename", ud.parm)
2487 self.assertEqual(ud.parm["downloadfilename"], "time-0.1.35.crate")
2488
Andrew Geissler595f6302022-01-24 19:11:47 +00002489 fetcher.download()
2490 fetcher.unpack(self.tempdir)
2491 self.assertEqual(sorted(os.listdir(self.tempdir)), ['cargo_home', 'download' , 'unpacked'])
2492 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'])
2493 self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/glob-0.2.11/.cargo-checksum.json"))
2494 self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/glob-0.2.11/src/lib.rs"))
2495 self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/time-0.1.35/.cargo-checksum.json"))
2496 self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/time-0.1.35/src/lib.rs"))
2497
Andrew Geisslerfc113ea2023-03-31 09:59:46 -05002498 @skipIfNoNetwork()
2499 def test_crate_incorrect_cksum(self):
2500 uri = "crate://crates.io/aho-corasick/0.7.20"
2501 self.d.setVar('SRC_URI', uri)
Patrick Williams8e7b46e2023-05-01 14:19:06 -05002502 self.d.setVarFlag("SRC_URI", "aho-corasick-0.7.20.sha256sum", hashlib.sha256("Invalid".encode("utf-8")).hexdigest())
Andrew Geisslerfc113ea2023-03-31 09:59:46 -05002503
2504 uris = self.d.getVar('SRC_URI').split()
2505
2506 fetcher = bb.fetch2.Fetch(uris, self.d)
Andrew Geissler8f840682023-07-21 09:09:43 -05002507 with self.assertRaisesRegex(bb.fetch2.FetchError, "Fetcher failure for URL"):
Andrew Geisslerfc113ea2023-03-31 09:59:46 -05002508 fetcher.download()
2509
Andrew Geissler82c905d2020-04-13 13:39:40 -05002510class NPMTest(FetcherTest):
2511 def skipIfNoNpm():
2512 import shutil
2513 if not shutil.which('npm'):
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002514 return unittest.skip('npm not installed')
Andrew Geissler82c905d2020-04-13 13:39:40 -05002515 return lambda f: f
2516
2517 @skipIfNoNpm()
2518 @skipIfNoNetwork()
2519 def test_npm(self):
2520 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2521 fetcher = bb.fetch.Fetch([url], self.d)
2522 ud = fetcher.ud[fetcher.urls[0]]
2523 fetcher.download()
2524 self.assertTrue(os.path.exists(ud.localpath))
2525 self.assertTrue(os.path.exists(ud.localpath + '.done'))
2526 self.assertTrue(os.path.exists(ud.resolvefile))
2527 fetcher.unpack(self.unpackdir)
2528 unpackdir = os.path.join(self.unpackdir, 'npm')
2529 self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
2530
2531 @skipIfNoNpm()
2532 @skipIfNoNetwork()
2533 def test_npm_bad_checksum(self):
2534 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2535 # Fetch once to get a tarball
2536 fetcher = bb.fetch.Fetch([url], self.d)
2537 ud = fetcher.ud[fetcher.urls[0]]
2538 fetcher.download()
2539 self.assertTrue(os.path.exists(ud.localpath))
2540 # Modify the tarball
2541 bad = b'bad checksum'
2542 with open(ud.localpath, 'wb') as f:
2543 f.write(bad)
2544 # Verify that the tarball is fetched again
2545 fetcher.download()
2546 badsum = hashlib.sha512(bad).hexdigest()
2547 self.assertTrue(os.path.exists(ud.localpath + '_bad-checksum_' + badsum))
2548 self.assertTrue(os.path.exists(ud.localpath))
2549
2550 @skipIfNoNpm()
2551 @skipIfNoNetwork()
2552 def test_npm_premirrors(self):
2553 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2554 # Fetch once to get a tarball
2555 fetcher = bb.fetch.Fetch([url], self.d)
2556 ud = fetcher.ud[fetcher.urls[0]]
2557 fetcher.download()
2558 self.assertTrue(os.path.exists(ud.localpath))
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002559
2560 # Setup the mirror by renaming the download directory
Andrew Geissler82c905d2020-04-13 13:39:40 -05002561 mirrordir = os.path.join(self.tempdir, 'mirror')
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002562 bb.utils.rename(self.dldir, mirrordir)
2563 os.mkdir(self.dldir)
2564
2565 # Configure the premirror to be used
2566 self.d.setVar('PREMIRRORS', 'https?$://.*/.* file://%s/npm2' % mirrordir)
Andrew Geissler82c905d2020-04-13 13:39:40 -05002567 self.d.setVar('BB_FETCH_PREMIRRORONLY', '1')
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002568
Andrew Geissler82c905d2020-04-13 13:39:40 -05002569 # Fetch again
2570 self.assertFalse(os.path.exists(ud.localpath))
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002571 # The npm fetcher doesn't handle that the .resolved file disappears
2572 # while the fetcher object exists, which it does when we rename the
2573 # download directory to "mirror" above. Thus we need a new fetcher to go
2574 # with the now empty download directory.
2575 fetcher = bb.fetch.Fetch([url], self.d)
2576 ud = fetcher.ud[fetcher.urls[0]]
Andrew Geissler82c905d2020-04-13 13:39:40 -05002577 fetcher.download()
2578 self.assertTrue(os.path.exists(ud.localpath))
2579
2580 @skipIfNoNpm()
2581 @skipIfNoNetwork()
Andrew Geissler5199d832021-09-24 16:47:35 -05002582 def test_npm_premirrors_with_specified_filename(self):
2583 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2584 # Fetch once to get a tarball
2585 fetcher = bb.fetch.Fetch([url], self.d)
2586 ud = fetcher.ud[fetcher.urls[0]]
2587 fetcher.download()
2588 self.assertTrue(os.path.exists(ud.localpath))
2589 # Setup the mirror
2590 mirrordir = os.path.join(self.tempdir, 'mirror')
2591 bb.utils.mkdirhier(mirrordir)
2592 mirrorfilename = os.path.join(mirrordir, os.path.basename(ud.localpath))
2593 os.replace(ud.localpath, mirrorfilename)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002594 self.d.setVar('PREMIRRORS', 'https?$://.*/.* file://%s' % mirrorfilename)
Andrew Geissler5199d832021-09-24 16:47:35 -05002595 self.d.setVar('BB_FETCH_PREMIRRORONLY', '1')
2596 # Fetch again
2597 self.assertFalse(os.path.exists(ud.localpath))
2598 fetcher.download()
2599 self.assertTrue(os.path.exists(ud.localpath))
2600
2601 @skipIfNoNpm()
2602 @skipIfNoNetwork()
Andrew Geissler82c905d2020-04-13 13:39:40 -05002603 def test_npm_mirrors(self):
2604 # Fetch once to get a tarball
2605 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2606 fetcher = bb.fetch.Fetch([url], self.d)
2607 ud = fetcher.ud[fetcher.urls[0]]
2608 fetcher.download()
2609 self.assertTrue(os.path.exists(ud.localpath))
2610 # Setup the mirror
2611 mirrordir = os.path.join(self.tempdir, 'mirror')
2612 bb.utils.mkdirhier(mirrordir)
2613 os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath)))
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002614 self.d.setVar('MIRRORS', 'https?$://.*/.* file://%s/' % mirrordir)
Andrew Geissler82c905d2020-04-13 13:39:40 -05002615 # Update the resolved url to an invalid url
2616 with open(ud.resolvefile, 'r') as f:
2617 url = f.read()
2618 uri = URI(url)
2619 uri.path = '/invalid'
2620 with open(ud.resolvefile, 'w') as f:
2621 f.write(str(uri))
2622 # Fetch again
2623 self.assertFalse(os.path.exists(ud.localpath))
2624 fetcher.download()
2625 self.assertTrue(os.path.exists(ud.localpath))
2626
2627 @skipIfNoNpm()
2628 @skipIfNoNetwork()
2629 def test_npm_destsuffix_downloadfilename(self):
2630 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0;destsuffix=foo/bar;downloadfilename=foo-bar.tgz'
2631 fetcher = bb.fetch.Fetch([url], self.d)
2632 fetcher.download()
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002633 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'foo-bar.tgz')))
Andrew Geissler82c905d2020-04-13 13:39:40 -05002634 fetcher.unpack(self.unpackdir)
2635 unpackdir = os.path.join(self.unpackdir, 'foo', 'bar')
2636 self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
2637
2638 def test_npm_no_network_no_tarball(self):
2639 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2640 self.d.setVar('BB_NO_NETWORK', '1')
2641 fetcher = bb.fetch.Fetch([url], self.d)
2642 with self.assertRaises(bb.fetch2.NetworkAccess):
2643 fetcher.download()
2644
2645 @skipIfNoNpm()
2646 @skipIfNoNetwork()
2647 def test_npm_no_network_with_tarball(self):
2648 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2649 # Fetch once to get a tarball
2650 fetcher = bb.fetch.Fetch([url], self.d)
2651 fetcher.download()
2652 # Disable network access
2653 self.d.setVar('BB_NO_NETWORK', '1')
2654 # Fetch again
2655 fetcher.download()
2656 fetcher.unpack(self.unpackdir)
2657 unpackdir = os.path.join(self.unpackdir, 'npm')
2658 self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
2659
2660 @skipIfNoNpm()
2661 @skipIfNoNetwork()
2662 def test_npm_registry_alternate(self):
Andrew Geissler5199d832021-09-24 16:47:35 -05002663 url = 'npm://skimdb.npmjs.com;package=@savoirfairelinux/node-server-example;version=1.0.0'
Andrew Geissler82c905d2020-04-13 13:39:40 -05002664 fetcher = bb.fetch.Fetch([url], self.d)
2665 fetcher.download()
2666 fetcher.unpack(self.unpackdir)
2667 unpackdir = os.path.join(self.unpackdir, 'npm')
2668 self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
2669
2670 @skipIfNoNpm()
2671 @skipIfNoNetwork()
2672 def test_npm_version_latest(self):
2673 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=latest'
2674 fetcher = bb.fetch.Fetch([url], self.d)
2675 fetcher.download()
2676 fetcher.unpack(self.unpackdir)
2677 unpackdir = os.path.join(self.unpackdir, 'npm')
2678 self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
2679
2680 @skipIfNoNpm()
2681 @skipIfNoNetwork()
2682 def test_npm_registry_invalid(self):
2683 url = 'npm://registry.invalid.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2684 fetcher = bb.fetch.Fetch([url], self.d)
2685 with self.assertRaises(bb.fetch2.FetchError):
2686 fetcher.download()
2687
2688 @skipIfNoNpm()
2689 @skipIfNoNetwork()
2690 def test_npm_package_invalid(self):
2691 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/invalid;version=1.0.0'
2692 fetcher = bb.fetch.Fetch([url], self.d)
2693 with self.assertRaises(bb.fetch2.FetchError):
2694 fetcher.download()
2695
2696 @skipIfNoNpm()
2697 @skipIfNoNetwork()
2698 def test_npm_version_invalid(self):
2699 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=invalid'
2700 with self.assertRaises(bb.fetch2.ParameterError):
2701 fetcher = bb.fetch.Fetch([url], self.d)
2702
2703 @skipIfNoNpm()
2704 @skipIfNoNetwork()
2705 def test_npm_registry_none(self):
2706 url = 'npm://;package=@savoirfairelinux/node-server-example;version=1.0.0'
2707 with self.assertRaises(bb.fetch2.MalformedUrl):
2708 fetcher = bb.fetch.Fetch([url], self.d)
2709
2710 @skipIfNoNpm()
2711 @skipIfNoNetwork()
2712 def test_npm_package_none(self):
2713 url = 'npm://registry.npmjs.org;version=1.0.0'
2714 with self.assertRaises(bb.fetch2.MissingParameterError):
2715 fetcher = bb.fetch.Fetch([url], self.d)
2716
2717 @skipIfNoNpm()
2718 @skipIfNoNetwork()
2719 def test_npm_version_none(self):
2720 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example'
2721 with self.assertRaises(bb.fetch2.MissingParameterError):
2722 fetcher = bb.fetch.Fetch([url], self.d)
2723
2724 def create_shrinkwrap_file(self, data):
2725 import json
2726 datadir = os.path.join(self.tempdir, 'data')
2727 swfile = os.path.join(datadir, 'npm-shrinkwrap.json')
2728 bb.utils.mkdirhier(datadir)
2729 with open(swfile, 'w') as f:
2730 json.dump(data, f)
2731 # Also configure the S directory
2732 self.sdir = os.path.join(self.unpackdir, 'S')
2733 self.d.setVar('S', self.sdir)
2734 return swfile
2735
2736 @skipIfNoNpm()
2737 @skipIfNoNetwork()
2738 def test_npmsw(self):
2739 swfile = self.create_shrinkwrap_file({
2740 'dependencies': {
2741 'array-flatten': {
2742 'version': '1.1.1',
2743 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2744 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=',
2745 'dependencies': {
2746 'content-type': {
2747 'version': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz',
2748 'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==',
2749 'dependencies': {
2750 'cookie': {
2751 'version': 'git+https://github.com/jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09',
2752 'from': 'git+https://github.com/jshttp/cookie.git'
2753 }
2754 }
2755 }
2756 }
2757 }
2758 }
2759 })
2760 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2761 fetcher.download()
2762 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')))
2763 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz')))
2764 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'github.com.jshttp.cookie.git')))
2765 fetcher.unpack(self.unpackdir)
2766 self.assertTrue(os.path.exists(os.path.join(self.sdir, 'npm-shrinkwrap.json')))
2767 self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'package.json')))
2768 self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'node_modules', 'content-type', 'package.json')))
2769 self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'node_modules', 'content-type', 'node_modules', 'cookie', 'package.json')))
2770
2771 @skipIfNoNpm()
2772 @skipIfNoNetwork()
Andrew Geissler6aa7eec2023-03-03 12:41:14 -06002773 def test_npmsw_git(self):
2774 swfile = self.create_shrinkwrap_file({
2775 'dependencies': {
2776 'cookie': {
2777 'version': 'github:jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09',
2778 'from': 'github:jshttp/cookie.git'
2779 }
2780 }
2781 })
2782 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2783 fetcher.download()
2784 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'github.com.jshttp.cookie.git')))
2785
2786 swfile = self.create_shrinkwrap_file({
2787 'dependencies': {
2788 'cookie': {
2789 'version': 'jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09',
2790 'from': 'jshttp/cookie.git'
2791 }
2792 }
2793 })
2794 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2795 fetcher.download()
2796 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'github.com.jshttp.cookie.git')))
2797
2798 swfile = self.create_shrinkwrap_file({
2799 'dependencies': {
2800 'nodejs': {
2801 'version': 'gitlab:gitlab-examples/nodejs.git#892a1f16725e56cc3a2cb0d677be42935c8fc262',
2802 'from': 'gitlab:gitlab-examples/nodejs'
2803 }
2804 }
2805 })
2806 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2807 fetcher.download()
2808 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'gitlab.com.gitlab-examples.nodejs.git')))
2809
2810 @skipIfNoNpm()
2811 @skipIfNoNetwork()
Andrew Geissler82c905d2020-04-13 13:39:40 -05002812 def test_npmsw_dev(self):
2813 swfile = self.create_shrinkwrap_file({
2814 'dependencies': {
2815 'array-flatten': {
2816 'version': '1.1.1',
2817 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2818 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
2819 },
2820 'content-type': {
2821 'version': '1.0.4',
2822 'resolved': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz',
2823 'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==',
2824 'dev': True
2825 }
2826 }
2827 })
2828 # Fetch with dev disabled
2829 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2830 fetcher.download()
2831 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')))
2832 self.assertFalse(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz')))
2833 # Fetch with dev enabled
2834 fetcher = bb.fetch.Fetch(['npmsw://' + swfile + ';dev=1'], self.d)
2835 fetcher.download()
2836 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')))
2837 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz')))
2838
2839 @skipIfNoNpm()
2840 @skipIfNoNetwork()
2841 def test_npmsw_destsuffix(self):
2842 swfile = self.create_shrinkwrap_file({
2843 'dependencies': {
2844 'array-flatten': {
2845 'version': '1.1.1',
2846 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2847 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
2848 }
2849 }
2850 })
2851 fetcher = bb.fetch.Fetch(['npmsw://' + swfile + ';destsuffix=foo/bar'], self.d)
2852 fetcher.download()
2853 fetcher.unpack(self.unpackdir)
2854 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'foo', 'bar', 'node_modules', 'array-flatten', 'package.json')))
2855
2856 def test_npmsw_no_network_no_tarball(self):
2857 swfile = self.create_shrinkwrap_file({
2858 'dependencies': {
2859 'array-flatten': {
2860 'version': '1.1.1',
2861 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2862 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
2863 }
2864 }
2865 })
2866 self.d.setVar('BB_NO_NETWORK', '1')
2867 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2868 with self.assertRaises(bb.fetch2.NetworkAccess):
2869 fetcher.download()
2870
2871 @skipIfNoNpm()
2872 @skipIfNoNetwork()
2873 def test_npmsw_no_network_with_tarball(self):
2874 # Fetch once to get a tarball
2875 fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d)
2876 fetcher.download()
2877 # Disable network access
2878 self.d.setVar('BB_NO_NETWORK', '1')
2879 # Fetch again
2880 swfile = self.create_shrinkwrap_file({
2881 'dependencies': {
2882 'array-flatten': {
2883 'version': '1.1.1',
2884 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2885 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
2886 }
2887 }
2888 })
2889 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2890 fetcher.download()
2891 fetcher.unpack(self.unpackdir)
2892 self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'package.json')))
2893
2894 @skipIfNoNpm()
2895 @skipIfNoNetwork()
2896 def test_npmsw_npm_reusability(self):
2897 # Fetch once with npmsw
2898 swfile = self.create_shrinkwrap_file({
2899 'dependencies': {
2900 'array-flatten': {
2901 'version': '1.1.1',
2902 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2903 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
2904 }
2905 }
2906 })
2907 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2908 fetcher.download()
2909 # Disable network access
2910 self.d.setVar('BB_NO_NETWORK', '1')
2911 # Fetch again with npm
2912 fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d)
2913 fetcher.download()
2914 fetcher.unpack(self.unpackdir)
2915 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'npm', 'package.json')))
2916
2917 @skipIfNoNpm()
2918 @skipIfNoNetwork()
2919 def test_npmsw_bad_checksum(self):
2920 # Try to fetch with bad checksum
2921 swfile = self.create_shrinkwrap_file({
2922 'dependencies': {
2923 'array-flatten': {
2924 'version': '1.1.1',
2925 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2926 'integrity': 'sha1-gfNEp2hqgLTFKT6P3AsBYMgsBqg='
2927 }
2928 }
2929 })
2930 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2931 with self.assertRaises(bb.fetch2.FetchError):
2932 fetcher.download()
2933 # Fetch correctly to get a tarball
2934 swfile = self.create_shrinkwrap_file({
2935 'dependencies': {
2936 'array-flatten': {
2937 'version': '1.1.1',
2938 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2939 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
2940 }
2941 }
2942 })
2943 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2944 fetcher.download()
2945 localpath = os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')
2946 self.assertTrue(os.path.exists(localpath))
2947 # Modify the tarball
2948 bad = b'bad checksum'
2949 with open(localpath, 'wb') as f:
2950 f.write(bad)
2951 # Verify that the tarball is fetched again
2952 fetcher.download()
2953 badsum = hashlib.sha1(bad).hexdigest()
2954 self.assertTrue(os.path.exists(localpath + '_bad-checksum_' + badsum))
2955 self.assertTrue(os.path.exists(localpath))
2956
2957 @skipIfNoNpm()
2958 @skipIfNoNetwork()
2959 def test_npmsw_premirrors(self):
2960 # Fetch once to get a tarball
2961 fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d)
2962 ud = fetcher.ud[fetcher.urls[0]]
2963 fetcher.download()
2964 self.assertTrue(os.path.exists(ud.localpath))
2965 # Setup the mirror
2966 mirrordir = os.path.join(self.tempdir, 'mirror')
2967 bb.utils.mkdirhier(mirrordir)
2968 os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath)))
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002969 self.d.setVar('PREMIRRORS', 'https?$://.*/.* file://%s/' % mirrordir)
Andrew Geissler82c905d2020-04-13 13:39:40 -05002970 self.d.setVar('BB_FETCH_PREMIRRORONLY', '1')
2971 # Fetch again
2972 self.assertFalse(os.path.exists(ud.localpath))
2973 swfile = self.create_shrinkwrap_file({
2974 'dependencies': {
2975 'array-flatten': {
2976 'version': '1.1.1',
2977 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2978 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
2979 }
2980 }
2981 })
2982 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2983 fetcher.download()
2984 self.assertTrue(os.path.exists(ud.localpath))
2985
2986 @skipIfNoNpm()
2987 @skipIfNoNetwork()
2988 def test_npmsw_mirrors(self):
2989 # Fetch once to get a tarball
2990 fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d)
2991 ud = fetcher.ud[fetcher.urls[0]]
2992 fetcher.download()
2993 self.assertTrue(os.path.exists(ud.localpath))
2994 # Setup the mirror
2995 mirrordir = os.path.join(self.tempdir, 'mirror')
2996 bb.utils.mkdirhier(mirrordir)
2997 os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath)))
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002998 self.d.setVar('MIRRORS', 'https?$://.*/.* file://%s/' % mirrordir)
Andrew Geissler82c905d2020-04-13 13:39:40 -05002999 # Fetch again with invalid url
3000 self.assertFalse(os.path.exists(ud.localpath))
3001 swfile = self.create_shrinkwrap_file({
3002 'dependencies': {
3003 'array-flatten': {
3004 'version': '1.1.1',
3005 'resolved': 'https://invalid',
3006 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
3007 }
3008 }
3009 })
3010 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
3011 fetcher.download()
3012 self.assertTrue(os.path.exists(ud.localpath))
Andrew Geisslerc926e172021-05-07 16:11:35 -05003013
3014class GitSharedTest(FetcherTest):
3015 def setUp(self):
3016 super(GitSharedTest, self).setUp()
Andrew Geissler028142b2023-05-05 11:29:21 -05003017 self.recipe_url = "git://git.openembedded.org/bitbake;branch=master;protocol=https"
Andrew Geisslerc926e172021-05-07 16:11:35 -05003018 self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
Andrew Geisslerfc113ea2023-03-31 09:59:46 -05003019 self.d.setVar("__BBSRCREV_SEEN", "1")
Andrew Geisslerc926e172021-05-07 16:11:35 -05003020
3021 @skipIfNoNetwork()
3022 def test_shared_unpack(self):
3023 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3024
3025 fetcher.download()
3026 fetcher.unpack(self.unpackdir)
3027 alt = os.path.join(self.unpackdir, 'git/.git/objects/info/alternates')
3028 self.assertTrue(os.path.exists(alt))
3029
3030 @skipIfNoNetwork()
3031 def test_noshared_unpack(self):
3032 self.d.setVar('BB_GIT_NOSHARED', '1')
3033 self.unpackdir += '_noshared'
3034 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3035
3036 fetcher.download()
3037 fetcher.unpack(self.unpackdir)
3038 alt = os.path.join(self.unpackdir, 'git/.git/objects/info/alternates')
3039 self.assertFalse(os.path.exists(alt))
Andrew Geissler78b72792022-06-14 06:47:25 -05003040
3041
3042class FetchPremirroronlyLocalTest(FetcherTest):
3043
3044 def setUp(self):
3045 super(FetchPremirroronlyLocalTest, self).setUp()
3046 self.mirrordir = os.path.join(self.tempdir, "mirrors")
3047 os.mkdir(self.mirrordir)
3048 self.reponame = "bitbake"
3049 self.gitdir = os.path.join(self.tempdir, "git", self.reponame)
Andrew Geissler028142b2023-05-05 11:29:21 -05003050 self.recipe_url = "git://git.fake.repo/bitbake;branch=master;protocol=https"
Andrew Geissler78b72792022-06-14 06:47:25 -05003051 self.d.setVar("BB_FETCH_PREMIRRORONLY", "1")
3052 self.d.setVar("BB_NO_NETWORK", "1")
3053 self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n")
Patrick Williamsac13d5f2023-11-24 18:59:46 -06003054 self.mirrorname = "git2_git.fake.repo.bitbake.tar.gz"
3055 self.mirrorfile = os.path.join(self.mirrordir, self.mirrorname)
3056 self.testfilename = "bitbake-fetch.test"
Andrew Geissler78b72792022-06-14 06:47:25 -05003057
3058 def make_git_repo(self):
Andrew Geissler78b72792022-06-14 06:47:25 -05003059 recipeurl = "git:/git.fake.repo/bitbake"
3060 os.makedirs(self.gitdir)
Andrew Geissler8f840682023-07-21 09:09:43 -05003061 self.git_init(cwd=self.gitdir)
Andrew Geissler78b72792022-06-14 06:47:25 -05003062 for i in range(0):
3063 self.git_new_commit()
3064 bb.process.run('tar -czvf {} .'.format(os.path.join(self.mirrordir, self.mirrorname)), cwd = self.gitdir)
3065
3066 def git_new_commit(self):
3067 import random
Andrew Geissler78b72792022-06-14 06:47:25 -05003068 os.unlink(os.path.join(self.mirrordir, self.mirrorname))
Patrick Williamsac13d5f2023-11-24 18:59:46 -06003069 branch = self.git("branch --show-current", self.gitdir).split()
3070 with open(os.path.join(self.gitdir, self.testfilename), "w") as testfile:
3071 testfile.write("File {} from branch {}; Useless random data {}".format(self.testfilename, branch, random.random()))
3072 self.git("add {}".format(self.testfilename), self.gitdir)
3073 self.git("commit -a -m \"This random commit {} in branch {}. I'm useless.\"".format(random.random(), branch), self.gitdir)
Andrew Geissler78b72792022-06-14 06:47:25 -05003074 bb.process.run('tar -czvf {} .'.format(os.path.join(self.mirrordir, self.mirrorname)), cwd = self.gitdir)
3075 return self.git("rev-parse HEAD", self.gitdir).strip()
3076
Patrick Williamsac13d5f2023-11-24 18:59:46 -06003077 def git_new_branch(self, name):
3078 self.git_new_commit()
3079 head = self.git("rev-parse HEAD", self.gitdir).strip()
3080 self.git("checkout -b {}".format(name), self.gitdir)
3081 newrev = self.git_new_commit()
3082 self.git("checkout {}".format(head), self.gitdir)
3083 return newrev
3084
Andrew Geissler78b72792022-06-14 06:47:25 -05003085 def test_mirror_commit_nonexistent(self):
3086 self.make_git_repo()
3087 self.d.setVar("SRCREV", "0"*40)
3088 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3089 with self.assertRaises(bb.fetch2.NetworkAccess):
3090 fetcher.download()
3091
3092 def test_mirror_commit_exists(self):
3093 self.make_git_repo()
3094 self.d.setVar("SRCREV", self.git_new_commit())
3095 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3096 fetcher.download()
3097 fetcher.unpack(self.unpackdir)
3098
3099 def test_mirror_tarball_nonexistent(self):
3100 self.d.setVar("SRCREV", "0"*40)
3101 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3102 with self.assertRaises(bb.fetch2.NetworkAccess):
3103 fetcher.download()
3104
Patrick Williamsac13d5f2023-11-24 18:59:46 -06003105 def test_mirror_tarball_multiple_branches(self):
3106 """
3107 test if PREMIRRORS can handle multiple name/branches correctly
3108 both branches have required revisions
3109 """
3110 self.make_git_repo()
3111 branch1rev = self.git_new_branch("testbranch1")
3112 branch2rev = self.git_new_branch("testbranch2")
3113 self.recipe_url = "git://git.fake.repo/bitbake;branch=testbranch1,testbranch2;protocol=https;name=branch1,branch2"
3114 self.d.setVar("SRCREV_branch1", branch1rev)
3115 self.d.setVar("SRCREV_branch2", branch2rev)
3116 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3117 self.assertTrue(os.path.exists(self.mirrorfile), "Mirror file doesn't exist")
3118 fetcher.download()
3119 fetcher.unpack(os.path.join(self.tempdir, "unpacked"))
3120 unpacked = os.path.join(self.tempdir, "unpacked", "git", self.testfilename)
3121 self.assertTrue(os.path.exists(unpacked), "Repo has not been unpackaged properly!")
3122 with open(unpacked, 'r') as f:
3123 content = f.read()
3124 ## We expect to see testbranch1 in the file, not master, not testbranch2
3125 self.assertTrue(content.find("testbranch1") != -1, "Wrong branch has been checked out!")
3126
3127 def test_mirror_tarball_multiple_branches_nobranch(self):
3128 """
3129 test if PREMIRRORS can handle multiple name/branches correctly
3130 Unbalanced name/branches raises ParameterError
3131 """
3132 self.make_git_repo()
3133 branch1rev = self.git_new_branch("testbranch1")
3134 branch2rev = self.git_new_branch("testbranch2")
3135 self.recipe_url = "git://git.fake.repo/bitbake;branch=testbranch1;protocol=https;name=branch1,branch2"
3136 self.d.setVar("SRCREV_branch1", branch1rev)
3137 self.d.setVar("SRCREV_branch2", branch2rev)
3138 with self.assertRaises(bb.fetch2.ParameterError):
3139 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3140
3141 def test_mirror_tarball_multiple_branches_norev(self):
3142 """
3143 test if PREMIRRORS can handle multiple name/branches correctly
3144 one of the branches specifies non existing SRCREV
3145 """
3146 self.make_git_repo()
3147 branch1rev = self.git_new_branch("testbranch1")
3148 branch2rev = self.git_new_branch("testbranch2")
3149 self.recipe_url = "git://git.fake.repo/bitbake;branch=testbranch1,testbranch2;protocol=https;name=branch1,branch2"
3150 self.d.setVar("SRCREV_branch1", branch1rev)
3151 self.d.setVar("SRCREV_branch2", "0"*40)
3152 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3153 self.assertTrue(os.path.exists(self.mirrorfile), "Mirror file doesn't exist")
3154 with self.assertRaises(bb.fetch2.NetworkAccess):
3155 fetcher.download()
3156
3157
Andrew Geissler78b72792022-06-14 06:47:25 -05003158class FetchPremirroronlyNetworkTest(FetcherTest):
3159
3160 def setUp(self):
3161 super(FetchPremirroronlyNetworkTest, self).setUp()
3162 self.mirrordir = os.path.join(self.tempdir, "mirrors")
3163 os.mkdir(self.mirrordir)
3164 self.reponame = "fstests"
3165 self.clonedir = os.path.join(self.tempdir, "git")
3166 self.gitdir = os.path.join(self.tempdir, "git", "{}.git".format(self.reponame))
Andrew Geissler028142b2023-05-05 11:29:21 -05003167 self.recipe_url = "git://git.yoctoproject.org/fstests;protocol=https"
Andrew Geissler78b72792022-06-14 06:47:25 -05003168 self.d.setVar("BB_FETCH_PREMIRRORONLY", "1")
3169 self.d.setVar("BB_NO_NETWORK", "0")
3170 self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n")
3171
3172 def make_git_repo(self):
3173 import shutil
3174 self.mirrorname = "git2_git.yoctoproject.org.fstests.tar.gz"
3175 os.makedirs(self.clonedir)
3176 self.git("clone --bare --shallow-since=\"01.01.2013\" {}".format(self.recipe_url), self.clonedir)
3177 bb.process.run('tar -czvf {} .'.format(os.path.join(self.mirrordir, self.mirrorname)), cwd = self.gitdir)
3178 shutil.rmtree(self.clonedir)
3179
3180 @skipIfNoNetwork()
3181 def test_mirror_tarball_updated(self):
3182 self.make_git_repo()
3183 ## Upstream commit is in the mirror
3184 self.d.setVar("SRCREV", "49d65d53c2bf558ae6e9185af0f3af7b79d255ec")
3185 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3186 fetcher.download()
3187
3188 @skipIfNoNetwork()
3189 def test_mirror_tarball_outdated(self):
3190 self.make_git_repo()
3191 ## Upstream commit not in the mirror
3192 self.d.setVar("SRCREV", "15413486df1f5a5b5af699b6f3ba5f0984e52a9f")
3193 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3194 with self.assertRaises(bb.fetch2.NetworkAccess):
3195 fetcher.download()
Andrew Geissler615f2f12022-07-15 14:00:58 -05003196
Andrew Geisslerc5535c92023-01-27 16:10:19 -06003197class FetchPremirroronlyMercurialTest(FetcherTest):
3198 """ Test for premirrors with mercurial repos
3199 the test covers also basic hg:// clone (see fetch_and_create_tarball
3200 """
3201 def skipIfNoHg():
3202 import shutil
3203 if not shutil.which('hg'):
3204 return unittest.skip('Mercurial not installed')
3205 return lambda f: f
3206
3207 def setUp(self):
3208 super(FetchPremirroronlyMercurialTest, self).setUp()
3209 self.mirrordir = os.path.join(self.tempdir, "mirrors")
3210 os.mkdir(self.mirrordir)
3211 self.reponame = "libgnt"
3212 self.clonedir = os.path.join(self.tempdir, "hg")
3213 self.recipe_url = "hg://keep.imfreedom.org/libgnt;module=libgnt"
3214 self.d.setVar("SRCREV", "53e8b422faaf")
3215 self.mirrorname = "hg_libgnt_keep.imfreedom.org_.libgnt.tar.gz"
3216
3217 def fetch_and_create_tarball(self):
3218 """
3219 Ask bitbake to download repo and prepare mirror tarball for us
3220 """
3221 self.d.setVar("BB_GENERATE_MIRROR_TARBALLS", "1")
3222 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3223 fetcher.download()
3224 mirrorfile = os.path.join(self.d.getVar("DL_DIR"), self.mirrorname)
3225 self.assertTrue(os.path.exists(mirrorfile), "Mirror tarball {} has not been created".format(mirrorfile))
3226 ## moving tarball to mirror directory
3227 os.rename(mirrorfile, os.path.join(self.mirrordir, self.mirrorname))
3228 self.d.setVar("BB_GENERATE_MIRROR_TARBALLS", "0")
3229
3230
3231 @skipIfNoNetwork()
3232 @skipIfNoHg()
3233 def test_premirror_mercurial(self):
3234 self.fetch_and_create_tarball()
3235 self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n")
3236 self.d.setVar("BB_FETCH_PREMIRRORONLY", "1")
3237 self.d.setVar("BB_NO_NETWORK", "1")
3238 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3239 fetcher.download()
3240
Andrew Geissler615f2f12022-07-15 14:00:58 -05003241class FetchPremirroronlyBrokenTarball(FetcherTest):
3242
3243 def setUp(self):
3244 super(FetchPremirroronlyBrokenTarball, self).setUp()
3245 self.mirrordir = os.path.join(self.tempdir, "mirrors")
3246 os.mkdir(self.mirrordir)
3247 self.reponame = "bitbake"
3248 self.gitdir = os.path.join(self.tempdir, "git", self.reponame)
Andrew Geissler028142b2023-05-05 11:29:21 -05003249 self.recipe_url = "git://git.fake.repo/bitbake;protocol=https"
Andrew Geissler615f2f12022-07-15 14:00:58 -05003250 self.d.setVar("BB_FETCH_PREMIRRORONLY", "1")
3251 self.d.setVar("BB_NO_NETWORK", "1")
3252 self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n")
3253 self.mirrorname = "git2_git.fake.repo.bitbake.tar.gz"
3254 with open(os.path.join(self.mirrordir, self.mirrorname), 'w') as targz:
3255 targz.write("This is not tar.gz file!")
3256
3257 def test_mirror_broken_download(self):
3258 import sys
3259 self.d.setVar("SRCREV", "0"*40)
3260 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
Andrew Geissler8f840682023-07-21 09:09:43 -05003261 with self.assertRaises(bb.fetch2.FetchError), self.assertLogs() as logs:
Andrew Geissler615f2f12022-07-15 14:00:58 -05003262 fetcher.download()
Andrew Geissler8f840682023-07-21 09:09:43 -05003263 output = "".join(logs.output)
3264 self.assertFalse(" not a git repository (or any parent up to mount point /)" in output)