blob: 8fb1e6c5304ce1c116d468c4a91ef6acb70bde13 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005import os
6
7from oeqa.selftest.case import OESelftestTestCase
Patrick Williams45852732022-04-02 08:58:32 -05008from oeqa.utils.commands import bitbake, get_bb_var
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009import oeqa.utils.ftools as ftools
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010
11class LayerAppendTests(OESelftestTestCase):
12 layerconf = """
13# We have a conf and classes directory, append to BBPATH
14BBPATH .= ":${LAYERDIR}"
15
16# We have a recipes directory, add to BBFILES
17BBFILES += "${LAYERDIR}/recipes*/*.bb ${LAYERDIR}/recipes*/*.bbappend"
18
19BBFILE_COLLECTIONS += "meta-layerINT"
20BBFILE_PATTERN_meta-layerINT := "^${LAYERDIR}/"
21BBFILE_PRIORITY_meta-layerINT = "6"
22"""
23 recipe = """
24LICENSE="CLOSED"
25INHIBIT_DEFAULT_DEPS = "1"
26
27python do_build() {
28 bb.plain('Building ...')
29}
30addtask build
31"""
32 append = """
Patrick Williams213cb262021-08-07 19:21:33 -050033FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050034
Patrick Williams213cb262021-08-07 19:21:33 -050035SRC_URI:append = " file://appendtest.txt"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050036
Patrick Williams213cb262021-08-07 19:21:33 -050037sysroot_stage_all:append() {
Brad Bishopd7bf8c12018-02-25 22:55:05 -050038 install -m 644 ${WORKDIR}/appendtest.txt ${SYSROOT_DESTDIR}/
39}
40
41"""
42
43 append2 = """
Patrick Williams213cb262021-08-07 19:21:33 -050044FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050045
Patrick Williams213cb262021-08-07 19:21:33 -050046SRC_URI:append = " file://appendtest.txt"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050047"""
48 layerappend = ''
49
50 def tearDownLocal(self):
51 if self.layerappend:
52 ftools.remove_from_file(self.builddir + "/conf/bblayers.conf", self.layerappend)
53 super(LayerAppendTests, self).tearDownLocal()
54
Brad Bishopd7bf8c12018-02-25 22:55:05 -050055 def test_layer_appends(self):
56 corebase = get_bb_var("COREBASE")
57
58 for l in ["0", "1", "2"]:
59 layer = os.path.join(corebase, "meta-layertest" + l)
60 self.assertFalse(os.path.exists(layer))
61 os.mkdir(layer)
62 os.mkdir(layer + "/conf")
63 with open(layer + "/conf/layer.conf", "w") as f:
64 f.write(self.layerconf.replace("INT", l))
65 os.mkdir(layer + "/recipes-test")
66 if l == "0":
67 with open(layer + "/recipes-test/layerappendtest.bb", "w") as f:
68 f.write(self.recipe)
69 elif l == "1":
70 with open(layer + "/recipes-test/layerappendtest.bbappend", "w") as f:
71 f.write(self.append)
72 os.mkdir(layer + "/recipes-test/layerappendtest")
73 with open(layer + "/recipes-test/layerappendtest/appendtest.txt", "w") as f:
74 f.write("Layer 1 test")
75 elif l == "2":
76 with open(layer + "/recipes-test/layerappendtest.bbappend", "w") as f:
77 f.write(self.append2)
78 os.mkdir(layer + "/recipes-test/layerappendtest")
79 with open(layer + "/recipes-test/layerappendtest/appendtest.txt", "w") as f:
80 f.write("Layer 2 test")
81 self.track_for_cleanup(layer)
82
83 self.layerappend = "BBLAYERS += \"{0}/meta-layertest0 {0}/meta-layertest1 {0}/meta-layertest2\"".format(corebase)
84 ftools.append_file(self.builddir + "/conf/bblayers.conf", self.layerappend)
85 stagingdir = get_bb_var("SYSROOT_DESTDIR", "layerappendtest")
86 bitbake("layerappendtest")
87 data = ftools.read_file(stagingdir + "/appendtest.txt")
88 self.assertEqual(data, "Layer 2 test")
89 os.remove(corebase + "/meta-layertest2/recipes-test/layerappendtest/appendtest.txt")
90 bitbake("layerappendtest")
91 data = ftools.read_file(stagingdir + "/appendtest.txt")
92 self.assertEqual(data, "Layer 1 test")
93 with open(corebase + "/meta-layertest2/recipes-test/layerappendtest/appendtest.txt", "w") as f:
94 f.write("Layer 2 test")
95 bitbake("layerappendtest")
96 data = ftools.read_file(stagingdir + "/appendtest.txt")
97 self.assertEqual(data, "Layer 2 test")