layerappend.py 3.5 KB

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