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