@@ -3443,3 +3443,124 @@ class GoModGitTest(FetcherTest):
self.assertTrue(os.path.exists(os.path.join(downloaddir, 'go.opencensus.io/@v/v0.24.0.mod')))
self.assertEqual(bb.utils.sha256_file(os.path.join(downloaddir, 'go.opencensus.io/@v/v0.24.0.mod')),
'0dc9ccc660ad21cebaffd548f2cc6efa27891c68b4fbc1f8a3893b00f1acec96')
+
+class DependencyTest(FetcherTest):
+ class DummyMixin:
+ def resolve_dependencies(self, ud, localpath, d):
+ urls = []
+ if os.path.isdir(localpath):
+ localpath = os.path.join(localpath, "dummy.txt")
+ with open(localpath, "r") as f:
+ for line in f:
+ line = line.strip()
+ urls.append(line)
+ return urls
+
+ def create_specification_file(self):
+ dummyfile = "dummy.txt"
+ lines = [
+ "https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz",
+ "git://git.openembedded.org/bitbake;branch=master;protocol=https;rev=82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40"
+ ]
+ with open(os.path.join(self.srcdir, dummyfile), "w") as f:
+ f.write("\n".join(lines) + "\n")
+ return dummyfile
+
+ def setUp(self):
+ from bb.fetch2.dependency import create_methods
+ super().setUp()
+ self.srcdir = os.path.join(self.tempdir, "src")
+ os.makedirs(self.srcdir)
+ bb.fetch.methods.extend(create_methods("dummy", self.DummyMixin))
+ self.srcfilename = self.create_specification_file()
+
+ @skipIfNoNetwork()
+ def test_dummy(self):
+ self.d.setVar("FILESPATH", self.srcdir)
+ fetcher = bb.fetch.Fetch([f"dummy://{self.srcfilename}"], self.d)
+ fetcher.download()
+ self.assertTrue(os.path.exists(os.path.join(self.dldir, "bitbake-1.0.tar.gz")))
+ self.assertTrue(os.path.exists(os.path.join(self.dldir, "bitbake-1.0.tar.gz.done")))
+ self.assertTrue(os.path.exists(os.path.join(self.dldir, "git2/git.openembedded.org.bitbake")))
+ fetcher.unpack(self.unpackdir)
+ self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "dummy.txt")))
+ self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "bitbake-1.0")))
+ self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "git")))
+
+ @skipIfNoNetwork()
+ def test_dummy_git(self):
+ self.git_init(self.srcdir)
+ self.git(["add", "--all", "."], self.srcdir)
+ self.git(["commit", "-m", "Dummy commit"], self.srcdir)
+ rev = self.git(["rev-parse", "HEAD"], self.srcdir).strip()
+ urls = [
+ f"dummy+git://{self.srcdir};branch=master;protocol=file;rev={rev}"
+ ]
+ fetcher = bb.fetch.Fetch(urls, self.d)
+ fetcher.download()
+ self.assertTrue(os.path.exists(os.path.join(self.dldir, "bitbake-1.0.tar.gz")))
+ self.assertTrue(os.path.exists(os.path.join(self.dldir, "bitbake-1.0.tar.gz.done")))
+ self.assertTrue(os.path.exists(os.path.join(self.dldir, "git2/git.openembedded.org.bitbake")))
+ archivename = self.srcdir[1:].replace('/', '.')
+ self.assertTrue(os.path.exists(os.path.join(self.dldir, "git2", archivename)))
+ fetcher.unpack(self.unpackdir)
+ self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "git/dummy.txt")))
+ self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "git/bitbake-1.0")))
+ self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "git/git")))
+
+ @skipIfNoNetwork()
+ def test_dummy_https_file(self):
+ archivename = "archive.tar.gz"
+ sha256sum = bb.utils.sha256_file(os.path.join(self.srcdir, self.srcfilename))
+ server = HTTPService(self.srcdir, "127.0.0.1")
+ server.start()
+ port = server.port
+ try:
+ urls = [
+ f"dummy+http://{server.host}:{server.port}/{self.srcfilename};"
+ f"sha256sum={sha256sum}"
+ ]
+ fetcher = bb.fetch.Fetch(urls, self.d)
+ fetcher.download()
+ finally:
+ server.stop()
+ self.assertTrue(os.path.exists(os.path.join(self.dldir, "dummy.txt")))
+ self.assertTrue(os.path.exists(os.path.join(self.dldir, "bitbake-1.0.tar.gz")))
+ self.assertTrue(os.path.exists(os.path.join(self.dldir, "bitbake-1.0.tar.gz.done")))
+ self.assertTrue(os.path.exists(os.path.join(self.dldir, "git2/git.openembedded.org.bitbake")))
+ fetcher.unpack(self.unpackdir)
+ self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "dummy.txt")))
+ self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "bitbake-1.0")))
+ self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "git")))
+
+ @skipIfNoNetwork()
+ def test_dummy_https_archive(self):
+ archivename = "archive.tar.gz"
+ projectname = "dummy"
+ projectdir = os.path.join(self.srcdir, projectname)
+ os.makedirs(projectdir)
+ os.rename(os.path.join(self.srcdir, self.srcfilename),
+ os.path.join(projectdir, self.srcfilename))
+ bb.process.run(f"tar czf {archivename} -C {projectname} .", cwd=self.srcdir)
+ sha256sum = bb.utils.sha256_file(os.path.join(self.srcdir, archivename))
+ server = HTTPService(self.srcdir, "127.0.0.1")
+ server.start()
+ port = server.port
+ try:
+ urls = [
+ f"dummy+http://{server.host}:{server.port}/{archivename};"
+ f"sha256sum={sha256sum};striplevel=1;subdir={projectname}"
+ ]
+ fetcher = bb.fetch.Fetch(urls, self.d)
+ fetcher.download()
+ finally:
+ server.stop()
+ self.assertTrue(os.path.exists(os.path.join(self.dldir, "archive.tar.gz")))
+ self.assertTrue(os.path.exists(os.path.join(self.dldir, "archive.tar.gz.done")))
+ self.assertTrue(os.path.exists(os.path.join(self.dldir, "bitbake-1.0.tar.gz")))
+ self.assertTrue(os.path.exists(os.path.join(self.dldir, "bitbake-1.0.tar.gz.done")))
+ self.assertTrue(os.path.exists(os.path.join(self.dldir, "git2/git.openembedded.org.bitbake")))
+ fetcher.unpack(self.unpackdir)
+ self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "dummy/dummy.txt")))
+ self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "dummy/bitbake-1.0")))
+ self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "dummy/git")))