summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/tests/fetch.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/tests/fetch.py')
-rw-r--r--bitbake/lib/bb/tests/fetch.py1098
1 files changed, 732 insertions, 366 deletions
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index ed7a39a723..077472b8b3 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -7,7 +7,10 @@
7# 7#
8 8
9import contextlib 9import contextlib
10import shutil
10import unittest 11import unittest
12import unittest.mock
13import urllib.parse
11import hashlib 14import hashlib
12import tempfile 15import tempfile
13import collections 16import collections
@@ -17,6 +20,7 @@ import tarfile
17from bb.fetch2 import URI 20from bb.fetch2 import URI
18from bb.fetch2 import FetchMethod 21from bb.fetch2 import FetchMethod
19import bb 22import bb
23import bb.utils
20from bb.tests.support.httpserver import HTTPService 24from bb.tests.support.httpserver import HTTPService
21 25
22def skipIfNoNetwork(): 26def skipIfNoNetwork():
@@ -24,6 +28,18 @@ def skipIfNoNetwork():
24 return unittest.skip("network test") 28 return unittest.skip("network test")
25 return lambda f: f 29 return lambda f: f
26 30
31
32@contextlib.contextmanager
33def hide_directory(directory):
34 """Hide the given directory and restore it after the context is left"""
35 temp_name = directory + ".bak"
36 os.rename(directory, temp_name)
37 try:
38 yield
39 finally:
40 os.rename(temp_name, directory)
41
42
27class TestTimeout(Exception): 43class TestTimeout(Exception):
28 # Indicate to pytest that this is not a test suite 44 # Indicate to pytest that this is not a test suite
29 __test__ = False 45 __test__ = False
@@ -323,6 +339,21 @@ class URITest(unittest.TestCase):
323 'params': {"downloadfilename" : "EGPL-T101.zip"}, 339 'params': {"downloadfilename" : "EGPL-T101.zip"},
324 'query': {"9BE0BF6657": None}, 340 'query': {"9BE0BF6657": None},
325 'relative': False 341 'relative': False
342 },
343 "file://example@.service": {
344 'uri': 'file:example%40.service',
345 'scheme': 'file',
346 'hostname': '',
347 'port': None,
348 'hostport': '',
349 'path': 'example@.service',
350 'userinfo': '',
351 'userinfo': '',
352 'username': '',
353 'password': '',
354 'params': {},
355 'query': {},
356 'relative': True
326 } 357 }
327 358
328 } 359 }
@@ -459,16 +490,16 @@ class FetcherTest(unittest.TestCase):
459class MirrorUriTest(FetcherTest): 490class MirrorUriTest(FetcherTest):
460 491
461 replaceuris = { 492 replaceuris = {
462 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "http://somewhere.org/somedir/") 493 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master", "git://.*/.*", "http://somewhere.org/somedir/")
463 : "http://somewhere.org/somedir/git2_git.invalid.infradead.org.mtd-utils.git.tar.gz", 494 : "http://somewhere.org/somedir/git2_git.invalid.infradead.org.mtd-utils.git.tar.gz",
464 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http") 495 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http")
465 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http", 496 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master;protocol=http",
466 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http") 497 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http")
467 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http", 498 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master;protocol=http",
468 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/\\2;protocol=http") 499 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/\\2;protocol=http")
469 : "git://somewhere.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http", 500 : "git://somewhere.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master;protocol=http",
470 ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890", "git://someserver.org/bitbake", "git://git.openembedded.org/bitbake") 501 ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master", "git://someserver.org/bitbake", "git://git.openembedded.org/bitbake")
471 : "git://git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890", 502 : "git://git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master",
472 ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache") 503 ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache")
473 : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz", 504 : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
474 ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache/") 505 ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache/")
@@ -481,12 +512,12 @@ class MirrorUriTest(FetcherTest):
481 : "http://archive.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", 512 : "http://archive.apache.org/dist/subversion/subversion-1.7.1.tar.bz2",
482 ("http://www.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", "http://.*/.*", "file:///somepath/downloads/") 513 ("http://www.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", "http://.*/.*", "file:///somepath/downloads/")
483 : "file:///somepath/downloads/subversion-1.7.1.tar.bz2", 514 : "file:///somepath/downloads/subversion-1.7.1.tar.bz2",
484 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http") 515 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http")
485 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http", 516 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master;protocol=http",
486 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http") 517 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http")
487 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http", 518 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master;protocol=http",
488 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/MIRRORNAME;protocol=http") 519 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master", "git://.*/.*", "git://somewhere.org/somedir/MIRRORNAME;protocol=http")
489 : "git://somewhere.org/somedir/git.invalid.infradead.org.foo.mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http", 520 : "git://somewhere.org/somedir/git.invalid.infradead.org.foo.mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master;protocol=http",
490 ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org") 521 ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org")
491 : "http://somewhere2.org/somefile_1.2.3.tar.gz", 522 : "http://somewhere2.org/somefile_1.2.3.tar.gz",
492 ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org/") 523 ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org/")
@@ -502,6 +533,10 @@ class MirrorUriTest(FetcherTest):
502 : "file:///mirror/example/1.0.0/some-example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz", 533 : "file:///mirror/example/1.0.0/some-example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz",
503 ("https://somewhere.org/example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz", "https://.*/.*", "file:///mirror/some-example-1.0.0.tgz") 534 ("https://somewhere.org/example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz", "https://.*/.*", "file:///mirror/some-example-1.0.0.tgz")
504 : "file:///mirror/some-example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz", 535 : "file:///mirror/some-example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz",
536 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master", r"git://(?!internal\.git\.server).*/.*", "http://somewhere.org/somedir/")
537 : "http://somewhere.org/somedir/git2_git.invalid.infradead.org.mtd-utils.git.tar.gz",
538 ("git://internal.git.server.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;branch=master", r"git://(?!internal\.git\.server).*/.*", "http://somewhere.org/somedir/")
539 : None,
505 540
506 #Renaming files doesn't work 541 #Renaming files doesn't work
507 #("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" 542 #("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"
@@ -510,8 +545,7 @@ class MirrorUriTest(FetcherTest):
510 545
511 mirrorvar = "http://.*/.* file:///somepath/downloads/ " \ 546 mirrorvar = "http://.*/.* file:///somepath/downloads/ " \
512 "git://someserver.org/bitbake git://git.openembedded.org/bitbake " \ 547 "git://someserver.org/bitbake git://git.openembedded.org/bitbake " \
513 "https://.*/.* file:///someotherpath/downloads/ " \ 548 "https?://.*/.* file:///someotherpath/downloads/ " \
514 "http://.*/.* file:///someotherpath/downloads/ " \
515 "svn://svn.server1.com/ svn://svn.server2.com/" 549 "svn://svn.server1.com/ svn://svn.server2.com/"
516 550
517 def test_urireplace(self): 551 def test_urireplace(self):
@@ -521,7 +555,7 @@ class MirrorUriTest(FetcherTest):
521 ud.setup_localpath(self.d) 555 ud.setup_localpath(self.d)
522 mirrors = bb.fetch2.mirror_from_string("%s %s" % (k[1], k[2])) 556 mirrors = bb.fetch2.mirror_from_string("%s %s" % (k[1], k[2]))
523 newuris, uds = bb.fetch2.build_mirroruris(ud, mirrors, self.d) 557 newuris, uds = bb.fetch2.build_mirroruris(ud, mirrors, self.d)
524 self.assertEqual([v], newuris) 558 self.assertEqual([v] if v else [], newuris)
525 559
526 def test_urilist1(self): 560 def test_urilist1(self):
527 fetcher = bb.fetch.FetchData("http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d) 561 fetcher = bb.fetch.FetchData("http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
@@ -555,16 +589,16 @@ class MirrorUriTest(FetcherTest):
555 'http://otherdownloads.yoctoproject.org/downloads/bitbake-1.0.tar.gz', 589 'http://otherdownloads.yoctoproject.org/downloads/bitbake-1.0.tar.gz',
556 'http://downloads2.yoctoproject.org/downloads/bitbake-1.0.tar.gz']) 590 'http://downloads2.yoctoproject.org/downloads/bitbake-1.0.tar.gz'])
557 591
558 recmirrorvar = "https://.*/[^/]* http://AAAA/A/A/A/ " \ 592 recmirrorvar = "https://.*/[^/]* http://aaaa/A/A/A/ " \
559 "https://.*/[^/]* https://BBBB/B/B/B/" 593 "https://.*/[^/]* https://bbbb/B/B/B/"
560 594
561 def test_recursive(self): 595 def test_recursive(self):
562 fetcher = bb.fetch.FetchData("https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d) 596 fetcher = bb.fetch.FetchData("https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
563 mirrors = bb.fetch2.mirror_from_string(self.recmirrorvar) 597 mirrors = bb.fetch2.mirror_from_string(self.recmirrorvar)
564 uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d) 598 uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
565 self.assertEqual(uris, ['http://AAAA/A/A/A/bitbake/bitbake-1.0.tar.gz', 599 self.assertEqual(uris, ['http://aaaa/A/A/A/bitbake/bitbake-1.0.tar.gz',
566 'https://BBBB/B/B/B/bitbake/bitbake-1.0.tar.gz', 600 'https://bbbb/B/B/B/bitbake/bitbake-1.0.tar.gz',
567 'http://AAAA/A/A/A/B/B/bitbake/bitbake-1.0.tar.gz']) 601 'http://aaaa/A/A/A/B/B/bitbake/bitbake-1.0.tar.gz'])
568 602
569 603
570class GitDownloadDirectoryNamingTest(FetcherTest): 604class GitDownloadDirectoryNamingTest(FetcherTest):
@@ -687,7 +721,7 @@ class GitShallowTarballNamingTest(FetcherTest):
687class CleanTarballTest(FetcherTest): 721class CleanTarballTest(FetcherTest):
688 def setUp(self): 722 def setUp(self):
689 super(CleanTarballTest, self).setUp() 723 super(CleanTarballTest, self).setUp()
690 self.recipe_url = "git://git.openembedded.org/bitbake;protocol=https" 724 self.recipe_url = "git://git.openembedded.org/bitbake;protocol=https;branch=master"
691 self.recipe_tarball = "git2_git.openembedded.org.bitbake.tar.gz" 725 self.recipe_tarball = "git2_git.openembedded.org.bitbake.tar.gz"
692 726
693 self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '1') 727 self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '1')
@@ -728,6 +762,7 @@ class FetcherLocalTest(FetcherTest):
728 os.makedirs(self.localsrcdir) 762 os.makedirs(self.localsrcdir)
729 touch(os.path.join(self.localsrcdir, 'a')) 763 touch(os.path.join(self.localsrcdir, 'a'))
730 touch(os.path.join(self.localsrcdir, 'b')) 764 touch(os.path.join(self.localsrcdir, 'b'))
765 touch(os.path.join(self.localsrcdir, 'c@d'))
731 os.makedirs(os.path.join(self.localsrcdir, 'dir')) 766 os.makedirs(os.path.join(self.localsrcdir, 'dir'))
732 touch(os.path.join(self.localsrcdir, 'dir', 'c')) 767 touch(os.path.join(self.localsrcdir, 'dir', 'c'))
733 touch(os.path.join(self.localsrcdir, 'dir', 'd')) 768 touch(os.path.join(self.localsrcdir, 'dir', 'd'))
@@ -759,6 +794,10 @@ class FetcherLocalTest(FetcherTest):
759 tree = self.fetchUnpack(['file://a', 'file://dir/c']) 794 tree = self.fetchUnpack(['file://a', 'file://dir/c'])
760 self.assertEqual(tree, ['a', 'dir/c']) 795 self.assertEqual(tree, ['a', 'dir/c'])
761 796
797 def test_local_at(self):
798 tree = self.fetchUnpack(['file://c@d'])
799 self.assertEqual(tree, ['c@d'])
800
762 def test_local_backslash(self): 801 def test_local_backslash(self):
763 tree = self.fetchUnpack([r'file://backslash\x2dsystemd-unit.device']) 802 tree = self.fetchUnpack([r'file://backslash\x2dsystemd-unit.device'])
764 self.assertEqual(tree, [r'backslash\x2dsystemd-unit.device']) 803 self.assertEqual(tree, [r'backslash\x2dsystemd-unit.device'])
@@ -1064,12 +1103,6 @@ class FetcherNetworkTest(FetcherTest):
1064 self.assertRaises(bb.fetch.FetchError, self.gitfetcher, url1, url2) 1103 self.assertRaises(bb.fetch.FetchError, self.gitfetcher, url1, url2)
1065 1104
1066 @skipIfNoNetwork() 1105 @skipIfNoNetwork()
1067 def test_gitfetch_tagandrev(self):
1068 # SRCREV is set but does not match rev= parameter
1069 url1 = url2 = "git://git.openembedded.org/bitbake;rev=270a05b0b4ba0959fe0624d2a4885d7b70426da5;tag=270a05b0b4ba0959fe0624d2a4885d7b70426da5;protocol=https"
1070 self.assertRaises(bb.fetch.FetchError, self.gitfetcher, url1, url2)
1071
1072 @skipIfNoNetwork()
1073 def test_gitfetch_usehead(self): 1106 def test_gitfetch_usehead(self):
1074 # Since self.gitfetcher() sets SRCREV we expect this to override 1107 # Since self.gitfetcher() sets SRCREV we expect this to override
1075 # `usehead=1' and instead fetch the specified SRCREV. See 1108 # `usehead=1' and instead fetch the specified SRCREV. See
@@ -1103,7 +1136,7 @@ class FetcherNetworkTest(FetcherTest):
1103 @skipIfNoNetwork() 1136 @skipIfNoNetwork()
1104 def test_gitfetch_finds_local_repository_when_premirror_rewrites_the_recipe_url(self): 1137 def test_gitfetch_finds_local_repository_when_premirror_rewrites_the_recipe_url(self):
1105 realurl = "https://git.openembedded.org/bitbake" 1138 realurl = "https://git.openembedded.org/bitbake"
1106 recipeurl = "git://someserver.org/bitbake;protocol=https" 1139 recipeurl = "git://someserver.org/bitbake;protocol=https;branch=master"
1107 self.sourcedir = self.unpackdir.replace("unpacked", "sourcemirror.git") 1140 self.sourcedir = self.unpackdir.replace("unpacked", "sourcemirror.git")
1108 os.chdir(self.tempdir) 1141 os.chdir(self.tempdir)
1109 self.git(['clone', realurl, self.sourcedir], cwd=self.tempdir) 1142 self.git(['clone', realurl, self.sourcedir], cwd=self.tempdir)
@@ -1258,7 +1291,6 @@ class FetcherNetworkTest(FetcherTest):
1258 1291
1259class SVNTest(FetcherTest): 1292class SVNTest(FetcherTest):
1260 def skipIfNoSvn(): 1293 def skipIfNoSvn():
1261 import shutil
1262 if not shutil.which("svn"): 1294 if not shutil.which("svn"):
1263 return unittest.skip("svn not installed, tests being skipped") 1295 return unittest.skip("svn not installed, tests being skipped")
1264 1296
@@ -1381,15 +1413,17 @@ class TrustedNetworksTest(FetcherTest):
1381 self.assertFalse(bb.fetch.trusted_network(self.d, url)) 1413 self.assertFalse(bb.fetch.trusted_network(self.d, url))
1382 1414
1383class URLHandle(unittest.TestCase): 1415class URLHandle(unittest.TestCase):
1384 1416 # Quote password as per RFC3986
1417 password = urllib.parse.quote(r"!#$%^&*()-_={}[]\|:?,.<>~`", r"!$&'/()*+,;=")
1385 datatable = { 1418 datatable = {
1386 "http://www.google.com/index.html" : ('http', 'www.google.com', '/index.html', '', '', {}), 1419 "http://www.google.com/index.html" : ('http', 'www.google.com', '/index.html', '', '', {}),
1387 "cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg" : ('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', '', {'module': 'familiar/dist/ipkg'}), 1420 "cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg" : ('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', '', {'module': 'familiar/dist/ipkg'}),
1388 "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')])), 1421 "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')])),
1389 "git://git.openembedded.org/bitbake;branch=@foo;protocol=https" : ('git', 'git.openembedded.org', '/bitbake', '', '', {'branch': '@foo', 'protocol' : 'https'}), 1422 "git://git.openembedded.org/bitbake;branch=@foo;protocol=https" : ('git', 'git.openembedded.org', '/bitbake', '', '', {'branch': '@foo', 'protocol' : 'https'}),
1390 "file://somelocation;someparam=1": ('file', '', 'somelocation', '', '', {'someparam': '1'}), 1423 "file://somelocation;someparam=1": ('file', '', 'somelocation', '', '', {'someparam': '1'}),
1424 "file://example@.service": ('file', '', 'example@.service', '', '', {}),
1391 "https://somesite.com/somerepo.git;user=anyUser:idtoken=1234" : ('https', 'somesite.com', '/somerepo.git', '', '', {'user': 'anyUser:idtoken=1234'}), 1425 "https://somesite.com/somerepo.git;user=anyUser:idtoken=1234" : ('https', 'somesite.com', '/somerepo.git', '', '', {'user': 'anyUser:idtoken=1234'}),
1392 r'git://s.o-me_ONE:!#$%^&*()-_={}[]\|:?,.<>~`@git.openembedded.org/bitbake;branch=main;protocol=https': ('git', 'git.openembedded.org', '/bitbake', 's.o-me_ONE', r'!#$%^&*()-_={}[]\|:?,.<>~`', {'branch': 'main', 'protocol' : 'https'}), 1426 'git://s.o-me_ONE:%s@git.openembedded.org/bitbake;branch=main;protocol=https' % password: ('git', 'git.openembedded.org', '/bitbake', 's.o-me_ONE', password, {'branch': 'main', 'protocol' : 'https'}),
1393 } 1427 }
1394 # we require a pathname to encodeurl but users can still pass such urls to 1428 # we require a pathname to encodeurl but users can still pass such urls to
1395 # decodeurl and we need to handle them 1429 # decodeurl and we need to handle them
@@ -1407,6 +1441,8 @@ class URLHandle(unittest.TestCase):
1407 def test_encodeurl(self): 1441 def test_encodeurl(self):
1408 for k, v in self.datatable.items(): 1442 for k, v in self.datatable.items():
1409 result = bb.fetch.encodeurl(v) 1443 result = bb.fetch.encodeurl(v)
1444 if result.startswith("file:"):
1445 result = urllib.parse.unquote(result)
1410 self.assertEqual(result, k) 1446 self.assertEqual(result, k)
1411 1447
1412class FetchLatestVersionTest(FetcherTest): 1448class FetchLatestVersionTest(FetcherTest):
@@ -1427,12 +1463,12 @@ class FetchLatestVersionTest(FetcherTest):
1427 ("dtc", "git://git.yoctoproject.org/bbfetchtests-dtc.git;branch=master;protocol=https", "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf", "", "") 1463 ("dtc", "git://git.yoctoproject.org/bbfetchtests-dtc.git;branch=master;protocol=https", "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf", "", "")
1428 : "1.4.0", 1464 : "1.4.0",
1429 # combination version pattern 1465 # combination version pattern
1430 ("sysprof", "git://gitlab.gnome.org/GNOME/sysprof.git;protocol=https;branch=master", "cd44ee6644c3641507fb53b8a2a69137f2971219", "", "") 1466 ("sysprof", "git://git.yoctoproject.org/sysprof.git;protocol=https;branch=master", "cd44ee6644c3641507fb53b8a2a69137f2971219", "", "")
1431 : "1.2.0", 1467 : "1.2.0",
1432 ("u-boot-mkimage", "git://git.denx.de/u-boot.git;branch=master;protocol=git", "62c175fbb8a0f9a926c88294ea9f7e88eb898f6c", "", "") 1468 ("u-boot-mkimage", "git://source.denx.de/u-boot/u-boot.git;branch=master;protocol=https", "62c175fbb8a0f9a926c88294ea9f7e88eb898f6c", "", "")
1433 : "2014.01", 1469 : "2014.01",
1434 # version pattern "yyyymmdd" 1470 # version pattern "yyyymmdd"
1435 ("mobile-broadband-provider-info", "git://gitlab.gnome.org/GNOME/mobile-broadband-provider-info.git;protocol=https;branch=master", "4ed19e11c2975105b71b956440acdb25d46a347d", "", "") 1471 ("mobile-broadband-provider-info", "git://git.yoctoproject.org/mobile-broadband-provider-info.git;protocol=https;branch=master", "4ed19e11c2975105b71b956440acdb25d46a347d", "", "")
1436 : "20120614", 1472 : "20120614",
1437 # packages with a valid UPSTREAM_CHECK_GITTAGREGEX 1473 # packages with a valid UPSTREAM_CHECK_GITTAGREGEX
1438 # mirror of git://anongit.freedesktop.org/xorg/driver/xf86-video-omap since network issues interfered with testing 1474 # mirror of git://anongit.freedesktop.org/xorg/driver/xf86-video-omap since network issues interfered with testing
@@ -1448,57 +1484,64 @@ class FetchLatestVersionTest(FetcherTest):
1448 : "0.28.0", 1484 : "0.28.0",
1449 } 1485 }
1450 1486
1487 WgetTestData = collections.namedtuple("WgetTestData", ["pn", "path", "pv", "check_uri", "check_regex"], defaults=[None, None, None])
1451 test_wget_uris = { 1488 test_wget_uris = {
1452 # 1489 #
1453 # packages with versions inside directory name 1490 # packages with versions inside directory name
1454 # 1491 #
1455 # http://kernel.org/pub/linux/utils/util-linux/v2.23/util-linux-2.24.2.tar.bz2 1492 # http://kernel.org/pub/linux/utils/util-linux/v2.23/util-linux-2.24.2.tar.bz2
1456 ("util-linux", "/pub/linux/utils/util-linux/v2.23/util-linux-2.24.2.tar.bz2", "", "") 1493 WgetTestData("util-linux", "/pub/linux/utils/util-linux/v2.23/util-linux-2.24.2.tar.bz2")
1457 : "2.24.2", 1494 : "2.24.2",
1458 # http://www.abisource.com/downloads/enchant/1.6.0/enchant-1.6.0.tar.gz 1495 # http://www.abisource.com/downloads/enchant/1.6.0/enchant-1.6.0.tar.gz
1459 ("enchant", "/downloads/enchant/1.6.0/enchant-1.6.0.tar.gz", "", "") 1496 WgetTestData("enchant", "/downloads/enchant/1.6.0/enchant-1.6.0.tar.gz")
1460 : "1.6.0", 1497 : "1.6.0",
1461 # http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz 1498 # http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz
1462 ("cmake", "/files/v2.8/cmake-2.8.12.1.tar.gz", "", "") 1499 WgetTestData("cmake", "/files/v2.8/cmake-2.8.12.1.tar.gz")
1463 : "2.8.12.1", 1500 : "2.8.12.1",
1464 # https://download.gnome.org/sources/libxml2/2.9/libxml2-2.9.14.tar.xz 1501 # https://download.gnome.org/sources/libxml2/2.9/libxml2-2.9.14.tar.xz
1465 ("libxml2", "/software/libxml2/2.9/libxml2-2.9.14.tar.xz", "", "") 1502 WgetTestData("libxml2", "/software/libxml2/2.9/libxml2-2.9.14.tar.xz")
1466 : "2.10.3", 1503 : "2.10.3",
1467 # 1504 #
1468 # packages with versions only in current directory 1505 # packages with versions only in current directory
1469 # 1506 #
1470 # https://downloads.yoctoproject.org/releases/eglibc/eglibc-2.18-svnr23787.tar.bz2 1507 # https://downloads.yoctoproject.org/releases/eglibc/eglibc-2.18-svnr23787.tar.bz2
1471 ("eglic", "/releases/eglibc/eglibc-2.18-svnr23787.tar.bz2", "", "") 1508 WgetTestData("eglic", "/releases/eglibc/eglibc-2.18-svnr23787.tar.bz2")
1472 : "2.19", 1509 : "2.19",
1473 # https://downloads.yoctoproject.org/releases/gnu-config/gnu-config-20120814.tar.bz2 1510 # https://downloads.yoctoproject.org/releases/gnu-config/gnu-config-20120814.tar.bz2
1474 ("gnu-config", "/releases/gnu-config/gnu-config-20120814.tar.bz2", "", "") 1511 WgetTestData("gnu-config", "/releases/gnu-config/gnu-config-20120814.tar.bz2")
1475 : "20120814", 1512 : "20120814",
1476 # 1513 #
1477 # packages with "99" in the name of possible version 1514 # packages with "99" in the name of possible version
1478 # 1515 #
1479 # http://freedesktop.org/software/pulseaudio/releases/pulseaudio-4.0.tar.xz 1516 # http://freedesktop.org/software/pulseaudio/releases/pulseaudio-4.0.tar.xz
1480 ("pulseaudio", "/software/pulseaudio/releases/pulseaudio-4.0.tar.xz", "", "") 1517 WgetTestData("pulseaudio", "/software/pulseaudio/releases/pulseaudio-4.0.tar.xz")
1481 : "5.0", 1518 : "5.0",
1482 # http://xorg.freedesktop.org/releases/individual/xserver/xorg-server-1.15.1.tar.bz2 1519 # http://xorg.freedesktop.org/releases/individual/xserver/xorg-server-1.15.1.tar.bz2
1483 ("xserver-xorg", "/releases/individual/xserver/xorg-server-1.15.1.tar.bz2", "", "") 1520 WgetTestData("xserver-xorg", "/releases/individual/xserver/xorg-server-1.15.1.tar.bz2")
1484 : "1.15.1", 1521 : "1.15.1",
1485 # 1522 #
1486 # packages with valid UPSTREAM_CHECK_URI and UPSTREAM_CHECK_REGEX 1523 # packages with valid UPSTREAM_CHECK_URI and UPSTREAM_CHECK_REGEX
1487 # 1524 #
1488 # http://www.cups.org/software/1.7.2/cups-1.7.2-source.tar.bz2 1525 # http://www.cups.org/software/1.7.2/cups-1.7.2-source.tar.bz2
1489 # https://github.com/apple/cups/releases 1526 # https://github.com/apple/cups/releases
1490 ("cups", "/software/1.7.2/cups-1.7.2-source.tar.bz2", "/apple/cups/releases", r"(?P<name>cups\-)(?P<pver>((\d+[\.\-_]*)+))\-source\.tar\.gz") 1527 WgetTestData("cups", "/software/1.7.2/cups-1.7.2-source.tar.bz2", check_uri="/apple/cups/releases", check_regex=r"(?P<name>cups\-)(?P<pver>((\d+[\.\-_]*)+))\-source\.tar\.gz")
1491 : "2.0.0", 1528 : "2.0.0",
1492 # http://download.oracle.com/berkeley-db/db-5.3.21.tar.gz 1529 # http://download.oracle.com/berkeley-db/db-5.3.21.tar.gz
1493 # http://ftp.debian.org/debian/pool/main/d/db5.3/ 1530 # http://ftp.debian.org/debian/pool/main/d/db5.3/
1494 ("db", "/berkeley-db/db-5.3.21.tar.gz", "/debian/pool/main/d/db5.3/", r"(?P<name>db5\.3_)(?P<pver>\d+(\.\d+)+).+\.orig\.tar\.xz") 1531 WgetTestData("db", "/berkeley-db/db-5.3.21.tar.gz", check_uri="/debian/pool/main/d/db5.3/", check_regex=r"(?P<name>db5\.3_)(?P<pver>\d+(\.\d+)+).+\.orig\.tar\.xz")
1495 : "5.3.10", 1532 : "5.3.10",
1496 # 1533 #
1497 # packages where the tarball compression changed in the new version 1534 # packages where the tarball compression changed in the new version
1498 # 1535 #
1499 # http://ftp.debian.org/debian/pool/main/m/minicom/minicom_2.7.1.orig.tar.gz 1536 # http://ftp.debian.org/debian/pool/main/m/minicom/minicom_2.7.1.orig.tar.gz
1500 ("minicom", "/debian/pool/main/m/minicom/minicom_2.7.1.orig.tar.gz", "", "") 1537 WgetTestData("minicom", "/debian/pool/main/m/minicom/minicom_2.7.1.orig.tar.gz")
1501 : "2.8", 1538 : "2.8",
1539
1540 #
1541 # packages where the path doesn't actually contain the filename, so downloadfilename should be respected
1542 #
1543 WgetTestData("miniupnpd", "/software/miniupnp/download.php?file=miniupnpd_2.1.20191006.tar.gz;downloadfilename=miniupnpd_2.1.20191006.tar.gz", pv="2.1.20191006", check_uri="/software/miniupnp/download.php", check_regex=r"miniupnpd-(?P<pver>\d+(\.\d+)+)\.tar")
1544 : "2.3.7",
1502 } 1545 }
1503 1546
1504 test_crate_uris = { 1547 test_crate_uris = {
@@ -1510,52 +1553,57 @@ class FetchLatestVersionTest(FetcherTest):
1510 @skipIfNoNetwork() 1553 @skipIfNoNetwork()
1511 def test_git_latest_versionstring(self): 1554 def test_git_latest_versionstring(self):
1512 for k, v in self.test_git_uris.items(): 1555 for k, v in self.test_git_uris.items():
1513 self.d.setVar("PN", k[0]) 1556 with self.subTest(pn=k[0]):
1514 self.d.setVar("SRCREV", k[2]) 1557 self.d.setVar("PN", k[0])
1515 self.d.setVar("UPSTREAM_CHECK_GITTAGREGEX", k[3]) 1558 self.d.setVar("SRCREV", k[2])
1516 ud = bb.fetch2.FetchData(k[1], self.d) 1559 self.d.setVar("UPSTREAM_CHECK_GITTAGREGEX", k[3])
1517 pupver= ud.method.latest_versionstring(ud, self.d) 1560 ud = bb.fetch2.FetchData(k[1], self.d)
1518 verstring = pupver[0] 1561 pupver= ud.method.latest_versionstring(ud, self.d)
1519 self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0]) 1562 verstring = pupver[0]
1520 r = bb.utils.vercmp_string(v, verstring) 1563 self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0])
1521 self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring)) 1564 r = bb.utils.vercmp_string(v, verstring)
1522 if k[4]: 1565 self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring))
1523 r = bb.utils.vercmp_string(verstring, k[4]) 1566 if k[4]:
1524 self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], verstring, k[4])) 1567 r = bb.utils.vercmp_string(verstring, k[4])
1568 self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], verstring, k[4]))
1525 1569
1526 def test_wget_latest_versionstring(self): 1570 def test_wget_latest_versionstring(self):
1527 testdata = os.path.dirname(os.path.abspath(__file__)) + "/fetch-testdata" 1571 testdata = os.path.dirname(os.path.abspath(__file__)) + "/fetch-testdata"
1528 server = HTTPService(testdata) 1572 server = HTTPService(testdata, host="127.0.0.1")
1529 server.start() 1573 server.start()
1530 port = server.port 1574 port = server.port
1531 try: 1575 try:
1532 for k, v in self.test_wget_uris.items(): 1576 for data, v in self.test_wget_uris.items():
1533 self.d.setVar("PN", k[0]) 1577 with self.subTest(pn=data.pn):
1534 checkuri = "" 1578 self.d.setVar("PN", data.pn)
1535 if k[2]: 1579 self.d.setVar("PV", data.pv)
1536 checkuri = "http://localhost:%s/" % port + k[2] 1580 if data.check_uri:
1537 self.d.setVar("UPSTREAM_CHECK_URI", checkuri) 1581 checkuri = "http://127.0.0.1:%s/%s" % (port, data.check_uri)
1538 self.d.setVar("UPSTREAM_CHECK_REGEX", k[3]) 1582 self.d.setVar("UPSTREAM_CHECK_URI", checkuri)
1539 url = "http://localhost:%s/" % port + k[1] 1583 if data.check_regex:
1540 ud = bb.fetch2.FetchData(url, self.d) 1584 self.d.setVar("UPSTREAM_CHECK_REGEX", data.check_regex)
1541 pupver = ud.method.latest_versionstring(ud, self.d) 1585
1542 verstring = pupver[0] 1586 url = "http://127.0.0.1:%s/%s" % (port, data.path)
1543 self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0]) 1587 ud = bb.fetch2.FetchData(url, self.d)
1544 r = bb.utils.vercmp_string(v, verstring) 1588 pupver = ud.method.latest_versionstring(ud, self.d)
1545 self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring)) 1589 verstring = pupver[0]
1590 self.assertTrue(verstring, msg="Could not find upstream version for %s" % data.pn)
1591 r = bb.utils.vercmp_string(v, verstring)
1592 self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (data.pn, v, verstring))
1546 finally: 1593 finally:
1547 server.stop() 1594 server.stop()
1548 1595
1549 @skipIfNoNetwork() 1596 @skipIfNoNetwork()
1550 def test_crate_latest_versionstring(self): 1597 def test_crate_latest_versionstring(self):
1551 for k, v in self.test_crate_uris.items(): 1598 for k, v in self.test_crate_uris.items():
1552 self.d.setVar("PN", k[0]) 1599 with self.subTest(pn=k[0]):
1553 ud = bb.fetch2.FetchData(k[1], self.d) 1600 self.d.setVar("PN", k[0])
1554 pupver = ud.method.latest_versionstring(ud, self.d) 1601 ud = bb.fetch2.FetchData(k[1], self.d)
1555 verstring = pupver[0] 1602 pupver = ud.method.latest_versionstring(ud, self.d)
1556 self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0]) 1603 verstring = pupver[0]
1557 r = bb.utils.vercmp_string(v, verstring) 1604 self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0])
1558 self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring)) 1605 r = bb.utils.vercmp_string(v, verstring)
1606 self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring))
1559 1607
1560class FetchCheckStatusTest(FetcherTest): 1608class FetchCheckStatusTest(FetcherTest):
1561 test_wget_uris = ["https://downloads.yoctoproject.org/releases/sato/sato-engine-0.1.tar.gz", 1609 test_wget_uris = ["https://downloads.yoctoproject.org/releases/sato/sato-engine-0.1.tar.gz",
@@ -1739,6 +1787,8 @@ class GitShallowTest(FetcherTest):
1739 if cwd is None: 1787 if cwd is None:
1740 cwd = self.gitdir 1788 cwd = self.gitdir
1741 actual_refs = self.git(['for-each-ref', '--format=%(refname)'], cwd=cwd).splitlines() 1789 actual_refs = self.git(['for-each-ref', '--format=%(refname)'], cwd=cwd).splitlines()
1790 # Resolve references into the same format as the comparision (needed by git 2.48 onwards)
1791 actual_refs = self.git(['rev-parse', '--symbolic-full-name'] + actual_refs, cwd=cwd).splitlines()
1742 full_expected = self.git(['rev-parse', '--symbolic-full-name'] + expected_refs, cwd=cwd).splitlines() 1792 full_expected = self.git(['rev-parse', '--symbolic-full-name'] + expected_refs, cwd=cwd).splitlines()
1743 self.assertEqual(sorted(set(full_expected)), sorted(set(actual_refs))) 1793 self.assertEqual(sorted(set(full_expected)), sorted(set(actual_refs)))
1744 1794
@@ -1785,7 +1835,6 @@ class GitShallowTest(FetcherTest):
1785 def fetch_shallow(self, uri=None, disabled=False, keepclone=False): 1835 def fetch_shallow(self, uri=None, disabled=False, keepclone=False):
1786 """Fetch a uri, generating a shallow tarball, then unpack using it""" 1836 """Fetch a uri, generating a shallow tarball, then unpack using it"""
1787 fetcher, ud = self.fetch_and_unpack(uri) 1837 fetcher, ud = self.fetch_and_unpack(uri)
1788 assert os.path.exists(ud.clonedir), 'Git clone in DLDIR (%s) does not exist for uri %s' % (ud.clonedir, uri)
1789 1838
1790 # Confirm that the unpacked repo is unshallow 1839 # Confirm that the unpacked repo is unshallow
1791 if not disabled: 1840 if not disabled:
@@ -1793,9 +1842,10 @@ class GitShallowTest(FetcherTest):
1793 1842
1794 # fetch and unpack, from the shallow tarball 1843 # fetch and unpack, from the shallow tarball
1795 bb.utils.remove(self.gitdir, recurse=True) 1844 bb.utils.remove(self.gitdir, recurse=True)
1796 bb.process.run('chmod u+w -R "%s"' % ud.clonedir) 1845 if os.path.exists(ud.clonedir):
1797 bb.utils.remove(ud.clonedir, recurse=True) 1846 bb.process.run('chmod u+w -R "%s"' % ud.clonedir)
1798 bb.utils.remove(ud.clonedir.replace('gitsource', 'gitsubmodule'), recurse=True) 1847 bb.utils.remove(ud.clonedir, recurse=True)
1848 bb.utils.remove(ud.clonedir.replace('gitsource', 'gitsubmodule'), recurse=True)
1799 1849
1800 # confirm that the unpacked repo is used when no git clone or git 1850 # confirm that the unpacked repo is used when no git clone or git
1801 # mirror tarball is available 1851 # mirror tarball is available
@@ -1878,7 +1928,12 @@ class GitShallowTest(FetcherTest):
1878 self.add_empty_file('c') 1928 self.add_empty_file('c')
1879 self.assertRevCount(3, cwd=self.srcdir) 1929 self.assertRevCount(3, cwd=self.srcdir)
1880 1930
1931 # Clone without tarball
1932 self.d.setVar('BB_GIT_SHALLOW', '0')
1933 fetcher, ud = self.fetch()
1934
1881 # Clone and generate mirror tarball 1935 # Clone and generate mirror tarball
1936 self.d.setVar('BB_GIT_SHALLOW', '1')
1882 fetcher, ud = self.fetch() 1937 fetcher, ud = self.fetch()
1883 1938
1884 # Ensure we have a current mirror tarball, but an out of date clone 1939 # Ensure we have a current mirror tarball, but an out of date clone
@@ -1890,6 +1945,7 @@ class GitShallowTest(FetcherTest):
1890 fetcher, ud = self.fetch() 1945 fetcher, ud = self.fetch()
1891 fetcher.unpack(self.d.getVar('WORKDIR')) 1946 fetcher.unpack(self.d.getVar('WORKDIR'))
1892 self.assertRevCount(1) 1947 self.assertRevCount(1)
1948 assert os.path.exists(os.path.join(self.d.getVar('WORKDIR'), 'git', 'c'))
1893 1949
1894 def test_shallow_single_branch_no_merge(self): 1950 def test_shallow_single_branch_no_merge(self):
1895 self.add_empty_file('a') 1951 self.add_empty_file('a')
@@ -1987,7 +2043,7 @@ class GitShallowTest(FetcherTest):
1987 self.git('submodule update', cwd=self.srcdir) 2043 self.git('submodule update', cwd=self.srcdir)
1988 self.git('commit -m submodule -a', cwd=self.srcdir) 2044 self.git('commit -m submodule -a', cwd=self.srcdir)
1989 2045
1990 uri = 'gitsm://%s;protocol=file;subdir=${S}' % self.srcdir 2046 uri = 'gitsm://%s;protocol=file;subdir=${S};branch=master' % self.srcdir
1991 2047
1992 # Fetch once to generate the shallow tarball 2048 # Fetch once to generate the shallow tarball
1993 fetcher, ud = self.fetch(uri) 2049 fetcher, ud = self.fetch(uri)
@@ -2028,70 +2084,17 @@ class GitShallowTest(FetcherTest):
2028 assert './.git/annex/' in bb.process.run('tar -tzf %s' % os.path.join(self.dldir, ud.mirrortarballs[0]))[0] 2084 assert './.git/annex/' in bb.process.run('tar -tzf %s' % os.path.join(self.dldir, ud.mirrortarballs[0]))[0]
2029 assert os.path.exists(os.path.join(self.gitdir, 'c')) 2085 assert os.path.exists(os.path.join(self.gitdir, 'c'))
2030 2086
2031 def test_shallow_multi_one_uri(self):
2032 # Create initial git repo
2033 self.add_empty_file('a')
2034 self.add_empty_file('b')
2035 self.git('checkout -b a_branch', cwd=self.srcdir)
2036 self.add_empty_file('c')
2037 self.add_empty_file('d')
2038 self.git('checkout master', cwd=self.srcdir)
2039 self.git('tag v0.0 a_branch', cwd=self.srcdir)
2040 self.add_empty_file('e')
2041 self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir)
2042 self.add_empty_file('f')
2043 self.assertRevCount(7, cwd=self.srcdir)
2044
2045 uri = self.d.getVar('SRC_URI').split()[0]
2046 uri = '%s;branch=master,a_branch;name=master,a_branch' % uri
2047
2048 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
2049 self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
2050 self.d.setVar('SRCREV_master', '${AUTOREV}')
2051 self.d.setVar('SRCREV_a_branch', '${AUTOREV}')
2052
2053 self.fetch_shallow(uri)
2054
2055 self.assertRevCount(5)
2056 self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
2057
2058 def test_shallow_multi_one_uri_depths(self):
2059 # Create initial git repo
2060 self.add_empty_file('a')
2061 self.add_empty_file('b')
2062 self.git('checkout -b a_branch', cwd=self.srcdir)
2063 self.add_empty_file('c')
2064 self.add_empty_file('d')
2065 self.git('checkout master', cwd=self.srcdir)
2066 self.add_empty_file('e')
2067 self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir)
2068 self.add_empty_file('f')
2069 self.assertRevCount(7, cwd=self.srcdir)
2070
2071 uri = self.d.getVar('SRC_URI').split()[0]
2072 uri = '%s;branch=master,a_branch;name=master,a_branch' % uri
2073
2074 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
2075 self.d.setVar('BB_GIT_SHALLOW_DEPTH_master', '3')
2076 self.d.setVar('BB_GIT_SHALLOW_DEPTH_a_branch', '1')
2077 self.d.setVar('SRCREV_master', '${AUTOREV}')
2078 self.d.setVar('SRCREV_a_branch', '${AUTOREV}')
2079
2080 self.fetch_shallow(uri)
2081
2082 self.assertRevCount(4, ['--all'])
2083 self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
2084
2085 def test_shallow_clone_preferred_over_shallow(self): 2087 def test_shallow_clone_preferred_over_shallow(self):
2086 self.add_empty_file('a') 2088 self.add_empty_file('a')
2087 self.add_empty_file('b') 2089 self.add_empty_file('b')
2088 2090
2089 # Fetch once to generate the shallow tarball 2091 # Fetch once to generate the shallow tarball
2092 self.d.setVar('BB_GIT_SHALLOW', '0')
2090 fetcher, ud = self.fetch() 2093 fetcher, ud = self.fetch()
2091 assert os.path.exists(os.path.join(self.dldir, ud.mirrortarballs[0]))
2092 2094
2093 # Fetch and unpack with both the clonedir and shallow tarball available 2095 # Fetch and unpack with both the clonedir and shallow tarball available
2094 bb.utils.remove(self.gitdir, recurse=True) 2096 bb.utils.remove(self.gitdir, recurse=True)
2097 self.d.setVar('BB_GIT_SHALLOW', '1')
2095 fetcher, ud = self.fetch_and_unpack() 2098 fetcher, ud = self.fetch_and_unpack()
2096 2099
2097 # The unpacked tree should *not* be shallow 2100 # The unpacked tree should *not* be shallow
@@ -2199,7 +2202,7 @@ class GitShallowTest(FetcherTest):
2199 2202
2200 self.fetch_shallow() 2203 self.fetch_shallow()
2201 2204
2202 self.assertRevCount(5) 2205 self.assertRevCount(2)
2203 2206
2204 def test_shallow_invalid_revs(self): 2207 def test_shallow_invalid_revs(self):
2205 self.add_empty_file('a') 2208 self.add_empty_file('a')
@@ -2218,7 +2221,10 @@ class GitShallowTest(FetcherTest):
2218 self.git('tag v0.0 master', cwd=self.srcdir) 2221 self.git('tag v0.0 master', cwd=self.srcdir)
2219 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0') 2222 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
2220 self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0') 2223 self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
2221 self.fetch_shallow() 2224
2225 with self.assertRaises(bb.fetch2.FetchError), self.assertLogs("BitBake.Fetcher", level="ERROR") as cm:
2226 self.fetch_shallow()
2227 self.assertIn("fatal: no commits selected for shallow requests", cm.output[0])
2222 2228
2223 def test_shallow_fetch_missing_revs_fails(self): 2229 def test_shallow_fetch_missing_revs_fails(self):
2224 self.add_empty_file('a') 2230 self.add_empty_file('a')
@@ -2232,6 +2238,33 @@ class GitShallowTest(FetcherTest):
2232 self.assertIn("Unable to find revision v0.0 even from upstream", cm.output[0]) 2238 self.assertIn("Unable to find revision v0.0 even from upstream", cm.output[0])
2233 2239
2234 @skipIfNoNetwork() 2240 @skipIfNoNetwork()
2241 def test_git_shallow_fetch_premirrors(self):
2242 url = "git://git.openembedded.org/bitbake;branch=master;protocol=https"
2243
2244 # Create a separate premirror directory within tempdir
2245 premirror = os.path.join(self.tempdir, "premirror")
2246 os.mkdir(premirror)
2247
2248 # Fetch a non-shallow clone into the premirror subdir
2249 self.d.setVar('BB_GIT_SHALLOW', '0')
2250 self.d.setVar("DL_DIR", premirror)
2251 fetcher, ud = self.fetch(url)
2252
2253 # Fetch a shallow clone from the premirror subdir with unpacking
2254 # using the original recipe URL and the premirror mapping
2255 self.d.setVar('BB_GIT_SHALLOW', '1')
2256 self.d.setVar("DL_DIR", self.dldir)
2257 self.d.setVar('BB_FETCH_PREMIRRORONLY', '1')
2258 self.d.setVar('BB_NO_NETWORK', '1')
2259 self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '0')
2260 self.d.setVar("PREMIRRORS", "git://.*/.* git://{0};protocol=file".format(premirror + "/git2/" + ud.host + ud.path.replace("/", ".")))
2261 fetcher = self.fetch_and_unpack(url)
2262
2263 # Verify that the unpacked sources are shallow clones
2264 self.assertRevCount(1)
2265 assert os.path.exists(os.path.join(self.gitdir, '.git', 'shallow'))
2266
2267 @skipIfNoNetwork()
2235 def test_bitbake(self): 2268 def test_bitbake(self):
2236 self.git('remote add --mirror=fetch origin https://github.com/openembedded/bitbake', cwd=self.srcdir) 2269 self.git('remote add --mirror=fetch origin https://github.com/openembedded/bitbake', cwd=self.srcdir)
2237 self.git('config core.bare true', cwd=self.srcdir) 2270 self.git('config core.bare true', cwd=self.srcdir)
@@ -2249,7 +2282,7 @@ class GitShallowTest(FetcherTest):
2249 revs = len(self.git('rev-list master').splitlines()) 2282 revs = len(self.git('rev-list master').splitlines())
2250 self.assertNotEqual(orig_revs, revs) 2283 self.assertNotEqual(orig_revs, revs)
2251 self.assertRefs(['master', 'origin/master']) 2284 self.assertRefs(['master', 'origin/master'])
2252 self.assertRevCount(orig_revs - 1758) 2285 self.assertRevCount(orig_revs - 1760)
2253 2286
2254 def test_that_unpack_throws_an_error_when_the_git_clone_nor_shallow_tarball_exist(self): 2287 def test_that_unpack_throws_an_error_when_the_git_clone_nor_shallow_tarball_exist(self):
2255 self.add_empty_file('a') 2288 self.add_empty_file('a')
@@ -2263,23 +2296,33 @@ class GitShallowTest(FetcherTest):
2263 self.assertIn("No up to date source found", context.exception.msg) 2296 self.assertIn("No up to date source found", context.exception.msg)
2264 self.assertIn("clone directory not available or not up to date", context.exception.msg) 2297 self.assertIn("clone directory not available or not up to date", context.exception.msg)
2265 2298
2266 @skipIfNoNetwork() 2299 def test_shallow_check_is_shallow(self):
2267 def test_that_unpack_does_work_when_using_git_shallow_tarball_but_tarball_is_not_available(self): 2300 self.add_empty_file('a')
2268 self.d.setVar('SRCREV', 'e5939ff608b95cdd4d0ab0e1935781ab9a276ac0') 2301 self.add_empty_file('b')
2269 self.d.setVar('BB_GIT_SHALLOW', '1')
2270 self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1')
2271 fetcher = bb.fetch.Fetch(["git://git.yoctoproject.org/fstests;branch=master;protocol=https"], self.d)
2272 fetcher.download()
2273 2302
2274 bb.utils.remove(self.dldir + "/*.tar.gz") 2303 # Fetch and unpack without the clonedir and *only* shallow tarball available
2275 fetcher.unpack(self.unpackdir) 2304 bb.utils.remove(self.gitdir, recurse=True)
2305 fetcher, ud = self.fetch_and_unpack()
2306
2307 # The unpacked tree *should* be shallow
2308 self.assertRevCount(1)
2309 assert os.path.exists(os.path.join(self.gitdir, '.git', 'shallow'))
2310
2311 def test_shallow_succeeds_with_tag_containing_slash(self):
2312 self.add_empty_file('a')
2313 self.add_empty_file('b')
2314 self.git('tag t1/t2/t3', cwd=self.srcdir)
2315 self.assertRevCount(2, cwd=self.srcdir)
2276 2316
2277 dir = os.listdir(self.unpackdir + "/git/") 2317 srcrev = self.git('rev-parse HEAD', cwd=self.srcdir).strip()
2278 self.assertIn("fstests.doap", dir) 2318 self.d.setVar('SRCREV', srcrev)
2319 uri = self.d.getVar('SRC_URI').split()[0]
2320 uri = '%s;tag=t1/t2/t3' % uri
2321 self.fetch_shallow(uri)
2322 self.assertRevCount(1)
2279 2323
2280class GitLfsTest(FetcherTest): 2324class GitLfsTest(FetcherTest):
2281 def skipIfNoGitLFS(): 2325 def skipIfNoGitLFS():
2282 import shutil
2283 if not shutil.which('git-lfs'): 2326 if not shutil.which('git-lfs'):
2284 return unittest.skip('git-lfs not installed') 2327 return unittest.skip('git-lfs not installed')
2285 return lambda f: f 2328 return lambda f: f
@@ -2303,12 +2346,18 @@ class GitLfsTest(FetcherTest):
2303 self.git_init(cwd=self.srcdir) 2346 self.git_init(cwd=self.srcdir)
2304 self.commit_file('.gitattributes', '*.mp3 filter=lfs -text') 2347 self.commit_file('.gitattributes', '*.mp3 filter=lfs -text')
2305 2348
2306 def commit_file(self, filename, content): 2349 def commit(self, *, cwd=None):
2307 with open(os.path.join(self.srcdir, filename), "w") as f: 2350 cwd = cwd or self.srcdir
2351 self.git(["commit", "-m", "Change"], cwd=cwd)
2352 return self.git(["rev-parse", "HEAD"], cwd=cwd).strip()
2353
2354 def commit_file(self, filename, content, *, cwd=None):
2355 cwd = cwd or self.srcdir
2356
2357 with open(os.path.join(cwd, filename), "w") as f:
2308 f.write(content) 2358 f.write(content)
2309 self.git(["add", filename], cwd=self.srcdir) 2359 self.git(["add", filename], cwd=cwd)
2310 self.git(["commit", "-m", "Change"], cwd=self.srcdir) 2360 return self.commit(cwd=cwd)
2311 return self.git(["rev-parse", "HEAD"], cwd=self.srcdir).strip()
2312 2361
2313 def fetch(self, uri=None, download=True): 2362 def fetch(self, uri=None, download=True):
2314 uris = self.d.getVar('SRC_URI').split() 2363 uris = self.d.getVar('SRC_URI').split()
@@ -2329,25 +2378,112 @@ class GitLfsTest(FetcherTest):
2329 return unpacked_lfs_file 2378 return unpacked_lfs_file
2330 2379
2331 @skipIfNoGitLFS() 2380 @skipIfNoGitLFS()
2381 def test_gitsm_lfs(self):
2382 """Test that the gitsm fetcher caches objects stored via LFS"""
2383 self.git(["lfs", "install", "--local"], cwd=self.srcdir)
2384
2385 def fetch_and_verify(revision, filename, content):
2386 self.d.setVar('SRCREV', revision)
2387 fetcher, ud = self.fetch()
2388
2389 with hide_directory(submoduledir), hide_directory(self.srcdir):
2390 workdir = self.d.getVar('WORKDIR')
2391 fetcher.unpack(workdir)
2392
2393 with open(os.path.join(workdir, "git", filename)) as f:
2394 self.assertEqual(f.read(), content)
2395
2396 # Create the git repository that will later be used as a submodule
2397 submoduledir = self.tempdir + "/submodule"
2398 bb.utils.mkdirhier(submoduledir)
2399 self.git_init(submoduledir)
2400 self.git(["lfs", "install", "--local"], cwd=submoduledir)
2401 self.commit_file('.gitattributes', '*.mp3 filter=lfs -text', cwd=submoduledir)
2402
2403 submodule_commit_1 = self.commit_file("a.mp3", "submodule version 1", cwd=submoduledir)
2404 _ = self.commit_file("a.mp3", "submodule version 2", cwd=submoduledir)
2405
2406 # Add the submodule to the repository at its current HEAD revision
2407 self.git(["-c", "protocol.file.allow=always", "submodule", "add", submoduledir, "submodule"],
2408 cwd=self.srcdir)
2409 base_commit_1 = self.commit()
2410
2411 # Let the submodule point at a different revision
2412 self.git(["checkout", submodule_commit_1], self.srcdir + "/submodule")
2413 self.git(["add", "submodule"], cwd=self.srcdir)
2414 base_commit_2 = self.commit()
2415
2416 # Add a LFS file to the repository
2417 base_commit_3 = self.commit_file("a.mp3", "version 1")
2418 # Update the added LFS file
2419 base_commit_4 = self.commit_file("a.mp3", "version 2")
2420
2421 self.d.setVar('SRC_URI', "gitsm://%s;protocol=file;lfs=1;branch=master" % self.srcdir)
2422
2423 # Verify that LFS objects referenced from submodules are fetched and checked out
2424 fetch_and_verify(base_commit_1, "submodule/a.mp3", "submodule version 2")
2425 # Verify that the repository inside the download cache of a submodile is extended with any
2426 # additional LFS objects needed when checking out a different revision.
2427 fetch_and_verify(base_commit_2, "submodule/a.mp3", "submodule version 1")
2428 # Verify that LFS objects referenced from the base repository are fetched and checked out
2429 fetch_and_verify(base_commit_3, "a.mp3", "version 1")
2430 # Verify that the cached repository is extended with any additional LFS objects required
2431 # when checking out a different revision.
2432 fetch_and_verify(base_commit_4, "a.mp3", "version 2")
2433
2434 @skipIfNoGitLFS()
2435 def test_gitsm_lfs_disabled(self):
2436 """Test that the gitsm fetcher does not use LFS when explicitly disabled"""
2437 self.git(["lfs", "install", "--local"], cwd=self.srcdir)
2438
2439 def fetch_and_verify(revision, filename, content):
2440 self.d.setVar('SRCREV', revision)
2441 fetcher, ud = self.fetch()
2442
2443 with hide_directory(submoduledir), hide_directory(self.srcdir):
2444 workdir = self.d.getVar('WORKDIR')
2445 fetcher.unpack(workdir)
2446
2447 with open(os.path.join(workdir, "git", filename)) as f:
2448 # Assume that LFS did not perform smudging when the expected content is
2449 # missing.
2450 self.assertNotEqual(f.read(), content)
2451
2452 # Create the git repository that will later be used as a submodule
2453 submoduledir = self.tempdir + "/submodule"
2454 bb.utils.mkdirhier(submoduledir)
2455 self.git_init(submoduledir)
2456 self.git(["lfs", "install", "--local"], cwd=submoduledir)
2457 self.commit_file('.gitattributes', '*.mp3 filter=lfs -text', cwd=submoduledir)
2458
2459 submodule_commit_1 = self.commit_file("a.mp3", "submodule version 1", cwd=submoduledir)
2460
2461 # Add the submodule to the repository at its current HEAD revision
2462 self.git(["-c", "protocol.file.allow=always", "submodule", "add", submoduledir, "submodule"],
2463 cwd=self.srcdir)
2464 base_commit_1 = self.commit()
2465
2466 # Add a LFS file to the repository
2467 base_commit_2 = self.commit_file("a.mp3", "version 1")
2468
2469 self.d.setVar('SRC_URI', "gitsm://%s;protocol=file;lfs=1;branch=master;lfs=0" % self.srcdir)
2470
2471 # Verify that LFS objects referenced from submodules are not fetched nor checked out
2472 fetch_and_verify(base_commit_1, "submodule/a.mp3", "submodule version 1")
2473 # Verify that the LFS objects referenced from the base repository are not fetched nor
2474 # checked out
2475 fetch_and_verify(base_commit_2, "a.mp3", "version 1")
2476
2477 @skipIfNoGitLFS()
2332 def test_fetch_lfs_on_srcrev_change(self): 2478 def test_fetch_lfs_on_srcrev_change(self):
2333 """Test if fetch downloads missing LFS objects when a different revision within an existing repository is requested""" 2479 """Test if fetch downloads missing LFS objects when a different revision within an existing repository is requested"""
2334 self.git(["lfs", "install", "--local"], cwd=self.srcdir) 2480 self.git(["lfs", "install", "--local"], cwd=self.srcdir)
2335 2481
2336 @contextlib.contextmanager
2337 def hide_upstream_repository():
2338 """Hide the upstream repository to make sure that git lfs cannot pull from it"""
2339 temp_name = self.srcdir + ".bak"
2340 os.rename(self.srcdir, temp_name)
2341 try:
2342 yield
2343 finally:
2344 os.rename(temp_name, self.srcdir)
2345
2346 def fetch_and_verify(revision, filename, content): 2482 def fetch_and_verify(revision, filename, content):
2347 self.d.setVar('SRCREV', revision) 2483 self.d.setVar('SRCREV', revision)
2348 fetcher, ud = self.fetch() 2484 fetcher, ud = self.fetch()
2349 2485
2350 with hide_upstream_repository(): 2486 with hide_directory(self.srcdir):
2351 workdir = self.d.getVar('WORKDIR') 2487 workdir = self.d.getVar('WORKDIR')
2352 fetcher.unpack(workdir) 2488 fetcher.unpack(workdir)
2353 2489
@@ -2399,8 +2535,6 @@ class GitLfsTest(FetcherTest):
2399 2535
2400 @skipIfNoGitLFS() 2536 @skipIfNoGitLFS()
2401 def test_lfs_enabled(self): 2537 def test_lfs_enabled(self):
2402 import shutil
2403
2404 uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir 2538 uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir
2405 self.d.setVar('SRC_URI', uri) 2539 self.d.setVar('SRC_URI', uri)
2406 2540
@@ -2411,8 +2545,6 @@ class GitLfsTest(FetcherTest):
2411 2545
2412 @skipIfNoGitLFS() 2546 @skipIfNoGitLFS()
2413 def test_lfs_disabled(self): 2547 def test_lfs_disabled(self):
2414 import shutil
2415
2416 uri = 'git://%s;protocol=file;lfs=0;branch=master' % self.srcdir 2548 uri = 'git://%s;protocol=file;lfs=0;branch=master' % self.srcdir
2417 self.d.setVar('SRC_URI', uri) 2549 self.d.setVar('SRC_URI', uri)
2418 2550
@@ -2421,58 +2553,76 @@ class GitLfsTest(FetcherTest):
2421 fetcher, ud = self.fetch() 2553 fetcher, ud = self.fetch()
2422 fetcher.unpack(self.d.getVar('WORKDIR')) 2554 fetcher.unpack(self.d.getVar('WORKDIR'))
2423 2555
2424 def test_lfs_enabled_not_installed(self): 2556 @skipIfNoGitLFS()
2425 import shutil 2557 def test_lfs_enabled_not_installed_during_unpack(self):
2558 uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir
2559 self.d.setVar('SRC_URI', uri)
2560
2561 # Careful: suppress initial attempt at downloading
2562 fetcher, ud = self.fetch(uri=None, download=False)
2426 2563
2564 fetcher.download()
2565 # If git-lfs cannot be found, the unpack should throw an error
2566 with self.assertRaises(bb.fetch2.FetchError):
2567 with unittest.mock.patch("shutil.which", return_value=None):
2568 shutil.rmtree(self.gitdir, ignore_errors=True)
2569 fetcher.unpack(self.d.getVar('WORKDIR'))
2570
2571 def test_lfs_enabled_not_installed(self):
2427 uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir 2572 uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir
2428 self.d.setVar('SRC_URI', uri) 2573 self.d.setVar('SRC_URI', uri)
2429 2574
2430 # Careful: suppress initial attempt at downloading 2575 # Careful: suppress initial attempt at downloading
2431 fetcher, ud = self.fetch(uri=None, download=False) 2576 fetcher, ud = self.fetch(uri=None, download=False)
2432 2577
2433 # Artificially assert that git-lfs is not installed, so 2578 # If git-lfs cannot be found, the download should throw an error
2434 # we can verify a failure to unpack in it's absence. 2579 with unittest.mock.patch("shutil.which", return_value=None):
2435 old_find_git_lfs = ud.method._find_git_lfs
2436 try:
2437 # If git-lfs cannot be found, the unpack should throw an error
2438 with self.assertRaises(bb.fetch2.FetchError): 2580 with self.assertRaises(bb.fetch2.FetchError):
2439 fetcher.download() 2581 fetcher.download()
2440 ud.method._find_git_lfs = lambda d: False
2441 shutil.rmtree(self.gitdir, ignore_errors=True)
2442 fetcher.unpack(self.d.getVar('WORKDIR'))
2443 finally:
2444 ud.method._find_git_lfs = old_find_git_lfs
2445 2582
2446 def test_lfs_disabled_not_installed(self): 2583 def test_lfs_disabled_not_installed(self):
2447 import shutil
2448
2449 uri = 'git://%s;protocol=file;lfs=0;branch=master' % self.srcdir 2584 uri = 'git://%s;protocol=file;lfs=0;branch=master' % self.srcdir
2450 self.d.setVar('SRC_URI', uri) 2585 self.d.setVar('SRC_URI', uri)
2451 2586
2452 # Careful: suppress initial attempt at downloading 2587 # Careful: suppress initial attempt at downloading
2453 fetcher, ud = self.fetch(uri=None, download=False) 2588 fetcher, ud = self.fetch(uri=None, download=False)
2454 2589
2455 # Artificially assert that git-lfs is not installed, so 2590 # Even if git-lfs cannot be found, the download / unpack should be successful
2456 # we can verify a failure to unpack in it's absence. 2591 with unittest.mock.patch("shutil.which", return_value=None):
2457 old_find_git_lfs = ud.method._find_git_lfs 2592 fetcher.download()
2458 try: 2593 shutil.rmtree(self.gitdir, ignore_errors=True)
2459 # Even if git-lfs cannot be found, the unpack should be successful 2594 fetcher.unpack(self.d.getVar('WORKDIR'))
2595
2596 def test_lfs_enabled_not_installed_but_not_needed(self):
2597 srcdir = os.path.join(self.tempdir, "emptygit")
2598 bb.utils.mkdirhier(srcdir)
2599 self.git_init(srcdir)
2600 self.commit_file("test", "test content", cwd=srcdir)
2601
2602 uri = 'git://%s;protocol=file;lfs=1;branch=master' % srcdir
2603 self.d.setVar('SRC_URI', uri)
2604
2605 # Careful: suppress initial attempt at downloading
2606 fetcher, ud = self.fetch(uri=None, download=False)
2607
2608 # It shouldnt't matter that git-lfs cannot be found as the repository configuration does not
2609 # specify any LFS filters.
2610 with unittest.mock.patch("shutil.which", return_value=None):
2460 fetcher.download() 2611 fetcher.download()
2461 ud.method._find_git_lfs = lambda d: False
2462 shutil.rmtree(self.gitdir, ignore_errors=True) 2612 shutil.rmtree(self.gitdir, ignore_errors=True)
2463 fetcher.unpack(self.d.getVar('WORKDIR')) 2613 fetcher.unpack(self.d.getVar('WORKDIR'))
2464 finally:
2465 ud.method._find_git_lfs = old_find_git_lfs
2466 2614
2467class GitURLWithSpacesTest(FetcherTest): 2615class GitURLWithSpacesTest(FetcherTest):
2468 test_git_urls = { 2616 test_git_urls = {
2469 "git://tfs-example.org:22/tfs/example%20path/example.git;branch=master" : { 2617 "git://tfs-example.org:22/tfs/example%20path/example.git;branch=master" : {
2470 'url': 'git://tfs-example.org:22/tfs/example%20path/example.git;branch=master', 2618 'url': 'git://tfs-example.org:22/tfs/example%20path/example.git;branch=master',
2619 'repo_url': 'git://tfs-example.org:22/tfs/example%20path/example.git',
2471 'gitsrcname': 'tfs-example.org.22.tfs.example_path.example.git', 2620 'gitsrcname': 'tfs-example.org.22.tfs.example_path.example.git',
2472 'path': '/tfs/example path/example.git' 2621 'path': '/tfs/example path/example.git'
2473 }, 2622 },
2474 "git://tfs-example.org:22/tfs/example%20path/example%20repo.git;branch=master" : { 2623 "git://tfs-example.org:22/tfs/example%20path/example%20repo.git;branch=master" : {
2475 'url': 'git://tfs-example.org:22/tfs/example%20path/example%20repo.git;branch=master', 2624 'url': 'git://tfs-example.org:22/tfs/example%20path/example%20repo.git;branch=master',
2625 'repo_url': 'git://tfs-example.org:22/tfs/example%20path/example%20repo.git',
2476 'gitsrcname': 'tfs-example.org.22.tfs.example_path.example_repo.git', 2626 'gitsrcname': 'tfs-example.org.22.tfs.example_path.example_repo.git',
2477 'path': '/tfs/example path/example repo.git' 2627 'path': '/tfs/example path/example repo.git'
2478 } 2628 }
@@ -2495,6 +2645,7 @@ class GitURLWithSpacesTest(FetcherTest):
2495 self.assertEqual(ud.lockfile, os.path.join(self.dldir, "git2", ref['gitsrcname'] + '.lock')) 2645 self.assertEqual(ud.lockfile, os.path.join(self.dldir, "git2", ref['gitsrcname'] + '.lock'))
2496 self.assertEqual(ud.clonedir, os.path.join(self.dldir, "git2", ref['gitsrcname'])) 2646 self.assertEqual(ud.clonedir, os.path.join(self.dldir, "git2", ref['gitsrcname']))
2497 self.assertEqual(ud.fullmirror, os.path.join(self.dldir, "git2_" + ref['gitsrcname'] + '.tar.gz')) 2647 self.assertEqual(ud.fullmirror, os.path.join(self.dldir, "git2_" + ref['gitsrcname'] + '.tar.gz'))
2648 self.assertEqual(ud.method._get_repo_url(ud), ref['repo_url'])
2498 2649
2499class CrateTest(FetcherTest): 2650class CrateTest(FetcherTest):
2500 @skipIfNoNetwork() 2651 @skipIfNoNetwork()
@@ -2616,7 +2767,6 @@ class CrateTest(FetcherTest):
2616 2767
2617class NPMTest(FetcherTest): 2768class NPMTest(FetcherTest):
2618 def skipIfNoNpm(): 2769 def skipIfNoNpm():
2619 import shutil
2620 if not shutil.which('npm'): 2770 if not shutil.which('npm'):
2621 return unittest.skip('npm not installed') 2771 return unittest.skip('npm not installed')
2622 return lambda f: f 2772 return lambda f: f
@@ -2624,8 +2774,8 @@ class NPMTest(FetcherTest):
2624 @skipIfNoNpm() 2774 @skipIfNoNpm()
2625 @skipIfNoNetwork() 2775 @skipIfNoNetwork()
2626 def test_npm(self): 2776 def test_npm(self):
2627 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0' 2777 urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
2628 fetcher = bb.fetch.Fetch([url], self.d) 2778 fetcher = bb.fetch.Fetch(urls, self.d)
2629 ud = fetcher.ud[fetcher.urls[0]] 2779 ud = fetcher.ud[fetcher.urls[0]]
2630 fetcher.download() 2780 fetcher.download()
2631 self.assertTrue(os.path.exists(ud.localpath)) 2781 self.assertTrue(os.path.exists(ud.localpath))
@@ -2638,9 +2788,9 @@ class NPMTest(FetcherTest):
2638 @skipIfNoNpm() 2788 @skipIfNoNpm()
2639 @skipIfNoNetwork() 2789 @skipIfNoNetwork()
2640 def test_npm_bad_checksum(self): 2790 def test_npm_bad_checksum(self):
2641 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0' 2791 urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
2642 # Fetch once to get a tarball 2792 # Fetch once to get a tarball
2643 fetcher = bb.fetch.Fetch([url], self.d) 2793 fetcher = bb.fetch.Fetch(urls, self.d)
2644 ud = fetcher.ud[fetcher.urls[0]] 2794 ud = fetcher.ud[fetcher.urls[0]]
2645 fetcher.download() 2795 fetcher.download()
2646 self.assertTrue(os.path.exists(ud.localpath)) 2796 self.assertTrue(os.path.exists(ud.localpath))
@@ -2657,9 +2807,9 @@ class NPMTest(FetcherTest):
2657 @skipIfNoNpm() 2807 @skipIfNoNpm()
2658 @skipIfNoNetwork() 2808 @skipIfNoNetwork()
2659 def test_npm_premirrors(self): 2809 def test_npm_premirrors(self):
2660 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0' 2810 urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
2661 # Fetch once to get a tarball 2811 # Fetch once to get a tarball
2662 fetcher = bb.fetch.Fetch([url], self.d) 2812 fetcher = bb.fetch.Fetch(urls, self.d)
2663 ud = fetcher.ud[fetcher.urls[0]] 2813 ud = fetcher.ud[fetcher.urls[0]]
2664 fetcher.download() 2814 fetcher.download()
2665 self.assertTrue(os.path.exists(ud.localpath)) 2815 self.assertTrue(os.path.exists(ud.localpath))
@@ -2679,7 +2829,7 @@ class NPMTest(FetcherTest):
2679 # while the fetcher object exists, which it does when we rename the 2829 # while the fetcher object exists, which it does when we rename the
2680 # download directory to "mirror" above. Thus we need a new fetcher to go 2830 # download directory to "mirror" above. Thus we need a new fetcher to go
2681 # with the now empty download directory. 2831 # with the now empty download directory.
2682 fetcher = bb.fetch.Fetch([url], self.d) 2832 fetcher = bb.fetch.Fetch(urls, self.d)
2683 ud = fetcher.ud[fetcher.urls[0]] 2833 ud = fetcher.ud[fetcher.urls[0]]
2684 fetcher.download() 2834 fetcher.download()
2685 self.assertTrue(os.path.exists(ud.localpath)) 2835 self.assertTrue(os.path.exists(ud.localpath))
@@ -2687,9 +2837,9 @@ class NPMTest(FetcherTest):
2687 @skipIfNoNpm() 2837 @skipIfNoNpm()
2688 @skipIfNoNetwork() 2838 @skipIfNoNetwork()
2689 def test_npm_premirrors_with_specified_filename(self): 2839 def test_npm_premirrors_with_specified_filename(self):
2690 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0' 2840 urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
2691 # Fetch once to get a tarball 2841 # Fetch once to get a tarball
2692 fetcher = bb.fetch.Fetch([url], self.d) 2842 fetcher = bb.fetch.Fetch(urls, self.d)
2693 ud = fetcher.ud[fetcher.urls[0]] 2843 ud = fetcher.ud[fetcher.urls[0]]
2694 fetcher.download() 2844 fetcher.download()
2695 self.assertTrue(os.path.exists(ud.localpath)) 2845 self.assertTrue(os.path.exists(ud.localpath))
@@ -2709,8 +2859,8 @@ class NPMTest(FetcherTest):
2709 @skipIfNoNetwork() 2859 @skipIfNoNetwork()
2710 def test_npm_mirrors(self): 2860 def test_npm_mirrors(self):
2711 # Fetch once to get a tarball 2861 # Fetch once to get a tarball
2712 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0' 2862 urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
2713 fetcher = bb.fetch.Fetch([url], self.d) 2863 fetcher = bb.fetch.Fetch(urls, self.d)
2714 ud = fetcher.ud[fetcher.urls[0]] 2864 ud = fetcher.ud[fetcher.urls[0]]
2715 fetcher.download() 2865 fetcher.download()
2716 self.assertTrue(os.path.exists(ud.localpath)) 2866 self.assertTrue(os.path.exists(ud.localpath))
@@ -2734,8 +2884,8 @@ class NPMTest(FetcherTest):
2734 @skipIfNoNpm() 2884 @skipIfNoNpm()
2735 @skipIfNoNetwork() 2885 @skipIfNoNetwork()
2736 def test_npm_destsuffix_downloadfilename(self): 2886 def test_npm_destsuffix_downloadfilename(self):
2737 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0;destsuffix=foo/bar;downloadfilename=foo-bar.tgz' 2887 urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0;destsuffix=foo/bar;downloadfilename=foo-bar.tgz']
2738 fetcher = bb.fetch.Fetch([url], self.d) 2888 fetcher = bb.fetch.Fetch(urls, self.d)
2739 fetcher.download() 2889 fetcher.download()
2740 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'foo-bar.tgz'))) 2890 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'foo-bar.tgz')))
2741 fetcher.unpack(self.unpackdir) 2891 fetcher.unpack(self.unpackdir)
@@ -2743,18 +2893,18 @@ class NPMTest(FetcherTest):
2743 self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json'))) 2893 self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
2744 2894
2745 def test_npm_no_network_no_tarball(self): 2895 def test_npm_no_network_no_tarball(self):
2746 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0' 2896 urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
2747 self.d.setVar('BB_NO_NETWORK', '1') 2897 self.d.setVar('BB_NO_NETWORK', '1')
2748 fetcher = bb.fetch.Fetch([url], self.d) 2898 fetcher = bb.fetch.Fetch(urls, self.d)
2749 with self.assertRaises(bb.fetch2.NetworkAccess): 2899 with self.assertRaises(bb.fetch2.NetworkAccess):
2750 fetcher.download() 2900 fetcher.download()
2751 2901
2752 @skipIfNoNpm() 2902 @skipIfNoNpm()
2753 @skipIfNoNetwork() 2903 @skipIfNoNetwork()
2754 def test_npm_no_network_with_tarball(self): 2904 def test_npm_no_network_with_tarball(self):
2755 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0' 2905 urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
2756 # Fetch once to get a tarball 2906 # Fetch once to get a tarball
2757 fetcher = bb.fetch.Fetch([url], self.d) 2907 fetcher = bb.fetch.Fetch(urls, self.d)
2758 fetcher.download() 2908 fetcher.download()
2759 # Disable network access 2909 # Disable network access
2760 self.d.setVar('BB_NO_NETWORK', '1') 2910 self.d.setVar('BB_NO_NETWORK', '1')
@@ -2767,8 +2917,8 @@ class NPMTest(FetcherTest):
2767 @skipIfNoNpm() 2917 @skipIfNoNpm()
2768 @skipIfNoNetwork() 2918 @skipIfNoNetwork()
2769 def test_npm_registry_alternate(self): 2919 def test_npm_registry_alternate(self):
2770 url = 'npm://skimdb.npmjs.com;package=@savoirfairelinux/node-server-example;version=1.0.0' 2920 urls = ['npm://skimdb.npmjs.com;package=@savoirfairelinux/node-server-example;version=1.0.0']
2771 fetcher = bb.fetch.Fetch([url], self.d) 2921 fetcher = bb.fetch.Fetch(urls, self.d)
2772 fetcher.download() 2922 fetcher.download()
2773 fetcher.unpack(self.unpackdir) 2923 fetcher.unpack(self.unpackdir)
2774 unpackdir = os.path.join(self.unpackdir, 'npm') 2924 unpackdir = os.path.join(self.unpackdir, 'npm')
@@ -2777,8 +2927,8 @@ class NPMTest(FetcherTest):
2777 @skipIfNoNpm() 2927 @skipIfNoNpm()
2778 @skipIfNoNetwork() 2928 @skipIfNoNetwork()
2779 def test_npm_version_latest(self): 2929 def test_npm_version_latest(self):
2780 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=latest' 2930 url = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=latest']
2781 fetcher = bb.fetch.Fetch([url], self.d) 2931 fetcher = bb.fetch.Fetch(url, self.d)
2782 fetcher.download() 2932 fetcher.download()
2783 fetcher.unpack(self.unpackdir) 2933 fetcher.unpack(self.unpackdir)
2784 unpackdir = os.path.join(self.unpackdir, 'npm') 2934 unpackdir = os.path.join(self.unpackdir, 'npm')
@@ -2787,46 +2937,46 @@ class NPMTest(FetcherTest):
2787 @skipIfNoNpm() 2937 @skipIfNoNpm()
2788 @skipIfNoNetwork() 2938 @skipIfNoNetwork()
2789 def test_npm_registry_invalid(self): 2939 def test_npm_registry_invalid(self):
2790 url = 'npm://registry.invalid.org;package=@savoirfairelinux/node-server-example;version=1.0.0' 2940 urls = ['npm://registry.invalid.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
2791 fetcher = bb.fetch.Fetch([url], self.d) 2941 fetcher = bb.fetch.Fetch(urls, self.d)
2792 with self.assertRaises(bb.fetch2.FetchError): 2942 with self.assertRaises(bb.fetch2.FetchError):
2793 fetcher.download() 2943 fetcher.download()
2794 2944
2795 @skipIfNoNpm() 2945 @skipIfNoNpm()
2796 @skipIfNoNetwork() 2946 @skipIfNoNetwork()
2797 def test_npm_package_invalid(self): 2947 def test_npm_package_invalid(self):
2798 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/invalid;version=1.0.0' 2948 urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/invalid;version=1.0.0']
2799 fetcher = bb.fetch.Fetch([url], self.d) 2949 fetcher = bb.fetch.Fetch(urls, self.d)
2800 with self.assertRaises(bb.fetch2.FetchError): 2950 with self.assertRaises(bb.fetch2.FetchError):
2801 fetcher.download() 2951 fetcher.download()
2802 2952
2803 @skipIfNoNpm() 2953 @skipIfNoNpm()
2804 @skipIfNoNetwork() 2954 @skipIfNoNetwork()
2805 def test_npm_version_invalid(self): 2955 def test_npm_version_invalid(self):
2806 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=invalid' 2956 urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=invalid']
2807 with self.assertRaises(bb.fetch2.ParameterError): 2957 with self.assertRaises(bb.fetch2.ParameterError):
2808 fetcher = bb.fetch.Fetch([url], self.d) 2958 fetcher = bb.fetch.Fetch(urls, self.d)
2809 2959
2810 @skipIfNoNpm() 2960 @skipIfNoNpm()
2811 @skipIfNoNetwork() 2961 @skipIfNoNetwork()
2812 def test_npm_registry_none(self): 2962 def test_npm_registry_none(self):
2813 url = 'npm://;package=@savoirfairelinux/node-server-example;version=1.0.0' 2963 urls = ['npm://;package=@savoirfairelinux/node-server-example;version=1.0.0']
2814 with self.assertRaises(bb.fetch2.MalformedUrl): 2964 with self.assertRaises(bb.fetch2.MalformedUrl):
2815 fetcher = bb.fetch.Fetch([url], self.d) 2965 fetcher = bb.fetch.Fetch(urls, self.d)
2816 2966
2817 @skipIfNoNpm() 2967 @skipIfNoNpm()
2818 @skipIfNoNetwork() 2968 @skipIfNoNetwork()
2819 def test_npm_package_none(self): 2969 def test_npm_package_none(self):
2820 url = 'npm://registry.npmjs.org;version=1.0.0' 2970 urls = ['npm://registry.npmjs.org;version=1.0.0']
2821 with self.assertRaises(bb.fetch2.MissingParameterError): 2971 with self.assertRaises(bb.fetch2.MissingParameterError):
2822 fetcher = bb.fetch.Fetch([url], self.d) 2972 fetcher = bb.fetch.Fetch(urls, self.d)
2823 2973
2824 @skipIfNoNpm() 2974 @skipIfNoNpm()
2825 @skipIfNoNetwork() 2975 @skipIfNoNetwork()
2826 def test_npm_version_none(self): 2976 def test_npm_version_none(self):
2827 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example' 2977 urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example']
2828 with self.assertRaises(bb.fetch2.MissingParameterError): 2978 with self.assertRaises(bb.fetch2.MissingParameterError):
2829 fetcher = bb.fetch.Fetch([url], self.d) 2979 fetcher = bb.fetch.Fetch(urls, self.d)
2830 2980
2831 def create_shrinkwrap_file(self, data): 2981 def create_shrinkwrap_file(self, data):
2832 import json 2982 import json
@@ -2835,32 +2985,30 @@ class NPMTest(FetcherTest):
2835 bb.utils.mkdirhier(datadir) 2985 bb.utils.mkdirhier(datadir)
2836 with open(swfile, 'w') as f: 2986 with open(swfile, 'w') as f:
2837 json.dump(data, f) 2987 json.dump(data, f)
2838 # Also configure the S directory
2839 self.sdir = os.path.join(self.unpackdir, 'S')
2840 self.d.setVar('S', self.sdir)
2841 return swfile 2988 return swfile
2842 2989
2843 @skipIfNoNpm()
2844 @skipIfNoNetwork() 2990 @skipIfNoNetwork()
2845 def test_npmsw(self): 2991 def test_npmsw(self):
2846 swfile = self.create_shrinkwrap_file({ 2992 swfile = self.create_shrinkwrap_file({
2847 'dependencies': { 2993 'packages': {
2848 'array-flatten': { 2994 'node_modules/array-flatten': {
2849 'version': '1.1.1', 2995 'version': '1.1.1',
2850 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', 2996 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2851 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=', 2997 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=',
2852 'dependencies': { 2998 'dependencies': {
2853 'content-type': { 2999 'content-type': "1.0.4"
2854 'version': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz', 3000 }
2855 'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==', 3001 },
2856 'dependencies': { 3002 'node_modules/array-flatten/node_modules/content-type': {
2857 'cookie': { 3003 'version': '1.0.4',
2858 'version': 'git+https://github.com/jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09', 3004 'resolved': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz',
2859 'from': 'git+https://github.com/jshttp/cookie.git' 3005 'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==',
2860 } 3006 'dependencies': {
2861 } 3007 'cookie': 'git+https://github.com/jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09'
2862 }
2863 } 3008 }
3009 },
3010 'node_modules/array-flatten/node_modules/content-type/node_modules/cookie': {
3011 'resolved': 'git+https://github.com/jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09'
2864 } 3012 }
2865 } 3013 }
2866 }) 3014 })
@@ -2870,31 +3018,17 @@ class NPMTest(FetcherTest):
2870 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz'))) 3018 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz')))
2871 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'github.com.jshttp.cookie.git'))) 3019 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'github.com.jshttp.cookie.git')))
2872 fetcher.unpack(self.unpackdir) 3020 fetcher.unpack(self.unpackdir)
2873 self.assertTrue(os.path.exists(os.path.join(self.sdir, 'npm-shrinkwrap.json'))) 3021 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'npm-shrinkwrap.json')))
2874 self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'package.json'))) 3022 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'node_modules', 'array-flatten', 'package.json')))
2875 self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'node_modules', 'content-type', 'package.json'))) 3023 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'node_modules', 'array-flatten', 'node_modules', 'content-type', 'package.json')))
2876 self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'node_modules', 'content-type', 'node_modules', 'cookie', 'package.json'))) 3024 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'node_modules', 'array-flatten', 'node_modules', 'content-type', 'node_modules', 'cookie', 'package.json')))
2877 3025
2878 @skipIfNoNpm()
2879 @skipIfNoNetwork() 3026 @skipIfNoNetwork()
2880 def test_npmsw_git(self): 3027 def test_npmsw_git(self):
2881 swfile = self.create_shrinkwrap_file({ 3028 swfile = self.create_shrinkwrap_file({
2882 'dependencies': { 3029 'packages': {
2883 'cookie': { 3030 'node_modules/cookie': {
2884 'version': 'github:jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09', 3031 'resolved': 'git+https://github.com/jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09'
2885 'from': 'github:jshttp/cookie.git'
2886 }
2887 }
2888 })
2889 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2890 fetcher.download()
2891 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'github.com.jshttp.cookie.git')))
2892
2893 swfile = self.create_shrinkwrap_file({
2894 'dependencies': {
2895 'cookie': {
2896 'version': 'jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09',
2897 'from': 'jshttp/cookie.git'
2898 } 3032 }
2899 } 3033 }
2900 }) 3034 })
@@ -2902,29 +3036,16 @@ class NPMTest(FetcherTest):
2902 fetcher.download() 3036 fetcher.download()
2903 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'github.com.jshttp.cookie.git'))) 3037 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'github.com.jshttp.cookie.git')))
2904 3038
2905 swfile = self.create_shrinkwrap_file({
2906 'dependencies': {
2907 'nodejs': {
2908 'version': 'gitlab:gitlab-examples/nodejs.git#892a1f16725e56cc3a2cb0d677be42935c8fc262',
2909 'from': 'gitlab:gitlab-examples/nodejs'
2910 }
2911 }
2912 })
2913 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2914 fetcher.download()
2915 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'gitlab.com.gitlab-examples.nodejs.git')))
2916
2917 @skipIfNoNpm()
2918 @skipIfNoNetwork() 3039 @skipIfNoNetwork()
2919 def test_npmsw_dev(self): 3040 def test_npmsw_dev(self):
2920 swfile = self.create_shrinkwrap_file({ 3041 swfile = self.create_shrinkwrap_file({
2921 'dependencies': { 3042 'packages': {
2922 'array-flatten': { 3043 'node_modules/array-flatten': {
2923 'version': '1.1.1', 3044 'version': '1.1.1',
2924 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', 3045 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2925 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' 3046 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
2926 }, 3047 },
2927 'content-type': { 3048 'node_modules/content-type': {
2928 'version': '1.0.4', 3049 'version': '1.0.4',
2929 'resolved': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz', 3050 'resolved': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz',
2930 'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==', 3051 'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==',
@@ -2943,12 +3064,11 @@ class NPMTest(FetcherTest):
2943 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz'))) 3064 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')))
2944 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz'))) 3065 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz')))
2945 3066
2946 @skipIfNoNpm()
2947 @skipIfNoNetwork() 3067 @skipIfNoNetwork()
2948 def test_npmsw_destsuffix(self): 3068 def test_npmsw_destsuffix(self):
2949 swfile = self.create_shrinkwrap_file({ 3069 swfile = self.create_shrinkwrap_file({
2950 'dependencies': { 3070 'packages': {
2951 'array-flatten': { 3071 'node_modules/array-flatten': {
2952 'version': '1.1.1', 3072 'version': '1.1.1',
2953 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', 3073 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2954 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' 3074 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
@@ -2962,8 +3082,8 @@ class NPMTest(FetcherTest):
2962 3082
2963 def test_npmsw_no_network_no_tarball(self): 3083 def test_npmsw_no_network_no_tarball(self):
2964 swfile = self.create_shrinkwrap_file({ 3084 swfile = self.create_shrinkwrap_file({
2965 'dependencies': { 3085 'packages': {
2966 'array-flatten': { 3086 'node_modules/array-flatten': {
2967 'version': '1.1.1', 3087 'version': '1.1.1',
2968 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', 3088 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2969 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' 3089 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
@@ -2985,8 +3105,8 @@ class NPMTest(FetcherTest):
2985 self.d.setVar('BB_NO_NETWORK', '1') 3105 self.d.setVar('BB_NO_NETWORK', '1')
2986 # Fetch again 3106 # Fetch again
2987 swfile = self.create_shrinkwrap_file({ 3107 swfile = self.create_shrinkwrap_file({
2988 'dependencies': { 3108 'packages': {
2989 'array-flatten': { 3109 'node_modules/array-flatten': {
2990 'version': '1.1.1', 3110 'version': '1.1.1',
2991 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', 3111 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
2992 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' 3112 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
@@ -2996,15 +3116,14 @@ class NPMTest(FetcherTest):
2996 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d) 3116 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2997 fetcher.download() 3117 fetcher.download()
2998 fetcher.unpack(self.unpackdir) 3118 fetcher.unpack(self.unpackdir)
2999 self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'package.json'))) 3119 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'node_modules', 'array-flatten', 'package.json')))
3000 3120
3001 @skipIfNoNpm()
3002 @skipIfNoNetwork() 3121 @skipIfNoNetwork()
3003 def test_npmsw_npm_reusability(self): 3122 def test_npmsw_npm_reusability(self):
3004 # Fetch once with npmsw 3123 # Fetch once with npmsw
3005 swfile = self.create_shrinkwrap_file({ 3124 swfile = self.create_shrinkwrap_file({
3006 'dependencies': { 3125 'packages': {
3007 'array-flatten': { 3126 'node_modules/array-flatten': {
3008 'version': '1.1.1', 3127 'version': '1.1.1',
3009 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', 3128 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
3010 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' 3129 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
@@ -3021,13 +3140,12 @@ class NPMTest(FetcherTest):
3021 fetcher.unpack(self.unpackdir) 3140 fetcher.unpack(self.unpackdir)
3022 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'npm', 'package.json'))) 3141 self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'npm', 'package.json')))
3023 3142
3024 @skipIfNoNpm()
3025 @skipIfNoNetwork() 3143 @skipIfNoNetwork()
3026 def test_npmsw_bad_checksum(self): 3144 def test_npmsw_bad_checksum(self):
3027 # Try to fetch with bad checksum 3145 # Try to fetch with bad checksum
3028 swfile = self.create_shrinkwrap_file({ 3146 swfile = self.create_shrinkwrap_file({
3029 'dependencies': { 3147 'packages': {
3030 'array-flatten': { 3148 'node_modules/array-flatten': {
3031 'version': '1.1.1', 3149 'version': '1.1.1',
3032 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', 3150 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
3033 'integrity': 'sha1-gfNEp2hqgLTFKT6P3AsBYMgsBqg=' 3151 'integrity': 'sha1-gfNEp2hqgLTFKT6P3AsBYMgsBqg='
@@ -3039,8 +3157,8 @@ class NPMTest(FetcherTest):
3039 fetcher.download() 3157 fetcher.download()
3040 # Fetch correctly to get a tarball 3158 # Fetch correctly to get a tarball
3041 swfile = self.create_shrinkwrap_file({ 3159 swfile = self.create_shrinkwrap_file({
3042 'dependencies': { 3160 'packages': {
3043 'array-flatten': { 3161 'node_modules/array-flatten': {
3044 'version': '1.1.1', 3162 'version': '1.1.1',
3045 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', 3163 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
3046 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' 3164 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
@@ -3078,8 +3196,8 @@ class NPMTest(FetcherTest):
3078 # Fetch again 3196 # Fetch again
3079 self.assertFalse(os.path.exists(ud.localpath)) 3197 self.assertFalse(os.path.exists(ud.localpath))
3080 swfile = self.create_shrinkwrap_file({ 3198 swfile = self.create_shrinkwrap_file({
3081 'dependencies': { 3199 'packages': {
3082 'array-flatten': { 3200 'node_modules/array-flatten': {
3083 'version': '1.1.1', 3201 'version': '1.1.1',
3084 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', 3202 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
3085 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' 3203 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
@@ -3106,8 +3224,8 @@ class NPMTest(FetcherTest):
3106 # Fetch again with invalid url 3224 # Fetch again with invalid url
3107 self.assertFalse(os.path.exists(ud.localpath)) 3225 self.assertFalse(os.path.exists(ud.localpath))
3108 swfile = self.create_shrinkwrap_file({ 3226 swfile = self.create_shrinkwrap_file({
3109 'dependencies': { 3227 'packages': {
3110 'array-flatten': { 3228 'node_modules/array-flatten': {
3111 'version': '1.1.1', 3229 'version': '1.1.1',
3112 'resolved': 'https://invalid', 3230 'resolved': 'https://invalid',
3113 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' 3231 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
@@ -3118,6 +3236,28 @@ class NPMTest(FetcherTest):
3118 fetcher.download() 3236 fetcher.download()
3119 self.assertTrue(os.path.exists(ud.localpath)) 3237 self.assertTrue(os.path.exists(ud.localpath))
3120 3238
3239 @skipIfNoNetwork()
3240 def test_npmsw_bundled(self):
3241 swfile = self.create_shrinkwrap_file({
3242 'packages': {
3243 'node_modules/array-flatten': {
3244 'version': '1.1.1',
3245 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
3246 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
3247 },
3248 'node_modules/content-type': {
3249 'version': '1.0.4',
3250 'resolved': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz',
3251 'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==',
3252 'inBundle': True
3253 }
3254 }
3255 })
3256 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
3257 fetcher.download()
3258 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')))
3259 self.assertFalse(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz')))
3260
3121class GitSharedTest(FetcherTest): 3261class GitSharedTest(FetcherTest):
3122 def setUp(self): 3262 def setUp(self):
3123 super(GitSharedTest, self).setUp() 3263 super(GitSharedTest, self).setUp()
@@ -3145,6 +3285,72 @@ class GitSharedTest(FetcherTest):
3145 alt = os.path.join(self.unpackdir, 'git/.git/objects/info/alternates') 3285 alt = os.path.join(self.unpackdir, 'git/.git/objects/info/alternates')
3146 self.assertFalse(os.path.exists(alt)) 3286 self.assertFalse(os.path.exists(alt))
3147 3287
3288class GitTagVerificationTests(FetcherTest):
3289
3290 @skipIfNoNetwork()
3291 def test_tag_rev_match(self):
3292 # Test a url with rev= and tag= set works
3293 fetcher = bb.fetch.Fetch(["git://git.openembedded.org/bitbake;branch=2.8;protocol=https;rev=aa0e540fc31a1c26839efd2c7785a751ce24ebfb;tag=2.8.7"], self.d)
3294 fetcher.download()
3295 fetcher.unpack(self.unpackdir)
3296
3297 def test_annotated_tag_rev_match(self):
3298 # Test a url with rev= and tag= set works
3299 # rev is the annotated tag revision in this case
3300 fetcher = bb.fetch.Fetch(["git://git.openembedded.org/bitbake;branch=2.8;protocol=https;rev=6d363159e4b7dc566fc40d069b2615e61774a7d8;tag=2.8.7"], self.d)
3301 fetcher.download()
3302 fetcher.unpack(self.unpackdir)
3303
3304 @skipIfNoNetwork()
3305 def test_tag_rev_match2(self):
3306 # Test a url with SRCREV and tag= set works
3307 self.d.setVar('SRCREV', 'aa0e540fc31a1c26839efd2c7785a751ce24ebfb')
3308 fetcher = bb.fetch.Fetch(["git://git.openembedded.org/bitbake;branch=2.8;protocol=https;tag=2.8.7"], self.d)
3309 fetcher.download()
3310 fetcher.unpack(self.unpackdir)
3311
3312 @skipIfNoNetwork()
3313 def test_tag_rev_match3(self):
3314 # Test a url with SRCREV, rev= and tag= set works
3315 self.d.setVar('SRCREV', 'aa0e540fc31a1c26839efd2c7785a751ce24ebfb')
3316 fetcher = bb.fetch.Fetch(["git://git.openembedded.org/bitbake;branch=2.8;protocol=https;rev=aa0e540fc31a1c26839efd2c7785a751ce24ebfb;tag=2.8.7"], self.d)
3317 fetcher.download()
3318 fetcher.unpack(self.unpackdir)
3319
3320 @skipIfNoNetwork()
3321 def test_tag_rev_match4(self):
3322 # Test a url with SRCREV and rev= mismatching errors
3323 self.d.setVar('SRCREV', 'bade540fc31a1c26839efd2c7785a751ce24ebfb')
3324 with self.assertRaises(bb.fetch2.FetchError):
3325 fetcher = bb.fetch.Fetch(["git://git.openembedded.org/bitbake;branch=2.8;protocol=https;rev=aa0e540fc31a1c26839efd2c7785a751ce24ebfb;tag=2.8.7"], self.d)
3326
3327 @skipIfNoNetwork()
3328 def test_tag_rev_match5(self):
3329 # Test a url with SRCREV, rev= and tag= set works when using shallow clones
3330 self.d.setVar('BB_GIT_SHALLOW', '1')
3331 self.d.setVar('SRCREV', 'aa0e540fc31a1c26839efd2c7785a751ce24ebfb')
3332 fetcher = bb.fetch.Fetch(["git://git.openembedded.org/bitbake;branch=2.8;protocol=https;rev=aa0e540fc31a1c26839efd2c7785a751ce24ebfb;tag=2.8.7"], self.d)
3333 fetcher.download()
3334 fetcher.unpack(self.unpackdir)
3335
3336 @skipIfNoNetwork()
3337 def test_tag_rev_match6(self):
3338 # Test a url with SRCREV, rev= and a mismatched tag= when using shallow clones
3339 self.d.setVar('BB_GIT_SHALLOW', '1')
3340 fetcher = bb.fetch.Fetch(["git://git.openembedded.org/bitbake;branch=2.8;protocol=https;rev=aa0e540fc31a1c26839efd2c7785a751ce24ebfb;tag=2.8.6"], self.d)
3341 fetcher.download()
3342 with self.assertRaises(bb.fetch2.FetchError):
3343 fetcher.unpack(self.unpackdir)
3344
3345 @skipIfNoNetwork()
3346 def test_tag_rev_match7(self):
3347 # Test a url with SRCREV, rev= and a mismatched tag=
3348 self.d.setVar('SRCREV', 'aa0e540fc31a1c26839efd2c7785a751ce24ebfb')
3349 fetcher = bb.fetch.Fetch(["git://git.openembedded.org/bitbake;branch=2.8;protocol=https;rev=aa0e540fc31a1c26839efd2c7785a751ce24ebfb;tag=2.8.6"], self.d)
3350 fetcher.download()
3351 with self.assertRaises(bb.fetch2.FetchError):
3352 fetcher.unpack(self.unpackdir)
3353
3148 3354
3149class FetchPremirroronlyLocalTest(FetcherTest): 3355class FetchPremirroronlyLocalTest(FetcherTest):
3150 3356
@@ -3227,58 +3433,6 @@ class FetchPremirroronlyLocalTest(FetcherTest):
3227 with self.assertRaises(bb.fetch2.NetworkAccess): 3433 with self.assertRaises(bb.fetch2.NetworkAccess):
3228 fetcher.download() 3434 fetcher.download()
3229 3435
3230 def test_mirror_tarball_multiple_branches(self):
3231 """
3232 test if PREMIRRORS can handle multiple name/branches correctly
3233 both branches have required revisions
3234 """
3235 self.make_git_repo()
3236 branch1rev = self.git_new_branch("testbranch1")
3237 branch2rev = self.git_new_branch("testbranch2")
3238 self.recipe_url = "git://git.fake.repo/bitbake;branch=testbranch1,testbranch2;protocol=https;name=branch1,branch2"
3239 self.d.setVar("SRCREV_branch1", branch1rev)
3240 self.d.setVar("SRCREV_branch2", branch2rev)
3241 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3242 self.assertTrue(os.path.exists(self.mirrorfile), "Mirror file doesn't exist")
3243 fetcher.download()
3244 fetcher.unpack(os.path.join(self.tempdir, "unpacked"))
3245 unpacked = os.path.join(self.tempdir, "unpacked", "git", self.testfilename)
3246 self.assertTrue(os.path.exists(unpacked), "Repo has not been unpackaged properly!")
3247 with open(unpacked, 'r') as f:
3248 content = f.read()
3249 ## We expect to see testbranch1 in the file, not master, not testbranch2
3250 self.assertTrue(content.find("testbranch1") != -1, "Wrong branch has been checked out!")
3251
3252 def test_mirror_tarball_multiple_branches_nobranch(self):
3253 """
3254 test if PREMIRRORS can handle multiple name/branches correctly
3255 Unbalanced name/branches raises ParameterError
3256 """
3257 self.make_git_repo()
3258 branch1rev = self.git_new_branch("testbranch1")
3259 branch2rev = self.git_new_branch("testbranch2")
3260 self.recipe_url = "git://git.fake.repo/bitbake;branch=testbranch1;protocol=https;name=branch1,branch2"
3261 self.d.setVar("SRCREV_branch1", branch1rev)
3262 self.d.setVar("SRCREV_branch2", branch2rev)
3263 with self.assertRaises(bb.fetch2.ParameterError):
3264 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3265
3266 def test_mirror_tarball_multiple_branches_norev(self):
3267 """
3268 test if PREMIRRORS can handle multiple name/branches correctly
3269 one of the branches specifies non existing SRCREV
3270 """
3271 self.make_git_repo()
3272 branch1rev = self.git_new_branch("testbranch1")
3273 branch2rev = self.git_new_branch("testbranch2")
3274 self.recipe_url = "git://git.fake.repo/bitbake;branch=testbranch1,testbranch2;protocol=https;name=branch1,branch2"
3275 self.d.setVar("SRCREV_branch1", branch1rev)
3276 self.d.setVar("SRCREV_branch2", "0"*40)
3277 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3278 self.assertTrue(os.path.exists(self.mirrorfile), "Mirror file doesn't exist")
3279 with self.assertRaises(bb.fetch2.NetworkAccess):
3280 fetcher.download()
3281
3282 3436
3283class FetchPremirroronlyNetworkTest(FetcherTest): 3437class FetchPremirroronlyNetworkTest(FetcherTest):
3284 3438
@@ -3289,16 +3443,16 @@ class FetchPremirroronlyNetworkTest(FetcherTest):
3289 self.reponame = "fstests" 3443 self.reponame = "fstests"
3290 self.clonedir = os.path.join(self.tempdir, "git") 3444 self.clonedir = os.path.join(self.tempdir, "git")
3291 self.gitdir = os.path.join(self.tempdir, "git", "{}.git".format(self.reponame)) 3445 self.gitdir = os.path.join(self.tempdir, "git", "{}.git".format(self.reponame))
3292 self.recipe_url = "git://git.yoctoproject.org/fstests;protocol=https" 3446 self.recipe_url = "git://git.yoctoproject.org/fstests;protocol=https;branch=master"
3293 self.d.setVar("BB_FETCH_PREMIRRORONLY", "1") 3447 self.d.setVar("BB_FETCH_PREMIRRORONLY", "1")
3294 self.d.setVar("BB_NO_NETWORK", "0") 3448 self.d.setVar("BB_NO_NETWORK", "0")
3295 self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n") 3449 self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n")
3296 3450
3297 def make_git_repo(self): 3451 def make_git_repo(self):
3298 import shutil
3299 self.mirrorname = "git2_git.yoctoproject.org.fstests.tar.gz" 3452 self.mirrorname = "git2_git.yoctoproject.org.fstests.tar.gz"
3300 os.makedirs(self.clonedir) 3453 os.makedirs(self.clonedir)
3301 self.git("clone --bare --shallow-since=\"01.01.2013\" {}".format(self.recipe_url), self.clonedir) 3454 self.git("clone --bare {}".format(self.recipe_url), self.clonedir)
3455 self.git("update-ref HEAD 15413486df1f5a5b5af699b6f3ba5f0984e52a9f", self.gitdir)
3302 bb.process.run('tar -czvf {} .'.format(os.path.join(self.mirrordir, self.mirrorname)), cwd = self.gitdir) 3456 bb.process.run('tar -czvf {} .'.format(os.path.join(self.mirrordir, self.mirrorname)), cwd = self.gitdir)
3303 shutil.rmtree(self.clonedir) 3457 shutil.rmtree(self.clonedir)
3304 3458
@@ -3306,7 +3460,7 @@ class FetchPremirroronlyNetworkTest(FetcherTest):
3306 def test_mirror_tarball_updated(self): 3460 def test_mirror_tarball_updated(self):
3307 self.make_git_repo() 3461 self.make_git_repo()
3308 ## Upstream commit is in the mirror 3462 ## Upstream commit is in the mirror
3309 self.d.setVar("SRCREV", "49d65d53c2bf558ae6e9185af0f3af7b79d255ec") 3463 self.d.setVar("SRCREV", "15413486df1f5a5b5af699b6f3ba5f0984e52a9f")
3310 fetcher = bb.fetch.Fetch([self.recipe_url], self.d) 3464 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3311 fetcher.download() 3465 fetcher.download()
3312 3466
@@ -3314,7 +3468,7 @@ class FetchPremirroronlyNetworkTest(FetcherTest):
3314 def test_mirror_tarball_outdated(self): 3468 def test_mirror_tarball_outdated(self):
3315 self.make_git_repo() 3469 self.make_git_repo()
3316 ## Upstream commit not in the mirror 3470 ## Upstream commit not in the mirror
3317 self.d.setVar("SRCREV", "15413486df1f5a5b5af699b6f3ba5f0984e52a9f") 3471 self.d.setVar("SRCREV", "49d65d53c2bf558ae6e9185af0f3af7b79d255ec")
3318 fetcher = bb.fetch.Fetch([self.recipe_url], self.d) 3472 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3319 with self.assertRaises(bb.fetch2.NetworkAccess): 3473 with self.assertRaises(bb.fetch2.NetworkAccess):
3320 fetcher.download() 3474 fetcher.download()
@@ -3324,7 +3478,6 @@ class FetchPremirroronlyMercurialTest(FetcherTest):
3324 the test covers also basic hg:// clone (see fetch_and_create_tarball 3478 the test covers also basic hg:// clone (see fetch_and_create_tarball
3325 """ 3479 """
3326 def skipIfNoHg(): 3480 def skipIfNoHg():
3327 import shutil
3328 if not shutil.which('hg'): 3481 if not shutil.which('hg'):
3329 return unittest.skip('Mercurial not installed') 3482 return unittest.skip('Mercurial not installed')
3330 return lambda f: f 3483 return lambda f: f
@@ -3371,7 +3524,7 @@ class FetchPremirroronlyBrokenTarball(FetcherTest):
3371 os.mkdir(self.mirrordir) 3524 os.mkdir(self.mirrordir)
3372 self.reponame = "bitbake" 3525 self.reponame = "bitbake"
3373 self.gitdir = os.path.join(self.tempdir, "git", self.reponame) 3526 self.gitdir = os.path.join(self.tempdir, "git", self.reponame)
3374 self.recipe_url = "git://git.fake.repo/bitbake;protocol=https" 3527 self.recipe_url = "git://git.fake.repo/bitbake;protocol=https;branch=master"
3375 self.d.setVar("BB_FETCH_PREMIRRORONLY", "1") 3528 self.d.setVar("BB_FETCH_PREMIRRORONLY", "1")
3376 self.d.setVar("BB_NO_NETWORK", "1") 3529 self.d.setVar("BB_NO_NETWORK", "1")
3377 self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n") 3530 self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n")
@@ -3380,10 +3533,223 @@ class FetchPremirroronlyBrokenTarball(FetcherTest):
3380 targz.write("This is not tar.gz file!") 3533 targz.write("This is not tar.gz file!")
3381 3534
3382 def test_mirror_broken_download(self): 3535 def test_mirror_broken_download(self):
3383 import sys
3384 self.d.setVar("SRCREV", "0"*40) 3536 self.d.setVar("SRCREV", "0"*40)
3385 fetcher = bb.fetch.Fetch([self.recipe_url], self.d) 3537 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3386 with self.assertRaises(bb.fetch2.FetchError), self.assertLogs() as logs: 3538 with self.assertRaises(bb.fetch2.FetchError), self.assertLogs() as logs:
3387 fetcher.download() 3539 fetcher.download()
3388 output = "".join(logs.output) 3540 output = "".join(logs.output)
3389 self.assertFalse(" not a git repository (or any parent up to mount point /)" in output) 3541 self.assertFalse(" not a git repository (or any parent up to mount point /)" in output)
3542
3543class GoModTest(FetcherTest):
3544
3545 @skipIfNoNetwork()
3546 def test_gomod_url(self):
3547 urls = ['gomod://github.com/Azure/azure-sdk-for-go/sdk/storage/azblob;version=v1.0.0;'
3548 'sha256sum=9bb69aea32f1d59711701f9562d66432c9c0374205e5009d1d1a62f03fb4fdad']
3549
3550 fetcher = bb.fetch2.Fetch(urls, self.d)
3551 ud = fetcher.ud[urls[0]]
3552 self.assertEqual(ud.url, 'https://proxy.golang.org/github.com/%21azure/azure-sdk-for-go/sdk/storage/azblob/%40v/v1.0.0.zip')
3553 self.assertEqual(ud.parm['downloadfilename'], 'github.com.Azure.azure-sdk-for-go.sdk.storage.azblob@v1.0.0.zip')
3554 self.assertEqual(ud.parm['name'], 'github.com/Azure/azure-sdk-for-go/sdk/storage/azblob@v1.0.0')
3555
3556 fetcher.download()
3557 fetcher.unpack(self.unpackdir)
3558 downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
3559 self.assertTrue(os.path.exists(os.path.join(downloaddir, 'github.com/!azure/azure-sdk-for-go/sdk/storage/azblob/@v/v1.0.0.zip')))
3560 self.assertTrue(os.path.exists(os.path.join(downloaddir, 'github.com/!azure/azure-sdk-for-go/sdk/storage/azblob/@v/v1.0.0.mod')))
3561 self.assertEqual(bb.utils.sha256_file(os.path.join(downloaddir, 'github.com/!azure/azure-sdk-for-go/sdk/storage/azblob/@v/v1.0.0.mod')),
3562 '7873b8544842329b4f385a3aa6cf82cc2bc8defb41a04fa5291c35fd5900e873')
3563
3564 @skipIfNoNetwork()
3565 def test_gomod_url_go_mod_only(self):
3566 urls = ['gomod://github.com/Azure/azure-sdk-for-go/sdk/storage/azblob;version=v1.0.0;mod=1;'
3567 'sha256sum=7873b8544842329b4f385a3aa6cf82cc2bc8defb41a04fa5291c35fd5900e873']
3568
3569 fetcher = bb.fetch2.Fetch(urls, self.d)
3570 ud = fetcher.ud[urls[0]]
3571 self.assertEqual(ud.url, 'https://proxy.golang.org/github.com/%21azure/azure-sdk-for-go/sdk/storage/azblob/%40v/v1.0.0.mod')
3572 self.assertEqual(ud.parm['downloadfilename'], 'github.com.Azure.azure-sdk-for-go.sdk.storage.azblob@v1.0.0.mod')
3573 self.assertEqual(ud.parm['name'], 'github.com/Azure/azure-sdk-for-go/sdk/storage/azblob@v1.0.0')
3574
3575 fetcher.download()
3576 fetcher.unpack(self.unpackdir)
3577 downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
3578 self.assertTrue(os.path.exists(os.path.join(downloaddir, 'github.com/!azure/azure-sdk-for-go/sdk/storage/azblob/@v/v1.0.0.mod')))
3579
3580 @skipIfNoNetwork()
3581 def test_gomod_url_sha256sum_varflag(self):
3582 urls = ['gomod://gopkg.in/ini.v1;version=v1.67.0']
3583 self.d.setVarFlag('SRC_URI', 'gopkg.in/ini.v1@v1.67.0.sha256sum', 'bd845dfc762a87a56e5a32a07770dc83e86976db7705d7f89c5dbafdc60b06c6')
3584
3585 fetcher = bb.fetch2.Fetch(urls, self.d)
3586 ud = fetcher.ud[urls[0]]
3587 self.assertEqual(ud.url, 'https://proxy.golang.org/gopkg.in/ini.v1/%40v/v1.67.0.zip')
3588 self.assertEqual(ud.parm['downloadfilename'], 'gopkg.in.ini.v1@v1.67.0.zip')
3589 self.assertEqual(ud.parm['name'], 'gopkg.in/ini.v1@v1.67.0')
3590
3591 fetcher.download()
3592 fetcher.unpack(self.unpackdir)
3593 downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
3594 self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.zip')))
3595 self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.mod')))
3596 self.assertEqual(bb.utils.sha256_file(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.mod')),
3597 '13aedd85db8e555104108e0e613bb7e4d1242af7f27c15423dd9ab63b60b72a1')
3598
3599 @skipIfNoNetwork()
3600 def test_gomod_url_no_go_mod_in_module(self):
3601 urls = ['gomod://gopkg.in/ini.v1;version=v1.67.0;'
3602 'sha256sum=bd845dfc762a87a56e5a32a07770dc83e86976db7705d7f89c5dbafdc60b06c6']
3603
3604 fetcher = bb.fetch2.Fetch(urls, self.d)
3605 ud = fetcher.ud[urls[0]]
3606 self.assertEqual(ud.url, 'https://proxy.golang.org/gopkg.in/ini.v1/%40v/v1.67.0.zip')
3607 self.assertEqual(ud.parm['downloadfilename'], 'gopkg.in.ini.v1@v1.67.0.zip')
3608 self.assertEqual(ud.parm['name'], 'gopkg.in/ini.v1@v1.67.0')
3609
3610 fetcher.download()
3611 fetcher.unpack(self.unpackdir)
3612 downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
3613 self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.zip')))
3614 self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.mod')))
3615 self.assertEqual(bb.utils.sha256_file(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.mod')),
3616 '13aedd85db8e555104108e0e613bb7e4d1242af7f27c15423dd9ab63b60b72a1')
3617
3618 @skipIfNoNetwork()
3619 def test_gomod_url_host_only(self):
3620 urls = ['gomod://go.opencensus.io;version=v0.24.0;'
3621 'sha256sum=203a767d7f8e7c1ebe5588220ad168d1e15b14ae70a636de7ca9a4a88a7e0d0c']
3622
3623 fetcher = bb.fetch2.Fetch(urls, self.d)
3624 ud = fetcher.ud[urls[0]]
3625 self.assertEqual(ud.url, 'https://proxy.golang.org/go.opencensus.io/%40v/v0.24.0.zip')
3626 self.assertEqual(ud.parm['downloadfilename'], 'go.opencensus.io@v0.24.0.zip')
3627 self.assertEqual(ud.parm['name'], 'go.opencensus.io@v0.24.0')
3628
3629 fetcher.download()
3630 fetcher.unpack(self.unpackdir)
3631 downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
3632 self.assertTrue(os.path.exists(os.path.join(downloaddir, 'go.opencensus.io/@v/v0.24.0.zip')))
3633 self.assertTrue(os.path.exists(os.path.join(downloaddir, 'go.opencensus.io/@v/v0.24.0.mod')))
3634 self.assertEqual(bb.utils.sha256_file(os.path.join(downloaddir, 'go.opencensus.io/@v/v0.24.0.mod')),
3635 '0dc9ccc660ad21cebaffd548f2cc6efa27891c68b4fbc1f8a3893b00f1acec96')
3636
3637class GoModGitTest(FetcherTest):
3638
3639 @skipIfNoNetwork()
3640 def test_gomodgit_url_repo(self):
3641 urls = ['gomodgit://golang.org/x/net;version=v0.9.0;'
3642 'repo=go.googlesource.com/net;'
3643 'srcrev=694cff8668bac64e0864b552bffc280cd27f21b1']
3644
3645 fetcher = bb.fetch2.Fetch(urls, self.d)
3646 ud = fetcher.ud[urls[0]]
3647 self.assertEqual(ud.host, 'go.googlesource.com')
3648 self.assertEqual(ud.path, '/net')
3649 self.assertEqual(ud.name, 'golang.org/x/net@v0.9.0')
3650 self.assertEqual(self.d.getVar('SRCREV_golang.org/x/net@v0.9.0'), '694cff8668bac64e0864b552bffc280cd27f21b1')
3651
3652 fetcher.download()
3653 self.assertTrue(os.path.exists(ud.localpath))
3654
3655 fetcher.unpack(self.unpackdir)
3656 vcsdir = os.path.join(self.unpackdir, 'pkg/mod/cache/vcs')
3657 self.assertTrue(os.path.exists(os.path.join(vcsdir, 'ed42bd05533fd84ae290a5d33ebd3695a0a2b06131beebd5450825bee8603aca')))
3658 downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
3659 self.assertTrue(os.path.exists(os.path.join(downloaddir, 'golang.org/x/net/@v/v0.9.0.zip')))
3660 self.assertTrue(os.path.exists(os.path.join(downloaddir, 'golang.org/x/net/@v/v0.9.0.mod')))
3661 self.assertEqual(bb.utils.sha256_file(os.path.join(downloaddir, 'golang.org/x/net/@v/v0.9.0.mod')),
3662 'c5d6851ede50ec1c001afb763040194b68961bf06997e2605e8bf06dcd2aeb2e')
3663
3664 @skipIfNoNetwork()
3665 def test_gomodgit_url_subdir(self):
3666 urls = ['gomodgit://github.com/Azure/azure-sdk-for-go/sdk/storage/azblob;version=v1.0.0;'
3667 'repo=github.com/Azure/azure-sdk-for-go;subdir=sdk/storage/azblob;'
3668 'srcrev=ec928e0ed34db682b3f783d3739d1c538142e0c3']
3669
3670 fetcher = bb.fetch2.Fetch(urls, self.d)
3671 ud = fetcher.ud[urls[0]]
3672 self.assertEqual(ud.host, 'github.com')
3673 self.assertEqual(ud.path, '/Azure/azure-sdk-for-go')
3674 self.assertEqual(ud.parm['subpath'], 'sdk/storage/azblob')
3675 self.assertEqual(ud.name, 'github.com/Azure/azure-sdk-for-go/sdk/storage/azblob@v1.0.0')
3676 self.assertEqual(self.d.getVar('SRCREV_github.com/Azure/azure-sdk-for-go/sdk/storage/azblob@v1.0.0'), 'ec928e0ed34db682b3f783d3739d1c538142e0c3')
3677
3678 fetcher.download()
3679 self.assertTrue(os.path.exists(ud.localpath))
3680
3681 fetcher.unpack(self.unpackdir)
3682 vcsdir = os.path.join(self.unpackdir, 'pkg/mod/cache/vcs')
3683 self.assertTrue(os.path.exists(os.path.join(vcsdir, 'd31d6145676ed3066ce573a8198f326dea5be45a43b3d8f41ce7787fd71d66b3')))
3684 downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
3685 self.assertTrue(os.path.exists(os.path.join(downloaddir, 'github.com/!azure/azure-sdk-for-go/sdk/storage/azblob/@v/v1.0.0.zip')))
3686 self.assertTrue(os.path.exists(os.path.join(downloaddir, 'github.com/!azure/azure-sdk-for-go/sdk/storage/azblob/@v/v1.0.0.mod')))
3687 self.assertEqual(bb.utils.sha256_file(os.path.join(downloaddir, 'github.com/!azure/azure-sdk-for-go/sdk/storage/azblob/@v/v1.0.0.mod')),
3688 '7873b8544842329b4f385a3aa6cf82cc2bc8defb41a04fa5291c35fd5900e873')
3689
3690 @skipIfNoNetwork()
3691 def test_gomodgit_url_srcrev_var(self):
3692 urls = ['gomodgit://gopkg.in/ini.v1;version=v1.67.0']
3693 self.d.setVar('SRCREV_gopkg.in/ini.v1@v1.67.0', 'b2f570e5b5b844226bbefe6fb521d891f529a951')
3694
3695 fetcher = bb.fetch2.Fetch(urls, self.d)
3696 ud = fetcher.ud[urls[0]]
3697 self.assertEqual(ud.host, 'gopkg.in')
3698 self.assertEqual(ud.path, '/ini.v1')
3699 self.assertEqual(ud.name, 'gopkg.in/ini.v1@v1.67.0')
3700 self.assertEqual(ud.parm['srcrev'], 'b2f570e5b5b844226bbefe6fb521d891f529a951')
3701
3702 fetcher.download()
3703 fetcher.unpack(self.unpackdir)
3704 vcsdir = os.path.join(self.unpackdir, 'pkg/mod/cache/vcs')
3705 self.assertTrue(os.path.exists(os.path.join(vcsdir, 'b7879a4be9ba8598851b8278b14c4f71a8316be64913298d1639cce6bde59bc3')))
3706 downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
3707 self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.zip')))
3708 self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.mod')))
3709 self.assertEqual(bb.utils.sha256_file(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.mod')),
3710 '13aedd85db8e555104108e0e613bb7e4d1242af7f27c15423dd9ab63b60b72a1')
3711
3712 @skipIfNoNetwork()
3713 def test_gomodgit_url_no_go_mod_in_module(self):
3714 urls = ['gomodgit://gopkg.in/ini.v1;version=v1.67.0;'
3715 'srcrev=b2f570e5b5b844226bbefe6fb521d891f529a951']
3716
3717 fetcher = bb.fetch2.Fetch(urls, self.d)
3718 ud = fetcher.ud[urls[0]]
3719 self.assertEqual(ud.host, 'gopkg.in')
3720 self.assertEqual(ud.path, '/ini.v1')
3721 self.assertEqual(ud.name, 'gopkg.in/ini.v1@v1.67.0')
3722 self.assertEqual(self.d.getVar('SRCREV_gopkg.in/ini.v1@v1.67.0'), 'b2f570e5b5b844226bbefe6fb521d891f529a951')
3723
3724 fetcher.download()
3725 fetcher.unpack(self.unpackdir)
3726 vcsdir = os.path.join(self.unpackdir, 'pkg/mod/cache/vcs')
3727 self.assertTrue(os.path.exists(os.path.join(vcsdir, 'b7879a4be9ba8598851b8278b14c4f71a8316be64913298d1639cce6bde59bc3')))
3728 downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
3729 self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.zip')))
3730 self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.mod')))
3731 self.assertEqual(bb.utils.sha256_file(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.mod')),
3732 '13aedd85db8e555104108e0e613bb7e4d1242af7f27c15423dd9ab63b60b72a1')
3733
3734 @skipIfNoNetwork()
3735 def test_gomodgit_url_host_only(self):
3736 urls = ['gomodgit://go.opencensus.io;version=v0.24.0;'
3737 'repo=github.com/census-instrumentation/opencensus-go;'
3738 'srcrev=b1a01ee95db0e690d91d7193d037447816fae4c5']
3739
3740 fetcher = bb.fetch2.Fetch(urls, self.d)
3741 ud = fetcher.ud[urls[0]]
3742 self.assertEqual(ud.host, 'github.com')
3743 self.assertEqual(ud.path, '/census-instrumentation/opencensus-go')
3744 self.assertEqual(ud.name, 'go.opencensus.io@v0.24.0')
3745 self.assertEqual(self.d.getVar('SRCREV_go.opencensus.io@v0.24.0'), 'b1a01ee95db0e690d91d7193d037447816fae4c5')
3746
3747 fetcher.download()
3748 fetcher.unpack(self.unpackdir)
3749 vcsdir = os.path.join(self.unpackdir, 'pkg/mod/cache/vcs')
3750 self.assertTrue(os.path.exists(os.path.join(vcsdir, 'aae3ac7b2122ed3345654e6327855e9682f4a5350d63e93dbcfc51c4419df0e1')))
3751 downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
3752 self.assertTrue(os.path.exists(os.path.join(downloaddir, 'go.opencensus.io/@v/v0.24.0.zip')))
3753 self.assertTrue(os.path.exists(os.path.join(downloaddir, 'go.opencensus.io/@v/v0.24.0.mod')))
3754 self.assertEqual(bb.utils.sha256_file(os.path.join(downloaddir, 'go.opencensus.io/@v/v0.24.0.mod')),
3755 '0dc9ccc660ad21cebaffd548f2cc6efa27891c68b4fbc1f8a3893b00f1acec96')