blob: 67e85d3e4c77efb978af5b7d4c3b84cb206fcb69 [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"
27MIRRORS_forcevariable = ""
28PREMIRRORS_forcevariable = ""
29""" % 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"
38MIRRORS_forcevariable = ""
39PREMIRRORS_forcevariable = ""
40""" % 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"
50MIRRORS_forcevariable = "git://.*/.* http://downloads.yoctoproject.org/mirror/sources/"
51""" % 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):
58 def write_recipe(self, content):
59 f = tempfile.NamedTemporaryFile(mode="wt", suffix=".bb")
60 f.write(content)
61 f.flush()
62 return f
63
64 def test_dependencies(self):
65 """
66 Verify that the correct dependencies are generated for specific SRC_URI entries.
67 """
68 with bb.tinfoil.Tinfoil() as tinfoil:
69 tinfoil.prepare(config_only=False, quiet=2)
70
71 r = """
72 LICENSE="CLOSED"
73 SRC_URI="http://example.com/tarball.zip"
74 """
75 f = self.write_recipe(textwrap.dedent(r))
76 d = tinfoil.parse_recipe_file(f.name)
77 self.assertIn("wget-native", d.getVarFlag("do_fetch", "depends"))
78 self.assertIn("unzip-native", d.getVarFlag("do_unpack", "depends"))
79
80 # Verify that the downloadfilename overrides the URI
81 r = """
82 LICENSE="CLOSED"
83 SRC_URI="https://example.com/tarball;downloadfilename=something.zip"
84 """
85 f = self.write_recipe(textwrap.dedent(r))
86 d = tinfoil.parse_recipe_file(f.name)
87 self.assertIn("wget-native", d.getVarFlag("do_fetch", "depends"))
88 self.assertIn("unzip-native", d.getVarFlag("do_unpack", "depends") or "")
89
90 r = """
91 LICENSE="CLOSED"
92 SRC_URI="ftp://example.com/tarball.lz"
93 """
94 f = self.write_recipe(textwrap.dedent(r))
95 d = tinfoil.parse_recipe_file(f.name)
96 self.assertIn("wget-native", d.getVarFlag("do_fetch", "depends"))
97 self.assertIn("lzip-native", d.getVarFlag("do_unpack", "depends"))
98
99 r = """
100 LICENSE="CLOSED"
101 SRC_URI="git://example.com/repo"
102 """
103 f = self.write_recipe(textwrap.dedent(r))
104 d = tinfoil.parse_recipe_file(f.name)
105 self.assertIn("git-native", d.getVarFlag("do_fetch", "depends"))