Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 7 | import tempfile |
| 8 | import textwrap |
| 9 | import bb.tinfoil |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 10 | import oe.path |
| 11 | from oeqa.selftest.case import OESelftestTestCase |
| 12 | from oeqa.utils.commands import bitbake |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 13 | |
| 14 | class Fetch(OESelftestTestCase): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 15 | 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 = """ |
| 28 | DL_DIR = "%s" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 29 | MIRRORS:forcevariable = "" |
| 30 | PREMIRRORS:forcevariable = "" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 31 | """ % 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 = """ |
| 38 | DL_DIR = "%s" |
Andrew Geissler | 028142b | 2023-05-05 11:29:21 -0500 | [diff] [blame] | 39 | SRC_URI:pn-dbus-wait = "git://git.yoctoproject.org/dbus-wait;branch=master;protocol=git" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 40 | GIT_PROXY_COMMAND = "false" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 41 | MIRRORS:forcevariable = "" |
| 42 | PREMIRRORS:forcevariable = "" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 43 | """ % dldir |
| 44 | self.write_config(features) |
| 45 | oe.path.remove(dldir, recurse=True) |
| 46 | with self.assertRaises(AssertionError): |
| 47 | bitbake("dbus-wait -c fetch -f") |
| 48 | |
| 49 | # Broken git but a specific mirror |
| 50 | features = """ |
| 51 | DL_DIR = "%s" |
Andrew Geissler | 028142b | 2023-05-05 11:29:21 -0500 | [diff] [blame] | 52 | SRC_URI:pn-dbus-wait = "git://git.yoctoproject.org/dbus-wait;branch=master;protocol=git" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 53 | GIT_PROXY_COMMAND = "false" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 54 | MIRRORS:forcevariable = "git://.*/.* http://downloads.yoctoproject.org/mirror/sources/" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 55 | """ % dldir |
| 56 | self.write_config(features) |
| 57 | oe.path.remove(dldir, recurse=True) |
| 58 | bitbake("dbus-wait -c fetch -f") |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 59 | |
| 60 | |
| 61 | class Dependencies(OESelftestTestCase): |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 62 | def write_recipe(self, content, tempdir): |
| 63 | f = os.path.join(tempdir, "test.bb") |
| 64 | with open(f, "w") as fd: |
| 65 | fd.write(content) |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 66 | return f |
| 67 | |
| 68 | def test_dependencies(self): |
| 69 | """ |
| 70 | Verify that the correct dependencies are generated for specific SRC_URI entries. |
| 71 | """ |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 72 | |
| 73 | 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] | 74 | tinfoil.prepare(config_only=False, quiet=2) |
| 75 | |
| 76 | r = """ |
| 77 | LICENSE="CLOSED" |
| 78 | SRC_URI="http://example.com/tarball.zip" |
| 79 | """ |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 80 | f = self.write_recipe(textwrap.dedent(r), tempdir) |
| 81 | d = tinfoil.parse_recipe_file(f) |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 82 | self.assertIn("wget-native", d.getVarFlag("do_fetch", "depends")) |
| 83 | self.assertIn("unzip-native", d.getVarFlag("do_unpack", "depends")) |
| 84 | |
| 85 | # Verify that the downloadfilename overrides the URI |
| 86 | r = """ |
| 87 | LICENSE="CLOSED" |
| 88 | SRC_URI="https://example.com/tarball;downloadfilename=something.zip" |
| 89 | """ |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 90 | f = self.write_recipe(textwrap.dedent(r), tempdir) |
| 91 | d = tinfoil.parse_recipe_file(f) |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 92 | self.assertIn("wget-native", d.getVarFlag("do_fetch", "depends")) |
| 93 | self.assertIn("unzip-native", d.getVarFlag("do_unpack", "depends") or "") |
| 94 | |
| 95 | r = """ |
| 96 | LICENSE="CLOSED" |
| 97 | SRC_URI="ftp://example.com/tarball.lz" |
| 98 | """ |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 99 | f = self.write_recipe(textwrap.dedent(r), tempdir) |
| 100 | d = tinfoil.parse_recipe_file(f) |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 101 | self.assertIn("wget-native", d.getVarFlag("do_fetch", "depends")) |
| 102 | self.assertIn("lzip-native", d.getVarFlag("do_unpack", "depends")) |
| 103 | |
| 104 | r = """ |
| 105 | LICENSE="CLOSED" |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 106 | SRC_URI="git://example.com/repo;branch=master" |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 107 | """ |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 108 | f = self.write_recipe(textwrap.dedent(r), tempdir) |
| 109 | d = tinfoil.parse_recipe_file(f) |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 110 | self.assertIn("git-native", d.getVarFlag("do_fetch", "depends")) |