Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 7 | import os |
| 8 | |
| 9 | from oeqa.selftest.case import OESelftestTestCase |
Patrick Williams | 4585273 | 2022-04-02 08:58:32 -0500 | [diff] [blame] | 10 | from oeqa.utils.commands import bitbake, get_bb_var |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 11 | import oeqa.utils.ftools as ftools |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 12 | |
| 13 | class LayerAppendTests(OESelftestTestCase): |
| 14 | layerconf = """ |
| 15 | # We have a conf and classes directory, append to BBPATH |
| 16 | BBPATH .= ":${LAYERDIR}" |
| 17 | |
| 18 | # We have a recipes directory, add to BBFILES |
| 19 | BBFILES += "${LAYERDIR}/recipes*/*.bb ${LAYERDIR}/recipes*/*.bbappend" |
| 20 | |
| 21 | BBFILE_COLLECTIONS += "meta-layerINT" |
| 22 | BBFILE_PATTERN_meta-layerINT := "^${LAYERDIR}/" |
| 23 | BBFILE_PRIORITY_meta-layerINT = "6" |
| 24 | """ |
| 25 | recipe = """ |
| 26 | LICENSE="CLOSED" |
| 27 | INHIBIT_DEFAULT_DEPS = "1" |
| 28 | |
| 29 | python do_build() { |
| 30 | bb.plain('Building ...') |
| 31 | } |
| 32 | addtask build |
| 33 | """ |
| 34 | append = """ |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 35 | FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 36 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 37 | SRC_URI:append = " file://appendtest.txt" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 38 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 39 | sysroot_stage_all:append() { |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 40 | install -m 644 ${WORKDIR}/appendtest.txt ${SYSROOT_DESTDIR}/ |
| 41 | } |
| 42 | |
| 43 | """ |
| 44 | |
| 45 | append2 = """ |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 46 | FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 47 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 48 | SRC_URI:append = " file://appendtest.txt" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 49 | """ |
| 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 57 | 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") |