cooker.py 2.5 KB

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