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