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