blob: b4ed691f33194ab7fda108ce53d1149d3851656a [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):
27 pass
28
29class Timeout():
30
31 def __init__(self, seconds):
32 self.seconds = seconds
33
34 def handle_timeout(self, signum, frame):
35 raise TestTimeout("Test failed: timeout reached")
36
37 def __enter__(self):
38 signal.signal(signal.SIGALRM, self.handle_timeout)
39 signal.alarm(self.seconds)
40
41 def __exit__(self, exc_type, exc_val, exc_tb):
42 signal.alarm(0)
43
Patrick Williamsc124f4f2015-09-15 14:41:29 -050044class URITest(unittest.TestCase):
45 test_uris = {
46 "http://www.google.com/index.html" : {
47 'uri': 'http://www.google.com/index.html',
48 'scheme': 'http',
49 'hostname': 'www.google.com',
50 'port': None,
51 'hostport': 'www.google.com',
52 'path': '/index.html',
53 'userinfo': '',
54 'username': '',
55 'password': '',
56 'params': {},
57 'query': {},
58 'relative': False
59 },
60 "http://www.google.com/index.html;param1=value1" : {
61 'uri': 'http://www.google.com/index.html;param1=value1',
62 'scheme': 'http',
63 'hostname': 'www.google.com',
64 'port': None,
65 'hostport': 'www.google.com',
66 'path': '/index.html',
67 'userinfo': '',
68 'username': '',
69 'password': '',
70 'params': {
71 'param1': 'value1'
72 },
73 'query': {},
74 'relative': False
75 },
76 "http://www.example.org/index.html?param1=value1" : {
77 'uri': 'http://www.example.org/index.html?param1=value1',
78 'scheme': 'http',
79 'hostname': 'www.example.org',
80 'port': None,
81 'hostport': 'www.example.org',
82 'path': '/index.html',
83 'userinfo': '',
84 'username': '',
85 'password': '',
86 'params': {},
87 'query': {
88 'param1': 'value1'
89 },
90 'relative': False
91 },
92 "http://www.example.org/index.html?qparam1=qvalue1;param2=value2" : {
93 'uri': 'http://www.example.org/index.html?qparam1=qvalue1;param2=value2',
94 'scheme': 'http',
95 'hostname': 'www.example.org',
96 'port': None,
97 'hostport': 'www.example.org',
98 'path': '/index.html',
99 'userinfo': '',
100 'username': '',
101 'password': '',
102 'params': {
103 'param2': 'value2'
104 },
105 'query': {
106 'qparam1': 'qvalue1'
107 },
108 'relative': False
109 },
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600110 # Check that trailing semicolons are handled correctly
111 "http://www.example.org/index.html?qparam1=qvalue1;param2=value2;" : {
112 'uri': 'http://www.example.org/index.html?qparam1=qvalue1;param2=value2',
113 'scheme': 'http',
114 'hostname': 'www.example.org',
115 'port': None,
116 'hostport': 'www.example.org',
117 'path': '/index.html',
118 'userinfo': '',
119 'username': '',
120 'password': '',
121 'params': {
122 'param2': 'value2'
123 },
124 'query': {
125 'qparam1': 'qvalue1'
126 },
127 'relative': False
128 },
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500129 "http://www.example.com:8080/index.html" : {
130 'uri': 'http://www.example.com:8080/index.html',
131 'scheme': 'http',
132 'hostname': 'www.example.com',
133 'port': 8080,
134 'hostport': 'www.example.com:8080',
135 'path': '/index.html',
136 'userinfo': '',
137 'username': '',
138 'password': '',
139 'params': {},
140 'query': {},
141 'relative': False
142 },
143 "cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg" : {
144 'uri': 'cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg',
145 'scheme': 'cvs',
146 'hostname': 'cvs.handhelds.org',
147 'port': None,
148 'hostport': 'cvs.handhelds.org',
149 'path': '/cvs',
150 'userinfo': 'anoncvs',
151 'username': 'anoncvs',
152 'password': '',
153 'params': {
154 'module': 'familiar/dist/ipkg'
155 },
156 'query': {},
157 'relative': False
158 },
159 "cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg": {
160 'uri': 'cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg',
161 'scheme': 'cvs',
162 'hostname': 'cvs.handhelds.org',
163 'port': None,
164 'hostport': 'cvs.handhelds.org',
165 'path': '/cvs',
166 'userinfo': 'anoncvs:anonymous',
167 'username': 'anoncvs',
168 'password': 'anonymous',
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600169 'params': collections.OrderedDict([
170 ('tag', 'V0-99-81'),
171 ('module', 'familiar/dist/ipkg')
172 ]),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500173 'query': {},
174 'relative': False
175 },
176 "file://example.diff": { # NOTE: Not RFC compliant!
177 'uri': 'file:example.diff',
178 'scheme': 'file',
179 'hostname': '',
180 'port': None,
181 'hostport': '',
182 'path': 'example.diff',
183 'userinfo': '',
184 'username': '',
185 'password': '',
186 'params': {},
187 'query': {},
188 'relative': True
189 },
190 "file:example.diff": { # NOTE: RFC compliant version of the former
191 'uri': 'file:example.diff',
192 'scheme': 'file',
193 'hostname': '',
194 'port': None,
195 'hostport': '',
196 'path': 'example.diff',
197 'userinfo': '',
198 'userinfo': '',
199 'username': '',
200 'password': '',
201 'params': {},
202 'query': {},
203 'relative': True
204 },
205 "file:///tmp/example.diff": {
206 'uri': 'file:///tmp/example.diff',
207 'scheme': 'file',
208 'hostname': '',
209 'port': None,
210 'hostport': '',
211 'path': '/tmp/example.diff',
212 'userinfo': '',
213 'userinfo': '',
214 'username': '',
215 'password': '',
216 'params': {},
217 'query': {},
218 'relative': False
219 },
220 "git:///path/example.git": {
221 'uri': 'git:///path/example.git',
222 'scheme': 'git',
223 'hostname': '',
224 'port': None,
225 'hostport': '',
226 'path': '/path/example.git',
227 'userinfo': '',
228 'userinfo': '',
229 'username': '',
230 'password': '',
231 'params': {},
232 'query': {},
233 'relative': False
234 },
235 "git:path/example.git": {
236 'uri': 'git:path/example.git',
237 'scheme': 'git',
238 'hostname': '',
239 'port': None,
240 'hostport': '',
241 'path': 'path/example.git',
242 'userinfo': '',
243 'userinfo': '',
244 'username': '',
245 'password': '',
246 'params': {},
247 'query': {},
248 'relative': True
249 },
250 "git://example.net/path/example.git": {
251 'uri': 'git://example.net/path/example.git',
252 'scheme': 'git',
253 'hostname': 'example.net',
254 'port': None,
255 'hostport': 'example.net',
256 'path': '/path/example.git',
257 'userinfo': '',
258 'userinfo': '',
259 'username': '',
260 'password': '',
261 'params': {},
262 'query': {},
263 'relative': False
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500264 },
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500265 "git://tfs-example.org:22/tfs/example%20path/example.git": {
266 'uri': 'git://tfs-example.org:22/tfs/example%20path/example.git',
267 'scheme': 'git',
268 'hostname': 'tfs-example.org',
269 'port': 22,
270 'hostport': 'tfs-example.org:22',
271 'path': '/tfs/example path/example.git',
272 'userinfo': '',
273 'userinfo': '',
274 'username': '',
275 'password': '',
276 'params': {},
277 'query': {},
278 'relative': False
279 },
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500280 "http://somesite.net;someparam=1": {
281 'uri': 'http://somesite.net;someparam=1',
282 'scheme': 'http',
283 'hostname': 'somesite.net',
284 'port': None,
285 'hostport': 'somesite.net',
286 'path': '',
287 'userinfo': '',
288 'userinfo': '',
289 'username': '',
290 'password': '',
291 'params': {"someparam" : "1"},
292 'query': {},
293 'relative': False
294 },
295 "file://somelocation;someparam=1": {
296 'uri': 'file:somelocation;someparam=1',
297 'scheme': 'file',
298 'hostname': '',
299 'port': None,
300 'hostport': '',
301 'path': 'somelocation',
302 'userinfo': '',
303 'userinfo': '',
304 'username': '',
305 'password': '',
306 'params': {"someparam" : "1"},
307 'query': {},
308 'relative': True
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500309 }
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500310
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500311 }
312
313 def test_uri(self):
314 for test_uri, ref in self.test_uris.items():
315 uri = URI(test_uri)
316
317 self.assertEqual(str(uri), ref['uri'])
318
319 # expected attributes
320 self.assertEqual(uri.scheme, ref['scheme'])
321
322 self.assertEqual(uri.userinfo, ref['userinfo'])
323 self.assertEqual(uri.username, ref['username'])
324 self.assertEqual(uri.password, ref['password'])
325
326 self.assertEqual(uri.hostname, ref['hostname'])
327 self.assertEqual(uri.port, ref['port'])
328 self.assertEqual(uri.hostport, ref['hostport'])
329
330 self.assertEqual(uri.path, ref['path'])
331 self.assertEqual(uri.params, ref['params'])
332
333 self.assertEqual(uri.relative, ref['relative'])
334
335 def test_dict(self):
336 for test in self.test_uris.values():
337 uri = URI()
338
339 self.assertEqual(uri.scheme, '')
340 self.assertEqual(uri.userinfo, '')
341 self.assertEqual(uri.username, '')
342 self.assertEqual(uri.password, '')
343 self.assertEqual(uri.hostname, '')
344 self.assertEqual(uri.port, None)
345 self.assertEqual(uri.path, '')
346 self.assertEqual(uri.params, {})
347
348
349 uri.scheme = test['scheme']
350 self.assertEqual(uri.scheme, test['scheme'])
351
352 uri.userinfo = test['userinfo']
353 self.assertEqual(uri.userinfo, test['userinfo'])
354 self.assertEqual(uri.username, test['username'])
355 self.assertEqual(uri.password, test['password'])
356
357 # make sure changing the values doesn't do anything unexpected
358 uri.username = 'changeme'
359 self.assertEqual(uri.username, 'changeme')
360 self.assertEqual(uri.password, test['password'])
361 uri.password = 'insecure'
362 self.assertEqual(uri.username, 'changeme')
363 self.assertEqual(uri.password, 'insecure')
364
365 # reset back after our trickery
366 uri.userinfo = test['userinfo']
367 self.assertEqual(uri.userinfo, test['userinfo'])
368 self.assertEqual(uri.username, test['username'])
369 self.assertEqual(uri.password, test['password'])
370
371 uri.hostname = test['hostname']
372 self.assertEqual(uri.hostname, test['hostname'])
373 self.assertEqual(uri.hostport, test['hostname'])
374
375 uri.port = test['port']
376 self.assertEqual(uri.port, test['port'])
377 self.assertEqual(uri.hostport, test['hostport'])
378
379 uri.path = test['path']
380 self.assertEqual(uri.path, test['path'])
381
382 uri.params = test['params']
383 self.assertEqual(uri.params, test['params'])
384
385 uri.query = test['query']
386 self.assertEqual(uri.query, test['query'])
387
388 self.assertEqual(str(uri), test['uri'])
389
390 uri.params = {}
391 self.assertEqual(uri.params, {})
392 self.assertEqual(str(uri), (str(uri).split(";"))[0])
393
394class FetcherTest(unittest.TestCase):
395
396 def setUp(self):
397 self.origdir = os.getcwd()
398 self.d = bb.data.init()
Andrew Geisslereff27472021-10-29 15:35:00 -0500399 self.tempdir = tempfile.mkdtemp(prefix="bitbake-fetch-")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500400 self.dldir = os.path.join(self.tempdir, "download")
401 os.mkdir(self.dldir)
402 self.d.setVar("DL_DIR", self.dldir)
403 self.unpackdir = os.path.join(self.tempdir, "unpacked")
404 os.mkdir(self.unpackdir)
405 persistdir = os.path.join(self.tempdir, "persistdata")
406 self.d.setVar("PERSISTENT_DIR", persistdir)
407
408 def tearDown(self):
409 os.chdir(self.origdir)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600410 if os.environ.get("BB_TMPDIR_NOCLEAN") == "yes":
411 print("Not cleaning up %s. Please remove manually." % self.tempdir)
412 else:
Andrew Geisslerc926e172021-05-07 16:11:35 -0500413 bb.process.run('chmod u+rw -R %s' % self.tempdir)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600414 bb.utils.prunedir(self.tempdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500415
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000416 def git(self, cmd, cwd=None):
417 if isinstance(cmd, str):
418 cmd = 'git ' + cmd
419 else:
420 cmd = ['git'] + cmd
421 if cwd is None:
422 cwd = self.gitdir
423 return bb.process.run(cmd, cwd=cwd)[0]
424
425 def git_init(self, cwd=None):
426 self.git('init', cwd=cwd)
427 if not self.git(['config', 'user.email'], cwd=cwd):
428 self.git(['config', 'user.email', 'you@example.com'], cwd=cwd)
429 if not self.git(['config', 'user.name'], cwd=cwd):
430 self.git(['config', 'user.name', 'Your Name'], cwd=cwd)
431
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500432class MirrorUriTest(FetcherTest):
433
434 replaceuris = {
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000435 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "http://somewhere.org/somedir/")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500436 : "http://somewhere.org/somedir/git2_git.invalid.infradead.org.mtd-utils.git.tar.gz",
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000437 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http")
438 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
439 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http")
440 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
441 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/\\2;protocol=http")
442 : "git://somewhere.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500443 ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890", "git://someserver.org/bitbake", "git://git.openembedded.org/bitbake")
444 : "git://git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890",
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000445 ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500446 : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000447 ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache/")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500448 : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000449 ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org/somedir3")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500450 : "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz",
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000451 ("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 -0500452 : "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz",
453 ("http://www.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", "http://www.apache.org/dist", "http://archive.apache.org/dist")
454 : "http://archive.apache.org/dist/subversion/subversion-1.7.1.tar.bz2",
455 ("http://www.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", "http://.*/.*", "file:///somepath/downloads/")
456 : "file:///somepath/downloads/subversion-1.7.1.tar.bz2",
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000457 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http")
458 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
459 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http")
460 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
461 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/MIRRORNAME;protocol=http")
462 : "git://somewhere.org/somedir/git.invalid.infradead.org.foo.mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800463 ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org")
464 : "http://somewhere2.org/somefile_1.2.3.tar.gz",
465 ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org/")
466 : "http://somewhere2.org/somefile_1.2.3.tar.gz",
467 ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master", "git://someserver.org/bitbake;branch=master", "git://git.openembedded.org/bitbake;protocol=http")
468 : "git://git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master;protocol=http",
Andrew Geissler595f6302022-01-24 19:11:47 +0000469 ("git://user1@someserver.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master", "git://someserver.org/bitbake;branch=master", "git://user2@git.openembedded.org/bitbake;protocol=http")
470 : "git://user2@git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master;protocol=http",
471 ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890;protocol=git;branch=master", "git://someserver.org/bitbake", "git://someotherserver.org/bitbake;protocol=https")
472 : "git://someotherserver.org/bitbake;tag=1234567890123456789012345678901234567890;protocol=https;branch=master",
Andrew Geissler595f6302022-01-24 19:11:47 +0000473 ("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 +0000474 ("https://somewhere.org/example/1.0.0/example;downloadfilename=some-example-1.0.0.tgz", "https://.*/.*", "file:///mirror/PATH")
475 : "file:///mirror/example/1.0.0/some-example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz",
476 ("https://somewhere.org/example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz", "https://.*/.*", "file:///mirror/some-example-1.0.0.tgz")
477 : "file:///mirror/some-example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz",
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500478
479 #Renaming files doesn't work
480 #("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"
481 #("file://sstate-xyz.tgz", "file://.*/.*", "file:///somewhere/1234/sstate-cache") : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
482 }
483
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000484 mirrorvar = "http://.*/.* file:///somepath/downloads/ " \
485 "git://someserver.org/bitbake git://git.openembedded.org/bitbake " \
486 "https://.*/.* file:///someotherpath/downloads/ " \
487 "http://.*/.* file:///someotherpath/downloads/"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500488
489 def test_urireplace(self):
Andrew Geissler615f2f12022-07-15 14:00:58 -0500490 self.d.setVar("FILESPATH", ".")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500491 for k, v in self.replaceuris.items():
492 ud = bb.fetch.FetchData(k[0], self.d)
493 ud.setup_localpath(self.d)
494 mirrors = bb.fetch2.mirror_from_string("%s %s" % (k[1], k[2]))
495 newuris, uds = bb.fetch2.build_mirroruris(ud, mirrors, self.d)
496 self.assertEqual([v], newuris)
497
498 def test_urilist1(self):
499 fetcher = bb.fetch.FetchData("http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
500 mirrors = bb.fetch2.mirror_from_string(self.mirrorvar)
501 uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
502 self.assertEqual(uris, ['file:///somepath/downloads/bitbake-1.0.tar.gz', 'file:///someotherpath/downloads/bitbake-1.0.tar.gz'])
503
504 def test_urilist2(self):
505 # Catch https:// -> files:// bug
506 fetcher = bb.fetch.FetchData("https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
507 mirrors = bb.fetch2.mirror_from_string(self.mirrorvar)
508 uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
509 self.assertEqual(uris, ['file:///someotherpath/downloads/bitbake-1.0.tar.gz'])
510
511 def test_mirror_of_mirror(self):
512 # Test if mirror of a mirror works
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000513 mirrorvar = self.mirrorvar + " http://.*/.* http://otherdownloads.yoctoproject.org/downloads/"
514 mirrorvar = mirrorvar + " http://otherdownloads.yoctoproject.org/.* http://downloads2.yoctoproject.org/downloads/"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500515 fetcher = bb.fetch.FetchData("http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
516 mirrors = bb.fetch2.mirror_from_string(mirrorvar)
517 uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
518 self.assertEqual(uris, ['file:///somepath/downloads/bitbake-1.0.tar.gz',
519 'file:///someotherpath/downloads/bitbake-1.0.tar.gz',
520 'http://otherdownloads.yoctoproject.org/downloads/bitbake-1.0.tar.gz',
521 'http://downloads2.yoctoproject.org/downloads/bitbake-1.0.tar.gz'])
522
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000523 recmirrorvar = "https://.*/[^/]* http://AAAA/A/A/A/ " \
524 "https://.*/[^/]* https://BBBB/B/B/B/"
Patrick Williamsd7e96312015-09-22 08:09:05 -0500525
526 def test_recursive(self):
527 fetcher = bb.fetch.FetchData("https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
528 mirrors = bb.fetch2.mirror_from_string(self.recmirrorvar)
529 uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
530 self.assertEqual(uris, ['http://AAAA/A/A/A/bitbake/bitbake-1.0.tar.gz',
531 'https://BBBB/B/B/B/bitbake/bitbake-1.0.tar.gz',
532 'http://AAAA/A/A/A/B/B/bitbake/bitbake-1.0.tar.gz'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500533
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800534
535class GitDownloadDirectoryNamingTest(FetcherTest):
536 def setUp(self):
537 super(GitDownloadDirectoryNamingTest, self).setUp()
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000538 self.recipe_url = "git://git.openembedded.org/bitbake;branch=master"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800539 self.recipe_dir = "git.openembedded.org.bitbake"
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000540 self.mirror_url = "git://github.com/openembedded/bitbake.git;protocol=https;branch=master"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800541 self.mirror_dir = "github.com.openembedded.bitbake.git"
542
543 self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
544
545 def setup_mirror_rewrite(self):
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000546 self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800547
548 @skipIfNoNetwork()
549 def test_that_directory_is_named_after_recipe_url_when_no_mirroring_is_used(self):
550 self.setup_mirror_rewrite()
551 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
552
553 fetcher.download()
554
555 dir = os.listdir(self.dldir + "/git2")
556 self.assertIn(self.recipe_dir, dir)
557
558 @skipIfNoNetwork()
559 def test_that_directory_exists_for_mirrored_url_and_recipe_url_when_mirroring_is_used(self):
560 self.setup_mirror_rewrite()
561 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
562
563 fetcher.download()
564
565 dir = os.listdir(self.dldir + "/git2")
566 self.assertIn(self.mirror_dir, dir)
567 self.assertIn(self.recipe_dir, dir)
568
569 @skipIfNoNetwork()
570 def test_that_recipe_directory_and_mirrored_directory_exists_when_mirroring_is_used_and_the_mirrored_directory_already_exists(self):
571 self.setup_mirror_rewrite()
572 fetcher = bb.fetch.Fetch([self.mirror_url], self.d)
573 fetcher.download()
574 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
575
576 fetcher.download()
577
578 dir = os.listdir(self.dldir + "/git2")
579 self.assertIn(self.mirror_dir, dir)
580 self.assertIn(self.recipe_dir, dir)
581
582
583class TarballNamingTest(FetcherTest):
584 def setUp(self):
585 super(TarballNamingTest, self).setUp()
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000586 self.recipe_url = "git://git.openembedded.org/bitbake;branch=master"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800587 self.recipe_tarball = "git2_git.openembedded.org.bitbake.tar.gz"
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000588 self.mirror_url = "git://github.com/openembedded/bitbake.git;protocol=https;branch=master"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800589 self.mirror_tarball = "git2_github.com.openembedded.bitbake.git.tar.gz"
590
591 self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '1')
592 self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
593
594 def setup_mirror_rewrite(self):
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000595 self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800596
597 @skipIfNoNetwork()
598 def test_that_the_recipe_tarball_is_created_when_no_mirroring_is_used(self):
599 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
600
601 fetcher.download()
602
603 dir = os.listdir(self.dldir)
604 self.assertIn(self.recipe_tarball, dir)
605
606 @skipIfNoNetwork()
607 def test_that_the_mirror_tarball_is_created_when_mirroring_is_used(self):
608 self.setup_mirror_rewrite()
609 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
610
611 fetcher.download()
612
613 dir = os.listdir(self.dldir)
614 self.assertIn(self.mirror_tarball, dir)
615
616
617class GitShallowTarballNamingTest(FetcherTest):
618 def setUp(self):
619 super(GitShallowTarballNamingTest, self).setUp()
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000620 self.recipe_url = "git://git.openembedded.org/bitbake;branch=master"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800621 self.recipe_tarball = "gitshallow_git.openembedded.org.bitbake_82ea737-1_master.tar.gz"
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000622 self.mirror_url = "git://github.com/openembedded/bitbake.git;protocol=https;branch=master"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800623 self.mirror_tarball = "gitshallow_github.com.openembedded.bitbake.git_82ea737-1_master.tar.gz"
624
625 self.d.setVar('BB_GIT_SHALLOW', '1')
626 self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1')
627 self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
628
629 def setup_mirror_rewrite(self):
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000630 self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800631
632 @skipIfNoNetwork()
633 def test_that_the_tarball_is_named_after_recipe_url_when_no_mirroring_is_used(self):
634 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
635
636 fetcher.download()
637
638 dir = os.listdir(self.dldir)
639 self.assertIn(self.recipe_tarball, dir)
640
641 @skipIfNoNetwork()
642 def test_that_the_mirror_tarball_is_created_when_mirroring_is_used(self):
643 self.setup_mirror_rewrite()
644 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
645
646 fetcher.download()
647
648 dir = os.listdir(self.dldir)
649 self.assertIn(self.mirror_tarball, dir)
650
651
Andrew Geissler9aee5002022-03-30 16:27:02 +0000652class CleanTarballTest(FetcherTest):
653 def setUp(self):
654 super(CleanTarballTest, self).setUp()
655 self.recipe_url = "git://git.openembedded.org/bitbake"
656 self.recipe_tarball = "git2_git.openembedded.org.bitbake.tar.gz"
657
658 self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '1')
659 self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
660
661 @skipIfNoNetwork()
662 def test_that_the_tarball_contents_does_not_leak_info(self):
663 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
664
665 fetcher.download()
666
667 fetcher.unpack(self.unpackdir)
668 mtime = bb.process.run('git log --all -1 --format=%ct',
669 cwd=os.path.join(self.unpackdir, 'git'))
670 self.assertEqual(len(mtime), 2)
671 mtime = int(mtime[0])
672
673 archive = tarfile.open(os.path.join(self.dldir, self.recipe_tarball))
674 self.assertNotEqual(len(archive.members), 0)
675 for member in archive.members:
Patrick Williams03907ee2022-05-01 06:28:52 -0500676 self.assertEqual(member.uname, 'oe')
677 self.assertEqual(member.uid, 0)
678 self.assertEqual(member.gname, 'oe')
679 self.assertEqual(member.gid, 0)
Andrew Geissler9aee5002022-03-30 16:27:02 +0000680 self.assertEqual(member.mtime, mtime)
681
682
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500683class FetcherLocalTest(FetcherTest):
684 def setUp(self):
685 def touch(fn):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600686 with open(fn, 'a'):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500687 os.utime(fn, None)
688
689 super(FetcherLocalTest, self).setUp()
690 self.localsrcdir = os.path.join(self.tempdir, 'localsrc')
691 os.makedirs(self.localsrcdir)
692 touch(os.path.join(self.localsrcdir, 'a'))
693 touch(os.path.join(self.localsrcdir, 'b'))
694 os.makedirs(os.path.join(self.localsrcdir, 'dir'))
695 touch(os.path.join(self.localsrcdir, 'dir', 'c'))
696 touch(os.path.join(self.localsrcdir, 'dir', 'd'))
697 os.makedirs(os.path.join(self.localsrcdir, 'dir', 'subdir'))
698 touch(os.path.join(self.localsrcdir, 'dir', 'subdir', 'e'))
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500699 touch(os.path.join(self.localsrcdir, r'backslash\x2dsystemd-unit.device'))
Andrew Geissler595f6302022-01-24 19:11:47 +0000700 bb.process.run('tar cf archive.tar -C dir .', cwd=self.localsrcdir)
701 bb.process.run('tar czf archive.tar.gz -C dir .', cwd=self.localsrcdir)
702 bb.process.run('tar cjf archive.tar.bz2 -C dir .', cwd=self.localsrcdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500703 self.d.setVar("FILESPATH", self.localsrcdir)
704
705 def fetchUnpack(self, uris):
706 fetcher = bb.fetch.Fetch(uris, self.d)
707 fetcher.download()
708 fetcher.unpack(self.unpackdir)
709 flst = []
710 for root, dirs, files in os.walk(self.unpackdir):
711 for f in files:
712 flst.append(os.path.relpath(os.path.join(root, f), self.unpackdir))
713 flst.sort()
714 return flst
715
Andrew Geissler615f2f12022-07-15 14:00:58 -0500716 def test_local_checksum_fails_no_file(self):
717 self.d.setVar("SRC_URI", "file://404")
718 with self.assertRaises(bb.BBHandledException):
719 bb.fetch.get_checksum_file_list(self.d)
720
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500721 def test_local(self):
722 tree = self.fetchUnpack(['file://a', 'file://dir/c'])
723 self.assertEqual(tree, ['a', 'dir/c'])
724
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500725 def test_local_backslash(self):
726 tree = self.fetchUnpack([r'file://backslash\x2dsystemd-unit.device'])
727 self.assertEqual(tree, [r'backslash\x2dsystemd-unit.device'])
728
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500729 def test_local_wildcard(self):
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500730 with self.assertRaises(bb.fetch2.ParameterError):
731 tree = self.fetchUnpack(['file://a', 'file://dir/*'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500732
733 def test_local_dir(self):
734 tree = self.fetchUnpack(['file://a', 'file://dir'])
735 self.assertEqual(tree, ['a', 'dir/c', 'dir/d', 'dir/subdir/e'])
736
737 def test_local_subdir(self):
738 tree = self.fetchUnpack(['file://dir/subdir'])
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500739 self.assertEqual(tree, ['dir/subdir/e'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500740
741 def test_local_subdir_file(self):
742 tree = self.fetchUnpack(['file://dir/subdir/e'])
743 self.assertEqual(tree, ['dir/subdir/e'])
744
745 def test_local_subdirparam(self):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500746 tree = self.fetchUnpack(['file://a;subdir=bar', 'file://dir;subdir=foo/moo'])
747 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 -0500748
749 def test_local_deepsubdirparam(self):
750 tree = self.fetchUnpack(['file://dir/subdir/e;subdir=bar'])
751 self.assertEqual(tree, ['bar/dir/subdir/e'])
752
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600753 def test_local_absolutedir(self):
754 # Unpacking to an absolute path that is a subdirectory of the root
755 # should work
756 tree = self.fetchUnpack(['file://a;subdir=%s' % os.path.join(self.unpackdir, 'bar')])
757
758 # Unpacking to an absolute path outside of the root should fail
759 with self.assertRaises(bb.fetch2.UnpackError):
760 self.fetchUnpack(['file://a;subdir=/bin/sh'])
761
Andrew Geissler595f6302022-01-24 19:11:47 +0000762 def test_local_striplevel(self):
763 tree = self.fetchUnpack(['file://archive.tar;subdir=bar;striplevel=1'])
764 self.assertEqual(tree, ['bar/c', 'bar/d', 'bar/subdir/e'])
765
766 def test_local_striplevel_gzip(self):
767 tree = self.fetchUnpack(['file://archive.tar.gz;subdir=bar;striplevel=1'])
768 self.assertEqual(tree, ['bar/c', 'bar/d', 'bar/subdir/e'])
769
770 def test_local_striplevel_bzip2(self):
771 tree = self.fetchUnpack(['file://archive.tar.bz2;subdir=bar;striplevel=1'])
772 self.assertEqual(tree, ['bar/c', 'bar/d', 'bar/subdir/e'])
773
Andrew Geisslerc926e172021-05-07 16:11:35 -0500774 def dummyGitTest(self, suffix):
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600775 # Create dummy local Git repo
776 src_dir = tempfile.mkdtemp(dir=self.tempdir,
777 prefix='gitfetch_localusehead_')
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000778 self.gitdir = os.path.abspath(src_dir)
779 self.git_init()
780 self.git(['commit', '--allow-empty', '-m', 'Dummy commit'])
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600781 # Use other branch than master
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000782 self.git(['checkout', '-b', 'my-devel'])
783 self.git(['commit', '--allow-empty', '-m', 'Dummy commit 2'])
784 orig_rev = self.git(['rev-parse', 'HEAD']).strip()
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600785
786 # Fetch and check revision
787 self.d.setVar("SRCREV", "AUTOINC")
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000788 self.d.setVar("__BBSEENSRCREV", "1")
789 url = "git://" + self.gitdir + ";branch=master;protocol=file;" + suffix
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600790 fetcher = bb.fetch.Fetch([url], self.d)
791 fetcher.download()
792 fetcher.unpack(self.unpackdir)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000793 unpack_rev = self.git(['rev-parse', 'HEAD'],
794 cwd=os.path.join(self.unpackdir, 'git')).strip()
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600795 self.assertEqual(orig_rev, unpack_rev)
796
Andrew Geisslerc926e172021-05-07 16:11:35 -0500797 def test_local_gitfetch_usehead(self):
798 self.dummyGitTest("usehead=1")
799
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600800 def test_local_gitfetch_usehead_withname(self):
Andrew Geisslerc926e172021-05-07 16:11:35 -0500801 self.dummyGitTest("usehead=1;name=newName")
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600802
Andrew Geisslerc926e172021-05-07 16:11:35 -0500803 def test_local_gitfetch_shared(self):
804 self.dummyGitTest("usehead=1;name=sharedName")
805 alt = os.path.join(self.unpackdir, 'git/.git/objects/info/alternates')
806 self.assertTrue(os.path.exists(alt))
807
808 def test_local_gitfetch_noshared(self):
809 self.d.setVar('BB_GIT_NOSHARED', '1')
810 self.unpackdir += '_noshared'
811 self.dummyGitTest("usehead=1;name=noSharedName")
812 alt = os.path.join(self.unpackdir, 'git/.git/objects/info/alternates')
813 self.assertFalse(os.path.exists(alt))
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600814
Brad Bishop316dfdd2018-06-25 12:45:53 -0400815class FetcherNoNetworkTest(FetcherTest):
816 def setUp(self):
817 super().setUp()
818 # all test cases are based on not having network
819 self.d.setVar("BB_NO_NETWORK", "1")
820
821 def test_missing(self):
822 string = "this is a test file\n".encode("utf-8")
823 self.d.setVarFlag("SRC_URI", "md5sum", hashlib.md5(string).hexdigest())
824 self.d.setVarFlag("SRC_URI", "sha256sum", hashlib.sha256(string).hexdigest())
825
826 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
827 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
828 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/test-file.tar.gz"], self.d)
829 with self.assertRaises(bb.fetch2.NetworkAccess):
830 fetcher.download()
831
832 def test_valid_missing_donestamp(self):
833 # create the file in the download directory with correct hash
834 string = "this is a test file\n".encode("utf-8")
835 with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb") as f:
836 f.write(string)
837
838 self.d.setVarFlag("SRC_URI", "md5sum", hashlib.md5(string).hexdigest())
839 self.d.setVarFlag("SRC_URI", "sha256sum", hashlib.sha256(string).hexdigest())
840
841 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
842 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
843 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/test-file.tar.gz"], self.d)
844 fetcher.download()
845 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
846
847 def test_invalid_missing_donestamp(self):
848 # create an invalid file in the download directory with incorrect hash
849 string = "this is a test file\n".encode("utf-8")
850 with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb"):
851 pass
852
853 self.d.setVarFlag("SRC_URI", "md5sum", hashlib.md5(string).hexdigest())
854 self.d.setVarFlag("SRC_URI", "sha256sum", hashlib.sha256(string).hexdigest())
855
856 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
857 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
858 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/test-file.tar.gz"], self.d)
859 with self.assertRaises(bb.fetch2.NetworkAccess):
860 fetcher.download()
861 # the existing file should not exist or should have be moved to "bad-checksum"
862 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
863
864 def test_nochecksums_missing(self):
865 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
866 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
867 # ssh fetch does not support checksums
868 fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d)
869 # attempts to download with missing donestamp
870 with self.assertRaises(bb.fetch2.NetworkAccess):
871 fetcher.download()
872
873 def test_nochecksums_missing_donestamp(self):
874 # create a file in the download directory
875 with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb"):
876 pass
877
878 self.assertTrue(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_has_donestamp(self):
887 # create a file in the download directory with the donestamp
888 with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb"):
889 pass
890 with open(os.path.join(self.dldir, "test-file.tar.gz.done"), "wb"):
891 pass
892
893 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
894 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
895 # ssh fetch does not support checksums
896 fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d)
897 # should not fetch
898 fetcher.download()
899 # both files should still exist
900 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
901 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
902
903 def test_nochecksums_missing_has_donestamp(self):
904 # create a file in the download directory with the donestamp
905 with open(os.path.join(self.dldir, "test-file.tar.gz.done"), "wb"):
906 pass
907
908 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
909 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
910 # ssh fetch does not support checksums
911 fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d)
912 with self.assertRaises(bb.fetch2.NetworkAccess):
913 fetcher.download()
914 # both files should still exist
915 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
916 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
917
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500918class FetcherNetworkTest(FetcherTest):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500919 @skipIfNoNetwork()
920 def test_fetch(self):
Andrew Geisslereff27472021-10-29 15:35:00 -0500921 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 -0500922 fetcher.download()
923 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
924 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.1.tar.gz"), 57892)
925 self.d.setVar("BB_NO_NETWORK", "1")
Andrew Geisslereff27472021-10-29 15:35:00 -0500926 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 -0500927 fetcher.download()
928 fetcher.unpack(self.unpackdir)
929 self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.0/")), 9)
930 self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.1/")), 9)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500931
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500932 @skipIfNoNetwork()
933 def test_fetch_mirror(self):
Andrew Geisslereff27472021-10-29 15:35:00 -0500934 self.d.setVar("MIRRORS", "http://.*/.* https://downloads.yoctoproject.org/releases/bitbake")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500935 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
936 fetcher.download()
937 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
938
939 @skipIfNoNetwork()
940 def test_fetch_mirror_of_mirror(self):
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000941 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 -0500942 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
943 fetcher.download()
944 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
945
946 @skipIfNoNetwork()
947 def test_fetch_file_mirror_of_mirror(self):
Andrew Geissler615f2f12022-07-15 14:00:58 -0500948 self.d.setVar("FILESPATH", ".")
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000949 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 -0500950 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
951 os.mkdir(self.dldir + "/some2where")
952 fetcher.download()
953 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
954
955 @skipIfNoNetwork()
956 def test_fetch_premirror(self):
Andrew Geisslereff27472021-10-29 15:35:00 -0500957 self.d.setVar("PREMIRRORS", "http://.*/.* https://downloads.yoctoproject.org/releases/bitbake")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500958 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
959 fetcher.download()
960 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
961
962 @skipIfNoNetwork()
Andrew Geissler5199d832021-09-24 16:47:35 -0500963 def test_fetch_specify_downloadfilename(self):
Andrew Geisslereff27472021-10-29 15:35:00 -0500964 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 -0500965 fetcher.download()
966 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-v1.0.0.tar.gz"), 57749)
967
968 @skipIfNoNetwork()
969 def test_fetch_premirror_specify_downloadfilename_regex_uri(self):
Andrew Geisslereff27472021-10-29 15:35:00 -0500970 self.d.setVar("PREMIRRORS", "http://.*/.* https://downloads.yoctoproject.org/releases/bitbake/")
Andrew Geissler595f6302022-01-24 19:11:47 +0000971 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 -0500972 fetcher.download()
Andrew Geissler595f6302022-01-24 19:11:47 +0000973 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
Andrew Geissler5199d832021-09-24 16:47:35 -0500974
975 @skipIfNoNetwork()
976 # BZ13039
977 def test_fetch_premirror_specify_downloadfilename_specific_uri(self):
Andrew Geisslereff27472021-10-29 15:35:00 -0500978 self.d.setVar("PREMIRRORS", "http://invalid.yoctoproject.org/releases/bitbake https://downloads.yoctoproject.org/releases/bitbake")
Andrew Geissler595f6302022-01-24 19:11:47 +0000979 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 -0500980 fetcher.download()
Andrew Geissler595f6302022-01-24 19:11:47 +0000981 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
982
983 @skipIfNoNetwork()
984 def test_fetch_premirror_use_downloadfilename_to_fetch(self):
985 # Ensure downloadfilename is used when fetching from premirror.
986 self.d.setVar("PREMIRRORS", "http://.*/.* https://downloads.yoctoproject.org/releases/bitbake")
987 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.1.tar.gz;downloadfilename=bitbake-1.0.tar.gz"], self.d)
988 fetcher.download()
989 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
Andrew Geissler5199d832021-09-24 16:47:35 -0500990
991 @skipIfNoNetwork()
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500992 def gitfetcher(self, url1, url2):
993 def checkrevision(self, fetcher):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500994 fetcher.unpack(self.unpackdir)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000995 revision = self.git(['rev-parse', 'HEAD'],
996 cwd=os.path.join(self.unpackdir, 'git')).strip()
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500997 self.assertEqual(revision, "270a05b0b4ba0959fe0624d2a4885d7b70426da5")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500998
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500999 self.d.setVar("BB_GENERATE_MIRROR_TARBALLS", "1")
1000 self.d.setVar("SRCREV", "270a05b0b4ba0959fe0624d2a4885d7b70426da5")
1001 fetcher = bb.fetch.Fetch([url1], self.d)
1002 fetcher.download()
1003 checkrevision(self, fetcher)
1004 # Wipe out the dldir clone and the unpacked source, turn off the network and check mirror tarball works
1005 bb.utils.prunedir(self.dldir + "/git2/")
1006 bb.utils.prunedir(self.unpackdir)
1007 self.d.setVar("BB_NO_NETWORK", "1")
1008 fetcher = bb.fetch.Fetch([url2], self.d)
1009 fetcher.download()
1010 checkrevision(self, fetcher)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001011
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001012 @skipIfNoNetwork()
1013 def test_gitfetch(self):
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001014 url1 = url2 = "git://git.openembedded.org/bitbake;branch=master"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001015 self.gitfetcher(url1, url2)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001016
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001017 @skipIfNoNetwork()
1018 def test_gitfetch_goodsrcrev(self):
1019 # SRCREV is set but matches rev= parameter
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001020 url1 = url2 = "git://git.openembedded.org/bitbake;rev=270a05b0b4ba0959fe0624d2a4885d7b70426da5;branch=master"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001021 self.gitfetcher(url1, url2)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001022
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001023 @skipIfNoNetwork()
1024 def test_gitfetch_badsrcrev(self):
1025 # SRCREV is set but does not match rev= parameter
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001026 url1 = url2 = "git://git.openembedded.org/bitbake;rev=dead05b0b4ba0959fe0624d2a4885d7b70426da5;branch=master"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001027 self.assertRaises(bb.fetch.FetchError, self.gitfetcher, url1, url2)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001028
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001029 @skipIfNoNetwork()
1030 def test_gitfetch_tagandrev(self):
1031 # SRCREV is set but does not match rev= parameter
1032 url1 = url2 = "git://git.openembedded.org/bitbake;rev=270a05b0b4ba0959fe0624d2a4885d7b70426da5;tag=270a05b0b4ba0959fe0624d2a4885d7b70426da5"
1033 self.assertRaises(bb.fetch.FetchError, self.gitfetcher, url1, url2)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001034
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001035 @skipIfNoNetwork()
Andrew Geisslerd1e89492021-02-12 15:35:20 -06001036 def test_gitfetch_usehead(self):
1037 # Since self.gitfetcher() sets SRCREV we expect this to override
1038 # `usehead=1' and instead fetch the specified SRCREV. See
1039 # test_local_gitfetch_usehead() for a positive use of the usehead
1040 # feature.
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001041 url = "git://git.openembedded.org/bitbake;usehead=1;branch=master"
Andrew Geisslerd1e89492021-02-12 15:35:20 -06001042 self.assertRaises(bb.fetch.ParameterError, self.gitfetcher, url, url)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001043
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001044 @skipIfNoNetwork()
Andrew Geisslerd1e89492021-02-12 15:35:20 -06001045 def test_gitfetch_usehead_withname(self):
1046 # Since self.gitfetcher() sets SRCREV we expect this to override
1047 # `usehead=1' and instead fetch the specified SRCREV. See
1048 # test_local_gitfetch_usehead() for a positive use of the usehead
1049 # feature.
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001050 url = "git://git.openembedded.org/bitbake;usehead=1;name=newName;branch=master"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001051 self.assertRaises(bb.fetch.ParameterError, self.gitfetcher, url, url)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001052
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001053 @skipIfNoNetwork()
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001054 def test_gitfetch_finds_local_tarball_for_mirrored_url_when_previous_downloaded_by_the_recipe_url(self):
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001055 recipeurl = "git://git.openembedded.org/bitbake;branch=master"
1056 mirrorurl = "git://someserver.org/bitbake;branch=master"
1057 self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake")
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001058 self.gitfetcher(recipeurl, mirrorurl)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001059
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001060 @skipIfNoNetwork()
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001061 def test_gitfetch_finds_local_tarball_when_previous_downloaded_from_a_premirror(self):
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001062 recipeurl = "git://someserver.org/bitbake;branch=master"
1063 self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake")
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001064 self.gitfetcher(recipeurl, recipeurl)
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_repository_when_premirror_rewrites_the_recipe_url(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001068 realurl = "git://git.openembedded.org/bitbake"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001069 recipeurl = "git://someserver.org/bitbake"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001070 self.sourcedir = self.unpackdir.replace("unpacked", "sourcemirror.git")
1071 os.chdir(self.tempdir)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001072 self.git(['clone', realurl, self.sourcedir], cwd=self.tempdir)
1073 self.d.setVar("PREMIRRORS", "%s git://%s;protocol=file" % (recipeurl, self.sourcedir))
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001074 self.gitfetcher(recipeurl, recipeurl)
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001075
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001076 @skipIfNoNetwork()
1077 def test_git_submodule(self):
Brad Bishopf8caae32019-03-25 13:13:56 -04001078 # URL with ssh submodules
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001079 url = "gitsm://git.yoctoproject.org/git-submodule-test;branch=ssh-gitsm-tests;rev=049da4a6cb198d7c0302e9e8b243a1443cb809a7;branch=master"
Brad Bishopf8caae32019-03-25 13:13:56 -04001080 # Original URL (comment this if you have ssh access to git.yoctoproject.org)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001081 url = "gitsm://git.yoctoproject.org/git-submodule-test;branch=master;rev=a2885dd7d25380d23627e7544b7bbb55014b16ee;branch=master"
Brad Bishopf8caae32019-03-25 13:13:56 -04001082 fetcher = bb.fetch.Fetch([url], self.d)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001083 fetcher.download()
1084 # Previous cwd has been deleted
1085 os.chdir(os.path.dirname(self.unpackdir))
1086 fetcher.unpack(self.unpackdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001087
Brad Bishopf8caae32019-03-25 13:13:56 -04001088 repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
1089 self.assertTrue(os.path.exists(repo_path), msg='Unpacked repository missing')
1090 self.assertTrue(os.path.exists(os.path.join(repo_path, 'bitbake')), msg='bitbake submodule missing')
1091 self.assertFalse(os.path.exists(os.path.join(repo_path, 'na')), msg='uninitialized submodule present')
1092
1093 # Only when we're running the extended test with a submodule's submodule, can we check this.
1094 if os.path.exists(os.path.join(repo_path, 'bitbake-gitsm-test1')):
1095 self.assertTrue(os.path.exists(os.path.join(repo_path, 'bitbake-gitsm-test1', 'bitbake')), msg='submodule of submodule missing')
1096
Brad Bishop96ff1982019-08-19 13:50:42 -04001097 @skipIfNoNetwork()
Brad Bishopf8caae32019-03-25 13:13:56 -04001098 def test_git_submodule_dbus_broker(self):
1099 # The following external repositories have show failures in fetch and unpack operations
1100 # We want to avoid regressions!
Andrew Geissler595f6302022-01-24 19:11:47 +00001101 url = "gitsm://github.com/bus1/dbus-broker;protocol=https;rev=fc874afa0992d0c75ec25acb43d344679f0ee7d2;branch=main"
Brad Bishopf8caae32019-03-25 13:13:56 -04001102 fetcher = bb.fetch.Fetch([url], self.d)
1103 fetcher.download()
1104 # Previous cwd has been deleted
1105 os.chdir(os.path.dirname(self.unpackdir))
1106 fetcher.unpack(self.unpackdir)
1107
1108 repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
1109 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-dvar/config')), msg='Missing submodule config "subprojects/c-dvar"')
1110 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-list/config')), msg='Missing submodule config "subprojects/c-list"')
1111 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-rbtree/config')), msg='Missing submodule config "subprojects/c-rbtree"')
1112 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-sundry/config')), msg='Missing submodule config "subprojects/c-sundry"')
1113 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-utf8/config')), msg='Missing submodule config "subprojects/c-utf8"')
1114
Brad Bishop96ff1982019-08-19 13:50:42 -04001115 @skipIfNoNetwork()
Brad Bishopf8caae32019-03-25 13:13:56 -04001116 def test_git_submodule_CLI11(self):
Andrew Geissler595f6302022-01-24 19:11:47 +00001117 url = "gitsm://github.com/CLIUtils/CLI11;protocol=https;rev=bd4dc911847d0cde7a6b41dfa626a85aab213baf;branch=main"
Brad Bishopf8caae32019-03-25 13:13:56 -04001118 fetcher = bb.fetch.Fetch([url], self.d)
1119 fetcher.download()
1120 # Previous cwd has been deleted
1121 os.chdir(os.path.dirname(self.unpackdir))
1122 fetcher.unpack(self.unpackdir)
1123
1124 repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
1125 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/googletest/config')), msg='Missing submodule config "extern/googletest"')
1126 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/json/config')), msg='Missing submodule config "extern/json"')
1127 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/sanitizers/config')), msg='Missing submodule config "extern/sanitizers"')
1128
Brad Bishop96ff1982019-08-19 13:50:42 -04001129 @skipIfNoNetwork()
Brad Bishop19323692019-04-05 15:28:33 -04001130 def test_git_submodule_update_CLI11(self):
1131 """ Prevent regression on update detection not finding missing submodule, or modules without needed commits """
Andrew Geissler595f6302022-01-24 19:11:47 +00001132 url = "gitsm://github.com/CLIUtils/CLI11;protocol=https;rev=cf6a99fa69aaefe477cc52e3ef4a7d2d7fa40714;branch=main"
Brad Bishop19323692019-04-05 15:28:33 -04001133 fetcher = bb.fetch.Fetch([url], self.d)
1134 fetcher.download()
1135
1136 # CLI11 that pulls in a newer nlohmann-json
Andrew Geissler595f6302022-01-24 19:11:47 +00001137 url = "gitsm://github.com/CLIUtils/CLI11;protocol=https;rev=49ac989a9527ee9bb496de9ded7b4872c2e0e5ca;branch=main"
Brad Bishop19323692019-04-05 15:28:33 -04001138 fetcher = bb.fetch.Fetch([url], self.d)
1139 fetcher.download()
1140 # Previous cwd has been deleted
1141 os.chdir(os.path.dirname(self.unpackdir))
1142 fetcher.unpack(self.unpackdir)
1143
1144 repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
1145 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/googletest/config')), msg='Missing submodule config "extern/googletest"')
1146 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/json/config')), msg='Missing submodule config "extern/json"')
1147 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/sanitizers/config')), msg='Missing submodule config "extern/sanitizers"')
1148
Brad Bishop96ff1982019-08-19 13:50:42 -04001149 @skipIfNoNetwork()
Brad Bishopf8caae32019-03-25 13:13:56 -04001150 def test_git_submodule_aktualizr(self):
Andrew Geissler595f6302022-01-24 19:11:47 +00001151 url = "gitsm://github.com/advancedtelematic/aktualizr;branch=master;protocol=https;rev=d00d1a04cc2366d1a5f143b84b9f507f8bd32c44"
Brad Bishopf8caae32019-03-25 13:13:56 -04001152 fetcher = bb.fetch.Fetch([url], self.d)
1153 fetcher.download()
1154 # Previous cwd has been deleted
1155 os.chdir(os.path.dirname(self.unpackdir))
1156 fetcher.unpack(self.unpackdir)
1157
1158 repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
1159 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"')
1160 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"')
1161 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")
1162 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"')
1163 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/third_party/googletest/config')), msg='Missing submodule config "third_party/googletest/config"')
1164 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 -05001165
Brad Bishop96ff1982019-08-19 13:50:42 -04001166 @skipIfNoNetwork()
Brad Bishop393846f2019-05-20 12:24:11 -04001167 def test_git_submodule_iotedge(self):
1168 """ Prevent regression on deeply nested submodules not being checked out properly, even though they were fetched. """
1169
1170 # This repository also has submodules where the module (name), path and url do not align
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001171 url = "gitsm://github.com/azure/iotedge.git;protocol=https;rev=d76e0316c6f324345d77c48a83ce836d09392699;branch=main"
Brad Bishop393846f2019-05-20 12:24:11 -04001172 fetcher = bb.fetch.Fetch([url], self.d)
1173 fetcher.download()
1174 # Previous cwd has been deleted
1175 os.chdir(os.path.dirname(self.unpackdir))
1176 fetcher.unpack(self.unpackdir)
1177
1178 repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
1179
1180 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')
1181 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')
1182 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')
1183 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')
1184 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')
1185 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')
1186 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')
1187 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')
1188 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')
1189 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')
1190 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')
1191 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')
1192 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')
1193
Patrick Williams92b42cb2022-09-03 06:53:57 -05001194 @skipIfNoNetwork()
1195 def test_git_submodule_reference_to_parent(self):
1196 self.recipe_url = "gitsm://github.com/gflags/gflags.git;protocol=https;branch=master"
1197 self.d.setVar("SRCREV", "14e1138441bbbb584160cb1c0a0426ec1bac35f1")
1198 with Timeout(60):
1199 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
1200 with self.assertRaises(bb.fetch2.FetchError):
1201 fetcher.download()
1202
Brad Bishop15ae2502019-06-18 21:44:24 -04001203class SVNTest(FetcherTest):
1204 def skipIfNoSvn():
1205 import shutil
1206 if not shutil.which("svn"):
1207 return unittest.skip("svn not installed, tests being skipped")
1208
1209 if not shutil.which("svnadmin"):
1210 return unittest.skip("svnadmin not installed, tests being skipped")
1211
1212 return lambda f: f
1213
1214 @skipIfNoSvn()
1215 def setUp(self):
1216 """ Create a local repository """
1217
1218 super(SVNTest, self).setUp()
1219
1220 # Create something we can fetch
1221 src_dir = tempfile.mkdtemp(dir=self.tempdir,
1222 prefix='svnfetch_srcdir_')
1223 src_dir = os.path.abspath(src_dir)
1224 bb.process.run("echo readme > README.md", cwd=src_dir)
1225
1226 # Store it in a local SVN repository
1227 repo_dir = tempfile.mkdtemp(dir=self.tempdir,
1228 prefix='svnfetch_localrepo_')
1229 repo_dir = os.path.abspath(repo_dir)
1230 bb.process.run("svnadmin create project", cwd=repo_dir)
1231
1232 self.repo_url = "file://%s/project" % repo_dir
1233 bb.process.run("svn import --non-interactive -m 'Initial import' %s %s/trunk" % (src_dir, self.repo_url),
1234 cwd=repo_dir)
1235
1236 bb.process.run("svn co %s svnfetch_co" % self.repo_url, cwd=self.tempdir)
1237 # Github will emulate SVN. Use this to check if we're downloding...
Andrew Geissler595f6302022-01-24 19:11:47 +00001238 bb.process.run("svn propset svn:externals 'bitbake https://github.com/PhilipHazel/pcre2.git' .",
Brad Bishop15ae2502019-06-18 21:44:24 -04001239 cwd=os.path.join(self.tempdir, 'svnfetch_co', 'trunk'))
1240 bb.process.run("svn commit --non-interactive -m 'Add external'",
1241 cwd=os.path.join(self.tempdir, 'svnfetch_co', 'trunk'))
1242
1243 self.src_dir = src_dir
1244 self.repo_dir = repo_dir
1245
1246 @skipIfNoSvn()
1247 def tearDown(self):
1248 os.chdir(self.origdir)
1249 if os.environ.get("BB_TMPDIR_NOCLEAN") == "yes":
1250 print("Not cleaning up %s. Please remove manually." % self.tempdir)
1251 else:
1252 bb.utils.prunedir(self.tempdir)
1253
1254 @skipIfNoSvn()
1255 @skipIfNoNetwork()
1256 def test_noexternal_svn(self):
1257 # Always match the rev count from setUp (currently rev 2)
1258 url = "svn://%s;module=trunk;protocol=file;rev=2" % self.repo_url.replace('file://', '')
1259 fetcher = bb.fetch.Fetch([url], self.d)
1260 fetcher.download()
1261 os.chdir(os.path.dirname(self.unpackdir))
1262 fetcher.unpack(self.unpackdir)
1263
1264 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk')), msg="Missing trunk")
1265 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk', 'README.md')), msg="Missing contents")
1266 self.assertFalse(os.path.exists(os.path.join(self.unpackdir, 'trunk/bitbake/trunk')), msg="External dir should NOT exist")
1267 self.assertFalse(os.path.exists(os.path.join(self.unpackdir, 'trunk/bitbake/trunk', 'README')), msg="External README should NOT exit")
1268
1269 @skipIfNoSvn()
1270 def test_external_svn(self):
1271 # Always match the rev count from setUp (currently rev 2)
1272 url = "svn://%s;module=trunk;protocol=file;externals=allowed;rev=2" % self.repo_url.replace('file://', '')
1273 fetcher = bb.fetch.Fetch([url], self.d)
1274 fetcher.download()
1275 os.chdir(os.path.dirname(self.unpackdir))
1276 fetcher.unpack(self.unpackdir)
1277
1278 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk')), msg="Missing trunk")
1279 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk', 'README.md')), msg="Missing contents")
1280 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk/bitbake/trunk')), msg="External dir should exist")
1281 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk/bitbake/trunk', 'README')), msg="External README should exit")
1282
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001283class TrustedNetworksTest(FetcherTest):
1284 def test_trusted_network(self):
1285 # Ensure trusted_network returns False when the host IS in the list.
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001286 url = "git://Someserver.org/foo;rev=1;branch=master"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001287 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org someserver.org server2.org server3.org")
1288 self.assertTrue(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001289
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001290 def test_wild_trusted_network(self):
1291 # Ensure trusted_network returns true when the *.host IS in the list.
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001292 url = "git://Someserver.org/foo;rev=1;branch=master"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001293 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
1294 self.assertTrue(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001295
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001296 def test_prefix_wild_trusted_network(self):
1297 # Ensure trusted_network returns true when the prefix matches *.host.
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001298 url = "git://git.Someserver.org/foo;rev=1;branch=master"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001299 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
1300 self.assertTrue(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001301
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001302 def test_two_prefix_wild_trusted_network(self):
1303 # Ensure trusted_network returns true when the prefix matches *.host.
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001304 url = "git://something.git.Someserver.org/foo;rev=1;branch=master"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001305 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
1306 self.assertTrue(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001307
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001308 def test_port_trusted_network(self):
1309 # Ensure trusted_network returns True, even if the url specifies a port.
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001310 url = "git://someserver.org:8080/foo;rev=1;branch=master"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001311 self.d.setVar("BB_ALLOWED_NETWORKS", "someserver.org")
1312 self.assertTrue(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001313
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001314 def test_untrusted_network(self):
1315 # Ensure trusted_network returns False when the host is NOT in the list.
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001316 url = "git://someserver.org/foo;rev=1;branch=master"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001317 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org server2.org server3.org")
1318 self.assertFalse(bb.fetch.trusted_network(self.d, url))
1319
1320 def test_wild_untrusted_network(self):
1321 # Ensure trusted_network returns False when the host is NOT in the list.
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001322 url = "git://*.someserver.org/foo;rev=1;branch=master"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001323 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org server2.org server3.org")
1324 self.assertFalse(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001325
1326class URLHandle(unittest.TestCase):
1327
1328 datatable = {
1329 "http://www.google.com/index.html" : ('http', 'www.google.com', '/index.html', '', '', {}),
1330 "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 -06001331 "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')])),
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001332 "git://git.openembedded.org/bitbake;branch=@foo" : ('git', 'git.openembedded.org', '/bitbake', '', '', {'branch': '@foo'}),
1333 "file://somelocation;someparam=1": ('file', '', 'somelocation', '', '', {'someparam': '1'}),
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001334 }
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001335 # we require a pathname to encodeurl but users can still pass such urls to
1336 # decodeurl and we need to handle them
1337 decodedata = datatable.copy()
1338 decodedata.update({
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001339 "http://somesite.net;someparam=1": ('http', 'somesite.net', '/', '', '', {'someparam': '1'}),
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001340 })
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001341
1342 def test_decodeurl(self):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001343 for k, v in self.decodedata.items():
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001344 result = bb.fetch.decodeurl(k)
1345 self.assertEqual(result, v)
1346
1347 def test_encodeurl(self):
1348 for k, v in self.datatable.items():
1349 result = bb.fetch.encodeurl(v)
1350 self.assertEqual(result, k)
1351
1352class FetchLatestVersionTest(FetcherTest):
1353
1354 test_git_uris = {
1355 # version pattern "X.Y.Z"
Andrew Geissler595f6302022-01-24 19:11:47 +00001356 ("mx-1.0", "git://github.com/clutter-project/mx.git;branch=mx-1.4;protocol=https", "9b1db6b8060bd00b121a692f942404a24ae2960f", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001357 : "1.99.4",
1358 # version pattern "vX.Y"
Andrew Geisslerd25ed322020-06-27 00:28:28 -05001359 # mirror of git.infradead.org since network issues interfered with testing
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001360 ("mtd-utils", "git://git.yoctoproject.org/mtd-utils.git;branch=master", "ca39eb1d98e736109c64ff9c1aa2a6ecca222d8f", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001361 : "1.5.0",
1362 # version pattern "pkg_name-X.Y"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001363 # mirror of git://anongit.freedesktop.org/git/xorg/proto/presentproto since network issues interfered with testing
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001364 ("presentproto", "git://git.yoctoproject.org/bbfetchtests-presentproto;branch=master", "24f3a56e541b0a9e6c6ee76081f441221a120ef9", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001365 : "1.0",
1366 # version pattern "pkg_name-vX.Y.Z"
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001367 ("dtc", "git://git.yoctoproject.org/bbfetchtests-dtc.git;branch=master", "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001368 : "1.4.0",
1369 # combination version pattern
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001370 ("sysprof", "git://gitlab.gnome.org/GNOME/sysprof.git;protocol=https;branch=master", "cd44ee6644c3641507fb53b8a2a69137f2971219", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001371 : "1.2.0",
1372 ("u-boot-mkimage", "git://git.denx.de/u-boot.git;branch=master;protocol=git", "62c175fbb8a0f9a926c88294ea9f7e88eb898f6c", "")
1373 : "2014.01",
1374 # version pattern "yyyymmdd"
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001375 ("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 -05001376 : "20120614",
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001377 # packages with a valid UPSTREAM_CHECK_GITTAGREGEX
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001378 # mirror of git://anongit.freedesktop.org/xorg/driver/xf86-video-omap since network issues interfered with testing
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001379 ("xf86-video-omap", "git://git.yoctoproject.org/bbfetchtests-xf86-video-omap;branch=master", "ae0394e687f1a77e966cf72f895da91840dffb8f", r"(?P<pver>(\d+\.(\d\.?)*))")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001380 : "0.4.3",
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001381 ("build-appliance-image", "git://git.yoctoproject.org/poky;branch=master", "b37dd451a52622d5b570183a81583cc34c2ff555", r"(?P<pver>(([0-9][\.|_]?)+[0-9]))")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001382 : "11.0.0",
Andrew Geissler595f6302022-01-24 19:11:47 +00001383 ("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 -05001384 : "1.3.59",
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001385 ("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 -05001386 : "3.82+dbg0.9",
1387 }
1388
1389 test_wget_uris = {
Andrew Geissler82c905d2020-04-13 13:39:40 -05001390 #
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001391 # packages with versions inside directory name
Andrew Geissler82c905d2020-04-13 13:39:40 -05001392 #
1393 # http://kernel.org/pub/linux/utils/util-linux/v2.23/util-linux-2.24.2.tar.bz2
1394 ("util-linux", "/pub/linux/utils/util-linux/v2.23/util-linux-2.24.2.tar.bz2", "", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001395 : "2.24.2",
Andrew Geissler82c905d2020-04-13 13:39:40 -05001396 # http://www.abisource.com/downloads/enchant/1.6.0/enchant-1.6.0.tar.gz
1397 ("enchant", "/downloads/enchant/1.6.0/enchant-1.6.0.tar.gz", "", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001398 : "1.6.0",
Andrew Geissler82c905d2020-04-13 13:39:40 -05001399 # http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz
1400 ("cmake", "/files/v2.8/cmake-2.8.12.1.tar.gz", "", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001401 : "2.8.12.1",
Andrew Geissler82c905d2020-04-13 13:39:40 -05001402 #
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001403 # packages with versions only in current directory
Andrew Geissler82c905d2020-04-13 13:39:40 -05001404 #
Andrew Geisslereff27472021-10-29 15:35:00 -05001405 # https://downloads.yoctoproject.org/releases/eglibc/eglibc-2.18-svnr23787.tar.bz2
Andrew Geissler82c905d2020-04-13 13:39:40 -05001406 ("eglic", "/releases/eglibc/eglibc-2.18-svnr23787.tar.bz2", "", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001407 : "2.19",
Andrew Geisslereff27472021-10-29 15:35:00 -05001408 # https://downloads.yoctoproject.org/releases/gnu-config/gnu-config-20120814.tar.bz2
Andrew Geissler82c905d2020-04-13 13:39:40 -05001409 ("gnu-config", "/releases/gnu-config/gnu-config-20120814.tar.bz2", "", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001410 : "20120814",
Andrew Geissler82c905d2020-04-13 13:39:40 -05001411 #
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001412 # packages with "99" in the name of possible version
Andrew Geissler82c905d2020-04-13 13:39:40 -05001413 #
1414 # http://freedesktop.org/software/pulseaudio/releases/pulseaudio-4.0.tar.xz
1415 ("pulseaudio", "/software/pulseaudio/releases/pulseaudio-4.0.tar.xz", "", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001416 : "5.0",
Andrew Geissler82c905d2020-04-13 13:39:40 -05001417 # http://xorg.freedesktop.org/releases/individual/xserver/xorg-server-1.15.1.tar.bz2
1418 ("xserver-xorg", "/releases/individual/xserver/xorg-server-1.15.1.tar.bz2", "", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001419 : "1.15.1",
Andrew Geissler82c905d2020-04-13 13:39:40 -05001420 #
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001421 # packages with valid UPSTREAM_CHECK_URI and UPSTREAM_CHECK_REGEX
Andrew Geissler82c905d2020-04-13 13:39:40 -05001422 #
1423 # http://www.cups.org/software/1.7.2/cups-1.7.2-source.tar.bz2
1424 # https://github.com/apple/cups/releases
Andrew Geissler5199d832021-09-24 16:47:35 -05001425 ("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 -05001426 : "2.0.0",
Andrew Geissler82c905d2020-04-13 13:39:40 -05001427 # http://download.oracle.com/berkeley-db/db-5.3.21.tar.gz
1428 # http://ftp.debian.org/debian/pool/main/d/db5.3/
Andrew Geissler5199d832021-09-24 16:47:35 -05001429 ("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 -04001430 : "5.3.10",
Andrew Geissler595f6302022-01-24 19:11:47 +00001431 #
1432 # packages where the tarball compression changed in the new version
1433 #
1434 # http://ftp.debian.org/debian/pool/main/m/minicom/minicom_2.7.1.orig.tar.gz
1435 ("minicom", "/debian/pool/main/m/minicom/minicom_2.7.1.orig.tar.gz", "", "")
1436 : "2.8",
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001437 }
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001438
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001439 @skipIfNoNetwork()
1440 def test_git_latest_versionstring(self):
1441 for k, v in self.test_git_uris.items():
1442 self.d.setVar("PN", k[0])
1443 self.d.setVar("SRCREV", k[2])
1444 self.d.setVar("UPSTREAM_CHECK_GITTAGREGEX", k[3])
1445 ud = bb.fetch2.FetchData(k[1], self.d)
1446 pupver= ud.method.latest_versionstring(ud, self.d)
1447 verstring = pupver[0]
Brad Bishop316dfdd2018-06-25 12:45:53 -04001448 self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0])
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001449 r = bb.utils.vercmp_string(v, verstring)
1450 self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring))
1451
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001452 def test_wget_latest_versionstring(self):
Andrew Geissler82c905d2020-04-13 13:39:40 -05001453 testdata = os.path.dirname(os.path.abspath(__file__)) + "/fetch-testdata"
1454 server = HTTPService(testdata)
1455 server.start()
1456 port = server.port
1457 try:
1458 for k, v in self.test_wget_uris.items():
1459 self.d.setVar("PN", k[0])
1460 checkuri = ""
1461 if k[2]:
1462 checkuri = "http://localhost:%s/" % port + k[2]
1463 self.d.setVar("UPSTREAM_CHECK_URI", checkuri)
1464 self.d.setVar("UPSTREAM_CHECK_REGEX", k[3])
1465 url = "http://localhost:%s/" % port + k[1]
1466 ud = bb.fetch2.FetchData(url, self.d)
1467 pupver = ud.method.latest_versionstring(ud, self.d)
1468 verstring = pupver[0]
1469 self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0])
1470 r = bb.utils.vercmp_string(v, verstring)
1471 self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring))
1472 finally:
1473 server.stop()
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001474
1475
1476class FetchCheckStatusTest(FetcherTest):
Andrew Geisslereff27472021-10-29 15:35:00 -05001477 test_wget_uris = ["https://downloads.yoctoproject.org/releases/sato/sato-engine-0.1.tar.gz",
1478 "https://downloads.yoctoproject.org/releases/sato/sato-engine-0.2.tar.gz",
1479 "https://downloads.yoctoproject.org/releases/sato/sato-engine-0.3.tar.gz",
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001480 "https://yoctoproject.org/",
Andrew Geissler95ac1b82021-03-31 14:34:31 -05001481 "https://docs.yoctoproject.org",
Andrew Geisslereff27472021-10-29 15:35:00 -05001482 "https://downloads.yoctoproject.org/releases/opkg/opkg-0.1.7.tar.gz",
1483 "https://downloads.yoctoproject.org/releases/opkg/opkg-0.3.0.tar.gz",
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001484 "ftp://sourceware.org/pub/libffi/libffi-1.20.tar.gz",
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001485 # GitHub releases are hosted on Amazon S3, which doesn't support HEAD
1486 "https://github.com/kergoth/tslib/releases/download/1.1/tslib-1.1.tar.xz"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001487 ]
1488
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001489 @skipIfNoNetwork()
1490 def test_wget_checkstatus(self):
1491 fetch = bb.fetch2.Fetch(self.test_wget_uris, self.d)
1492 for u in self.test_wget_uris:
1493 with self.subTest(url=u):
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001494 ud = fetch.ud[u]
1495 m = ud.method
1496 ret = m.checkstatus(fetch, ud, self.d)
1497 self.assertTrue(ret, msg="URI %s, can't check status" % (u))
1498
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001499 @skipIfNoNetwork()
1500 def test_wget_checkstatus_connection_cache(self):
1501 from bb.fetch2 import FetchConnectionCache
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001502
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001503 connection_cache = FetchConnectionCache()
1504 fetch = bb.fetch2.Fetch(self.test_wget_uris, self.d,
1505 connection_cache = connection_cache)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001506
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001507 for u in self.test_wget_uris:
1508 with self.subTest(url=u):
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001509 ud = fetch.ud[u]
1510 m = ud.method
1511 ret = m.checkstatus(fetch, ud, self.d)
1512 self.assertTrue(ret, msg="URI %s, can't check status" % (u))
1513
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001514 connection_cache.close_connections()
1515
1516
1517class GitMakeShallowTest(FetcherTest):
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001518 def setUp(self):
1519 FetcherTest.setUp(self)
1520 self.gitdir = os.path.join(self.tempdir, 'gitshallow')
1521 bb.utils.mkdirhier(self.gitdir)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001522 self.git_init()
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001523
1524 def assertRefs(self, expected_refs):
1525 actual_refs = self.git(['for-each-ref', '--format=%(refname)']).splitlines()
1526 full_expected = self.git(['rev-parse', '--symbolic-full-name'] + expected_refs).splitlines()
1527 self.assertEqual(sorted(full_expected), sorted(actual_refs))
1528
1529 def assertRevCount(self, expected_count, args=None):
1530 if args is None:
1531 args = ['HEAD']
1532 revs = self.git(['rev-list'] + args)
1533 actual_count = len(revs.splitlines())
1534 self.assertEqual(expected_count, actual_count, msg='Object count `%d` is not the expected `%d`' % (actual_count, expected_count))
1535
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001536 def make_shallow(self, args=None):
1537 if args is None:
1538 args = ['HEAD']
Brad Bishop316dfdd2018-06-25 12:45:53 -04001539 return bb.process.run([bb.fetch2.git.Git.make_shallow_path] + args, cwd=self.gitdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001540
1541 def add_empty_file(self, path, msg=None):
1542 if msg is None:
1543 msg = path
1544 open(os.path.join(self.gitdir, path), 'w').close()
1545 self.git(['add', path])
1546 self.git(['commit', '-m', msg, path])
1547
1548 def test_make_shallow_single_branch_no_merge(self):
1549 self.add_empty_file('a')
1550 self.add_empty_file('b')
1551 self.assertRevCount(2)
1552 self.make_shallow()
1553 self.assertRevCount(1)
1554
1555 def test_make_shallow_single_branch_one_merge(self):
1556 self.add_empty_file('a')
1557 self.add_empty_file('b')
1558 self.git('checkout -b a_branch')
1559 self.add_empty_file('c')
1560 self.git('checkout master')
1561 self.add_empty_file('d')
1562 self.git('merge --no-ff --no-edit a_branch')
1563 self.git('branch -d a_branch')
1564 self.add_empty_file('e')
1565 self.assertRevCount(6)
1566 self.make_shallow(['HEAD~2'])
1567 self.assertRevCount(5)
1568
1569 def test_make_shallow_at_merge(self):
1570 self.add_empty_file('a')
1571 self.git('checkout -b a_branch')
1572 self.add_empty_file('b')
1573 self.git('checkout master')
1574 self.git('merge --no-ff --no-edit a_branch')
1575 self.git('branch -d a_branch')
1576 self.assertRevCount(3)
1577 self.make_shallow()
1578 self.assertRevCount(1)
1579
1580 def test_make_shallow_annotated_tag(self):
1581 self.add_empty_file('a')
1582 self.add_empty_file('b')
1583 self.git('tag -a -m a_tag a_tag')
1584 self.assertRevCount(2)
1585 self.make_shallow(['a_tag'])
1586 self.assertRevCount(1)
1587
1588 def test_make_shallow_multi_ref(self):
1589 self.add_empty_file('a')
1590 self.add_empty_file('b')
1591 self.git('checkout -b a_branch')
1592 self.add_empty_file('c')
1593 self.git('checkout master')
1594 self.add_empty_file('d')
1595 self.git('checkout -b a_branch_2')
1596 self.add_empty_file('a_tag')
1597 self.git('tag a_tag')
1598 self.git('checkout master')
1599 self.git('branch -D a_branch_2')
1600 self.add_empty_file('e')
1601 self.assertRevCount(6, ['--all'])
1602 self.make_shallow()
1603 self.assertRevCount(5, ['--all'])
1604
1605 def test_make_shallow_multi_ref_trim(self):
1606 self.add_empty_file('a')
1607 self.git('checkout -b a_branch')
1608 self.add_empty_file('c')
1609 self.git('checkout master')
1610 self.assertRevCount(1)
1611 self.assertRevCount(2, ['--all'])
1612 self.assertRefs(['master', 'a_branch'])
1613 self.make_shallow(['-r', 'master', 'HEAD'])
1614 self.assertRevCount(1, ['--all'])
1615 self.assertRefs(['master'])
1616
1617 def test_make_shallow_noop(self):
1618 self.add_empty_file('a')
1619 self.assertRevCount(1)
1620 self.make_shallow()
1621 self.assertRevCount(1)
1622
1623 @skipIfNoNetwork()
1624 def test_make_shallow_bitbake(self):
1625 self.git('remote add origin https://github.com/openembedded/bitbake')
1626 self.git('fetch --tags origin')
1627 orig_revs = len(self.git('rev-list --all').splitlines())
1628 self.make_shallow(['refs/tags/1.10.0'])
1629 self.assertRevCount(orig_revs - 1746, ['--all'])
1630
1631class GitShallowTest(FetcherTest):
1632 def setUp(self):
1633 FetcherTest.setUp(self)
1634 self.gitdir = os.path.join(self.tempdir, 'git')
1635 self.srcdir = os.path.join(self.tempdir, 'gitsource')
1636
1637 bb.utils.mkdirhier(self.srcdir)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001638 self.git_init(cwd=self.srcdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001639 self.d.setVar('WORKDIR', self.tempdir)
1640 self.d.setVar('S', self.gitdir)
1641 self.d.delVar('PREMIRRORS')
1642 self.d.delVar('MIRRORS')
1643
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001644 uri = 'git://%s;protocol=file;subdir=${S};branch=master' % self.srcdir
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001645 self.d.setVar('SRC_URI', uri)
1646 self.d.setVar('SRCREV', '${AUTOREV}')
1647 self.d.setVar('AUTOREV', '${@bb.fetch2.get_autorev(d)}')
1648
1649 self.d.setVar('BB_GIT_SHALLOW', '1')
1650 self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '0')
1651 self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1')
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001652 self.d.setVar("__BBSEENSRCREV", "1")
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001653
1654 def assertRefs(self, expected_refs, cwd=None):
1655 if cwd is None:
1656 cwd = self.gitdir
1657 actual_refs = self.git(['for-each-ref', '--format=%(refname)'], cwd=cwd).splitlines()
1658 full_expected = self.git(['rev-parse', '--symbolic-full-name'] + expected_refs, cwd=cwd).splitlines()
1659 self.assertEqual(sorted(set(full_expected)), sorted(set(actual_refs)))
1660
1661 def assertRevCount(self, expected_count, args=None, cwd=None):
1662 if args is None:
1663 args = ['HEAD']
1664 if cwd is None:
1665 cwd = self.gitdir
1666 revs = self.git(['rev-list'] + args, cwd=cwd)
1667 actual_count = len(revs.splitlines())
1668 self.assertEqual(expected_count, actual_count, msg='Object count `%d` is not the expected `%d`' % (actual_count, expected_count))
1669
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001670 def add_empty_file(self, path, cwd=None, msg=None):
1671 if msg is None:
1672 msg = path
1673 if cwd is None:
1674 cwd = self.srcdir
1675 open(os.path.join(cwd, path), 'w').close()
1676 self.git(['add', path], cwd)
1677 self.git(['commit', '-m', msg, path], cwd)
1678
1679 def fetch(self, uri=None):
1680 if uri is None:
Brad Bishop19323692019-04-05 15:28:33 -04001681 uris = self.d.getVar('SRC_URI').split()
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001682 uri = uris[0]
1683 d = self.d
1684 else:
1685 d = self.d.createCopy()
1686 d.setVar('SRC_URI', uri)
1687 uri = d.expand(uri)
1688 uris = [uri]
1689
1690 fetcher = bb.fetch2.Fetch(uris, d)
1691 fetcher.download()
1692 ud = fetcher.ud[uri]
1693 return fetcher, ud
1694
1695 def fetch_and_unpack(self, uri=None):
1696 fetcher, ud = self.fetch(uri)
1697 fetcher.unpack(self.d.getVar('WORKDIR'))
1698 assert os.path.exists(self.d.getVar('S'))
1699 return fetcher, ud
1700
1701 def fetch_shallow(self, uri=None, disabled=False, keepclone=False):
1702 """Fetch a uri, generating a shallow tarball, then unpack using it"""
1703 fetcher, ud = self.fetch_and_unpack(uri)
1704 assert os.path.exists(ud.clonedir), 'Git clone in DLDIR (%s) does not exist for uri %s' % (ud.clonedir, uri)
1705
1706 # Confirm that the unpacked repo is unshallow
1707 if not disabled:
1708 assert os.path.exists(os.path.join(self.dldir, ud.mirrortarballs[0]))
1709
1710 # fetch and unpack, from the shallow tarball
1711 bb.utils.remove(self.gitdir, recurse=True)
Andrew Geisslerc926e172021-05-07 16:11:35 -05001712 bb.process.run('chmod u+w -R "%s"' % ud.clonedir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001713 bb.utils.remove(ud.clonedir, recurse=True)
Brad Bishopf8caae32019-03-25 13:13:56 -04001714 bb.utils.remove(ud.clonedir.replace('gitsource', 'gitsubmodule'), recurse=True)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001715
1716 # confirm that the unpacked repo is used when no git clone or git
1717 # mirror tarball is available
1718 fetcher, ud = self.fetch_and_unpack(uri)
1719 if not disabled:
1720 assert os.path.exists(os.path.join(self.gitdir, '.git', 'shallow')), 'Unpacked git repository at %s is not shallow' % self.gitdir
1721 else:
1722 assert not os.path.exists(os.path.join(self.gitdir, '.git', 'shallow')), 'Unpacked git repository at %s is shallow' % self.gitdir
1723 return fetcher, ud
1724
1725 def test_shallow_disabled(self):
1726 self.add_empty_file('a')
1727 self.add_empty_file('b')
1728 self.assertRevCount(2, cwd=self.srcdir)
1729
1730 self.d.setVar('BB_GIT_SHALLOW', '0')
1731 self.fetch_shallow(disabled=True)
1732 self.assertRevCount(2)
1733
1734 def test_shallow_nobranch(self):
1735 self.add_empty_file('a')
1736 self.add_empty_file('b')
1737 self.assertRevCount(2, cwd=self.srcdir)
1738
1739 srcrev = self.git('rev-parse HEAD', cwd=self.srcdir).strip()
1740 self.d.setVar('SRCREV', srcrev)
Brad Bishop19323692019-04-05 15:28:33 -04001741 uri = self.d.getVar('SRC_URI').split()[0]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001742 uri = '%s;nobranch=1;bare=1' % uri
1743
1744 self.fetch_shallow(uri)
1745 self.assertRevCount(1)
1746
1747 # shallow refs are used to ensure the srcrev sticks around when we
1748 # have no other branches referencing it
1749 self.assertRefs(['refs/shallow/default'])
1750
1751 def test_shallow_default_depth_1(self):
1752 # Create initial git repo
1753 self.add_empty_file('a')
1754 self.add_empty_file('b')
1755 self.assertRevCount(2, cwd=self.srcdir)
1756
1757 self.fetch_shallow()
1758 self.assertRevCount(1)
1759
1760 def test_shallow_depth_0_disables(self):
1761 self.add_empty_file('a')
1762 self.add_empty_file('b')
1763 self.assertRevCount(2, cwd=self.srcdir)
1764
1765 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
1766 self.fetch_shallow(disabled=True)
1767 self.assertRevCount(2)
1768
1769 def test_shallow_depth_default_override(self):
1770 self.add_empty_file('a')
1771 self.add_empty_file('b')
1772 self.assertRevCount(2, cwd=self.srcdir)
1773
1774 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '2')
1775 self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '1')
1776 self.fetch_shallow()
1777 self.assertRevCount(1)
1778
1779 def test_shallow_depth_default_override_disable(self):
1780 self.add_empty_file('a')
1781 self.add_empty_file('b')
1782 self.add_empty_file('c')
1783 self.assertRevCount(3, cwd=self.srcdir)
1784
1785 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
1786 self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '2')
1787 self.fetch_shallow()
1788 self.assertRevCount(2)
1789
1790 def test_current_shallow_out_of_date_clone(self):
1791 # Create initial git repo
1792 self.add_empty_file('a')
1793 self.add_empty_file('b')
1794 self.add_empty_file('c')
1795 self.assertRevCount(3, cwd=self.srcdir)
1796
1797 # Clone and generate mirror tarball
1798 fetcher, ud = self.fetch()
1799
1800 # Ensure we have a current mirror tarball, but an out of date clone
1801 self.git('update-ref refs/heads/master refs/heads/master~1', cwd=ud.clonedir)
1802 self.assertRevCount(2, cwd=ud.clonedir)
1803
1804 # Fetch and unpack, from the current tarball, not the out of date clone
1805 bb.utils.remove(self.gitdir, recurse=True)
1806 fetcher, ud = self.fetch()
1807 fetcher.unpack(self.d.getVar('WORKDIR'))
1808 self.assertRevCount(1)
1809
1810 def test_shallow_single_branch_no_merge(self):
1811 self.add_empty_file('a')
1812 self.add_empty_file('b')
1813 self.assertRevCount(2, cwd=self.srcdir)
1814
1815 self.fetch_shallow()
1816 self.assertRevCount(1)
1817 assert os.path.exists(os.path.join(self.gitdir, 'a'))
1818 assert os.path.exists(os.path.join(self.gitdir, 'b'))
1819
1820 def test_shallow_no_dangling(self):
1821 self.add_empty_file('a')
1822 self.add_empty_file('b')
1823 self.assertRevCount(2, cwd=self.srcdir)
1824
1825 self.fetch_shallow()
1826 self.assertRevCount(1)
1827 assert not self.git('fsck --dangling')
1828
1829 def test_shallow_srcrev_branch_truncation(self):
1830 self.add_empty_file('a')
1831 self.add_empty_file('b')
1832 b_commit = self.git('rev-parse HEAD', cwd=self.srcdir).rstrip()
1833 self.add_empty_file('c')
1834 self.assertRevCount(3, cwd=self.srcdir)
1835
1836 self.d.setVar('SRCREV', b_commit)
1837 self.fetch_shallow()
1838
1839 # The 'c' commit was removed entirely, and 'a' was removed from history
1840 self.assertRevCount(1, ['--all'])
1841 self.assertEqual(self.git('rev-parse HEAD').strip(), b_commit)
1842 assert os.path.exists(os.path.join(self.gitdir, 'a'))
1843 assert os.path.exists(os.path.join(self.gitdir, 'b'))
1844 assert not os.path.exists(os.path.join(self.gitdir, 'c'))
1845
1846 def test_shallow_ref_pruning(self):
1847 self.add_empty_file('a')
1848 self.add_empty_file('b')
1849 self.git('branch a_branch', cwd=self.srcdir)
1850 self.assertRefs(['master', 'a_branch'], cwd=self.srcdir)
1851 self.assertRevCount(2, cwd=self.srcdir)
1852
1853 self.fetch_shallow()
1854
1855 self.assertRefs(['master', 'origin/master'])
1856 self.assertRevCount(1)
1857
1858 def test_shallow_submodules(self):
1859 self.add_empty_file('a')
1860 self.add_empty_file('b')
1861
1862 smdir = os.path.join(self.tempdir, 'gitsubmodule')
1863 bb.utils.mkdirhier(smdir)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001864 self.git_init(cwd=smdir)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001865 # Make this look like it was cloned from a remote...
1866 self.git('config --add remote.origin.url "%s"' % smdir, cwd=smdir)
1867 self.git('config --add remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"', cwd=smdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001868 self.add_empty_file('asub', cwd=smdir)
Brad Bishopf8caae32019-03-25 13:13:56 -04001869 self.add_empty_file('bsub', cwd=smdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001870
1871 self.git('submodule init', cwd=self.srcdir)
1872 self.git('submodule add file://%s' % smdir, cwd=self.srcdir)
1873 self.git('submodule update', cwd=self.srcdir)
1874 self.git('commit -m submodule -a', cwd=self.srcdir)
1875
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001876 uri = 'gitsm://%s;protocol=file;subdir=${S};branch=master' % self.srcdir
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001877 fetcher, ud = self.fetch_shallow(uri)
1878
Brad Bishopf8caae32019-03-25 13:13:56 -04001879 # Verify the main repository is shallow
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001880 self.assertRevCount(1)
Brad Bishopf8caae32019-03-25 13:13:56 -04001881
1882 # Verify the gitsubmodule directory is present
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001883 assert os.listdir(os.path.join(self.gitdir, 'gitsubmodule'))
1884
Brad Bishopf8caae32019-03-25 13:13:56 -04001885 # Verify the submodule is also shallow
1886 self.assertRevCount(1, cwd=os.path.join(self.gitdir, 'gitsubmodule'))
1887
Andrew Geissler82c905d2020-04-13 13:39:40 -05001888 def test_shallow_submodule_mirrors(self):
1889 self.add_empty_file('a')
1890 self.add_empty_file('b')
1891
1892 smdir = os.path.join(self.tempdir, 'gitsubmodule')
1893 bb.utils.mkdirhier(smdir)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001894 self.git_init(cwd=smdir)
Andrew Geissler82c905d2020-04-13 13:39:40 -05001895 # Make this look like it was cloned from a remote...
1896 self.git('config --add remote.origin.url "%s"' % smdir, cwd=smdir)
1897 self.git('config --add remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"', cwd=smdir)
1898 self.add_empty_file('asub', cwd=smdir)
1899 self.add_empty_file('bsub', cwd=smdir)
1900
1901 self.git('submodule init', cwd=self.srcdir)
1902 self.git('submodule add file://%s' % smdir, cwd=self.srcdir)
1903 self.git('submodule update', cwd=self.srcdir)
1904 self.git('commit -m submodule -a', cwd=self.srcdir)
1905
1906 uri = 'gitsm://%s;protocol=file;subdir=${S}' % self.srcdir
1907
1908 # Fetch once to generate the shallow tarball
1909 fetcher, ud = self.fetch(uri)
1910
1911 # Set up the mirror
1912 mirrordir = os.path.join(self.tempdir, 'mirror')
Andrew Geisslerc926e172021-05-07 16:11:35 -05001913 bb.utils.rename(self.dldir, mirrordir)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001914 self.d.setVar('PREMIRRORS', 'gitsm://.*/.* file://%s/' % mirrordir)
Andrew Geissler82c905d2020-04-13 13:39:40 -05001915
1916 # Fetch from the mirror
1917 bb.utils.remove(self.dldir, recurse=True)
1918 bb.utils.remove(self.gitdir, recurse=True)
1919 self.fetch_and_unpack(uri)
1920
1921 # Verify the main repository is shallow
1922 self.assertRevCount(1)
1923
1924 # Verify the gitsubmodule directory is present
1925 assert os.listdir(os.path.join(self.gitdir, 'gitsubmodule'))
1926
1927 # Verify the submodule is also shallow
1928 self.assertRevCount(1, cwd=os.path.join(self.gitdir, 'gitsubmodule'))
Brad Bishopf8caae32019-03-25 13:13:56 -04001929
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001930 if any(os.path.exists(os.path.join(p, 'git-annex')) for p in os.environ.get('PATH').split(':')):
1931 def test_shallow_annex(self):
1932 self.add_empty_file('a')
1933 self.add_empty_file('b')
1934 self.git('annex init', cwd=self.srcdir)
1935 open(os.path.join(self.srcdir, 'c'), 'w').close()
1936 self.git('annex add c', cwd=self.srcdir)
Andrew Geisslerc926e172021-05-07 16:11:35 -05001937 self.git('commit --author "Foo Bar <foo@bar>" -m annex-c -a', cwd=self.srcdir)
1938 bb.process.run('chmod u+w -R %s' % self.srcdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001939
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001940 uri = 'gitannex://%s;protocol=file;subdir=${S};branch=master' % self.srcdir
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001941 fetcher, ud = self.fetch_shallow(uri)
1942
1943 self.assertRevCount(1)
1944 assert './.git/annex/' in bb.process.run('tar -tzf %s' % os.path.join(self.dldir, ud.mirrortarballs[0]))[0]
1945 assert os.path.exists(os.path.join(self.gitdir, 'c'))
1946
1947 def test_shallow_multi_one_uri(self):
1948 # Create initial git repo
1949 self.add_empty_file('a')
1950 self.add_empty_file('b')
1951 self.git('checkout -b a_branch', cwd=self.srcdir)
1952 self.add_empty_file('c')
1953 self.add_empty_file('d')
1954 self.git('checkout master', cwd=self.srcdir)
1955 self.git('tag v0.0 a_branch', cwd=self.srcdir)
1956 self.add_empty_file('e')
1957 self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir)
1958 self.add_empty_file('f')
1959 self.assertRevCount(7, cwd=self.srcdir)
1960
Brad Bishop19323692019-04-05 15:28:33 -04001961 uri = self.d.getVar('SRC_URI').split()[0]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001962 uri = '%s;branch=master,a_branch;name=master,a_branch' % uri
1963
1964 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
1965 self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
1966 self.d.setVar('SRCREV_master', '${AUTOREV}')
1967 self.d.setVar('SRCREV_a_branch', '${AUTOREV}')
1968
1969 self.fetch_shallow(uri)
1970
1971 self.assertRevCount(5)
1972 self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
1973
1974 def test_shallow_multi_one_uri_depths(self):
1975 # Create initial git repo
1976 self.add_empty_file('a')
1977 self.add_empty_file('b')
1978 self.git('checkout -b a_branch', cwd=self.srcdir)
1979 self.add_empty_file('c')
1980 self.add_empty_file('d')
1981 self.git('checkout master', cwd=self.srcdir)
1982 self.add_empty_file('e')
1983 self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir)
1984 self.add_empty_file('f')
1985 self.assertRevCount(7, cwd=self.srcdir)
1986
Brad Bishop19323692019-04-05 15:28:33 -04001987 uri = self.d.getVar('SRC_URI').split()[0]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001988 uri = '%s;branch=master,a_branch;name=master,a_branch' % uri
1989
1990 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
1991 self.d.setVar('BB_GIT_SHALLOW_DEPTH_master', '3')
1992 self.d.setVar('BB_GIT_SHALLOW_DEPTH_a_branch', '1')
1993 self.d.setVar('SRCREV_master', '${AUTOREV}')
1994 self.d.setVar('SRCREV_a_branch', '${AUTOREV}')
1995
1996 self.fetch_shallow(uri)
1997
1998 self.assertRevCount(4, ['--all'])
1999 self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
2000
2001 def test_shallow_clone_preferred_over_shallow(self):
2002 self.add_empty_file('a')
2003 self.add_empty_file('b')
2004
2005 # Fetch once to generate the shallow tarball
2006 fetcher, ud = self.fetch()
2007 assert os.path.exists(os.path.join(self.dldir, ud.mirrortarballs[0]))
2008
2009 # Fetch and unpack with both the clonedir and shallow tarball available
2010 bb.utils.remove(self.gitdir, recurse=True)
2011 fetcher, ud = self.fetch_and_unpack()
2012
2013 # The unpacked tree should *not* be shallow
2014 self.assertRevCount(2)
2015 assert not os.path.exists(os.path.join(self.gitdir, '.git', 'shallow'))
2016
2017 def test_shallow_mirrors(self):
2018 self.add_empty_file('a')
2019 self.add_empty_file('b')
2020
2021 # Fetch once to generate the shallow tarball
2022 fetcher, ud = self.fetch()
2023 mirrortarball = ud.mirrortarballs[0]
2024 assert os.path.exists(os.path.join(self.dldir, mirrortarball))
2025
2026 # Set up the mirror
2027 mirrordir = os.path.join(self.tempdir, 'mirror')
2028 bb.utils.mkdirhier(mirrordir)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002029 self.d.setVar('PREMIRRORS', 'git://.*/.* file://%s/' % mirrordir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002030
Andrew Geisslerc926e172021-05-07 16:11:35 -05002031 bb.utils.rename(os.path.join(self.dldir, mirrortarball),
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002032 os.path.join(mirrordir, mirrortarball))
2033
2034 # Fetch from the mirror
2035 bb.utils.remove(self.dldir, recurse=True)
2036 bb.utils.remove(self.gitdir, recurse=True)
2037 self.fetch_and_unpack()
2038 self.assertRevCount(1)
2039
2040 def test_shallow_invalid_depth(self):
2041 self.add_empty_file('a')
2042 self.add_empty_file('b')
2043
2044 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '-12')
2045 with self.assertRaises(bb.fetch2.FetchError):
2046 self.fetch()
2047
2048 def test_shallow_invalid_depth_default(self):
2049 self.add_empty_file('a')
2050 self.add_empty_file('b')
2051
2052 self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '-12')
2053 with self.assertRaises(bb.fetch2.FetchError):
2054 self.fetch()
2055
2056 def test_shallow_extra_refs(self):
2057 self.add_empty_file('a')
2058 self.add_empty_file('b')
2059 self.git('branch a_branch', cwd=self.srcdir)
2060 self.assertRefs(['master', 'a_branch'], cwd=self.srcdir)
2061 self.assertRevCount(2, cwd=self.srcdir)
2062
2063 self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/heads/a_branch')
2064 self.fetch_shallow()
2065
2066 self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
2067 self.assertRevCount(1)
2068
2069 def test_shallow_extra_refs_wildcard(self):
2070 self.add_empty_file('a')
2071 self.add_empty_file('b')
2072 self.git('branch a_branch', cwd=self.srcdir)
2073 self.git('tag v1.0', cwd=self.srcdir)
2074 self.assertRefs(['master', 'a_branch', 'v1.0'], cwd=self.srcdir)
2075 self.assertRevCount(2, cwd=self.srcdir)
2076
2077 self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/tags/*')
2078 self.fetch_shallow()
2079
2080 self.assertRefs(['master', 'origin/master', 'v1.0'])
2081 self.assertRevCount(1)
2082
2083 def test_shallow_missing_extra_refs(self):
2084 self.add_empty_file('a')
2085 self.add_empty_file('b')
2086
2087 self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/heads/foo')
2088 with self.assertRaises(bb.fetch2.FetchError):
2089 self.fetch()
2090
2091 def test_shallow_missing_extra_refs_wildcard(self):
2092 self.add_empty_file('a')
2093 self.add_empty_file('b')
2094
2095 self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/tags/*')
2096 self.fetch()
2097
2098 def test_shallow_remove_revs(self):
2099 # Create initial git repo
2100 self.add_empty_file('a')
2101 self.add_empty_file('b')
2102 self.git('checkout -b a_branch', cwd=self.srcdir)
2103 self.add_empty_file('c')
2104 self.add_empty_file('d')
2105 self.git('checkout master', cwd=self.srcdir)
2106 self.git('tag v0.0 a_branch', cwd=self.srcdir)
2107 self.add_empty_file('e')
2108 self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir)
2109 self.git('branch -d a_branch', cwd=self.srcdir)
2110 self.add_empty_file('f')
2111 self.assertRevCount(7, cwd=self.srcdir)
2112
2113 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
2114 self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
2115
2116 self.fetch_shallow()
2117
2118 self.assertRevCount(5)
2119
2120 def test_shallow_invalid_revs(self):
2121 self.add_empty_file('a')
2122 self.add_empty_file('b')
2123
2124 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
2125 self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
2126
2127 with self.assertRaises(bb.fetch2.FetchError):
2128 self.fetch()
2129
Brad Bishop64c979e2019-11-04 13:55:29 -05002130 def test_shallow_fetch_missing_revs(self):
2131 self.add_empty_file('a')
2132 self.add_empty_file('b')
2133 fetcher, ud = self.fetch(self.d.getVar('SRC_URI'))
2134 self.git('tag v0.0 master', cwd=self.srcdir)
2135 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
2136 self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
2137 self.fetch_shallow()
2138
2139 def test_shallow_fetch_missing_revs_fails(self):
2140 self.add_empty_file('a')
2141 self.add_empty_file('b')
2142 fetcher, ud = self.fetch(self.d.getVar('SRC_URI'))
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), self.assertLogs("BitBake.Fetcher", level="ERROR") as cm:
2147 self.fetch_shallow()
2148 self.assertIn("Unable to find revision v0.0 even from upstream", cm.output[0])
2149
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002150 @skipIfNoNetwork()
2151 def test_bitbake(self):
Andrew Geissler595f6302022-01-24 19:11:47 +00002152 self.git('remote add --mirror=fetch origin https://github.com/openembedded/bitbake', cwd=self.srcdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002153 self.git('config core.bare true', cwd=self.srcdir)
2154 self.git('fetch', cwd=self.srcdir)
2155
2156 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
2157 # Note that the 1.10.0 tag is annotated, so this also tests
2158 # reference of an annotated vs unannotated tag
2159 self.d.setVar('BB_GIT_SHALLOW_REVS', '1.10.0')
2160
2161 self.fetch_shallow()
2162
2163 # Confirm that the history of 1.10.0 was removed
2164 orig_revs = len(self.git('rev-list master', cwd=self.srcdir).splitlines())
2165 revs = len(self.git('rev-list master').splitlines())
2166 self.assertNotEqual(orig_revs, revs)
2167 self.assertRefs(['master', 'origin/master'])
2168 self.assertRevCount(orig_revs - 1758)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08002169
2170 def test_that_unpack_throws_an_error_when_the_git_clone_nor_shallow_tarball_exist(self):
2171 self.add_empty_file('a')
2172 fetcher, ud = self.fetch()
2173 bb.utils.remove(self.gitdir, recurse=True)
2174 bb.utils.remove(self.dldir, recurse=True)
2175
2176 with self.assertRaises(bb.fetch2.UnpackError) as context:
2177 fetcher.unpack(self.d.getVar('WORKDIR'))
2178
2179 self.assertIn("No up to date source found", context.exception.msg)
2180 self.assertIn("clone directory not available or not up to date", context.exception.msg)
2181
2182 @skipIfNoNetwork()
2183 def test_that_unpack_does_work_when_using_git_shallow_tarball_but_tarball_is_not_available(self):
2184 self.d.setVar('SRCREV', 'e5939ff608b95cdd4d0ab0e1935781ab9a276ac0')
2185 self.d.setVar('BB_GIT_SHALLOW', '1')
2186 self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1')
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002187 fetcher = bb.fetch.Fetch(["git://git.yoctoproject.org/fstests;branch=master"], self.d)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08002188 fetcher.download()
2189
2190 bb.utils.remove(self.dldir + "/*.tar.gz")
2191 fetcher.unpack(self.unpackdir)
2192
2193 dir = os.listdir(self.unpackdir + "/git/")
2194 self.assertIn("fstests.doap", dir)
Brad Bishop00e122a2019-10-05 11:10:57 -04002195
2196class GitLfsTest(FetcherTest):
2197 def setUp(self):
2198 FetcherTest.setUp(self)
2199
2200 self.gitdir = os.path.join(self.tempdir, 'git')
2201 self.srcdir = os.path.join(self.tempdir, 'gitsource')
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002202
Brad Bishop00e122a2019-10-05 11:10:57 -04002203 self.d.setVar('WORKDIR', self.tempdir)
2204 self.d.setVar('S', self.gitdir)
2205 self.d.delVar('PREMIRRORS')
2206 self.d.delVar('MIRRORS')
2207
2208 self.d.setVar('SRCREV', '${AUTOREV}')
2209 self.d.setVar('AUTOREV', '${@bb.fetch2.get_autorev(d)}')
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002210 self.d.setVar("__BBSEENSRCREV", "1")
Brad Bishop00e122a2019-10-05 11:10:57 -04002211
2212 bb.utils.mkdirhier(self.srcdir)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002213 self.git_init(cwd=self.srcdir)
Brad Bishop00e122a2019-10-05 11:10:57 -04002214 with open(os.path.join(self.srcdir, '.gitattributes'), 'wt') as attrs:
2215 attrs.write('*.mp3 filter=lfs -text')
2216 self.git(['add', '.gitattributes'], cwd=self.srcdir)
2217 self.git(['commit', '-m', "attributes", '.gitattributes'], cwd=self.srcdir)
2218
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002219 def fetch(self, uri=None, download=True):
Brad Bishop00e122a2019-10-05 11:10:57 -04002220 uris = self.d.getVar('SRC_URI').split()
2221 uri = uris[0]
2222 d = self.d
2223
2224 fetcher = bb.fetch2.Fetch(uris, d)
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002225 if download:
2226 fetcher.download()
Brad Bishop00e122a2019-10-05 11:10:57 -04002227 ud = fetcher.ud[uri]
2228 return fetcher, ud
2229
2230 def test_lfs_enabled(self):
2231 import shutil
2232
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002233 uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir
Brad Bishop00e122a2019-10-05 11:10:57 -04002234 self.d.setVar('SRC_URI', uri)
2235
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002236 # Careful: suppress initial attempt at downloading until
2237 # we know whether git-lfs is installed.
2238 fetcher, ud = self.fetch(uri=None, download=False)
Brad Bishop00e122a2019-10-05 11:10:57 -04002239 self.assertIsNotNone(ud.method._find_git_lfs)
2240
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002241 # If git-lfs can be found, the unpack should be successful. Only
2242 # attempt this with the real live copy of git-lfs installed.
2243 if ud.method._find_git_lfs(self.d):
2244 fetcher.download()
2245 shutil.rmtree(self.gitdir, ignore_errors=True)
2246 fetcher.unpack(self.d.getVar('WORKDIR'))
Brad Bishop00e122a2019-10-05 11:10:57 -04002247
2248 # If git-lfs cannot be found, the unpack should throw an error
2249 with self.assertRaises(bb.fetch2.FetchError):
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002250 fetcher.download()
Brad Bishop00e122a2019-10-05 11:10:57 -04002251 ud.method._find_git_lfs = lambda d: False
2252 shutil.rmtree(self.gitdir, ignore_errors=True)
2253 fetcher.unpack(self.d.getVar('WORKDIR'))
2254
2255 def test_lfs_disabled(self):
2256 import shutil
2257
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002258 uri = 'git://%s;protocol=file;lfs=0;branch=master' % self.srcdir
Brad Bishop00e122a2019-10-05 11:10:57 -04002259 self.d.setVar('SRC_URI', uri)
2260
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002261 # In contrast to test_lfs_enabled(), allow the implicit download
2262 # done by self.fetch() to occur here. The point of this test case
2263 # is to verify that the fetcher can survive even if the source
2264 # repository has Git LFS usage configured.
Brad Bishop00e122a2019-10-05 11:10:57 -04002265 fetcher, ud = self.fetch()
2266 self.assertIsNotNone(ud.method._find_git_lfs)
2267
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002268 # If git-lfs can be found, the unpack should be successful. A
2269 # live copy of git-lfs is not required for this case, so
2270 # unconditionally forge its presence.
Brad Bishop00e122a2019-10-05 11:10:57 -04002271 ud.method._find_git_lfs = lambda d: True
2272 shutil.rmtree(self.gitdir, ignore_errors=True)
2273 fetcher.unpack(self.d.getVar('WORKDIR'))
2274
2275 # If git-lfs cannot be found, the unpack should be successful
2276 ud.method._find_git_lfs = lambda d: False
2277 shutil.rmtree(self.gitdir, ignore_errors=True)
2278 fetcher.unpack(self.d.getVar('WORKDIR'))
Andrew Geissler82c905d2020-04-13 13:39:40 -05002279
Andrew Geisslerc3d88e42020-10-02 09:45:00 -05002280class GitURLWithSpacesTest(FetcherTest):
2281 test_git_urls = {
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002282 "git://tfs-example.org:22/tfs/example%20path/example.git;branch=master" : {
2283 'url': 'git://tfs-example.org:22/tfs/example%20path/example.git;branch=master',
Andrew Geisslerc3d88e42020-10-02 09:45:00 -05002284 'gitsrcname': 'tfs-example.org.22.tfs.example_path.example.git',
2285 'path': '/tfs/example path/example.git'
2286 },
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002287 "git://tfs-example.org:22/tfs/example%20path/example%20repo.git;branch=master" : {
2288 'url': 'git://tfs-example.org:22/tfs/example%20path/example%20repo.git;branch=master',
Andrew Geisslerc3d88e42020-10-02 09:45:00 -05002289 'gitsrcname': 'tfs-example.org.22.tfs.example_path.example_repo.git',
2290 'path': '/tfs/example path/example repo.git'
2291 }
2292 }
2293
2294 def test_urls(self):
2295
2296 # Set fake SRCREV to stop git fetcher from trying to contact non-existent git repo
2297 self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
2298
2299 for test_git_url, ref in self.test_git_urls.items():
2300
2301 fetcher = bb.fetch.Fetch([test_git_url], self.d)
2302 ud = fetcher.ud[fetcher.urls[0]]
2303
2304 self.assertEqual(ud.url, ref['url'])
2305 self.assertEqual(ud.path, ref['path'])
2306 self.assertEqual(ud.localfile, os.path.join(self.dldir, "git2", ref['gitsrcname']))
2307 self.assertEqual(ud.localpath, os.path.join(self.dldir, "git2", ref['gitsrcname']))
2308 self.assertEqual(ud.lockfile, os.path.join(self.dldir, "git2", ref['gitsrcname'] + '.lock'))
2309 self.assertEqual(ud.clonedir, os.path.join(self.dldir, "git2", ref['gitsrcname']))
2310 self.assertEqual(ud.fullmirror, os.path.join(self.dldir, "git2_" + ref['gitsrcname'] + '.tar.gz'))
2311
Andrew Geissler595f6302022-01-24 19:11:47 +00002312class CrateTest(FetcherTest):
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002313 @skipIfNoNetwork()
Andrew Geissler595f6302022-01-24 19:11:47 +00002314 def test_crate_url(self):
2315
2316 uri = "crate://crates.io/glob/0.2.11"
2317 self.d.setVar('SRC_URI', uri)
2318
2319 uris = self.d.getVar('SRC_URI').split()
2320 d = self.d
2321
2322 fetcher = bb.fetch2.Fetch(uris, self.d)
2323 fetcher.download()
2324 fetcher.unpack(self.tempdir)
2325 self.assertEqual(sorted(os.listdir(self.tempdir)), ['cargo_home', 'download' , 'unpacked'])
2326 self.assertEqual(sorted(os.listdir(self.tempdir + "/download")), ['glob-0.2.11.crate', 'glob-0.2.11.crate.done'])
2327 self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/glob-0.2.11/.cargo-checksum.json"))
2328 self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/glob-0.2.11/src/lib.rs"))
2329
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002330 @skipIfNoNetwork()
Andrew Geissler595f6302022-01-24 19:11:47 +00002331 def test_crate_url_multi(self):
2332
2333 uri = "crate://crates.io/glob/0.2.11 crate://crates.io/time/0.1.35"
2334 self.d.setVar('SRC_URI', uri)
2335
2336 uris = self.d.getVar('SRC_URI').split()
2337 d = self.d
2338
2339 fetcher = bb.fetch2.Fetch(uris, self.d)
2340 fetcher.download()
2341 fetcher.unpack(self.tempdir)
2342 self.assertEqual(sorted(os.listdir(self.tempdir)), ['cargo_home', 'download' , 'unpacked'])
2343 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'])
2344 self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/glob-0.2.11/.cargo-checksum.json"))
2345 self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/glob-0.2.11/src/lib.rs"))
2346 self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/time-0.1.35/.cargo-checksum.json"))
2347 self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/time-0.1.35/src/lib.rs"))
2348
Andrew Geissler82c905d2020-04-13 13:39:40 -05002349class NPMTest(FetcherTest):
2350 def skipIfNoNpm():
2351 import shutil
2352 if not shutil.which('npm'):
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002353 return unittest.skip('npm not installed')
Andrew Geissler82c905d2020-04-13 13:39:40 -05002354 return lambda f: f
2355
2356 @skipIfNoNpm()
2357 @skipIfNoNetwork()
2358 def test_npm(self):
2359 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2360 fetcher = bb.fetch.Fetch([url], self.d)
2361 ud = fetcher.ud[fetcher.urls[0]]
2362 fetcher.download()
2363 self.assertTrue(os.path.exists(ud.localpath))
2364 self.assertTrue(os.path.exists(ud.localpath + '.done'))
2365 self.assertTrue(os.path.exists(ud.resolvefile))
2366 fetcher.unpack(self.unpackdir)
2367 unpackdir = os.path.join(self.unpackdir, 'npm')
2368 self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
2369
2370 @skipIfNoNpm()
2371 @skipIfNoNetwork()
2372 def test_npm_bad_checksum(self):
2373 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2374 # Fetch once to get a tarball
2375 fetcher = bb.fetch.Fetch([url], self.d)
2376 ud = fetcher.ud[fetcher.urls[0]]
2377 fetcher.download()
2378 self.assertTrue(os.path.exists(ud.localpath))
2379 # Modify the tarball
2380 bad = b'bad checksum'
2381 with open(ud.localpath, 'wb') as f:
2382 f.write(bad)
2383 # Verify that the tarball is fetched again
2384 fetcher.download()
2385 badsum = hashlib.sha512(bad).hexdigest()
2386 self.assertTrue(os.path.exists(ud.localpath + '_bad-checksum_' + badsum))
2387 self.assertTrue(os.path.exists(ud.localpath))
2388
2389 @skipIfNoNpm()
2390 @skipIfNoNetwork()
2391 def test_npm_premirrors(self):
2392 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2393 # Fetch once to get a tarball
2394 fetcher = bb.fetch.Fetch([url], self.d)
2395 ud = fetcher.ud[fetcher.urls[0]]
2396 fetcher.download()
2397 self.assertTrue(os.path.exists(ud.localpath))
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002398
2399 # Setup the mirror by renaming the download directory
Andrew Geissler82c905d2020-04-13 13:39:40 -05002400 mirrordir = os.path.join(self.tempdir, 'mirror')
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002401 bb.utils.rename(self.dldir, mirrordir)
2402 os.mkdir(self.dldir)
2403
2404 # Configure the premirror to be used
2405 self.d.setVar('PREMIRRORS', 'https?$://.*/.* file://%s/npm2' % mirrordir)
Andrew Geissler82c905d2020-04-13 13:39:40 -05002406 self.d.setVar('BB_FETCH_PREMIRRORONLY', '1')
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002407
Andrew Geissler82c905d2020-04-13 13:39:40 -05002408 # Fetch again
2409 self.assertFalse(os.path.exists(ud.localpath))
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002410 # The npm fetcher doesn't handle that the .resolved file disappears
2411 # while the fetcher object exists, which it does when we rename the
2412 # download directory to "mirror" above. Thus we need a new fetcher to go
2413 # with the now empty download directory.
2414 fetcher = bb.fetch.Fetch([url], self.d)
2415 ud = fetcher.ud[fetcher.urls[0]]
Andrew Geissler82c905d2020-04-13 13:39:40 -05002416 fetcher.download()
2417 self.assertTrue(os.path.exists(ud.localpath))
2418
2419 @skipIfNoNpm()
2420 @skipIfNoNetwork()
Andrew Geissler5199d832021-09-24 16:47:35 -05002421 def test_npm_premirrors_with_specified_filename(self):
2422 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2423 # Fetch once to get a tarball
2424 fetcher = bb.fetch.Fetch([url], self.d)
2425 ud = fetcher.ud[fetcher.urls[0]]
2426 fetcher.download()
2427 self.assertTrue(os.path.exists(ud.localpath))
2428 # Setup the mirror
2429 mirrordir = os.path.join(self.tempdir, 'mirror')
2430 bb.utils.mkdirhier(mirrordir)
2431 mirrorfilename = os.path.join(mirrordir, os.path.basename(ud.localpath))
2432 os.replace(ud.localpath, mirrorfilename)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002433 self.d.setVar('PREMIRRORS', 'https?$://.*/.* file://%s' % mirrorfilename)
Andrew Geissler5199d832021-09-24 16:47:35 -05002434 self.d.setVar('BB_FETCH_PREMIRRORONLY', '1')
2435 # Fetch again
2436 self.assertFalse(os.path.exists(ud.localpath))
2437 fetcher.download()
2438 self.assertTrue(os.path.exists(ud.localpath))
2439
2440 @skipIfNoNpm()
2441 @skipIfNoNetwork()
Andrew Geissler82c905d2020-04-13 13:39:40 -05002442 def test_npm_mirrors(self):
2443 # Fetch once to get a tarball
2444 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2445 fetcher = bb.fetch.Fetch([url], self.d)
2446 ud = fetcher.ud[fetcher.urls[0]]
2447 fetcher.download()
2448 self.assertTrue(os.path.exists(ud.localpath))
2449 # Setup the mirror
2450 mirrordir = os.path.join(self.tempdir, 'mirror')
2451 bb.utils.mkdirhier(mirrordir)
2452 os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath)))
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002453 self.d.setVar('MIRRORS', 'https?$://.*/.* file://%s/' % mirrordir)
Andrew Geissler82c905d2020-04-13 13:39:40 -05002454 # Update the resolved url to an invalid url
2455 with open(ud.resolvefile, 'r') as f:
2456 url = f.read()
2457 uri = URI(url)
2458 uri.path = '/invalid'
2459 with open(ud.resolvefile, 'w') as f:
2460 f.write(str(uri))
2461 # Fetch again
2462 self.assertFalse(os.path.exists(ud.localpath))
2463 fetcher.download()
2464 self.assertTrue(os.path.exists(ud.localpath))
2465
2466 @skipIfNoNpm()
2467 @skipIfNoNetwork()
2468 def test_npm_destsuffix_downloadfilename(self):
2469 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0;destsuffix=foo/bar;downloadfilename=foo-bar.tgz'
2470 fetcher = bb.fetch.Fetch([url], self.d)
2471 fetcher.download()
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002472 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'foo-bar.tgz')))
Andrew Geissler82c905d2020-04-13 13:39:40 -05002473 fetcher.unpack(self.unpackdir)
2474 unpackdir = os.path.join(self.unpackdir, 'foo', 'bar')
2475 self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
2476
2477 def test_npm_no_network_no_tarball(self):
2478 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2479 self.d.setVar('BB_NO_NETWORK', '1')
2480 fetcher = bb.fetch.Fetch([url], self.d)
2481 with self.assertRaises(bb.fetch2.NetworkAccess):
2482 fetcher.download()
2483
2484 @skipIfNoNpm()
2485 @skipIfNoNetwork()
2486 def test_npm_no_network_with_tarball(self):
2487 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2488 # Fetch once to get a tarball
2489 fetcher = bb.fetch.Fetch([url], self.d)
2490 fetcher.download()
2491 # Disable network access
2492 self.d.setVar('BB_NO_NETWORK', '1')
2493 # Fetch again
2494 fetcher.download()
2495 fetcher.unpack(self.unpackdir)
2496 unpackdir = os.path.join(self.unpackdir, 'npm')
2497 self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
2498
2499 @skipIfNoNpm()
2500 @skipIfNoNetwork()
2501 def test_npm_registry_alternate(self):
Andrew Geissler5199d832021-09-24 16:47:35 -05002502 url = 'npm://skimdb.npmjs.com;package=@savoirfairelinux/node-server-example;version=1.0.0'
Andrew Geissler82c905d2020-04-13 13:39:40 -05002503 fetcher = bb.fetch.Fetch([url], self.d)
2504 fetcher.download()
2505 fetcher.unpack(self.unpackdir)
2506 unpackdir = os.path.join(self.unpackdir, 'npm')
2507 self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
2508
2509 @skipIfNoNpm()
2510 @skipIfNoNetwork()
2511 def test_npm_version_latest(self):
2512 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=latest'
2513 fetcher = bb.fetch.Fetch([url], self.d)
2514 fetcher.download()
2515 fetcher.unpack(self.unpackdir)
2516 unpackdir = os.path.join(self.unpackdir, 'npm')
2517 self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
2518
2519 @skipIfNoNpm()
2520 @skipIfNoNetwork()
2521 def test_npm_registry_invalid(self):
2522 url = 'npm://registry.invalid.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2523 fetcher = bb.fetch.Fetch([url], self.d)
2524 with self.assertRaises(bb.fetch2.FetchError):
2525 fetcher.download()
2526
2527 @skipIfNoNpm()
2528 @skipIfNoNetwork()
2529 def test_npm_package_invalid(self):
2530 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/invalid;version=1.0.0'
2531 fetcher = bb.fetch.Fetch([url], self.d)
2532 with self.assertRaises(bb.fetch2.FetchError):
2533 fetcher.download()
2534
2535 @skipIfNoNpm()
2536 @skipIfNoNetwork()
2537 def test_npm_version_invalid(self):
2538 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=invalid'
2539 with self.assertRaises(bb.fetch2.ParameterError):
2540 fetcher = bb.fetch.Fetch([url], self.d)
2541
2542 @skipIfNoNpm()
2543 @skipIfNoNetwork()
2544 def test_npm_registry_none(self):
2545 url = 'npm://;package=@savoirfairelinux/node-server-example;version=1.0.0'
2546 with self.assertRaises(bb.fetch2.MalformedUrl):
2547 fetcher = bb.fetch.Fetch([url], self.d)
2548
2549 @skipIfNoNpm()
2550 @skipIfNoNetwork()
2551 def test_npm_package_none(self):
2552 url = 'npm://registry.npmjs.org;version=1.0.0'
2553 with self.assertRaises(bb.fetch2.MissingParameterError):
2554 fetcher = bb.fetch.Fetch([url], self.d)
2555
2556 @skipIfNoNpm()
2557 @skipIfNoNetwork()
2558 def test_npm_version_none(self):
2559 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example'
2560 with self.assertRaises(bb.fetch2.MissingParameterError):
2561 fetcher = bb.fetch.Fetch([url], self.d)
2562
2563 def create_shrinkwrap_file(self, data):
2564 import json
2565 datadir = os.path.join(self.tempdir, 'data')
2566 swfile = os.path.join(datadir, 'npm-shrinkwrap.json')
2567 bb.utils.mkdirhier(datadir)
2568 with open(swfile, 'w') as f:
2569 json.dump(data, f)
2570 # Also configure the S directory
2571 self.sdir = os.path.join(self.unpackdir, 'S')
2572 self.d.setVar('S', self.sdir)
2573 return swfile
2574
2575 @skipIfNoNpm()
2576 @skipIfNoNetwork()
2577 def test_npmsw(self):
2578 swfile = self.create_shrinkwrap_file({
2579 'dependencies': {
2580 'array-flatten': {
2581 'version': '1.1.1',
2582 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2583 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=',
2584 'dependencies': {
2585 'content-type': {
2586 'version': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz',
2587 'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==',
2588 'dependencies': {
2589 'cookie': {
2590 'version': 'git+https://github.com/jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09',
2591 'from': 'git+https://github.com/jshttp/cookie.git'
2592 }
2593 }
2594 }
2595 }
2596 }
2597 }
2598 })
2599 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2600 fetcher.download()
2601 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')))
2602 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz')))
2603 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'github.com.jshttp.cookie.git')))
2604 fetcher.unpack(self.unpackdir)
2605 self.assertTrue(os.path.exists(os.path.join(self.sdir, 'npm-shrinkwrap.json')))
2606 self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'package.json')))
2607 self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'node_modules', 'content-type', 'package.json')))
2608 self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'node_modules', 'content-type', 'node_modules', 'cookie', 'package.json')))
2609
2610 @skipIfNoNpm()
2611 @skipIfNoNetwork()
2612 def test_npmsw_dev(self):
2613 swfile = self.create_shrinkwrap_file({
2614 'dependencies': {
2615 'array-flatten': {
2616 'version': '1.1.1',
2617 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2618 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
2619 },
2620 'content-type': {
2621 'version': '1.0.4',
2622 'resolved': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz',
2623 'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==',
2624 'dev': True
2625 }
2626 }
2627 })
2628 # Fetch with dev disabled
2629 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2630 fetcher.download()
2631 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')))
2632 self.assertFalse(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz')))
2633 # Fetch with dev enabled
2634 fetcher = bb.fetch.Fetch(['npmsw://' + swfile + ';dev=1'], self.d)
2635 fetcher.download()
2636 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')))
2637 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz')))
2638
2639 @skipIfNoNpm()
2640 @skipIfNoNetwork()
2641 def test_npmsw_destsuffix(self):
2642 swfile = self.create_shrinkwrap_file({
2643 'dependencies': {
2644 'array-flatten': {
2645 'version': '1.1.1',
2646 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2647 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
2648 }
2649 }
2650 })
2651 fetcher = bb.fetch.Fetch(['npmsw://' + swfile + ';destsuffix=foo/bar'], self.d)
2652 fetcher.download()
2653 fetcher.unpack(self.unpackdir)
2654 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'foo', 'bar', 'node_modules', 'array-flatten', 'package.json')))
2655
2656 def test_npmsw_no_network_no_tarball(self):
2657 swfile = self.create_shrinkwrap_file({
2658 'dependencies': {
2659 'array-flatten': {
2660 'version': '1.1.1',
2661 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2662 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
2663 }
2664 }
2665 })
2666 self.d.setVar('BB_NO_NETWORK', '1')
2667 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2668 with self.assertRaises(bb.fetch2.NetworkAccess):
2669 fetcher.download()
2670
2671 @skipIfNoNpm()
2672 @skipIfNoNetwork()
2673 def test_npmsw_no_network_with_tarball(self):
2674 # Fetch once to get a tarball
2675 fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d)
2676 fetcher.download()
2677 # Disable network access
2678 self.d.setVar('BB_NO_NETWORK', '1')
2679 # Fetch again
2680 swfile = self.create_shrinkwrap_file({
2681 'dependencies': {
2682 'array-flatten': {
2683 'version': '1.1.1',
2684 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2685 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
2686 }
2687 }
2688 })
2689 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2690 fetcher.download()
2691 fetcher.unpack(self.unpackdir)
2692 self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'package.json')))
2693
2694 @skipIfNoNpm()
2695 @skipIfNoNetwork()
2696 def test_npmsw_npm_reusability(self):
2697 # Fetch once with npmsw
2698 swfile = self.create_shrinkwrap_file({
2699 'dependencies': {
2700 'array-flatten': {
2701 'version': '1.1.1',
2702 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2703 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
2704 }
2705 }
2706 })
2707 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2708 fetcher.download()
2709 # Disable network access
2710 self.d.setVar('BB_NO_NETWORK', '1')
2711 # Fetch again with npm
2712 fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d)
2713 fetcher.download()
2714 fetcher.unpack(self.unpackdir)
2715 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'npm', 'package.json')))
2716
2717 @skipIfNoNpm()
2718 @skipIfNoNetwork()
2719 def test_npmsw_bad_checksum(self):
2720 # Try to fetch with bad checksum
2721 swfile = self.create_shrinkwrap_file({
2722 'dependencies': {
2723 'array-flatten': {
2724 'version': '1.1.1',
2725 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2726 'integrity': 'sha1-gfNEp2hqgLTFKT6P3AsBYMgsBqg='
2727 }
2728 }
2729 })
2730 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2731 with self.assertRaises(bb.fetch2.FetchError):
2732 fetcher.download()
2733 # Fetch correctly to get a tarball
2734 swfile = self.create_shrinkwrap_file({
2735 'dependencies': {
2736 'array-flatten': {
2737 'version': '1.1.1',
2738 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2739 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
2740 }
2741 }
2742 })
2743 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2744 fetcher.download()
2745 localpath = os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')
2746 self.assertTrue(os.path.exists(localpath))
2747 # Modify the tarball
2748 bad = b'bad checksum'
2749 with open(localpath, 'wb') as f:
2750 f.write(bad)
2751 # Verify that the tarball is fetched again
2752 fetcher.download()
2753 badsum = hashlib.sha1(bad).hexdigest()
2754 self.assertTrue(os.path.exists(localpath + '_bad-checksum_' + badsum))
2755 self.assertTrue(os.path.exists(localpath))
2756
2757 @skipIfNoNpm()
2758 @skipIfNoNetwork()
2759 def test_npmsw_premirrors(self):
2760 # Fetch once to get a tarball
2761 fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d)
2762 ud = fetcher.ud[fetcher.urls[0]]
2763 fetcher.download()
2764 self.assertTrue(os.path.exists(ud.localpath))
2765 # Setup the mirror
2766 mirrordir = os.path.join(self.tempdir, 'mirror')
2767 bb.utils.mkdirhier(mirrordir)
2768 os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath)))
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002769 self.d.setVar('PREMIRRORS', 'https?$://.*/.* file://%s/' % mirrordir)
Andrew Geissler82c905d2020-04-13 13:39:40 -05002770 self.d.setVar('BB_FETCH_PREMIRRORONLY', '1')
2771 # Fetch again
2772 self.assertFalse(os.path.exists(ud.localpath))
2773 swfile = self.create_shrinkwrap_file({
2774 'dependencies': {
2775 'array-flatten': {
2776 'version': '1.1.1',
2777 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2778 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
2779 }
2780 }
2781 })
2782 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2783 fetcher.download()
2784 self.assertTrue(os.path.exists(ud.localpath))
2785
2786 @skipIfNoNpm()
2787 @skipIfNoNetwork()
2788 def test_npmsw_mirrors(self):
2789 # Fetch once to get a tarball
2790 fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d)
2791 ud = fetcher.ud[fetcher.urls[0]]
2792 fetcher.download()
2793 self.assertTrue(os.path.exists(ud.localpath))
2794 # Setup the mirror
2795 mirrordir = os.path.join(self.tempdir, 'mirror')
2796 bb.utils.mkdirhier(mirrordir)
2797 os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath)))
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002798 self.d.setVar('MIRRORS', 'https?$://.*/.* file://%s/' % mirrordir)
Andrew Geissler82c905d2020-04-13 13:39:40 -05002799 # Fetch again with invalid url
2800 self.assertFalse(os.path.exists(ud.localpath))
2801 swfile = self.create_shrinkwrap_file({
2802 'dependencies': {
2803 'array-flatten': {
2804 'version': '1.1.1',
2805 'resolved': 'https://invalid',
2806 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
2807 }
2808 }
2809 })
2810 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2811 fetcher.download()
2812 self.assertTrue(os.path.exists(ud.localpath))
Andrew Geisslerc926e172021-05-07 16:11:35 -05002813
2814class GitSharedTest(FetcherTest):
2815 def setUp(self):
2816 super(GitSharedTest, self).setUp()
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002817 self.recipe_url = "git://git.openembedded.org/bitbake;branch=master"
Andrew Geisslerc926e172021-05-07 16:11:35 -05002818 self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002819 self.d.setVar("__BBSEENSRCREV", "1")
Andrew Geisslerc926e172021-05-07 16:11:35 -05002820
2821 @skipIfNoNetwork()
2822 def test_shared_unpack(self):
2823 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
2824
2825 fetcher.download()
2826 fetcher.unpack(self.unpackdir)
2827 alt = os.path.join(self.unpackdir, 'git/.git/objects/info/alternates')
2828 self.assertTrue(os.path.exists(alt))
2829
2830 @skipIfNoNetwork()
2831 def test_noshared_unpack(self):
2832 self.d.setVar('BB_GIT_NOSHARED', '1')
2833 self.unpackdir += '_noshared'
2834 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
2835
2836 fetcher.download()
2837 fetcher.unpack(self.unpackdir)
2838 alt = os.path.join(self.unpackdir, 'git/.git/objects/info/alternates')
2839 self.assertFalse(os.path.exists(alt))
Andrew Geissler78b72792022-06-14 06:47:25 -05002840
2841
2842class FetchPremirroronlyLocalTest(FetcherTest):
2843
2844 def setUp(self):
2845 super(FetchPremirroronlyLocalTest, self).setUp()
2846 self.mirrordir = os.path.join(self.tempdir, "mirrors")
2847 os.mkdir(self.mirrordir)
2848 self.reponame = "bitbake"
2849 self.gitdir = os.path.join(self.tempdir, "git", self.reponame)
2850 self.recipe_url = "git://git.fake.repo/bitbake"
2851 self.d.setVar("BB_FETCH_PREMIRRORONLY", "1")
2852 self.d.setVar("BB_NO_NETWORK", "1")
2853 self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n")
2854
2855 def make_git_repo(self):
2856 self.mirrorname = "git2_git.fake.repo.bitbake.tar.gz"
2857 recipeurl = "git:/git.fake.repo/bitbake"
2858 os.makedirs(self.gitdir)
2859 self.git("init", self.gitdir)
2860 for i in range(0):
2861 self.git_new_commit()
2862 bb.process.run('tar -czvf {} .'.format(os.path.join(self.mirrordir, self.mirrorname)), cwd = self.gitdir)
2863
2864 def git_new_commit(self):
2865 import random
2866 testfilename = "bibake-fetch.test"
2867 os.unlink(os.path.join(self.mirrordir, self.mirrorname))
2868 with open(os.path.join(self.gitdir, testfilename), "w") as testfile:
2869 testfile.write("Useless random data {}".format(random.random()))
2870 self.git("add {}".format(testfilename), self.gitdir)
2871 self.git("commit -a -m \"This random commit {}. I'm useless.\"".format(random.random()), self.gitdir)
2872 bb.process.run('tar -czvf {} .'.format(os.path.join(self.mirrordir, self.mirrorname)), cwd = self.gitdir)
2873 return self.git("rev-parse HEAD", self.gitdir).strip()
2874
2875 def test_mirror_commit_nonexistent(self):
2876 self.make_git_repo()
2877 self.d.setVar("SRCREV", "0"*40)
2878 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
2879 with self.assertRaises(bb.fetch2.NetworkAccess):
2880 fetcher.download()
2881
2882 def test_mirror_commit_exists(self):
2883 self.make_git_repo()
2884 self.d.setVar("SRCREV", self.git_new_commit())
2885 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
2886 fetcher.download()
2887 fetcher.unpack(self.unpackdir)
2888
2889 def test_mirror_tarball_nonexistent(self):
2890 self.d.setVar("SRCREV", "0"*40)
2891 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
2892 with self.assertRaises(bb.fetch2.NetworkAccess):
2893 fetcher.download()
2894
2895class FetchPremirroronlyNetworkTest(FetcherTest):
2896
2897 def setUp(self):
2898 super(FetchPremirroronlyNetworkTest, self).setUp()
2899 self.mirrordir = os.path.join(self.tempdir, "mirrors")
2900 os.mkdir(self.mirrordir)
2901 self.reponame = "fstests"
2902 self.clonedir = os.path.join(self.tempdir, "git")
2903 self.gitdir = os.path.join(self.tempdir, "git", "{}.git".format(self.reponame))
2904 self.recipe_url = "git://git.yoctoproject.org/fstests"
2905 self.d.setVar("BB_FETCH_PREMIRRORONLY", "1")
2906 self.d.setVar("BB_NO_NETWORK", "0")
2907 self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n")
2908
2909 def make_git_repo(self):
2910 import shutil
2911 self.mirrorname = "git2_git.yoctoproject.org.fstests.tar.gz"
2912 os.makedirs(self.clonedir)
2913 self.git("clone --bare --shallow-since=\"01.01.2013\" {}".format(self.recipe_url), self.clonedir)
2914 bb.process.run('tar -czvf {} .'.format(os.path.join(self.mirrordir, self.mirrorname)), cwd = self.gitdir)
2915 shutil.rmtree(self.clonedir)
2916
2917 @skipIfNoNetwork()
2918 def test_mirror_tarball_updated(self):
2919 self.make_git_repo()
2920 ## Upstream commit is in the mirror
2921 self.d.setVar("SRCREV", "49d65d53c2bf558ae6e9185af0f3af7b79d255ec")
2922 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
2923 fetcher.download()
2924
2925 @skipIfNoNetwork()
2926 def test_mirror_tarball_outdated(self):
2927 self.make_git_repo()
2928 ## Upstream commit not in the mirror
2929 self.d.setVar("SRCREV", "15413486df1f5a5b5af699b6f3ba5f0984e52a9f")
2930 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
2931 with self.assertRaises(bb.fetch2.NetworkAccess):
2932 fetcher.download()
Andrew Geissler615f2f12022-07-15 14:00:58 -05002933
2934class FetchPremirroronlyBrokenTarball(FetcherTest):
2935
2936 def setUp(self):
2937 super(FetchPremirroronlyBrokenTarball, self).setUp()
2938 self.mirrordir = os.path.join(self.tempdir, "mirrors")
2939 os.mkdir(self.mirrordir)
2940 self.reponame = "bitbake"
2941 self.gitdir = os.path.join(self.tempdir, "git", self.reponame)
2942 self.recipe_url = "git://git.fake.repo/bitbake"
2943 self.d.setVar("BB_FETCH_PREMIRRORONLY", "1")
2944 self.d.setVar("BB_NO_NETWORK", "1")
2945 self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n")
2946 self.mirrorname = "git2_git.fake.repo.bitbake.tar.gz"
2947 with open(os.path.join(self.mirrordir, self.mirrorname), 'w') as targz:
2948 targz.write("This is not tar.gz file!")
2949
2950 def test_mirror_broken_download(self):
2951 import sys
2952 self.d.setVar("SRCREV", "0"*40)
2953 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
2954 with self.assertRaises(bb.fetch2.FetchError):
2955 fetcher.download()
2956 stdout = sys.stdout.getvalue()
2957 self.assertFalse(" not a git repository (or any parent up to mount point /)" in stdout)