blob: 4de5034a94f9eeae80264d712f4e328f7b4cd864 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001import unittest
2import os
3import logging
4import re
5
6from oeqa.selftest.base import oeSelfTest
7from oeqa.selftest.buildhistory import BuildhistoryBase
8from oeqa.utils.commands import runCmd, bitbake, get_bb_var
9import oeqa.utils.ftools as ftools
10from oeqa.utils.decorators import testcase
11
12class LayerAppendTests(oeSelfTest):
13 layerconf = """
14# We have a conf and classes directory, append to BBPATH
15BBPATH .= ":${LAYERDIR}"
16
17# We have a recipes directory, add to BBFILES
18BBFILES += "${LAYERDIR}/recipes*/*.bb ${LAYERDIR}/recipes*/*.bbappend"
19
20BBFILE_COLLECTIONS += "meta-layerINT"
21BBFILE_PATTERN_meta-layerINT := "^${LAYERDIR}/"
22BBFILE_PRIORITY_meta-layerINT = "6"
23"""
24 recipe = """
25LICENSE="CLOSED"
26INHIBIT_DEFAULT_DEPS = "1"
27
28python do_build() {
29 bb.plain('Building ...')
30}
31addtask build
32"""
33 append = """
34FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
35
36SRC_URI_append = " file://appendtest.txt"
37
38sysroot_stage_all_append() {
39 install -m 644 ${WORKDIR}/appendtest.txt ${SYSROOT_DESTDIR}/
40}
41
42"""
43
44 append2 = """
45FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
46
47SRC_URI_append += "file://appendtest.txt"
48"""
Patrick Williamsf1e5d692016-03-30 15:21:19 -050049 layerappend = ''
Patrick Williamsc124f4f2015-09-15 14:41:29 -050050
51 def tearDownLocal(self):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050052 if self.layerappend:
53 ftools.remove_from_file(self.builddir + "/conf/bblayers.conf", self.layerappend)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050054
55 @testcase(1196)
56 def test_layer_appends(self):
57 corebase = get_bb_var("COREBASE")
58 stagingdir = get_bb_var("STAGING_DIR_TARGET")
59 for l in ["0", "1", "2"]:
60 layer = os.path.join(corebase, "meta-layertest" + l)
61 self.assertFalse(os.path.exists(layer))
62 os.mkdir(layer)
63 os.mkdir(layer + "/conf")
64 with open(layer + "/conf/layer.conf", "w") as f:
65 f.write(self.layerconf.replace("INT", l))
66 os.mkdir(layer + "/recipes-test")
67 if l == "0":
68 with open(layer + "/recipes-test/layerappendtest.bb", "w") as f:
69 f.write(self.recipe)
70 elif l == "1":
71 with open(layer + "/recipes-test/layerappendtest.bbappend", "w") as f:
72 f.write(self.append)
73 os.mkdir(layer + "/recipes-test/layerappendtest")
74 with open(layer + "/recipes-test/layerappendtest/appendtest.txt", "w") as f:
75 f.write("Layer 1 test")
76 elif l == "2":
77 with open(layer + "/recipes-test/layerappendtest.bbappend", "w") as f:
78 f.write(self.append2)
79 os.mkdir(layer + "/recipes-test/layerappendtest")
80 with open(layer + "/recipes-test/layerappendtest/appendtest.txt", "w") as f:
81 f.write("Layer 2 test")
82 self.track_for_cleanup(layer)
Patrick Williamsf1e5d692016-03-30 15:21:19 -050083
84 self.layerappend = "BBLAYERS += \"{0}/meta-layertest0 {0}/meta-layertest1 {0}/meta-layertest2\"".format(corebase)
85 ftools.append_file(self.builddir + "/conf/bblayers.conf", self.layerappend)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050086 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")
98
99