blob: 9f50abadc1fb9540c0c6f3c464753cd460703668 [file] [log] [blame]
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001# 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
22class Board:
23 """A particular board that we can build"""
24 def __init__(self, target, arch, cpu, board_name, vendor, soc, options):
25 """Create a new board type.
26
27 Args:
28 target: Target name (use make <target>_config to configure)
29 arch: Architecture name (e.g. arm)
30 cpu: Cpu name (e.g. arm1136)
31 board_name: Name of board (e.g. integrator)
32 vendor: Name of vendor (e.g. armltd)
33 soc: Name of SOC, or '' if none (e.g. mx31)
34 options: board-specific options (e.g. integratorcp:CM1136)
35 """
36 self.target = target
37 self.arch = arch
38 self.cpu = cpu
39 self.board_name = board_name
40 self.vendor = vendor
41 self.soc = soc
42 self.props = [self.target, self.arch, self.cpu, self.board_name,
43 self.vendor, self.soc]
44 self.options = options
45 self.build_it = False
46
47
48class Boards:
49 """Manage a list of boards."""
50 def __init__(self):
51 # Use a simple list here, sinc OrderedDict requires Python 2.7
52 self._boards = []
53
54 def AddBoard(self, board):
55 """Add a new board to the list.
56
57 The board's target member must not already exist in the board list.
58
59 Args:
60 board: board to add
61 """
62 self._boards.append(board)
63
64 def ReadBoards(self, fname):
65 """Read a list of boards from a board file.
66
67 Create a board object for each and add it to our _boards list.
68
69 Args:
70 fname: Filename of boards.cfg file
71 """
72 with open(fname, 'r') as fd:
73 for line in fd:
74 if line[0] == '#':
75 continue
76 fields = line.split()
77 if not fields:
78 continue
79 for upto in range(len(fields)):
80 if fields[upto] == '-':
81 fields[upto] = ''
82 while len(fields) < 7:
83 fields.append('')
84
85 board = Board(*fields)
86 self.AddBoard(board)
87
88
89 def GetList(self):
90 """Return a list of available boards.
91
92 Returns:
93 List of Board objects
94 """
95 return self._boards
96
97 def GetDict(self):
98 """Build a dictionary containing all the boards.
99
100 Returns:
101 Dictionary:
102 key is board.target
103 value is board
104 """
105 board_dict = {}
106 for board in self._boards:
107 board_dict[board.target] = board
108 return board_dict
109
110 def GetSelectedDict(self):
111 """Return a dictionary containing the selected boards
112
113 Returns:
114 List of Board objects that are marked selected
115 """
116 board_dict = {}
117 for board in self._boards:
118 if board.build_it:
119 board_dict[board.target] = board
120 return board_dict
121
122 def GetSelected(self):
123 """Return a list of selected boards
124
125 Returns:
126 List of Board objects that are marked selected
127 """
128 return [board for board in self._boards if board.build_it]
129
130 def GetSelectedNames(self):
131 """Return a list of selected boards
132
133 Returns:
134 List of board names that are marked selected
135 """
136 return [board.target for board in self._boards if board.build_it]
137
138 def SelectBoards(self, args):
139 """Mark boards selected based on args
140
141 Args:
142 List of strings specifying boards to include, either named, or
143 by their target, architecture, cpu, vendor or soc. If empty, all
144 boards are selected.
145
146 Returns:
147 Dictionary which holds the number of boards which were selected
148 due to each argument, arranged by argument.
149 """
150 result = {}
151 for arg in args:
152 result[arg] = 0
153 result['all'] = 0
154
155 for board in self._boards:
156 if args:
157 for arg in args:
158 if arg in board.props:
159 if not board.build_it:
160 board.build_it = True
161 result[arg] += 1
162 result['all'] += 1
163 else:
164 board.build_it = True
165 result['all'] += 1
166
167 return result