blob: 6bdf0416d7e96c883096e593274f9d52eddad07b [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
12import subprocess
Patrick Williamsc0f7c042017-02-23 20:41:17 -060013import collections
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014import os
15from bb.fetch2 import URI
16from bb.fetch2 import FetchMethod
17import bb
18
Brad Bishopd7bf8c12018-02-25 22:55:05 -050019def skipIfNoNetwork():
20 if os.environ.get("BB_SKIP_NETTESTS") == "yes":
21 return unittest.skip("Network tests being skipped")
22 return lambda f: f
23
Patrick Williamsc124f4f2015-09-15 14:41:29 -050024class URITest(unittest.TestCase):
25 test_uris = {
26 "http://www.google.com/index.html" : {
27 'uri': 'http://www.google.com/index.html',
28 'scheme': 'http',
29 'hostname': 'www.google.com',
30 'port': None,
31 'hostport': 'www.google.com',
32 'path': '/index.html',
33 'userinfo': '',
34 'username': '',
35 'password': '',
36 'params': {},
37 'query': {},
38 'relative': False
39 },
40 "http://www.google.com/index.html;param1=value1" : {
41 'uri': 'http://www.google.com/index.html;param1=value1',
42 'scheme': 'http',
43 'hostname': 'www.google.com',
44 'port': None,
45 'hostport': 'www.google.com',
46 'path': '/index.html',
47 'userinfo': '',
48 'username': '',
49 'password': '',
50 'params': {
51 'param1': 'value1'
52 },
53 'query': {},
54 'relative': False
55 },
56 "http://www.example.org/index.html?param1=value1" : {
57 'uri': 'http://www.example.org/index.html?param1=value1',
58 'scheme': 'http',
59 'hostname': 'www.example.org',
60 'port': None,
61 'hostport': 'www.example.org',
62 'path': '/index.html',
63 'userinfo': '',
64 'username': '',
65 'password': '',
66 'params': {},
67 'query': {
68 'param1': 'value1'
69 },
70 'relative': False
71 },
72 "http://www.example.org/index.html?qparam1=qvalue1;param2=value2" : {
73 'uri': 'http://www.example.org/index.html?qparam1=qvalue1;param2=value2',
74 'scheme': 'http',
75 'hostname': 'www.example.org',
76 'port': None,
77 'hostport': 'www.example.org',
78 'path': '/index.html',
79 'userinfo': '',
80 'username': '',
81 'password': '',
82 'params': {
83 'param2': 'value2'
84 },
85 'query': {
86 'qparam1': 'qvalue1'
87 },
88 'relative': False
89 },
90 "http://www.example.com:8080/index.html" : {
91 'uri': 'http://www.example.com:8080/index.html',
92 'scheme': 'http',
93 'hostname': 'www.example.com',
94 'port': 8080,
95 'hostport': 'www.example.com:8080',
96 'path': '/index.html',
97 'userinfo': '',
98 'username': '',
99 'password': '',
100 'params': {},
101 'query': {},
102 'relative': False
103 },
104 "cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg" : {
105 'uri': 'cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg',
106 'scheme': 'cvs',
107 'hostname': 'cvs.handhelds.org',
108 'port': None,
109 'hostport': 'cvs.handhelds.org',
110 'path': '/cvs',
111 'userinfo': 'anoncvs',
112 'username': 'anoncvs',
113 'password': '',
114 'params': {
115 'module': 'familiar/dist/ipkg'
116 },
117 'query': {},
118 'relative': False
119 },
120 "cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg": {
121 'uri': 'cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg',
122 'scheme': 'cvs',
123 'hostname': 'cvs.handhelds.org',
124 'port': None,
125 'hostport': 'cvs.handhelds.org',
126 'path': '/cvs',
127 'userinfo': 'anoncvs:anonymous',
128 'username': 'anoncvs',
129 'password': 'anonymous',
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600130 'params': collections.OrderedDict([
131 ('tag', 'V0-99-81'),
132 ('module', 'familiar/dist/ipkg')
133 ]),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500134 'query': {},
135 'relative': False
136 },
137 "file://example.diff": { # NOTE: Not RFC compliant!
138 'uri': 'file:example.diff',
139 'scheme': 'file',
140 'hostname': '',
141 'port': None,
142 'hostport': '',
143 'path': 'example.diff',
144 'userinfo': '',
145 'username': '',
146 'password': '',
147 'params': {},
148 'query': {},
149 'relative': True
150 },
151 "file:example.diff": { # NOTE: RFC compliant version of the former
152 'uri': 'file:example.diff',
153 'scheme': 'file',
154 'hostname': '',
155 'port': None,
156 'hostport': '',
157 'path': 'example.diff',
158 'userinfo': '',
159 'userinfo': '',
160 'username': '',
161 'password': '',
162 'params': {},
163 'query': {},
164 'relative': True
165 },
166 "file:///tmp/example.diff": {
167 'uri': 'file:///tmp/example.diff',
168 'scheme': 'file',
169 'hostname': '',
170 'port': None,
171 'hostport': '',
172 'path': '/tmp/example.diff',
173 'userinfo': '',
174 'userinfo': '',
175 'username': '',
176 'password': '',
177 'params': {},
178 'query': {},
179 'relative': False
180 },
181 "git:///path/example.git": {
182 'uri': 'git:///path/example.git',
183 'scheme': 'git',
184 'hostname': '',
185 'port': None,
186 'hostport': '',
187 'path': '/path/example.git',
188 'userinfo': '',
189 'userinfo': '',
190 'username': '',
191 'password': '',
192 'params': {},
193 'query': {},
194 'relative': False
195 },
196 "git:path/example.git": {
197 'uri': 'git:path/example.git',
198 'scheme': 'git',
199 'hostname': '',
200 'port': None,
201 'hostport': '',
202 'path': 'path/example.git',
203 'userinfo': '',
204 'userinfo': '',
205 'username': '',
206 'password': '',
207 'params': {},
208 'query': {},
209 'relative': True
210 },
211 "git://example.net/path/example.git": {
212 'uri': 'git://example.net/path/example.git',
213 'scheme': 'git',
214 'hostname': 'example.net',
215 'port': None,
216 'hostport': 'example.net',
217 'path': '/path/example.git',
218 'userinfo': '',
219 'userinfo': '',
220 'username': '',
221 'password': '',
222 'params': {},
223 'query': {},
224 'relative': False
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500225 },
226 "http://somesite.net;someparam=1": {
227 'uri': 'http://somesite.net;someparam=1',
228 'scheme': 'http',
229 'hostname': 'somesite.net',
230 'port': None,
231 'hostport': 'somesite.net',
232 'path': '',
233 'userinfo': '',
234 'userinfo': '',
235 'username': '',
236 'password': '',
237 'params': {"someparam" : "1"},
238 'query': {},
239 'relative': False
240 },
241 "file://somelocation;someparam=1": {
242 'uri': 'file:somelocation;someparam=1',
243 'scheme': 'file',
244 'hostname': '',
245 'port': None,
246 'hostport': '',
247 'path': 'somelocation',
248 'userinfo': '',
249 'userinfo': '',
250 'username': '',
251 'password': '',
252 'params': {"someparam" : "1"},
253 'query': {},
254 'relative': True
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500255 }
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500256
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500257 }
258
259 def test_uri(self):
260 for test_uri, ref in self.test_uris.items():
261 uri = URI(test_uri)
262
263 self.assertEqual(str(uri), ref['uri'])
264
265 # expected attributes
266 self.assertEqual(uri.scheme, ref['scheme'])
267
268 self.assertEqual(uri.userinfo, ref['userinfo'])
269 self.assertEqual(uri.username, ref['username'])
270 self.assertEqual(uri.password, ref['password'])
271
272 self.assertEqual(uri.hostname, ref['hostname'])
273 self.assertEqual(uri.port, ref['port'])
274 self.assertEqual(uri.hostport, ref['hostport'])
275
276 self.assertEqual(uri.path, ref['path'])
277 self.assertEqual(uri.params, ref['params'])
278
279 self.assertEqual(uri.relative, ref['relative'])
280
281 def test_dict(self):
282 for test in self.test_uris.values():
283 uri = URI()
284
285 self.assertEqual(uri.scheme, '')
286 self.assertEqual(uri.userinfo, '')
287 self.assertEqual(uri.username, '')
288 self.assertEqual(uri.password, '')
289 self.assertEqual(uri.hostname, '')
290 self.assertEqual(uri.port, None)
291 self.assertEqual(uri.path, '')
292 self.assertEqual(uri.params, {})
293
294
295 uri.scheme = test['scheme']
296 self.assertEqual(uri.scheme, test['scheme'])
297
298 uri.userinfo = test['userinfo']
299 self.assertEqual(uri.userinfo, test['userinfo'])
300 self.assertEqual(uri.username, test['username'])
301 self.assertEqual(uri.password, test['password'])
302
303 # make sure changing the values doesn't do anything unexpected
304 uri.username = 'changeme'
305 self.assertEqual(uri.username, 'changeme')
306 self.assertEqual(uri.password, test['password'])
307 uri.password = 'insecure'
308 self.assertEqual(uri.username, 'changeme')
309 self.assertEqual(uri.password, 'insecure')
310
311 # reset back after our trickery
312 uri.userinfo = test['userinfo']
313 self.assertEqual(uri.userinfo, test['userinfo'])
314 self.assertEqual(uri.username, test['username'])
315 self.assertEqual(uri.password, test['password'])
316
317 uri.hostname = test['hostname']
318 self.assertEqual(uri.hostname, test['hostname'])
319 self.assertEqual(uri.hostport, test['hostname'])
320
321 uri.port = test['port']
322 self.assertEqual(uri.port, test['port'])
323 self.assertEqual(uri.hostport, test['hostport'])
324
325 uri.path = test['path']
326 self.assertEqual(uri.path, test['path'])
327
328 uri.params = test['params']
329 self.assertEqual(uri.params, test['params'])
330
331 uri.query = test['query']
332 self.assertEqual(uri.query, test['query'])
333
334 self.assertEqual(str(uri), test['uri'])
335
336 uri.params = {}
337 self.assertEqual(uri.params, {})
338 self.assertEqual(str(uri), (str(uri).split(";"))[0])
339
340class FetcherTest(unittest.TestCase):
341
342 def setUp(self):
343 self.origdir = os.getcwd()
344 self.d = bb.data.init()
345 self.tempdir = tempfile.mkdtemp()
346 self.dldir = os.path.join(self.tempdir, "download")
347 os.mkdir(self.dldir)
348 self.d.setVar("DL_DIR", self.dldir)
349 self.unpackdir = os.path.join(self.tempdir, "unpacked")
350 os.mkdir(self.unpackdir)
351 persistdir = os.path.join(self.tempdir, "persistdata")
352 self.d.setVar("PERSISTENT_DIR", persistdir)
353
354 def tearDown(self):
355 os.chdir(self.origdir)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600356 if os.environ.get("BB_TMPDIR_NOCLEAN") == "yes":
357 print("Not cleaning up %s. Please remove manually." % self.tempdir)
358 else:
359 bb.utils.prunedir(self.tempdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500360
361class MirrorUriTest(FetcherTest):
362
363 replaceuris = {
364 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "http://somewhere.org/somedir/")
365 : "http://somewhere.org/somedir/git2_git.invalid.infradead.org.mtd-utils.git.tar.gz",
366 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http")
367 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
368 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http")
369 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
370 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/\\2;protocol=http")
371 : "git://somewhere.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
372 ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890", "git://someserver.org/bitbake", "git://git.openembedded.org/bitbake")
373 : "git://git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890",
374 ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache")
375 : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
376 ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache/")
377 : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
378 ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org/somedir3")
379 : "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz",
380 ("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")
381 : "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz",
382 ("http://www.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", "http://www.apache.org/dist", "http://archive.apache.org/dist")
383 : "http://archive.apache.org/dist/subversion/subversion-1.7.1.tar.bz2",
384 ("http://www.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", "http://.*/.*", "file:///somepath/downloads/")
385 : "file:///somepath/downloads/subversion-1.7.1.tar.bz2",
386 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http")
387 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
388 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http")
389 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
390 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/MIRRORNAME;protocol=http")
391 : "git://somewhere.org/somedir/git.invalid.infradead.org.foo.mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800392 ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org")
393 : "http://somewhere2.org/somefile_1.2.3.tar.gz",
394 ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org/")
395 : "http://somewhere2.org/somefile_1.2.3.tar.gz",
396 ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master", "git://someserver.org/bitbake;branch=master", "git://git.openembedded.org/bitbake;protocol=http")
397 : "git://git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master;protocol=http",
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500398
399 #Renaming files doesn't work
400 #("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"
401 #("file://sstate-xyz.tgz", "file://.*/.*", "file:///somewhere/1234/sstate-cache") : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
402 }
403
404 mirrorvar = "http://.*/.* file:///somepath/downloads/ \n" \
405 "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n" \
406 "https://.*/.* file:///someotherpath/downloads/ \n" \
407 "http://.*/.* file:///someotherpath/downloads/ \n"
408
409 def test_urireplace(self):
410 for k, v in self.replaceuris.items():
411 ud = bb.fetch.FetchData(k[0], self.d)
412 ud.setup_localpath(self.d)
413 mirrors = bb.fetch2.mirror_from_string("%s %s" % (k[1], k[2]))
414 newuris, uds = bb.fetch2.build_mirroruris(ud, mirrors, self.d)
415 self.assertEqual([v], newuris)
416
417 def test_urilist1(self):
418 fetcher = bb.fetch.FetchData("http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
419 mirrors = bb.fetch2.mirror_from_string(self.mirrorvar)
420 uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
421 self.assertEqual(uris, ['file:///somepath/downloads/bitbake-1.0.tar.gz', 'file:///someotherpath/downloads/bitbake-1.0.tar.gz'])
422
423 def test_urilist2(self):
424 # Catch https:// -> files:// bug
425 fetcher = bb.fetch.FetchData("https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
426 mirrors = bb.fetch2.mirror_from_string(self.mirrorvar)
427 uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
428 self.assertEqual(uris, ['file:///someotherpath/downloads/bitbake-1.0.tar.gz'])
429
430 def test_mirror_of_mirror(self):
431 # Test if mirror of a mirror works
432 mirrorvar = self.mirrorvar + " http://.*/.* http://otherdownloads.yoctoproject.org/downloads/ \n"
433 mirrorvar = mirrorvar + " http://otherdownloads.yoctoproject.org/.* http://downloads2.yoctoproject.org/downloads/ \n"
434 fetcher = bb.fetch.FetchData("http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
435 mirrors = bb.fetch2.mirror_from_string(mirrorvar)
436 uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
437 self.assertEqual(uris, ['file:///somepath/downloads/bitbake-1.0.tar.gz',
438 'file:///someotherpath/downloads/bitbake-1.0.tar.gz',
439 'http://otherdownloads.yoctoproject.org/downloads/bitbake-1.0.tar.gz',
440 'http://downloads2.yoctoproject.org/downloads/bitbake-1.0.tar.gz'])
441
Patrick Williamsd7e96312015-09-22 08:09:05 -0500442 recmirrorvar = "https://.*/[^/]* http://AAAA/A/A/A/ \n" \
443 "https://.*/[^/]* https://BBBB/B/B/B/ \n"
444
445 def test_recursive(self):
446 fetcher = bb.fetch.FetchData("https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
447 mirrors = bb.fetch2.mirror_from_string(self.recmirrorvar)
448 uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
449 self.assertEqual(uris, ['http://AAAA/A/A/A/bitbake/bitbake-1.0.tar.gz',
450 'https://BBBB/B/B/B/bitbake/bitbake-1.0.tar.gz',
451 'http://AAAA/A/A/A/B/B/bitbake/bitbake-1.0.tar.gz'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500452
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800453
454class GitDownloadDirectoryNamingTest(FetcherTest):
455 def setUp(self):
456 super(GitDownloadDirectoryNamingTest, self).setUp()
457 self.recipe_url = "git://git.openembedded.org/bitbake"
458 self.recipe_dir = "git.openembedded.org.bitbake"
459 self.mirror_url = "git://github.com/openembedded/bitbake.git"
460 self.mirror_dir = "github.com.openembedded.bitbake.git"
461
462 self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
463
464 def setup_mirror_rewrite(self):
465 self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url + " \n")
466
467 @skipIfNoNetwork()
468 def test_that_directory_is_named_after_recipe_url_when_no_mirroring_is_used(self):
469 self.setup_mirror_rewrite()
470 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
471
472 fetcher.download()
473
474 dir = os.listdir(self.dldir + "/git2")
475 self.assertIn(self.recipe_dir, dir)
476
477 @skipIfNoNetwork()
478 def test_that_directory_exists_for_mirrored_url_and_recipe_url_when_mirroring_is_used(self):
479 self.setup_mirror_rewrite()
480 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
481
482 fetcher.download()
483
484 dir = os.listdir(self.dldir + "/git2")
485 self.assertIn(self.mirror_dir, dir)
486 self.assertIn(self.recipe_dir, dir)
487
488 @skipIfNoNetwork()
489 def test_that_recipe_directory_and_mirrored_directory_exists_when_mirroring_is_used_and_the_mirrored_directory_already_exists(self):
490 self.setup_mirror_rewrite()
491 fetcher = bb.fetch.Fetch([self.mirror_url], self.d)
492 fetcher.download()
493 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
494
495 fetcher.download()
496
497 dir = os.listdir(self.dldir + "/git2")
498 self.assertIn(self.mirror_dir, dir)
499 self.assertIn(self.recipe_dir, dir)
500
501
502class TarballNamingTest(FetcherTest):
503 def setUp(self):
504 super(TarballNamingTest, self).setUp()
505 self.recipe_url = "git://git.openembedded.org/bitbake"
506 self.recipe_tarball = "git2_git.openembedded.org.bitbake.tar.gz"
507 self.mirror_url = "git://github.com/openembedded/bitbake.git"
508 self.mirror_tarball = "git2_github.com.openembedded.bitbake.git.tar.gz"
509
510 self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '1')
511 self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
512
513 def setup_mirror_rewrite(self):
514 self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url + " \n")
515
516 @skipIfNoNetwork()
517 def test_that_the_recipe_tarball_is_created_when_no_mirroring_is_used(self):
518 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
519
520 fetcher.download()
521
522 dir = os.listdir(self.dldir)
523 self.assertIn(self.recipe_tarball, dir)
524
525 @skipIfNoNetwork()
526 def test_that_the_mirror_tarball_is_created_when_mirroring_is_used(self):
527 self.setup_mirror_rewrite()
528 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
529
530 fetcher.download()
531
532 dir = os.listdir(self.dldir)
533 self.assertIn(self.mirror_tarball, dir)
534
535
536class GitShallowTarballNamingTest(FetcherTest):
537 def setUp(self):
538 super(GitShallowTarballNamingTest, self).setUp()
539 self.recipe_url = "git://git.openembedded.org/bitbake"
540 self.recipe_tarball = "gitshallow_git.openembedded.org.bitbake_82ea737-1_master.tar.gz"
541 self.mirror_url = "git://github.com/openembedded/bitbake.git"
542 self.mirror_tarball = "gitshallow_github.com.openembedded.bitbake.git_82ea737-1_master.tar.gz"
543
544 self.d.setVar('BB_GIT_SHALLOW', '1')
545 self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1')
546 self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
547
548 def setup_mirror_rewrite(self):
549 self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url + " \n")
550
551 @skipIfNoNetwork()
552 def test_that_the_tarball_is_named_after_recipe_url_when_no_mirroring_is_used(self):
553 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
554
555 fetcher.download()
556
557 dir = os.listdir(self.dldir)
558 self.assertIn(self.recipe_tarball, dir)
559
560 @skipIfNoNetwork()
561 def test_that_the_mirror_tarball_is_created_when_mirroring_is_used(self):
562 self.setup_mirror_rewrite()
563 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
564
565 fetcher.download()
566
567 dir = os.listdir(self.dldir)
568 self.assertIn(self.mirror_tarball, dir)
569
570
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500571class FetcherLocalTest(FetcherTest):
572 def setUp(self):
573 def touch(fn):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600574 with open(fn, 'a'):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500575 os.utime(fn, None)
576
577 super(FetcherLocalTest, self).setUp()
578 self.localsrcdir = os.path.join(self.tempdir, 'localsrc')
579 os.makedirs(self.localsrcdir)
580 touch(os.path.join(self.localsrcdir, 'a'))
581 touch(os.path.join(self.localsrcdir, 'b'))
582 os.makedirs(os.path.join(self.localsrcdir, 'dir'))
583 touch(os.path.join(self.localsrcdir, 'dir', 'c'))
584 touch(os.path.join(self.localsrcdir, 'dir', 'd'))
585 os.makedirs(os.path.join(self.localsrcdir, 'dir', 'subdir'))
586 touch(os.path.join(self.localsrcdir, 'dir', 'subdir', 'e'))
587 self.d.setVar("FILESPATH", self.localsrcdir)
588
589 def fetchUnpack(self, uris):
590 fetcher = bb.fetch.Fetch(uris, self.d)
591 fetcher.download()
592 fetcher.unpack(self.unpackdir)
593 flst = []
594 for root, dirs, files in os.walk(self.unpackdir):
595 for f in files:
596 flst.append(os.path.relpath(os.path.join(root, f), self.unpackdir))
597 flst.sort()
598 return flst
599
600 def test_local(self):
601 tree = self.fetchUnpack(['file://a', 'file://dir/c'])
602 self.assertEqual(tree, ['a', 'dir/c'])
603
604 def test_local_wildcard(self):
605 tree = self.fetchUnpack(['file://a', 'file://dir/*'])
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500606 self.assertEqual(tree, ['a', 'dir/c', 'dir/d', 'dir/subdir/e'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500607
608 def test_local_dir(self):
609 tree = self.fetchUnpack(['file://a', 'file://dir'])
610 self.assertEqual(tree, ['a', 'dir/c', 'dir/d', 'dir/subdir/e'])
611
612 def test_local_subdir(self):
613 tree = self.fetchUnpack(['file://dir/subdir'])
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500614 self.assertEqual(tree, ['dir/subdir/e'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500615
616 def test_local_subdir_file(self):
617 tree = self.fetchUnpack(['file://dir/subdir/e'])
618 self.assertEqual(tree, ['dir/subdir/e'])
619
620 def test_local_subdirparam(self):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500621 tree = self.fetchUnpack(['file://a;subdir=bar', 'file://dir;subdir=foo/moo'])
622 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 -0500623
624 def test_local_deepsubdirparam(self):
625 tree = self.fetchUnpack(['file://dir/subdir/e;subdir=bar'])
626 self.assertEqual(tree, ['bar/dir/subdir/e'])
627
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600628 def test_local_absolutedir(self):
629 # Unpacking to an absolute path that is a subdirectory of the root
630 # should work
631 tree = self.fetchUnpack(['file://a;subdir=%s' % os.path.join(self.unpackdir, 'bar')])
632
633 # Unpacking to an absolute path outside of the root should fail
634 with self.assertRaises(bb.fetch2.UnpackError):
635 self.fetchUnpack(['file://a;subdir=/bin/sh'])
636
Brad Bishop316dfdd2018-06-25 12:45:53 -0400637class FetcherNoNetworkTest(FetcherTest):
638 def setUp(self):
639 super().setUp()
640 # all test cases are based on not having network
641 self.d.setVar("BB_NO_NETWORK", "1")
642
643 def test_missing(self):
644 string = "this is a test file\n".encode("utf-8")
645 self.d.setVarFlag("SRC_URI", "md5sum", hashlib.md5(string).hexdigest())
646 self.d.setVarFlag("SRC_URI", "sha256sum", hashlib.sha256(string).hexdigest())
647
648 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
649 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
650 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/test-file.tar.gz"], self.d)
651 with self.assertRaises(bb.fetch2.NetworkAccess):
652 fetcher.download()
653
654 def test_valid_missing_donestamp(self):
655 # create the file in the download directory with correct hash
656 string = "this is a test file\n".encode("utf-8")
657 with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb") as f:
658 f.write(string)
659
660 self.d.setVarFlag("SRC_URI", "md5sum", hashlib.md5(string).hexdigest())
661 self.d.setVarFlag("SRC_URI", "sha256sum", hashlib.sha256(string).hexdigest())
662
663 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
664 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
665 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/test-file.tar.gz"], self.d)
666 fetcher.download()
667 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
668
669 def test_invalid_missing_donestamp(self):
670 # create an invalid file in the download directory with incorrect hash
671 string = "this is a test file\n".encode("utf-8")
672 with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb"):
673 pass
674
675 self.d.setVarFlag("SRC_URI", "md5sum", hashlib.md5(string).hexdigest())
676 self.d.setVarFlag("SRC_URI", "sha256sum", hashlib.sha256(string).hexdigest())
677
678 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
679 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
680 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/test-file.tar.gz"], self.d)
681 with self.assertRaises(bb.fetch2.NetworkAccess):
682 fetcher.download()
683 # the existing file should not exist or should have be moved to "bad-checksum"
684 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
685
686 def test_nochecksums_missing(self):
687 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
688 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
689 # ssh fetch does not support checksums
690 fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d)
691 # attempts to download with missing donestamp
692 with self.assertRaises(bb.fetch2.NetworkAccess):
693 fetcher.download()
694
695 def test_nochecksums_missing_donestamp(self):
696 # create a file in the download directory
697 with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb"):
698 pass
699
700 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
701 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
702 # ssh fetch does not support checksums
703 fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d)
704 # attempts to download with missing donestamp
705 with self.assertRaises(bb.fetch2.NetworkAccess):
706 fetcher.download()
707
708 def test_nochecksums_has_donestamp(self):
709 # create a file in the download directory with the donestamp
710 with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb"):
711 pass
712 with open(os.path.join(self.dldir, "test-file.tar.gz.done"), "wb"):
713 pass
714
715 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
716 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
717 # ssh fetch does not support checksums
718 fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d)
719 # should not fetch
720 fetcher.download()
721 # both files should still exist
722 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
723 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
724
725 def test_nochecksums_missing_has_donestamp(self):
726 # create a file in the download directory with the donestamp
727 with open(os.path.join(self.dldir, "test-file.tar.gz.done"), "wb"):
728 pass
729
730 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
731 self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
732 # ssh fetch does not support checksums
733 fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d)
734 with self.assertRaises(bb.fetch2.NetworkAccess):
735 fetcher.download()
736 # both files should still exist
737 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz")))
738 self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done")))
739
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500740class FetcherNetworkTest(FetcherTest):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500741 @skipIfNoNetwork()
742 def test_fetch(self):
743 fetcher = bb.fetch.Fetch(["http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", "http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.1.tar.gz"], self.d)
744 fetcher.download()
745 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
746 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.1.tar.gz"), 57892)
747 self.d.setVar("BB_NO_NETWORK", "1")
748 fetcher = bb.fetch.Fetch(["http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", "http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.1.tar.gz"], self.d)
749 fetcher.download()
750 fetcher.unpack(self.unpackdir)
751 self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.0/")), 9)
752 self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.1/")), 9)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500753
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500754 @skipIfNoNetwork()
755 def test_fetch_mirror(self):
756 self.d.setVar("MIRRORS", "http://.*/.* http://downloads.yoctoproject.org/releases/bitbake")
757 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
758 fetcher.download()
759 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
760
761 @skipIfNoNetwork()
762 def test_fetch_mirror_of_mirror(self):
763 self.d.setVar("MIRRORS", "http://.*/.* http://invalid2.yoctoproject.org/ \n http://invalid2.yoctoproject.org/.* http://downloads.yoctoproject.org/releases/bitbake")
764 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
765 fetcher.download()
766 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
767
768 @skipIfNoNetwork()
769 def test_fetch_file_mirror_of_mirror(self):
770 self.d.setVar("MIRRORS", "http://.*/.* file:///some1where/ \n file:///some1where/.* file://some2where/ \n file://some2where/.* http://downloads.yoctoproject.org/releases/bitbake")
771 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
772 os.mkdir(self.dldir + "/some2where")
773 fetcher.download()
774 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
775
776 @skipIfNoNetwork()
777 def test_fetch_premirror(self):
778 self.d.setVar("PREMIRRORS", "http://.*/.* http://downloads.yoctoproject.org/releases/bitbake")
779 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
780 fetcher.download()
781 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
782
783 @skipIfNoNetwork()
784 def gitfetcher(self, url1, url2):
785 def checkrevision(self, fetcher):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500786 fetcher.unpack(self.unpackdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500787 revision = bb.process.run("git rev-parse HEAD", shell=True, cwd=self.unpackdir + "/git")[0].strip()
788 self.assertEqual(revision, "270a05b0b4ba0959fe0624d2a4885d7b70426da5")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500789
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500790 self.d.setVar("BB_GENERATE_MIRROR_TARBALLS", "1")
791 self.d.setVar("SRCREV", "270a05b0b4ba0959fe0624d2a4885d7b70426da5")
792 fetcher = bb.fetch.Fetch([url1], self.d)
793 fetcher.download()
794 checkrevision(self, fetcher)
795 # Wipe out the dldir clone and the unpacked source, turn off the network and check mirror tarball works
796 bb.utils.prunedir(self.dldir + "/git2/")
797 bb.utils.prunedir(self.unpackdir)
798 self.d.setVar("BB_NO_NETWORK", "1")
799 fetcher = bb.fetch.Fetch([url2], self.d)
800 fetcher.download()
801 checkrevision(self, fetcher)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500802
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500803 @skipIfNoNetwork()
804 def test_gitfetch(self):
805 url1 = url2 = "git://git.openembedded.org/bitbake"
806 self.gitfetcher(url1, url2)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500807
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500808 @skipIfNoNetwork()
809 def test_gitfetch_goodsrcrev(self):
810 # SRCREV is set but matches rev= parameter
811 url1 = url2 = "git://git.openembedded.org/bitbake;rev=270a05b0b4ba0959fe0624d2a4885d7b70426da5"
812 self.gitfetcher(url1, url2)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500813
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500814 @skipIfNoNetwork()
815 def test_gitfetch_badsrcrev(self):
816 # SRCREV is set but does not match rev= parameter
817 url1 = url2 = "git://git.openembedded.org/bitbake;rev=dead05b0b4ba0959fe0624d2a4885d7b70426da5"
818 self.assertRaises(bb.fetch.FetchError, self.gitfetcher, url1, url2)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500819
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500820 @skipIfNoNetwork()
821 def test_gitfetch_tagandrev(self):
822 # SRCREV is set but does not match rev= parameter
823 url1 = url2 = "git://git.openembedded.org/bitbake;rev=270a05b0b4ba0959fe0624d2a4885d7b70426da5;tag=270a05b0b4ba0959fe0624d2a4885d7b70426da5"
824 self.assertRaises(bb.fetch.FetchError, self.gitfetcher, url1, url2)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500825
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500826 @skipIfNoNetwork()
827 def test_gitfetch_localusehead(self):
828 # Create dummy local Git repo
829 src_dir = tempfile.mkdtemp(dir=self.tempdir,
830 prefix='gitfetch_localusehead_')
831 src_dir = os.path.abspath(src_dir)
832 bb.process.run("git init", cwd=src_dir)
833 bb.process.run("git commit --allow-empty -m'Dummy commit'",
834 cwd=src_dir)
835 # Use other branch than master
836 bb.process.run("git checkout -b my-devel", cwd=src_dir)
837 bb.process.run("git commit --allow-empty -m'Dummy commit 2'",
838 cwd=src_dir)
839 stdout = bb.process.run("git rev-parse HEAD", cwd=src_dir)
840 orig_rev = stdout[0].strip()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500841
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500842 # Fetch and check revision
843 self.d.setVar("SRCREV", "AUTOINC")
844 url = "git://" + src_dir + ";protocol=file;usehead=1"
845 fetcher = bb.fetch.Fetch([url], self.d)
846 fetcher.download()
847 fetcher.unpack(self.unpackdir)
848 stdout = bb.process.run("git rev-parse HEAD",
849 cwd=os.path.join(self.unpackdir, 'git'))
850 unpack_rev = stdout[0].strip()
851 self.assertEqual(orig_rev, unpack_rev)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500852
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500853 @skipIfNoNetwork()
854 def test_gitfetch_remoteusehead(self):
855 url = "git://git.openembedded.org/bitbake;usehead=1"
856 self.assertRaises(bb.fetch.ParameterError, self.gitfetcher, url, url)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500857
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500858 @skipIfNoNetwork()
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800859 def test_gitfetch_finds_local_tarball_for_mirrored_url_when_previous_downloaded_by_the_recipe_url(self):
860 recipeurl = "git://git.openembedded.org/bitbake"
861 mirrorurl = "git://someserver.org/bitbake"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500862 self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n")
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800863 self.gitfetcher(recipeurl, mirrorurl)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500864
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500865 @skipIfNoNetwork()
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800866 def test_gitfetch_finds_local_tarball_when_previous_downloaded_from_a_premirror(self):
867 recipeurl = "git://someserver.org/bitbake"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500868 self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n")
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800869 self.gitfetcher(recipeurl, recipeurl)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500870
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500871 @skipIfNoNetwork()
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800872 def test_gitfetch_finds_local_repository_when_premirror_rewrites_the_recipe_url(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500873 realurl = "git://git.openembedded.org/bitbake"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800874 recipeurl = "git://someserver.org/bitbake"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500875 self.sourcedir = self.unpackdir.replace("unpacked", "sourcemirror.git")
876 os.chdir(self.tempdir)
877 bb.process.run("git clone %s %s 2> /dev/null" % (realurl, self.sourcedir), shell=True)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800878 self.d.setVar("PREMIRRORS", "%s git://%s;protocol=file \n" % (recipeurl, self.sourcedir))
879 self.gitfetcher(recipeurl, recipeurl)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600880
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500881 @skipIfNoNetwork()
882 def test_git_submodule(self):
Brad Bishopf8caae32019-03-25 13:13:56 -0400883 # URL with ssh submodules
884 url = "gitsm://git.yoctoproject.org/git-submodule-test;branch=ssh-gitsm-tests;rev=049da4a6cb198d7c0302e9e8b243a1443cb809a7"
885 # Original URL (comment this if you have ssh access to git.yoctoproject.org)
886 url = "gitsm://git.yoctoproject.org/git-submodule-test;branch=master;rev=a2885dd7d25380d23627e7544b7bbb55014b16ee"
887 fetcher = bb.fetch.Fetch([url], self.d)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500888 fetcher.download()
889 # Previous cwd has been deleted
890 os.chdir(os.path.dirname(self.unpackdir))
891 fetcher.unpack(self.unpackdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500892
Brad Bishopf8caae32019-03-25 13:13:56 -0400893 repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
894 self.assertTrue(os.path.exists(repo_path), msg='Unpacked repository missing')
895 self.assertTrue(os.path.exists(os.path.join(repo_path, 'bitbake')), msg='bitbake submodule missing')
896 self.assertFalse(os.path.exists(os.path.join(repo_path, 'na')), msg='uninitialized submodule present')
897
898 # Only when we're running the extended test with a submodule's submodule, can we check this.
899 if os.path.exists(os.path.join(repo_path, 'bitbake-gitsm-test1')):
900 self.assertTrue(os.path.exists(os.path.join(repo_path, 'bitbake-gitsm-test1', 'bitbake')), msg='submodule of submodule missing')
901
902 def test_git_submodule_dbus_broker(self):
903 # The following external repositories have show failures in fetch and unpack operations
904 # We want to avoid regressions!
905 url = "gitsm://github.com/bus1/dbus-broker;protocol=git;rev=fc874afa0992d0c75ec25acb43d344679f0ee7d2"
906 fetcher = bb.fetch.Fetch([url], self.d)
907 fetcher.download()
908 # Previous cwd has been deleted
909 os.chdir(os.path.dirname(self.unpackdir))
910 fetcher.unpack(self.unpackdir)
911
912 repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
913 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-dvar/config')), msg='Missing submodule config "subprojects/c-dvar"')
914 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-list/config')), msg='Missing submodule config "subprojects/c-list"')
915 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-rbtree/config')), msg='Missing submodule config "subprojects/c-rbtree"')
916 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-sundry/config')), msg='Missing submodule config "subprojects/c-sundry"')
917 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-utf8/config')), msg='Missing submodule config "subprojects/c-utf8"')
918
919 def test_git_submodule_CLI11(self):
920 url = "gitsm://github.com/CLIUtils/CLI11;protocol=git;rev=bd4dc911847d0cde7a6b41dfa626a85aab213baf"
921 fetcher = bb.fetch.Fetch([url], self.d)
922 fetcher.download()
923 # Previous cwd has been deleted
924 os.chdir(os.path.dirname(self.unpackdir))
925 fetcher.unpack(self.unpackdir)
926
927 repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
928 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/googletest/config')), msg='Missing submodule config "extern/googletest"')
929 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/json/config')), msg='Missing submodule config "extern/json"')
930 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/sanitizers/config')), msg='Missing submodule config "extern/sanitizers"')
931
Brad Bishop19323692019-04-05 15:28:33 -0400932 def test_git_submodule_update_CLI11(self):
933 """ Prevent regression on update detection not finding missing submodule, or modules without needed commits """
934 url = "gitsm://github.com/CLIUtils/CLI11;protocol=git;rev=cf6a99fa69aaefe477cc52e3ef4a7d2d7fa40714"
935 fetcher = bb.fetch.Fetch([url], self.d)
936 fetcher.download()
937
938 # CLI11 that pulls in a newer nlohmann-json
939 url = "gitsm://github.com/CLIUtils/CLI11;protocol=git;rev=49ac989a9527ee9bb496de9ded7b4872c2e0e5ca"
940 fetcher = bb.fetch.Fetch([url], self.d)
941 fetcher.download()
942 # Previous cwd has been deleted
943 os.chdir(os.path.dirname(self.unpackdir))
944 fetcher.unpack(self.unpackdir)
945
946 repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
947 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/googletest/config')), msg='Missing submodule config "extern/googletest"')
948 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/json/config')), msg='Missing submodule config "extern/json"')
949 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/sanitizers/config')), msg='Missing submodule config "extern/sanitizers"')
950
Brad Bishopf8caae32019-03-25 13:13:56 -0400951 def test_git_submodule_aktualizr(self):
952 url = "gitsm://github.com/advancedtelematic/aktualizr;branch=master;protocol=git;rev=d00d1a04cc2366d1a5f143b84b9f507f8bd32c44"
953 fetcher = bb.fetch.Fetch([url], self.d)
954 fetcher.download()
955 # Previous cwd has been deleted
956 os.chdir(os.path.dirname(self.unpackdir))
957 fetcher.unpack(self.unpackdir)
958
959 repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
960 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"')
961 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"')
962 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")
963 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"')
964 self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/third_party/googletest/config')), msg='Missing submodule config "third_party/googletest/config"')
965 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 -0500966
Brad Bishop393846f2019-05-20 12:24:11 -0400967 def test_git_submodule_iotedge(self):
968 """ Prevent regression on deeply nested submodules not being checked out properly, even though they were fetched. """
969
970 # This repository also has submodules where the module (name), path and url do not align
971 url = "gitsm://github.com/azure/iotedge.git;protocol=git;rev=d76e0316c6f324345d77c48a83ce836d09392699"
972 fetcher = bb.fetch.Fetch([url], self.d)
973 fetcher.download()
974 # Previous cwd has been deleted
975 os.chdir(os.path.dirname(self.unpackdir))
976 fetcher.unpack(self.unpackdir)
977
978 repo_path = os.path.join(self.tempdir, 'unpacked', 'git')
979
980 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')
981 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')
982 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')
983 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')
984 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')
985 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')
986 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')
987 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')
988 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')
989 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')
990 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')
991 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')
992 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')
993
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500994class TrustedNetworksTest(FetcherTest):
995 def test_trusted_network(self):
996 # Ensure trusted_network returns False when the host IS in the list.
997 url = "git://Someserver.org/foo;rev=1"
998 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org someserver.org server2.org server3.org")
999 self.assertTrue(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001000
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001001 def test_wild_trusted_network(self):
1002 # Ensure trusted_network returns true when the *.host IS in the list.
1003 url = "git://Someserver.org/foo;rev=1"
1004 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
1005 self.assertTrue(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001006
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001007 def test_prefix_wild_trusted_network(self):
1008 # Ensure trusted_network returns true when the prefix matches *.host.
1009 url = "git://git.Someserver.org/foo;rev=1"
1010 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
1011 self.assertTrue(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001012
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001013 def test_two_prefix_wild_trusted_network(self):
1014 # Ensure trusted_network returns true when the prefix matches *.host.
1015 url = "git://something.git.Someserver.org/foo;rev=1"
1016 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
1017 self.assertTrue(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001018
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001019 def test_port_trusted_network(self):
1020 # Ensure trusted_network returns True, even if the url specifies a port.
1021 url = "git://someserver.org:8080/foo;rev=1"
1022 self.d.setVar("BB_ALLOWED_NETWORKS", "someserver.org")
1023 self.assertTrue(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001024
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001025 def test_untrusted_network(self):
1026 # Ensure trusted_network returns False when the host is NOT in the list.
1027 url = "git://someserver.org/foo;rev=1"
1028 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org server2.org server3.org")
1029 self.assertFalse(bb.fetch.trusted_network(self.d, url))
1030
1031 def test_wild_untrusted_network(self):
1032 # Ensure trusted_network returns False when the host is NOT in the list.
1033 url = "git://*.someserver.org/foo;rev=1"
1034 self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org server2.org server3.org")
1035 self.assertFalse(bb.fetch.trusted_network(self.d, url))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001036
1037class URLHandle(unittest.TestCase):
1038
1039 datatable = {
1040 "http://www.google.com/index.html" : ('http', 'www.google.com', '/index.html', '', '', {}),
1041 "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 -06001042 "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 -05001043 "git://git.openembedded.org/bitbake;branch=@foo" : ('git', 'git.openembedded.org', '/bitbake', '', '', {'branch': '@foo'}),
1044 "file://somelocation;someparam=1": ('file', '', 'somelocation', '', '', {'someparam': '1'}),
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001045 }
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001046 # we require a pathname to encodeurl but users can still pass such urls to
1047 # decodeurl and we need to handle them
1048 decodedata = datatable.copy()
1049 decodedata.update({
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001050 "http://somesite.net;someparam=1": ('http', 'somesite.net', '/', '', '', {'someparam': '1'}),
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001051 })
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001052
1053 def test_decodeurl(self):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001054 for k, v in self.decodedata.items():
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001055 result = bb.fetch.decodeurl(k)
1056 self.assertEqual(result, v)
1057
1058 def test_encodeurl(self):
1059 for k, v in self.datatable.items():
1060 result = bb.fetch.encodeurl(v)
1061 self.assertEqual(result, k)
1062
1063class FetchLatestVersionTest(FetcherTest):
1064
1065 test_git_uris = {
1066 # version pattern "X.Y.Z"
1067 ("mx-1.0", "git://github.com/clutter-project/mx.git;branch=mx-1.4", "9b1db6b8060bd00b121a692f942404a24ae2960f", "")
1068 : "1.99.4",
1069 # version pattern "vX.Y"
1070 ("mtd-utils", "git://git.infradead.org/mtd-utils.git", "ca39eb1d98e736109c64ff9c1aa2a6ecca222d8f", "")
1071 : "1.5.0",
1072 # version pattern "pkg_name-X.Y"
1073 ("presentproto", "git://anongit.freedesktop.org/git/xorg/proto/presentproto", "24f3a56e541b0a9e6c6ee76081f441221a120ef9", "")
1074 : "1.0",
1075 # version pattern "pkg_name-vX.Y.Z"
1076 ("dtc", "git://git.qemu.org/dtc.git", "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf", "")
1077 : "1.4.0",
1078 # combination version pattern
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001079 ("sysprof", "git://gitlab.gnome.org/GNOME/sysprof.git;protocol=https", "cd44ee6644c3641507fb53b8a2a69137f2971219", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001080 : "1.2.0",
1081 ("u-boot-mkimage", "git://git.denx.de/u-boot.git;branch=master;protocol=git", "62c175fbb8a0f9a926c88294ea9f7e88eb898f6c", "")
1082 : "2014.01",
1083 # version pattern "yyyymmdd"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001084 ("mobile-broadband-provider-info", "git://gitlab.gnome.org/GNOME/mobile-broadband-provider-info.git;protocol=https", "4ed19e11c2975105b71b956440acdb25d46a347d", "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001085 : "20120614",
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001086 # packages with a valid UPSTREAM_CHECK_GITTAGREGEX
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001087 ("xf86-video-omap", "git://anongit.freedesktop.org/xorg/driver/xf86-video-omap", "ae0394e687f1a77e966cf72f895da91840dffb8f", "(?P<pver>(\d+\.(\d\.?)*))")
1088 : "0.4.3",
1089 ("build-appliance-image", "git://git.yoctoproject.org/poky", "b37dd451a52622d5b570183a81583cc34c2ff555", "(?P<pver>(([0-9][\.|_]?)+[0-9]))")
1090 : "11.0.0",
1091 ("chkconfig-alternatives-native", "git://github.com/kergoth/chkconfig;branch=sysroot", "cd437ecbd8986c894442f8fce1e0061e20f04dee", "chkconfig\-(?P<pver>((\d+[\.\-_]*)+))")
1092 : "1.3.59",
1093 ("remake", "git://github.com/rocky/remake.git", "f05508e521987c8494c92d9c2871aec46307d51d", "(?P<pver>(\d+\.(\d+\.)*\d*(\+dbg\d+(\.\d+)*)*))")
1094 : "3.82+dbg0.9",
1095 }
1096
1097 test_wget_uris = {
1098 # packages with versions inside directory name
1099 ("util-linux", "http://kernel.org/pub/linux/utils/util-linux/v2.23/util-linux-2.24.2.tar.bz2", "", "")
1100 : "2.24.2",
1101 ("enchant", "http://www.abisource.com/downloads/enchant/1.6.0/enchant-1.6.0.tar.gz", "", "")
1102 : "1.6.0",
1103 ("cmake", "http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz", "", "")
1104 : "2.8.12.1",
1105 # packages with versions only in current directory
1106 ("eglic", "http://downloads.yoctoproject.org/releases/eglibc/eglibc-2.18-svnr23787.tar.bz2", "", "")
1107 : "2.19",
1108 ("gnu-config", "http://downloads.yoctoproject.org/releases/gnu-config/gnu-config-20120814.tar.bz2", "", "")
1109 : "20120814",
1110 # packages with "99" in the name of possible version
1111 ("pulseaudio", "http://freedesktop.org/software/pulseaudio/releases/pulseaudio-4.0.tar.xz", "", "")
1112 : "5.0",
1113 ("xserver-xorg", "http://xorg.freedesktop.org/releases/individual/xserver/xorg-server-1.15.1.tar.bz2", "", "")
1114 : "1.15.1",
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001115 # packages with valid UPSTREAM_CHECK_URI and UPSTREAM_CHECK_REGEX
1116 ("cups", "http://www.cups.org/software/1.7.2/cups-1.7.2-source.tar.bz2", "https://github.com/apple/cups/releases", "(?P<name>cups\-)(?P<pver>((\d+[\.\-_]*)+))\-source\.tar\.gz")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001117 : "2.0.0",
1118 ("db", "http://download.oracle.com/berkeley-db/db-5.3.21.tar.gz", "http://www.oracle.com/technetwork/products/berkeleydb/downloads/index-082944.html", "http://download.oracle.com/otn/berkeley-db/(?P<name>db-)(?P<pver>((\d+[\.\-_]*)+))\.tar\.gz")
1119 : "6.1.19",
1120 }
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001121
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001122 @skipIfNoNetwork()
1123 def test_git_latest_versionstring(self):
1124 for k, v in self.test_git_uris.items():
1125 self.d.setVar("PN", k[0])
1126 self.d.setVar("SRCREV", k[2])
1127 self.d.setVar("UPSTREAM_CHECK_GITTAGREGEX", k[3])
1128 ud = bb.fetch2.FetchData(k[1], self.d)
1129 pupver= ud.method.latest_versionstring(ud, self.d)
1130 verstring = pupver[0]
Brad Bishop316dfdd2018-06-25 12:45:53 -04001131 self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0])
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001132 r = bb.utils.vercmp_string(v, verstring)
1133 self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring))
1134
1135 @skipIfNoNetwork()
1136 def test_wget_latest_versionstring(self):
1137 for k, v in self.test_wget_uris.items():
1138 self.d.setVar("PN", k[0])
1139 self.d.setVar("UPSTREAM_CHECK_URI", k[2])
1140 self.d.setVar("UPSTREAM_CHECK_REGEX", k[3])
1141 ud = bb.fetch2.FetchData(k[1], self.d)
1142 pupver = ud.method.latest_versionstring(ud, self.d)
1143 verstring = pupver[0]
Brad Bishop316dfdd2018-06-25 12:45:53 -04001144 self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0])
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001145 r = bb.utils.vercmp_string(v, verstring)
1146 self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001147
1148
1149class FetchCheckStatusTest(FetcherTest):
1150 test_wget_uris = ["http://www.cups.org/software/1.7.2/cups-1.7.2-source.tar.bz2",
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001151 "http://www.cups.org/",
1152 "http://downloads.yoctoproject.org/releases/sato/sato-engine-0.1.tar.gz",
1153 "http://downloads.yoctoproject.org/releases/sato/sato-engine-0.2.tar.gz",
1154 "http://downloads.yoctoproject.org/releases/sato/sato-engine-0.3.tar.gz",
1155 "https://yoctoproject.org/",
1156 "https://yoctoproject.org/documentation",
1157 "http://downloads.yoctoproject.org/releases/opkg/opkg-0.1.7.tar.gz",
1158 "http://downloads.yoctoproject.org/releases/opkg/opkg-0.3.0.tar.gz",
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001159 "ftp://sourceware.org/pub/libffi/libffi-1.20.tar.gz",
1160 "http://ftp.gnu.org/gnu/autoconf/autoconf-2.60.tar.gz",
1161 "https://ftp.gnu.org/gnu/chess/gnuchess-5.08.tar.gz",
1162 "https://ftp.gnu.org/gnu/gmp/gmp-4.0.tar.gz",
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001163 # GitHub releases are hosted on Amazon S3, which doesn't support HEAD
1164 "https://github.com/kergoth/tslib/releases/download/1.1/tslib-1.1.tar.xz"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001165 ]
1166
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001167 @skipIfNoNetwork()
1168 def test_wget_checkstatus(self):
1169 fetch = bb.fetch2.Fetch(self.test_wget_uris, self.d)
1170 for u in self.test_wget_uris:
1171 with self.subTest(url=u):
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001172 ud = fetch.ud[u]
1173 m = ud.method
1174 ret = m.checkstatus(fetch, ud, self.d)
1175 self.assertTrue(ret, msg="URI %s, can't check status" % (u))
1176
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001177 @skipIfNoNetwork()
1178 def test_wget_checkstatus_connection_cache(self):
1179 from bb.fetch2 import FetchConnectionCache
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001180
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001181 connection_cache = FetchConnectionCache()
1182 fetch = bb.fetch2.Fetch(self.test_wget_uris, self.d,
1183 connection_cache = connection_cache)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001184
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001185 for u in self.test_wget_uris:
1186 with self.subTest(url=u):
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001187 ud = fetch.ud[u]
1188 m = ud.method
1189 ret = m.checkstatus(fetch, ud, self.d)
1190 self.assertTrue(ret, msg="URI %s, can't check status" % (u))
1191
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001192 connection_cache.close_connections()
1193
1194
1195class GitMakeShallowTest(FetcherTest):
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001196 def setUp(self):
1197 FetcherTest.setUp(self)
1198 self.gitdir = os.path.join(self.tempdir, 'gitshallow')
1199 bb.utils.mkdirhier(self.gitdir)
1200 bb.process.run('git init', cwd=self.gitdir)
1201
1202 def assertRefs(self, expected_refs):
1203 actual_refs = self.git(['for-each-ref', '--format=%(refname)']).splitlines()
1204 full_expected = self.git(['rev-parse', '--symbolic-full-name'] + expected_refs).splitlines()
1205 self.assertEqual(sorted(full_expected), sorted(actual_refs))
1206
1207 def assertRevCount(self, expected_count, args=None):
1208 if args is None:
1209 args = ['HEAD']
1210 revs = self.git(['rev-list'] + args)
1211 actual_count = len(revs.splitlines())
1212 self.assertEqual(expected_count, actual_count, msg='Object count `%d` is not the expected `%d`' % (actual_count, expected_count))
1213
1214 def git(self, cmd):
1215 if isinstance(cmd, str):
1216 cmd = 'git ' + cmd
1217 else:
1218 cmd = ['git'] + cmd
1219 return bb.process.run(cmd, cwd=self.gitdir)[0]
1220
1221 def make_shallow(self, args=None):
1222 if args is None:
1223 args = ['HEAD']
Brad Bishop316dfdd2018-06-25 12:45:53 -04001224 return bb.process.run([bb.fetch2.git.Git.make_shallow_path] + args, cwd=self.gitdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001225
1226 def add_empty_file(self, path, msg=None):
1227 if msg is None:
1228 msg = path
1229 open(os.path.join(self.gitdir, path), 'w').close()
1230 self.git(['add', path])
1231 self.git(['commit', '-m', msg, path])
1232
1233 def test_make_shallow_single_branch_no_merge(self):
1234 self.add_empty_file('a')
1235 self.add_empty_file('b')
1236 self.assertRevCount(2)
1237 self.make_shallow()
1238 self.assertRevCount(1)
1239
1240 def test_make_shallow_single_branch_one_merge(self):
1241 self.add_empty_file('a')
1242 self.add_empty_file('b')
1243 self.git('checkout -b a_branch')
1244 self.add_empty_file('c')
1245 self.git('checkout master')
1246 self.add_empty_file('d')
1247 self.git('merge --no-ff --no-edit a_branch')
1248 self.git('branch -d a_branch')
1249 self.add_empty_file('e')
1250 self.assertRevCount(6)
1251 self.make_shallow(['HEAD~2'])
1252 self.assertRevCount(5)
1253
1254 def test_make_shallow_at_merge(self):
1255 self.add_empty_file('a')
1256 self.git('checkout -b a_branch')
1257 self.add_empty_file('b')
1258 self.git('checkout master')
1259 self.git('merge --no-ff --no-edit a_branch')
1260 self.git('branch -d a_branch')
1261 self.assertRevCount(3)
1262 self.make_shallow()
1263 self.assertRevCount(1)
1264
1265 def test_make_shallow_annotated_tag(self):
1266 self.add_empty_file('a')
1267 self.add_empty_file('b')
1268 self.git('tag -a -m a_tag a_tag')
1269 self.assertRevCount(2)
1270 self.make_shallow(['a_tag'])
1271 self.assertRevCount(1)
1272
1273 def test_make_shallow_multi_ref(self):
1274 self.add_empty_file('a')
1275 self.add_empty_file('b')
1276 self.git('checkout -b a_branch')
1277 self.add_empty_file('c')
1278 self.git('checkout master')
1279 self.add_empty_file('d')
1280 self.git('checkout -b a_branch_2')
1281 self.add_empty_file('a_tag')
1282 self.git('tag a_tag')
1283 self.git('checkout master')
1284 self.git('branch -D a_branch_2')
1285 self.add_empty_file('e')
1286 self.assertRevCount(6, ['--all'])
1287 self.make_shallow()
1288 self.assertRevCount(5, ['--all'])
1289
1290 def test_make_shallow_multi_ref_trim(self):
1291 self.add_empty_file('a')
1292 self.git('checkout -b a_branch')
1293 self.add_empty_file('c')
1294 self.git('checkout master')
1295 self.assertRevCount(1)
1296 self.assertRevCount(2, ['--all'])
1297 self.assertRefs(['master', 'a_branch'])
1298 self.make_shallow(['-r', 'master', 'HEAD'])
1299 self.assertRevCount(1, ['--all'])
1300 self.assertRefs(['master'])
1301
1302 def test_make_shallow_noop(self):
1303 self.add_empty_file('a')
1304 self.assertRevCount(1)
1305 self.make_shallow()
1306 self.assertRevCount(1)
1307
1308 @skipIfNoNetwork()
1309 def test_make_shallow_bitbake(self):
1310 self.git('remote add origin https://github.com/openembedded/bitbake')
1311 self.git('fetch --tags origin')
1312 orig_revs = len(self.git('rev-list --all').splitlines())
1313 self.make_shallow(['refs/tags/1.10.0'])
1314 self.assertRevCount(orig_revs - 1746, ['--all'])
1315
1316class GitShallowTest(FetcherTest):
1317 def setUp(self):
1318 FetcherTest.setUp(self)
1319 self.gitdir = os.path.join(self.tempdir, 'git')
1320 self.srcdir = os.path.join(self.tempdir, 'gitsource')
1321
1322 bb.utils.mkdirhier(self.srcdir)
1323 self.git('init', cwd=self.srcdir)
1324 self.d.setVar('WORKDIR', self.tempdir)
1325 self.d.setVar('S', self.gitdir)
1326 self.d.delVar('PREMIRRORS')
1327 self.d.delVar('MIRRORS')
1328
1329 uri = 'git://%s;protocol=file;subdir=${S}' % self.srcdir
1330 self.d.setVar('SRC_URI', uri)
1331 self.d.setVar('SRCREV', '${AUTOREV}')
1332 self.d.setVar('AUTOREV', '${@bb.fetch2.get_autorev(d)}')
1333
1334 self.d.setVar('BB_GIT_SHALLOW', '1')
1335 self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '0')
1336 self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1')
1337
1338 def assertRefs(self, expected_refs, cwd=None):
1339 if cwd is None:
1340 cwd = self.gitdir
1341 actual_refs = self.git(['for-each-ref', '--format=%(refname)'], cwd=cwd).splitlines()
1342 full_expected = self.git(['rev-parse', '--symbolic-full-name'] + expected_refs, cwd=cwd).splitlines()
1343 self.assertEqual(sorted(set(full_expected)), sorted(set(actual_refs)))
1344
1345 def assertRevCount(self, expected_count, args=None, cwd=None):
1346 if args is None:
1347 args = ['HEAD']
1348 if cwd is None:
1349 cwd = self.gitdir
1350 revs = self.git(['rev-list'] + args, cwd=cwd)
1351 actual_count = len(revs.splitlines())
1352 self.assertEqual(expected_count, actual_count, msg='Object count `%d` is not the expected `%d`' % (actual_count, expected_count))
1353
1354 def git(self, cmd, cwd=None):
1355 if isinstance(cmd, str):
1356 cmd = 'git ' + cmd
1357 else:
1358 cmd = ['git'] + cmd
1359 if cwd is None:
1360 cwd = self.gitdir
1361 return bb.process.run(cmd, cwd=cwd)[0]
1362
1363 def add_empty_file(self, path, cwd=None, msg=None):
1364 if msg is None:
1365 msg = path
1366 if cwd is None:
1367 cwd = self.srcdir
1368 open(os.path.join(cwd, path), 'w').close()
1369 self.git(['add', path], cwd)
1370 self.git(['commit', '-m', msg, path], cwd)
1371
1372 def fetch(self, uri=None):
1373 if uri is None:
Brad Bishop19323692019-04-05 15:28:33 -04001374 uris = self.d.getVar('SRC_URI').split()
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001375 uri = uris[0]
1376 d = self.d
1377 else:
1378 d = self.d.createCopy()
1379 d.setVar('SRC_URI', uri)
1380 uri = d.expand(uri)
1381 uris = [uri]
1382
1383 fetcher = bb.fetch2.Fetch(uris, d)
1384 fetcher.download()
1385 ud = fetcher.ud[uri]
1386 return fetcher, ud
1387
1388 def fetch_and_unpack(self, uri=None):
1389 fetcher, ud = self.fetch(uri)
1390 fetcher.unpack(self.d.getVar('WORKDIR'))
1391 assert os.path.exists(self.d.getVar('S'))
1392 return fetcher, ud
1393
1394 def fetch_shallow(self, uri=None, disabled=False, keepclone=False):
1395 """Fetch a uri, generating a shallow tarball, then unpack using it"""
1396 fetcher, ud = self.fetch_and_unpack(uri)
1397 assert os.path.exists(ud.clonedir), 'Git clone in DLDIR (%s) does not exist for uri %s' % (ud.clonedir, uri)
1398
1399 # Confirm that the unpacked repo is unshallow
1400 if not disabled:
1401 assert os.path.exists(os.path.join(self.dldir, ud.mirrortarballs[0]))
1402
1403 # fetch and unpack, from the shallow tarball
1404 bb.utils.remove(self.gitdir, recurse=True)
1405 bb.utils.remove(ud.clonedir, recurse=True)
Brad Bishopf8caae32019-03-25 13:13:56 -04001406 bb.utils.remove(ud.clonedir.replace('gitsource', 'gitsubmodule'), recurse=True)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001407
1408 # confirm that the unpacked repo is used when no git clone or git
1409 # mirror tarball is available
1410 fetcher, ud = self.fetch_and_unpack(uri)
1411 if not disabled:
1412 assert os.path.exists(os.path.join(self.gitdir, '.git', 'shallow')), 'Unpacked git repository at %s is not shallow' % self.gitdir
1413 else:
1414 assert not os.path.exists(os.path.join(self.gitdir, '.git', 'shallow')), 'Unpacked git repository at %s is shallow' % self.gitdir
1415 return fetcher, ud
1416
1417 def test_shallow_disabled(self):
1418 self.add_empty_file('a')
1419 self.add_empty_file('b')
1420 self.assertRevCount(2, cwd=self.srcdir)
1421
1422 self.d.setVar('BB_GIT_SHALLOW', '0')
1423 self.fetch_shallow(disabled=True)
1424 self.assertRevCount(2)
1425
1426 def test_shallow_nobranch(self):
1427 self.add_empty_file('a')
1428 self.add_empty_file('b')
1429 self.assertRevCount(2, cwd=self.srcdir)
1430
1431 srcrev = self.git('rev-parse HEAD', cwd=self.srcdir).strip()
1432 self.d.setVar('SRCREV', srcrev)
Brad Bishop19323692019-04-05 15:28:33 -04001433 uri = self.d.getVar('SRC_URI').split()[0]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001434 uri = '%s;nobranch=1;bare=1' % uri
1435
1436 self.fetch_shallow(uri)
1437 self.assertRevCount(1)
1438
1439 # shallow refs are used to ensure the srcrev sticks around when we
1440 # have no other branches referencing it
1441 self.assertRefs(['refs/shallow/default'])
1442
1443 def test_shallow_default_depth_1(self):
1444 # Create initial git repo
1445 self.add_empty_file('a')
1446 self.add_empty_file('b')
1447 self.assertRevCount(2, cwd=self.srcdir)
1448
1449 self.fetch_shallow()
1450 self.assertRevCount(1)
1451
1452 def test_shallow_depth_0_disables(self):
1453 self.add_empty_file('a')
1454 self.add_empty_file('b')
1455 self.assertRevCount(2, cwd=self.srcdir)
1456
1457 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
1458 self.fetch_shallow(disabled=True)
1459 self.assertRevCount(2)
1460
1461 def test_shallow_depth_default_override(self):
1462 self.add_empty_file('a')
1463 self.add_empty_file('b')
1464 self.assertRevCount(2, cwd=self.srcdir)
1465
1466 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '2')
1467 self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '1')
1468 self.fetch_shallow()
1469 self.assertRevCount(1)
1470
1471 def test_shallow_depth_default_override_disable(self):
1472 self.add_empty_file('a')
1473 self.add_empty_file('b')
1474 self.add_empty_file('c')
1475 self.assertRevCount(3, cwd=self.srcdir)
1476
1477 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
1478 self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '2')
1479 self.fetch_shallow()
1480 self.assertRevCount(2)
1481
1482 def test_current_shallow_out_of_date_clone(self):
1483 # Create initial git repo
1484 self.add_empty_file('a')
1485 self.add_empty_file('b')
1486 self.add_empty_file('c')
1487 self.assertRevCount(3, cwd=self.srcdir)
1488
1489 # Clone and generate mirror tarball
1490 fetcher, ud = self.fetch()
1491
1492 # Ensure we have a current mirror tarball, but an out of date clone
1493 self.git('update-ref refs/heads/master refs/heads/master~1', cwd=ud.clonedir)
1494 self.assertRevCount(2, cwd=ud.clonedir)
1495
1496 # Fetch and unpack, from the current tarball, not the out of date clone
1497 bb.utils.remove(self.gitdir, recurse=True)
1498 fetcher, ud = self.fetch()
1499 fetcher.unpack(self.d.getVar('WORKDIR'))
1500 self.assertRevCount(1)
1501
1502 def test_shallow_single_branch_no_merge(self):
1503 self.add_empty_file('a')
1504 self.add_empty_file('b')
1505 self.assertRevCount(2, cwd=self.srcdir)
1506
1507 self.fetch_shallow()
1508 self.assertRevCount(1)
1509 assert os.path.exists(os.path.join(self.gitdir, 'a'))
1510 assert os.path.exists(os.path.join(self.gitdir, 'b'))
1511
1512 def test_shallow_no_dangling(self):
1513 self.add_empty_file('a')
1514 self.add_empty_file('b')
1515 self.assertRevCount(2, cwd=self.srcdir)
1516
1517 self.fetch_shallow()
1518 self.assertRevCount(1)
1519 assert not self.git('fsck --dangling')
1520
1521 def test_shallow_srcrev_branch_truncation(self):
1522 self.add_empty_file('a')
1523 self.add_empty_file('b')
1524 b_commit = self.git('rev-parse HEAD', cwd=self.srcdir).rstrip()
1525 self.add_empty_file('c')
1526 self.assertRevCount(3, cwd=self.srcdir)
1527
1528 self.d.setVar('SRCREV', b_commit)
1529 self.fetch_shallow()
1530
1531 # The 'c' commit was removed entirely, and 'a' was removed from history
1532 self.assertRevCount(1, ['--all'])
1533 self.assertEqual(self.git('rev-parse HEAD').strip(), b_commit)
1534 assert os.path.exists(os.path.join(self.gitdir, 'a'))
1535 assert os.path.exists(os.path.join(self.gitdir, 'b'))
1536 assert not os.path.exists(os.path.join(self.gitdir, 'c'))
1537
1538 def test_shallow_ref_pruning(self):
1539 self.add_empty_file('a')
1540 self.add_empty_file('b')
1541 self.git('branch a_branch', cwd=self.srcdir)
1542 self.assertRefs(['master', 'a_branch'], cwd=self.srcdir)
1543 self.assertRevCount(2, cwd=self.srcdir)
1544
1545 self.fetch_shallow()
1546
1547 self.assertRefs(['master', 'origin/master'])
1548 self.assertRevCount(1)
1549
1550 def test_shallow_submodules(self):
1551 self.add_empty_file('a')
1552 self.add_empty_file('b')
1553
1554 smdir = os.path.join(self.tempdir, 'gitsubmodule')
1555 bb.utils.mkdirhier(smdir)
1556 self.git('init', cwd=smdir)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001557 # Make this look like it was cloned from a remote...
1558 self.git('config --add remote.origin.url "%s"' % smdir, cwd=smdir)
1559 self.git('config --add remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"', cwd=smdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001560 self.add_empty_file('asub', cwd=smdir)
Brad Bishopf8caae32019-03-25 13:13:56 -04001561 self.add_empty_file('bsub', cwd=smdir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001562
1563 self.git('submodule init', cwd=self.srcdir)
1564 self.git('submodule add file://%s' % smdir, cwd=self.srcdir)
1565 self.git('submodule update', cwd=self.srcdir)
1566 self.git('commit -m submodule -a', cwd=self.srcdir)
1567
1568 uri = 'gitsm://%s;protocol=file;subdir=${S}' % self.srcdir
1569 fetcher, ud = self.fetch_shallow(uri)
1570
Brad Bishopf8caae32019-03-25 13:13:56 -04001571 # Verify the main repository is shallow
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001572 self.assertRevCount(1)
Brad Bishopf8caae32019-03-25 13:13:56 -04001573
1574 # Verify the gitsubmodule directory is present
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001575 assert os.listdir(os.path.join(self.gitdir, 'gitsubmodule'))
1576
Brad Bishopf8caae32019-03-25 13:13:56 -04001577 # Verify the submodule is also shallow
1578 self.assertRevCount(1, cwd=os.path.join(self.gitdir, 'gitsubmodule'))
1579
1580
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001581 if any(os.path.exists(os.path.join(p, 'git-annex')) for p in os.environ.get('PATH').split(':')):
1582 def test_shallow_annex(self):
1583 self.add_empty_file('a')
1584 self.add_empty_file('b')
1585 self.git('annex init', cwd=self.srcdir)
1586 open(os.path.join(self.srcdir, 'c'), 'w').close()
1587 self.git('annex add c', cwd=self.srcdir)
1588 self.git('commit -m annex-c -a', cwd=self.srcdir)
1589 bb.process.run('chmod u+w -R %s' % os.path.join(self.srcdir, '.git', 'annex'))
1590
1591 uri = 'gitannex://%s;protocol=file;subdir=${S}' % self.srcdir
1592 fetcher, ud = self.fetch_shallow(uri)
1593
1594 self.assertRevCount(1)
1595 assert './.git/annex/' in bb.process.run('tar -tzf %s' % os.path.join(self.dldir, ud.mirrortarballs[0]))[0]
1596 assert os.path.exists(os.path.join(self.gitdir, 'c'))
1597
1598 def test_shallow_multi_one_uri(self):
1599 # Create initial git repo
1600 self.add_empty_file('a')
1601 self.add_empty_file('b')
1602 self.git('checkout -b a_branch', cwd=self.srcdir)
1603 self.add_empty_file('c')
1604 self.add_empty_file('d')
1605 self.git('checkout master', cwd=self.srcdir)
1606 self.git('tag v0.0 a_branch', cwd=self.srcdir)
1607 self.add_empty_file('e')
1608 self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir)
1609 self.add_empty_file('f')
1610 self.assertRevCount(7, cwd=self.srcdir)
1611
Brad Bishop19323692019-04-05 15:28:33 -04001612 uri = self.d.getVar('SRC_URI').split()[0]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001613 uri = '%s;branch=master,a_branch;name=master,a_branch' % uri
1614
1615 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
1616 self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
1617 self.d.setVar('SRCREV_master', '${AUTOREV}')
1618 self.d.setVar('SRCREV_a_branch', '${AUTOREV}')
1619
1620 self.fetch_shallow(uri)
1621
1622 self.assertRevCount(5)
1623 self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
1624
1625 def test_shallow_multi_one_uri_depths(self):
1626 # Create initial git repo
1627 self.add_empty_file('a')
1628 self.add_empty_file('b')
1629 self.git('checkout -b a_branch', cwd=self.srcdir)
1630 self.add_empty_file('c')
1631 self.add_empty_file('d')
1632 self.git('checkout master', cwd=self.srcdir)
1633 self.add_empty_file('e')
1634 self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir)
1635 self.add_empty_file('f')
1636 self.assertRevCount(7, cwd=self.srcdir)
1637
Brad Bishop19323692019-04-05 15:28:33 -04001638 uri = self.d.getVar('SRC_URI').split()[0]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001639 uri = '%s;branch=master,a_branch;name=master,a_branch' % uri
1640
1641 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
1642 self.d.setVar('BB_GIT_SHALLOW_DEPTH_master', '3')
1643 self.d.setVar('BB_GIT_SHALLOW_DEPTH_a_branch', '1')
1644 self.d.setVar('SRCREV_master', '${AUTOREV}')
1645 self.d.setVar('SRCREV_a_branch', '${AUTOREV}')
1646
1647 self.fetch_shallow(uri)
1648
1649 self.assertRevCount(4, ['--all'])
1650 self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
1651
1652 def test_shallow_clone_preferred_over_shallow(self):
1653 self.add_empty_file('a')
1654 self.add_empty_file('b')
1655
1656 # Fetch once to generate the shallow tarball
1657 fetcher, ud = self.fetch()
1658 assert os.path.exists(os.path.join(self.dldir, ud.mirrortarballs[0]))
1659
1660 # Fetch and unpack with both the clonedir and shallow tarball available
1661 bb.utils.remove(self.gitdir, recurse=True)
1662 fetcher, ud = self.fetch_and_unpack()
1663
1664 # The unpacked tree should *not* be shallow
1665 self.assertRevCount(2)
1666 assert not os.path.exists(os.path.join(self.gitdir, '.git', 'shallow'))
1667
1668 def test_shallow_mirrors(self):
1669 self.add_empty_file('a')
1670 self.add_empty_file('b')
1671
1672 # Fetch once to generate the shallow tarball
1673 fetcher, ud = self.fetch()
1674 mirrortarball = ud.mirrortarballs[0]
1675 assert os.path.exists(os.path.join(self.dldir, mirrortarball))
1676
1677 # Set up the mirror
1678 mirrordir = os.path.join(self.tempdir, 'mirror')
1679 bb.utils.mkdirhier(mirrordir)
1680 self.d.setVar('PREMIRRORS', 'git://.*/.* file://%s/\n' % mirrordir)
1681
1682 os.rename(os.path.join(self.dldir, mirrortarball),
1683 os.path.join(mirrordir, mirrortarball))
1684
1685 # Fetch from the mirror
1686 bb.utils.remove(self.dldir, recurse=True)
1687 bb.utils.remove(self.gitdir, recurse=True)
1688 self.fetch_and_unpack()
1689 self.assertRevCount(1)
1690
1691 def test_shallow_invalid_depth(self):
1692 self.add_empty_file('a')
1693 self.add_empty_file('b')
1694
1695 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '-12')
1696 with self.assertRaises(bb.fetch2.FetchError):
1697 self.fetch()
1698
1699 def test_shallow_invalid_depth_default(self):
1700 self.add_empty_file('a')
1701 self.add_empty_file('b')
1702
1703 self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '-12')
1704 with self.assertRaises(bb.fetch2.FetchError):
1705 self.fetch()
1706
1707 def test_shallow_extra_refs(self):
1708 self.add_empty_file('a')
1709 self.add_empty_file('b')
1710 self.git('branch a_branch', cwd=self.srcdir)
1711 self.assertRefs(['master', 'a_branch'], cwd=self.srcdir)
1712 self.assertRevCount(2, cwd=self.srcdir)
1713
1714 self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/heads/a_branch')
1715 self.fetch_shallow()
1716
1717 self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
1718 self.assertRevCount(1)
1719
1720 def test_shallow_extra_refs_wildcard(self):
1721 self.add_empty_file('a')
1722 self.add_empty_file('b')
1723 self.git('branch a_branch', cwd=self.srcdir)
1724 self.git('tag v1.0', cwd=self.srcdir)
1725 self.assertRefs(['master', 'a_branch', 'v1.0'], cwd=self.srcdir)
1726 self.assertRevCount(2, cwd=self.srcdir)
1727
1728 self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/tags/*')
1729 self.fetch_shallow()
1730
1731 self.assertRefs(['master', 'origin/master', 'v1.0'])
1732 self.assertRevCount(1)
1733
1734 def test_shallow_missing_extra_refs(self):
1735 self.add_empty_file('a')
1736 self.add_empty_file('b')
1737
1738 self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/heads/foo')
1739 with self.assertRaises(bb.fetch2.FetchError):
1740 self.fetch()
1741
1742 def test_shallow_missing_extra_refs_wildcard(self):
1743 self.add_empty_file('a')
1744 self.add_empty_file('b')
1745
1746 self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/tags/*')
1747 self.fetch()
1748
1749 def test_shallow_remove_revs(self):
1750 # Create initial git repo
1751 self.add_empty_file('a')
1752 self.add_empty_file('b')
1753 self.git('checkout -b a_branch', cwd=self.srcdir)
1754 self.add_empty_file('c')
1755 self.add_empty_file('d')
1756 self.git('checkout master', cwd=self.srcdir)
1757 self.git('tag v0.0 a_branch', cwd=self.srcdir)
1758 self.add_empty_file('e')
1759 self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir)
1760 self.git('branch -d a_branch', cwd=self.srcdir)
1761 self.add_empty_file('f')
1762 self.assertRevCount(7, cwd=self.srcdir)
1763
1764 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
1765 self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
1766
1767 self.fetch_shallow()
1768
1769 self.assertRevCount(5)
1770
1771 def test_shallow_invalid_revs(self):
1772 self.add_empty_file('a')
1773 self.add_empty_file('b')
1774
1775 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
1776 self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
1777
1778 with self.assertRaises(bb.fetch2.FetchError):
1779 self.fetch()
1780
1781 @skipIfNoNetwork()
1782 def test_bitbake(self):
1783 self.git('remote add --mirror=fetch origin git://github.com/openembedded/bitbake', cwd=self.srcdir)
1784 self.git('config core.bare true', cwd=self.srcdir)
1785 self.git('fetch', cwd=self.srcdir)
1786
1787 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
1788 # Note that the 1.10.0 tag is annotated, so this also tests
1789 # reference of an annotated vs unannotated tag
1790 self.d.setVar('BB_GIT_SHALLOW_REVS', '1.10.0')
1791
1792 self.fetch_shallow()
1793
1794 # Confirm that the history of 1.10.0 was removed
1795 orig_revs = len(self.git('rev-list master', cwd=self.srcdir).splitlines())
1796 revs = len(self.git('rev-list master').splitlines())
1797 self.assertNotEqual(orig_revs, revs)
1798 self.assertRefs(['master', 'origin/master'])
1799 self.assertRevCount(orig_revs - 1758)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001800
1801 def test_that_unpack_throws_an_error_when_the_git_clone_nor_shallow_tarball_exist(self):
1802 self.add_empty_file('a')
1803 fetcher, ud = self.fetch()
1804 bb.utils.remove(self.gitdir, recurse=True)
1805 bb.utils.remove(self.dldir, recurse=True)
1806
1807 with self.assertRaises(bb.fetch2.UnpackError) as context:
1808 fetcher.unpack(self.d.getVar('WORKDIR'))
1809
1810 self.assertIn("No up to date source found", context.exception.msg)
1811 self.assertIn("clone directory not available or not up to date", context.exception.msg)
1812
1813 @skipIfNoNetwork()
1814 def test_that_unpack_does_work_when_using_git_shallow_tarball_but_tarball_is_not_available(self):
1815 self.d.setVar('SRCREV', 'e5939ff608b95cdd4d0ab0e1935781ab9a276ac0')
1816 self.d.setVar('BB_GIT_SHALLOW', '1')
1817 self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1')
1818 fetcher = bb.fetch.Fetch(["git://git.yoctoproject.org/fstests"], self.d)
1819 fetcher.download()
1820
1821 bb.utils.remove(self.dldir + "/*.tar.gz")
1822 fetcher.unpack(self.unpackdir)
1823
1824 dir = os.listdir(self.unpackdir + "/git/")
1825 self.assertIn("fstests.doap", dir)