cooker.py 3.1 KB

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