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