blob: 9e524ae34505b26bf38360c18af7c74be4b994de [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001#
2# BitBake Tests for cooker.py
3#
Patrick Williams92b42cb2022-09-03 06:53:57 -05004# Copyright BitBake Contributors
5#
Brad Bishopc342db32019-05-15 21:57:59 -04006# SPDX-License-Identifier: GPL-2.0-only
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08007#
8
9import unittest
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080010import os
11import bb, bb.cooker
12import re
13import logging
14
15# Cooker tests
16class 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 Geisslerb7d28612020-07-24 16:15:54 -050065 collection.collection_priorities(pkgfns, pkgfns, self.d)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080066 logger.removeHandler(log_handler)
67
68 # Should be empty (no generated messages)
69 expected = []
70
71 self.assertEqual(log_handler.logdata, expected)