Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | # |
| 4 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 5 | import tempfile |
| 6 | import textwrap |
| 7 | import bb.tinfoil |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 8 | import oe.path |
| 9 | from oeqa.selftest.case import OESelftestTestCase |
| 10 | from oeqa.utils.commands import bitbake |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 11 | |
| 12 | class Fetch(OESelftestTestCase): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 13 | 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 = """ |
| 26 | DL_DIR = "%s" |
| 27 | MIRRORS_forcevariable = "" |
| 28 | PREMIRRORS_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 = """ |
| 36 | DL_DIR = "%s" |
| 37 | GIT_PROXY_COMMAND = "false" |
| 38 | MIRRORS_forcevariable = "" |
| 39 | PREMIRRORS_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 = """ |
| 48 | DL_DIR = "%s" |
| 49 | GIT_PROXY_COMMAND = "false" |
| 50 | MIRRORS_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 Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 55 | |
| 56 | |
| 57 | class 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")) |