blob: 3d01cf69f2c0cfa88fb658b9311aac288fe3eb99 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright OpenEmbedded Contributors
3#
Brad Bishopc342db32019-05-15 21:57:59 -04004# SPDX-License-Identifier: MIT
5#
6
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05007import tempfile
8import textwrap
9import bb.tinfoil
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080010import oe.path
11from oeqa.selftest.case import OESelftestTestCase
12from oeqa.utils.commands import bitbake
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080013
14class Fetch(OESelftestTestCase):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080015 def test_git_mirrors(self):
16 """
17 Verify that the git fetcher will fall back to the HTTP mirrors. The
18 recipe needs to be one that we have on the Yocto Project source mirror
19 and is hosted in git.
20 """
21
22 # TODO: mktempd instead of hardcoding
23 dldir = os.path.join(self.builddir, "download-git-mirrors")
24 self.track_for_cleanup(dldir)
25
26 # No mirrors, should use git to fetch successfully
27 features = """
28DL_DIR = "%s"
Patrick Williams213cb262021-08-07 19:21:33 -050029MIRRORS:forcevariable = ""
30PREMIRRORS:forcevariable = ""
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080031""" % dldir
32 self.write_config(features)
33 oe.path.remove(dldir, recurse=True)
34 bitbake("dbus-wait -c fetch -f")
35
36 # No mirrors and broken git, should fail
37 features = """
38DL_DIR = "%s"
39GIT_PROXY_COMMAND = "false"
Patrick Williams213cb262021-08-07 19:21:33 -050040MIRRORS:forcevariable = ""
41PREMIRRORS:forcevariable = ""
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080042""" % dldir
43 self.write_config(features)
44 oe.path.remove(dldir, recurse=True)
45 with self.assertRaises(AssertionError):
46 bitbake("dbus-wait -c fetch -f")
47
48 # Broken git but a specific mirror
49 features = """
50DL_DIR = "%s"
51GIT_PROXY_COMMAND = "false"
Patrick Williams213cb262021-08-07 19:21:33 -050052MIRRORS:forcevariable = "git://.*/.* http://downloads.yoctoproject.org/mirror/sources/"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080053""" % dldir
54 self.write_config(features)
55 oe.path.remove(dldir, recurse=True)
56 bitbake("dbus-wait -c fetch -f")
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050057
58
59class Dependencies(OESelftestTestCase):
Andrew Geissler5f350902021-07-23 13:09:54 -040060 def write_recipe(self, content, tempdir):
61 f = os.path.join(tempdir, "test.bb")
62 with open(f, "w") as fd:
63 fd.write(content)
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050064 return f
65
66 def test_dependencies(self):
67 """
68 Verify that the correct dependencies are generated for specific SRC_URI entries.
69 """
Andrew Geissler5f350902021-07-23 13:09:54 -040070
71 with bb.tinfoil.Tinfoil() as tinfoil, tempfile.TemporaryDirectory(prefix="selftest-fetch") as tempdir:
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050072 tinfoil.prepare(config_only=False, quiet=2)
73
74 r = """
75 LICENSE="CLOSED"
76 SRC_URI="http://example.com/tarball.zip"
77 """
Andrew Geissler5f350902021-07-23 13:09:54 -040078 f = self.write_recipe(textwrap.dedent(r), tempdir)
79 d = tinfoil.parse_recipe_file(f)
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050080 self.assertIn("wget-native", d.getVarFlag("do_fetch", "depends"))
81 self.assertIn("unzip-native", d.getVarFlag("do_unpack", "depends"))
82
83 # Verify that the downloadfilename overrides the URI
84 r = """
85 LICENSE="CLOSED"
86 SRC_URI="https://example.com/tarball;downloadfilename=something.zip"
87 """
Andrew Geissler5f350902021-07-23 13:09:54 -040088 f = self.write_recipe(textwrap.dedent(r), tempdir)
89 d = tinfoil.parse_recipe_file(f)
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050090 self.assertIn("wget-native", d.getVarFlag("do_fetch", "depends"))
91 self.assertIn("unzip-native", d.getVarFlag("do_unpack", "depends") or "")
92
93 r = """
94 LICENSE="CLOSED"
95 SRC_URI="ftp://example.com/tarball.lz"
96 """
Andrew Geissler5f350902021-07-23 13:09:54 -040097 f = self.write_recipe(textwrap.dedent(r), tempdir)
98 d = tinfoil.parse_recipe_file(f)
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050099 self.assertIn("wget-native", d.getVarFlag("do_fetch", "depends"))
100 self.assertIn("lzip-native", d.getVarFlag("do_unpack", "depends"))
101
102 r = """
103 LICENSE="CLOSED"
Andrew Geissler595f6302022-01-24 19:11:47 +0000104 SRC_URI="git://example.com/repo;branch=master"
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500105 """
Andrew Geissler5f350902021-07-23 13:09:54 -0400106 f = self.write_recipe(textwrap.dedent(r), tempdir)
107 d = tinfoil.parse_recipe_file(f)
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500108 self.assertIn("git-native", d.getVarFlag("do_fetch", "depends"))