layerappend.py 3.5 KB

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