blob: 9aa91e59c13d7e1fb0a066056915b0b62e86d6fc [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005import tempfile
6import textwrap
7import bb.tinfoil
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08008import oe.path
9from oeqa.selftest.case import OESelftestTestCase
10from oeqa.utils.commands import bitbake
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011
12class Fetch(OESelftestTestCase):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080013 def test_git_mirrors(self):
14 """
15 Verify that the git fetcher will fall back to the HTTP mirrors. The
16 recipe needs to be one that we have on the Yocto Project source mirror
17 and is hosted in git.
18 """
19
20 # TODO: mktempd instead of hardcoding
21 dldir = os.path.join(self.builddir, "download-git-mirrors")
22 self.track_for_cleanup(dldir)
23
24 # No mirrors, should use git to fetch successfully
25 features = """
26DL_DIR = "%s"
Patrick Williams213cb262021-08-07 19:21:33 -050027MIRRORS:forcevariable = ""
28PREMIRRORS:forcevariable = ""
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080029""" % dldir
30 self.write_config(features)
31 oe.path.remove(dldir, recurse=True)
32 bitbake("dbus-wait -c fetch -f")
33
34 # No mirrors and broken git, should fail
35 features = """
36DL_DIR = "%s"
37GIT_PROXY_COMMAND = "false"
Patrick Williams213cb262021-08-07 19:21:33 -050038MIRRORS:forcevariable = ""
39PREMIRRORS:forcevariable = ""
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080040""" % dldir
41 self.write_config(features)
42 oe.path.remove(dldir, recurse=True)
43 with self.assertRaises(AssertionError):
44 bitbake("dbus-wait -c fetch -f")
45
46 # Broken git but a specific mirror
47 features = """
48DL_DIR = "%s"
49GIT_PROXY_COMMAND = "false"
Patrick Williams213cb262021-08-07 19:21:33 -050050MIRRORS:forcevariable = "git://.*/.* http://downloads.yoctoproject.org/mirror/sources/"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080051""" % dldir
52 self.write_config(features)
53 oe.path.remove(dldir, recurse=True)
54 bitbake("dbus-wait -c fetch -f")
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050055
56
57class Dependencies(OESelftestTestCase):
Andrew Geissler5f350902021-07-23 13:09:54 -040058 def write_recipe(self, content, tempdir):
59 f = os.path.join(tempdir, "test.bb")
60 with open(f, "w") as fd:
61 fd.write(content)
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050062 return f
63
64 def test_dependencies(self):
65 """
66 Verify that the correct dependencies are generated for specific SRC_URI entries.
67 """
Andrew Geissler5f350902021-07-23 13:09:54 -040068
69 with bb.tinfoil.Tinfoil() as tinfoil, tempfile.TemporaryDirectory(prefix="selftest-fetch") as tempdir:
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050070 tinfoil.prepare(config_only=False, quiet=2)
71
72 r = """
73 LICENSE="CLOSED"
74 SRC_URI="http://example.com/tarball.zip"
75 """
Andrew Geissler5f350902021-07-23 13:09:54 -040076 f = self.write_recipe(textwrap.dedent(r), tempdir)
77 d = tinfoil.parse_recipe_file(f)
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050078 self.assertIn("wget-native", d.getVarFlag("do_fetch", "depends"))
79 self.assertIn("unzip-native", d.getVarFlag("do_unpack", "depends"))
80
81 # Verify that the downloadfilename overrides the URI
82 r = """
83 LICENSE="CLOSED"
84 SRC_URI="https://example.com/tarball;downloadfilename=something.zip"
85 """
Andrew Geissler5f350902021-07-23 13:09:54 -040086 f = self.write_recipe(textwrap.dedent(r), tempdir)
87 d = tinfoil.parse_recipe_file(f)
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050088 self.assertIn("wget-native", d.getVarFlag("do_fetch", "depends"))
89 self.assertIn("unzip-native", d.getVarFlag("do_unpack", "depends") or "")
90
91 r = """
92 LICENSE="CLOSED"
93 SRC_URI="ftp://example.com/tarball.lz"
94 """
Andrew Geissler5f350902021-07-23 13:09:54 -040095 f = self.write_recipe(textwrap.dedent(r), tempdir)
96 d = tinfoil.parse_recipe_file(f)
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050097 self.assertIn("wget-native", d.getVarFlag("do_fetch", "depends"))
98 self.assertIn("lzip-native", d.getVarFlag("do_unpack", "depends"))
99
100 r = """
101 LICENSE="CLOSED"
102 SRC_URI="git://example.com/repo"
103 """
Andrew Geissler5f350902021-07-23 13:09:54 -0400104 f = self.write_recipe(textwrap.dedent(r), tempdir)
105 d = tinfoil.parse_recipe_file(f)
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500106 self.assertIn("git-native", d.getVarFlag("do_fetch", "depends"))