board.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. # Copyright (c) 2012 The Chromium OS Authors.
  2. #
  3. # SPDX-License-Identifier: GPL-2.0+
  4. #
  5. class Board:
  6. """A particular board that we can build"""
  7. def __init__(self, status, arch, cpu, soc, vendor, board_name, target, options):
  8. """Create a new board type.
  9. Args:
  10. status: define whether the board is 'Active' or 'Orphaned'
  11. arch: Architecture name (e.g. arm)
  12. cpu: Cpu name (e.g. arm1136)
  13. soc: Name of SOC, or '' if none (e.g. mx31)
  14. vendor: Name of vendor (e.g. armltd)
  15. board_name: Name of board (e.g. integrator)
  16. target: Target name (use make <target>_config to configure)
  17. options: board-specific options (e.g. integratorcp:CM1136)
  18. """
  19. self.target = target
  20. self.arch = arch
  21. self.cpu = cpu
  22. self.board_name = board_name
  23. self.vendor = vendor
  24. self.soc = soc
  25. self.props = [self.target, self.arch, self.cpu, self.board_name,
  26. self.vendor, self.soc]
  27. self.options = options
  28. self.build_it = False
  29. class Boards:
  30. """Manage a list of boards."""
  31. def __init__(self):
  32. # Use a simple list here, sinc OrderedDict requires Python 2.7
  33. self._boards = []
  34. def AddBoard(self, board):
  35. """Add a new board to the list.
  36. The board's target member must not already exist in the board list.
  37. Args:
  38. board: board to add
  39. """
  40. self._boards.append(board)
  41. def ReadBoards(self, fname):
  42. """Read a list of boards from a board file.
  43. Create a board object for each and add it to our _boards list.
  44. Args:
  45. fname: Filename of boards.cfg file
  46. """
  47. with open(fname, 'r') as fd:
  48. for line in fd:
  49. if line[0] == '#':
  50. continue
  51. fields = line.split()
  52. if not fields:
  53. continue
  54. for upto in range(len(fields)):
  55. if fields[upto] == '-':
  56. fields[upto] = ''
  57. while len(fields) < 8:
  58. fields.append('')
  59. if len(fields) > 8:
  60. fields = fields[:8]
  61. board = Board(*fields)
  62. self.AddBoard(board)
  63. def GetList(self):
  64. """Return a list of available boards.
  65. Returns:
  66. List of Board objects
  67. """
  68. return self._boards
  69. def GetDict(self):
  70. """Build a dictionary containing all the boards.
  71. Returns:
  72. Dictionary:
  73. key is board.target
  74. value is board
  75. """
  76. board_dict = {}
  77. for board in self._boards:
  78. board_dict[board.target] = board
  79. return board_dict
  80. def GetSelectedDict(self):
  81. """Return a dictionary containing the selected boards
  82. Returns:
  83. List of Board objects that are marked selected
  84. """
  85. board_dict = {}
  86. for board in self._boards:
  87. if board.build_it:
  88. board_dict[board.target] = board
  89. return board_dict
  90. def GetSelected(self):
  91. """Return a list of selected boards
  92. Returns:
  93. List of Board objects that are marked selected
  94. """
  95. return [board for board in self._boards if board.build_it]
  96. def GetSelectedNames(self):
  97. """Return a list of selected boards
  98. Returns:
  99. List of board names that are marked selected
  100. """
  101. return [board.target for board in self._boards if board.build_it]
  102. def SelectBoards(self, args):
  103. """Mark boards selected based on args
  104. Args:
  105. List of strings specifying boards to include, either named, or
  106. by their target, architecture, cpu, vendor or soc. If empty, all
  107. boards are selected.
  108. Returns:
  109. Dictionary which holds the number of boards which were selected
  110. due to each argument, arranged by argument.
  111. """
  112. result = {}
  113. for arg in args:
  114. result[arg] = 0
  115. result['all'] = 0
  116. for board in self._boards:
  117. if args:
  118. for arg in args:
  119. if arg in board.props:
  120. if not board.build_it:
  121. board.build_it = True
  122. result[arg] += 1
  123. result['all'] += 1
  124. else:
  125. board.build_it = True
  126. result['all'] += 1
  127. return result