blob: 2b4423650600d249ff911ae6bde30d1faf3c660c [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3#
4# BitBake Tests for cooker.py
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License version 2 as
8# published by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18#
19
20import unittest
21import tempfile
22import os
23import bb, bb.cooker
24import re
25import logging
26
27# Cooker tests
28class CookerTest(unittest.TestCase):
29 def setUp(self):
30 # At least one variable needs to be set
31 self.d = bb.data.init()
32 topdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "testdata/cooker")
33 self.d.setVar('TOPDIR', topdir)
34
35 def test_CookerCollectFiles_sublayers(self):
36 '''Test that a sublayer of an existing layer does not trigger
37 No bb files matched ...'''
38
39 def append_collection(topdir, path, d):
40 collection = path.split('/')[-1]
41 pattern = "^" + topdir + "/" + path + "/"
42 regex = re.compile(pattern)
43 priority = 5
44
45 d.setVar('BBFILE_COLLECTIONS', (d.getVar('BBFILE_COLLECTIONS') or "") + " " + collection)
46 d.setVar('BBFILE_PATTERN_%s' % (collection), pattern)
47 d.setVar('BBFILE_PRIORITY_%s' % (collection), priority)
48
49 return (collection, pattern, regex, priority)
50
51 topdir = self.d.getVar("TOPDIR")
52
53 # Priorities: list of (collection, pattern, regex, priority)
54 bbfile_config_priorities = []
55 # Order is important for this test, shortest to longest is typical failure case
56 bbfile_config_priorities.append( append_collection(topdir, 'first', self.d) )
57 bbfile_config_priorities.append( append_collection(topdir, 'second', self.d) )
58 bbfile_config_priorities.append( append_collection(topdir, 'second/third', self.d) )
59
60 pkgfns = [ topdir + '/first/recipes/sample1_1.0.bb',
61 topdir + '/second/recipes/sample2_1.0.bb',
62 topdir + '/second/third/recipes/sample3_1.0.bb' ]
63
64 class LogHandler(logging.Handler):
65 def __init__(self):
66 logging.Handler.__init__(self)
67 self.logdata = []
68
69 def emit(self, record):
70 self.logdata.append(record.getMessage())
71
72 # Move cooker to use my special logging
73 logger = bb.cooker.logger
74 log_handler = LogHandler()
75 logger.addHandler(log_handler)
76 collection = bb.cooker.CookerCollectFiles(bbfile_config_priorities)
77 collection.collection_priorities(pkgfns, self.d)
78 logger.removeHandler(log_handler)
79
80 # Should be empty (no generated messages)
81 expected = []
82
83 self.assertEqual(log_handler.logdata, expected)