fetch.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: MIT
  5. #
  6. import tempfile
  7. import textwrap
  8. import bb.tinfoil
  9. import oe.path
  10. from oeqa.selftest.case import OESelftestTestCase
  11. from oeqa.utils.commands import bitbake
  12. class Fetch(OESelftestTestCase):
  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. # TODO: mktempd instead of hardcoding
  20. dldir = os.path.join(self.builddir, "download-git-mirrors")
  21. self.track_for_cleanup(dldir)
  22. # No mirrors, should use git to fetch successfully
  23. features = """
  24. DL_DIR = "%s"
  25. MIRRORS:forcevariable = ""
  26. PREMIRRORS:forcevariable = ""
  27. """ % dldir
  28. self.write_config(features)
  29. oe.path.remove(dldir, recurse=True)
  30. bitbake("dbus-wait -c fetch -f")
  31. # No mirrors and broken git, should fail
  32. features = """
  33. DL_DIR = "%s"
  34. SRC_URI:pn-dbus-wait = "git://git.yoctoproject.org/dbus-wait;branch=master;protocol=git"
  35. GIT_PROXY_COMMAND = "false"
  36. MIRRORS:forcevariable = ""
  37. PREMIRRORS:forcevariable = ""
  38. """ % dldir
  39. self.write_config(features)
  40. oe.path.remove(dldir, recurse=True)
  41. with self.assertRaises(AssertionError):
  42. bitbake("dbus-wait -c fetch -f")
  43. # Broken git but a specific mirror
  44. features = """
  45. DL_DIR = "%s"
  46. SRC_URI:pn-dbus-wait = "git://git.yoctoproject.org/dbus-wait;branch=master;protocol=git"
  47. GIT_PROXY_COMMAND = "false"
  48. MIRRORS:forcevariable = "git://.*/.* http://downloads.yoctoproject.org/mirror/sources/"
  49. """ % dldir
  50. self.write_config(features)
  51. oe.path.remove(dldir, recurse=True)
  52. bitbake("dbus-wait -c fetch -f")
  53. class Dependencies(OESelftestTestCase):
  54. def write_recipe(self, content, tempdir):
  55. f = os.path.join(tempdir, "test.bb")
  56. with open(f, "w") as fd:
  57. fd.write(content)
  58. return f
  59. def test_dependencies(self):
  60. """
  61. Verify that the correct dependencies are generated for specific SRC_URI entries.
  62. """
  63. with bb.tinfoil.Tinfoil() as tinfoil, tempfile.TemporaryDirectory(prefix="selftest-fetch") as tempdir:
  64. tinfoil.prepare(config_only=False, quiet=2)
  65. r = """
  66. LICENSE = "CLOSED"
  67. SRC_URI = "http://example.com/tarball.zip"
  68. """
  69. f = self.write_recipe(textwrap.dedent(r), tempdir)
  70. d = tinfoil.parse_recipe_file(f)
  71. self.assertIn("wget-native", d.getVarFlag("do_fetch", "depends"))
  72. self.assertIn("unzip-native", d.getVarFlag("do_unpack", "depends"))
  73. # Verify that the downloadfilename overrides the URI
  74. r = """
  75. LICENSE = "CLOSED"
  76. SRC_URI = "https://example.com/tarball;downloadfilename=something.zip"
  77. """
  78. f = self.write_recipe(textwrap.dedent(r), tempdir)
  79. d = tinfoil.parse_recipe_file(f)
  80. self.assertIn("wget-native", d.getVarFlag("do_fetch", "depends"))
  81. self.assertIn("unzip-native", d.getVarFlag("do_unpack", "depends") or "")
  82. r = """
  83. LICENSE = "CLOSED"
  84. SRC_URI = "ftp://example.com/tarball.lz"
  85. """
  86. f = self.write_recipe(textwrap.dedent(r), tempdir)
  87. d = tinfoil.parse_recipe_file(f)
  88. self.assertIn("wget-native", d.getVarFlag("do_fetch", "depends"))
  89. self.assertIn("lzip-native", d.getVarFlag("do_unpack", "depends"))
  90. r = """
  91. LICENSE = "CLOSED"
  92. SRC_URI = "git://example.com/repo;branch=master;rev=ffffffffffffffffffffffffffffffffffffffff"
  93. """
  94. f = self.write_recipe(textwrap.dedent(r), tempdir)
  95. d = tinfoil.parse_recipe_file(f)
  96. self.assertIn("git-native", d.getVarFlag("do_fetch", "depends"))