cooker.py 2.6 KB

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