board.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. # Copyright (c) 2012 The Chromium OS Authors.
  2. #
  3. # See file CREDITS for list of people who contributed to this
  4. # project.
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License as
  8. # published by the Free Software Foundation; either version 2 of
  9. # the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19. # MA 02111-1307 USA
  20. #
  21. class Board:
  22. """A particular board that we can build"""
  23. def __init__(self, target, arch, cpu, board_name, vendor, soc, options):
  24. """Create a new board type.
  25. Args:
  26. target: Target name (use make <target>_config to configure)
  27. arch: Architecture name (e.g. arm)
  28. cpu: Cpu name (e.g. arm1136)
  29. board_name: Name of board (e.g. integrator)
  30. vendor: Name of vendor (e.g. armltd)
  31. soc: Name of SOC, or '' if none (e.g. mx31)
  32. options: board-specific options (e.g. integratorcp:CM1136)
  33. """
  34. self.target = target
  35. self.arch = arch
  36. self.cpu = cpu
  37. self.board_name = board_name
  38. self.vendor = vendor
  39. self.soc = soc
  40. self.props = [self.target, self.arch, self.cpu, self.board_name,
  41. self.vendor, self.soc]
  42. self.options = options
  43. self.build_it = False
  44. class Boards:
  45. """Manage a list of boards."""
  46. def __init__(self):
  47. # Use a simple list here, sinc OrderedDict requires Python 2.7
  48. self._boards = []
  49. def AddBoard(self, board):
  50. """Add a new board to the list.
  51. The board's target member must not already exist in the board list.
  52. Args:
  53. board: board to add
  54. """
  55. self._boards.append(board)
  56. def ReadBoards(self, fname):
  57. """Read a list of boards from a board file.
  58. Create a board object for each and add it to our _boards list.
  59. Args:
  60. fname: Filename of boards.cfg file
  61. """
  62. with open(fname, 'r') as fd:
  63. for line in fd:
  64. if line[0] == '#':
  65. continue
  66. fields = line.split()
  67. if not fields:
  68. continue
  69. for upto in range(len(fields)):
  70. if fields[upto] == '-':
  71. fields[upto] = ''
  72. while len(fields) < 7:
  73. fields.append('')
  74. board = Board(*fields)
  75. self.AddBoard(board)
  76. def GetList(self):
  77. """Return a list of available boards.
  78. Returns:
  79. List of Board objects
  80. """
  81. return self._boards
  82. def GetDict(self):
  83. """Build a dictionary containing all the boards.
  84. Returns:
  85. Dictionary:
  86. key is board.target
  87. value is board
  88. """
  89. board_dict = {}
  90. for board in self._boards:
  91. board_dict[board.target] = board
  92. return board_dict
  93. def GetSelectedDict(self):
  94. """Return a dictionary containing the selected boards
  95. Returns:
  96. List of Board objects that are marked selected
  97. """
  98. board_dict = {}
  99. for board in self._boards:
  100. if board.build_it:
  101. board_dict[board.target] = board
  102. return board_dict
  103. def GetSelected(self):
  104. """Return a list of selected boards
  105. Returns:
  106. List of Board objects that are marked selected
  107. """
  108. return [board for board in self._boards if board.build_it]
  109. def GetSelectedNames(self):
  110. """Return a list of selected boards
  111. Returns:
  112. List of board names that are marked selected
  113. """
  114. return [board.target for board in self._boards if board.build_it]
  115. def SelectBoards(self, args):
  116. """Mark boards selected based on args
  117. Args:
  118. List of strings specifying boards to include, either named, or
  119. by their target, architecture, cpu, vendor or soc. If empty, all
  120. boards are selected.
  121. Returns:
  122. Dictionary which holds the number of boards which were selected
  123. due to each argument, arranged by argument.
  124. """
  125. result = {}
  126. for arg in args:
  127. result[arg] = 0
  128. result['all'] = 0
  129. for board in self._boards:
  130. if args:
  131. for arg in args:
  132. if arg in board.props:
  133. if not board.build_it:
  134. board.build_it = True
  135. result[arg] += 1
  136. result['all'] += 1
  137. else:
  138. board.build_it = True
  139. result['all'] += 1
  140. return result