Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1 | # |
| 2 | # BitBake Tests for cooker.py |
| 3 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 4 | # Copyright BitBake Contributors |
| 5 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 6 | # SPDX-License-Identifier: GPL-2.0-only |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 7 | # |
| 8 | |
| 9 | import unittest |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 10 | import os |
| 11 | import bb, bb.cooker |
| 12 | import re |
| 13 | import logging |
| 14 | |
| 15 | # Cooker tests |
| 16 | class CookerTest(unittest.TestCase): |
| 17 | def setUp(self): |
| 18 | # At least one variable needs to be set |
| 19 | self.d = bb.data.init() |
| 20 | topdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "testdata/cooker") |
| 21 | self.d.setVar('TOPDIR', topdir) |
| 22 | |
| 23 | def test_CookerCollectFiles_sublayers(self): |
| 24 | '''Test that a sublayer of an existing layer does not trigger |
| 25 | No bb files matched ...''' |
| 26 | |
| 27 | def append_collection(topdir, path, d): |
| 28 | collection = path.split('/')[-1] |
| 29 | pattern = "^" + topdir + "/" + path + "/" |
| 30 | regex = re.compile(pattern) |
| 31 | priority = 5 |
| 32 | |
| 33 | d.setVar('BBFILE_COLLECTIONS', (d.getVar('BBFILE_COLLECTIONS') or "") + " " + collection) |
| 34 | d.setVar('BBFILE_PATTERN_%s' % (collection), pattern) |
| 35 | d.setVar('BBFILE_PRIORITY_%s' % (collection), priority) |
| 36 | |
| 37 | return (collection, pattern, regex, priority) |
| 38 | |
| 39 | topdir = self.d.getVar("TOPDIR") |
| 40 | |
| 41 | # Priorities: list of (collection, pattern, regex, priority) |
| 42 | bbfile_config_priorities = [] |
| 43 | # Order is important for this test, shortest to longest is typical failure case |
| 44 | bbfile_config_priorities.append( append_collection(topdir, 'first', self.d) ) |
| 45 | bbfile_config_priorities.append( append_collection(topdir, 'second', self.d) ) |
| 46 | bbfile_config_priorities.append( append_collection(topdir, 'second/third', self.d) ) |
| 47 | |
| 48 | pkgfns = [ topdir + '/first/recipes/sample1_1.0.bb', |
| 49 | topdir + '/second/recipes/sample2_1.0.bb', |
| 50 | topdir + '/second/third/recipes/sample3_1.0.bb' ] |
| 51 | |
| 52 | class LogHandler(logging.Handler): |
| 53 | def __init__(self): |
| 54 | logging.Handler.__init__(self) |
| 55 | self.logdata = [] |
| 56 | |
| 57 | def emit(self, record): |
| 58 | self.logdata.append(record.getMessage()) |
| 59 | |
| 60 | # Move cooker to use my special logging |
| 61 | logger = bb.cooker.logger |
| 62 | log_handler = LogHandler() |
| 63 | logger.addHandler(log_handler) |
| 64 | collection = bb.cooker.CookerCollectFiles(bbfile_config_priorities) |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 65 | collection.collection_priorities(pkgfns, pkgfns, self.d) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 66 | logger.removeHandler(log_handler) |
| 67 | |
| 68 | # Should be empty (no generated messages) |
| 69 | expected = [] |
| 70 | |
| 71 | self.assertEqual(log_handler.logdata, expected) |