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