layerappend.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: MIT
  5. #
  6. import os
  7. from oeqa.selftest.case import OESelftestTestCase
  8. from oeqa.utils.commands import bitbake, get_bb_var
  9. import oeqa.utils.ftools as ftools
  10. class LayerAppendTests(OESelftestTestCase):
  11. layerconf = """
  12. # We have a conf and classes directory, append to BBPATH
  13. BBPATH .= ":${LAYERDIR}"
  14. # We have a recipes directory, add to BBFILES
  15. BBFILES += "${LAYERDIR}/recipes*/*.bb ${LAYERDIR}/recipes*/*.bbappend"
  16. BBFILE_COLLECTIONS += "meta-layerINT"
  17. BBFILE_PATTERN_meta-layerINT := "^${LAYERDIR}/"
  18. BBFILE_PRIORITY_meta-layerINT = "6"
  19. """
  20. recipe = """
  21. LICENSE="CLOSED"
  22. INHIBIT_DEFAULT_DEPS = "1"
  23. python do_build() {
  24. bb.plain('Building ...')
  25. }
  26. addtask build
  27. """
  28. append = """
  29. FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
  30. SRC_URI:append = " file://appendtest.txt"
  31. sysroot_stage_all:append() {
  32. install -m 644 ${UNPACKDIR}/appendtest.txt ${SYSROOT_DESTDIR}/
  33. }
  34. """
  35. append2 = """
  36. FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
  37. SRC_URI:append = " file://appendtest.txt"
  38. """
  39. layerappend = ''
  40. def tearDownLocal(self):
  41. if self.layerappend:
  42. ftools.remove_from_file(self.builddir + "/conf/bblayers.conf", self.layerappend)
  43. super(LayerAppendTests, self).tearDownLocal()
  44. def test_layer_appends(self):
  45. corebase = get_bb_var("COREBASE")
  46. for l in ["0", "1", "2"]:
  47. layer = os.path.join(corebase, "meta-layertest" + l)
  48. self.assertFalse(os.path.exists(layer))
  49. os.mkdir(layer)
  50. os.mkdir(layer + "/conf")
  51. with open(layer + "/conf/layer.conf", "w") as f:
  52. f.write(self.layerconf.replace("INT", l))
  53. os.mkdir(layer + "/recipes-test")
  54. if l == "0":
  55. with open(layer + "/recipes-test/layerappendtest.bb", "w") as f:
  56. f.write(self.recipe)
  57. elif l == "1":
  58. with open(layer + "/recipes-test/layerappendtest.bbappend", "w") as f:
  59. f.write(self.append)
  60. os.mkdir(layer + "/recipes-test/layerappendtest")
  61. with open(layer + "/recipes-test/layerappendtest/appendtest.txt", "w") as f:
  62. f.write("Layer 1 test")
  63. elif l == "2":
  64. with open(layer + "/recipes-test/layerappendtest.bbappend", "w") as f:
  65. f.write(self.append2)
  66. os.mkdir(layer + "/recipes-test/layerappendtest")
  67. with open(layer + "/recipes-test/layerappendtest/appendtest.txt", "w") as f:
  68. f.write("Layer 2 test")
  69. self.track_for_cleanup(layer)
  70. self.layerappend = "BBLAYERS += \"{0}/meta-layertest0 {0}/meta-layertest1 {0}/meta-layertest2\"".format(corebase)
  71. ftools.append_file(self.builddir + "/conf/bblayers.conf", self.layerappend)
  72. stagingdir = get_bb_var("SYSROOT_DESTDIR", "layerappendtest")
  73. bitbake("layerappendtest")
  74. data = ftools.read_file(stagingdir + "/appendtest.txt")
  75. self.assertEqual(data, "Layer 2 test")
  76. os.remove(corebase + "/meta-layertest2/recipes-test/layerappendtest/appendtest.txt")
  77. bitbake("layerappendtest")
  78. data = ftools.read_file(stagingdir + "/appendtest.txt")
  79. self.assertEqual(data, "Layer 1 test")
  80. with open(corebase + "/meta-layertest2/recipes-test/layerappendtest/appendtest.txt", "w") as f:
  81. f.write("Layer 2 test")
  82. bitbake("layerappendtest")
  83. data = ftools.read_file(stagingdir + "/appendtest.txt")
  84. self.assertEqual(data, "Layer 2 test")