cooker.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License version 2 as
  10. # published by the Free Software Foundation.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. #
  21. import unittest
  22. import tempfile
  23. import os
  24. import bb, bb.cooker
  25. import re
  26. import logging
  27. # Cooker tests
  28. class 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. def test_CookerCollectFiles_sublayers(self):
  35. '''Test that a sublayer of an existing layer does not trigger
  36. No bb files matched ...'''
  37. def append_collection(topdir, path, d):
  38. collection = path.split('/')[-1]
  39. pattern = "^" + topdir + "/" + path + "/"
  40. regex = re.compile(pattern)
  41. priority = 5
  42. d.setVar('BBFILE_COLLECTIONS', (d.getVar('BBFILE_COLLECTIONS') or "") + " " + collection)
  43. d.setVar('BBFILE_PATTERN_%s' % (collection), pattern)
  44. d.setVar('BBFILE_PRIORITY_%s' % (collection), priority)
  45. return (collection, pattern, regex, priority)
  46. topdir = self.d.getVar("TOPDIR")
  47. # Priorities: list of (collection, pattern, regex, priority)
  48. bbfile_config_priorities = []
  49. # Order is important for this test, shortest to longest is typical failure case
  50. bbfile_config_priorities.append( append_collection(topdir, 'first', self.d) )
  51. bbfile_config_priorities.append( append_collection(topdir, 'second', self.d) )
  52. bbfile_config_priorities.append( append_collection(topdir, 'second/third', self.d) )
  53. pkgfns = [ topdir + '/first/recipes/sample1_1.0.bb',
  54. topdir + '/second/recipes/sample2_1.0.bb',
  55. topdir + '/second/third/recipes/sample3_1.0.bb' ]
  56. class LogHandler(logging.Handler):
  57. def __init__(self):
  58. logging.Handler.__init__(self)
  59. self.logdata = []
  60. def emit(self, record):
  61. self.logdata.append(record.getMessage())
  62. # Move cooker to use my special logging
  63. logger = bb.cooker.logger
  64. log_handler = LogHandler()
  65. logger.addHandler(log_handler)
  66. collection = bb.cooker.CookerCollectFiles(bbfile_config_priorities)
  67. collection.collection_priorities(pkgfns, self.d)
  68. logger.removeHandler(log_handler)
  69. # Should be empty (no generated messages)
  70. expected = []
  71. self.assertEqual(log_handler.logdata, expected)