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" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 27 | MIRRORS:forcevariable = "" |
| 28 | PREMIRRORS:forcevariable = "" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 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" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 38 | MIRRORS:forcevariable = "" |
| 39 | PREMIRRORS:forcevariable = "" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 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" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 50 | MIRRORS:forcevariable = "git://.*/.* http://downloads.yoctoproject.org/mirror/sources/" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 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): |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 58 | 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 Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 62 | return f |
| 63 | |
| 64 | def test_dependencies(self): |
| 65 | """ |
| 66 | Verify that the correct dependencies are generated for specific SRC_URI entries. |
| 67 | """ |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 68 | |
| 69 | with bb.tinfoil.Tinfoil() as tinfoil, tempfile.TemporaryDirectory(prefix="selftest-fetch") as tempdir: |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 70 | tinfoil.prepare(config_only=False, quiet=2) |
| 71 | |
| 72 | r = """ |
| 73 | LICENSE="CLOSED" |
| 74 | SRC_URI="http://example.com/tarball.zip" |
| 75 | """ |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 76 | f = self.write_recipe(textwrap.dedent(r), tempdir) |
| 77 | d = tinfoil.parse_recipe_file(f) |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 78 | 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 Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 86 | f = self.write_recipe(textwrap.dedent(r), tempdir) |
| 87 | d = tinfoil.parse_recipe_file(f) |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 88 | 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 Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 95 | f = self.write_recipe(textwrap.dedent(r), tempdir) |
| 96 | d = tinfoil.parse_recipe_file(f) |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 97 | 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 Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 104 | f = self.write_recipe(textwrap.dedent(r), tempdir) |
| 105 | d = tinfoil.parse_recipe_file(f) |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 106 | self.assertIn("git-native", d.getVarFlag("do_fetch", "depends")) |