blob: 5172a473e35333296b97eb1a4bb6dfa79a6f51a0 [file] [log] [blame]
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001# Copyright (c) 2012 The Chromium OS Authors.
2#
Wolfgang Denk1a459662013-07-08 09:37:19 +02003# SPDX-License-Identifier: GPL-2.0+
Simon Glassfc3fe1c2013-04-03 11:07:16 +00004#
5
Stephen Warren8426d8b2013-10-10 10:00:20 -06006import re
7
Simon Glassfc3fe1c2013-04-03 11:07:16 +00008class Board:
9 """A particular board that we can build"""
Andreas Bießmann03c1bb22013-09-19 10:08:45 +020010 def __init__(self, status, arch, cpu, soc, vendor, board_name, target, options):
Simon Glassfc3fe1c2013-04-03 11:07:16 +000011 """Create a new board type.
12
13 Args:
Andreas Bießmann03c1bb22013-09-19 10:08:45 +020014 status: define whether the board is 'Active' or 'Orphaned'
Simon Glassfc3fe1c2013-04-03 11:07:16 +000015 arch: Architecture name (e.g. arm)
16 cpu: Cpu name (e.g. arm1136)
Simon Glassfc3fe1c2013-04-03 11:07:16 +000017 soc: Name of SOC, or '' if none (e.g. mx31)
Andreas Bießmann03c1bb22013-09-19 10:08:45 +020018 vendor: Name of vendor (e.g. armltd)
19 board_name: Name of board (e.g. integrator)
20 target: Target name (use make <target>_config to configure)
Simon Glassfc3fe1c2013-04-03 11:07:16 +000021 options: board-specific options (e.g. integratorcp:CM1136)
22 """
23 self.target = target
24 self.arch = arch
25 self.cpu = cpu
26 self.board_name = board_name
27 self.vendor = vendor
28 self.soc = soc
29 self.props = [self.target, self.arch, self.cpu, self.board_name,
30 self.vendor, self.soc]
31 self.options = options
32 self.build_it = False
33
34
35class Boards:
36 """Manage a list of boards."""
37 def __init__(self):
38 # Use a simple list here, sinc OrderedDict requires Python 2.7
39 self._boards = []
40
41 def AddBoard(self, board):
42 """Add a new board to the list.
43
44 The board's target member must not already exist in the board list.
45
46 Args:
47 board: board to add
48 """
49 self._boards.append(board)
50
51 def ReadBoards(self, fname):
52 """Read a list of boards from a board file.
53
54 Create a board object for each and add it to our _boards list.
55
56 Args:
57 fname: Filename of boards.cfg file
58 """
59 with open(fname, 'r') as fd:
60 for line in fd:
61 if line[0] == '#':
62 continue
63 fields = line.split()
64 if not fields:
65 continue
66 for upto in range(len(fields)):
67 if fields[upto] == '-':
68 fields[upto] = ''
Andreas Bießmann03c1bb22013-09-19 10:08:45 +020069 while len(fields) < 8:
Simon Glassfc3fe1c2013-04-03 11:07:16 +000070 fields.append('')
Andreas Bießmann03c1bb22013-09-19 10:08:45 +020071 if len(fields) > 8:
72 fields = fields[:8]
Simon Glassfc3fe1c2013-04-03 11:07:16 +000073
74 board = Board(*fields)
75 self.AddBoard(board)
76
77
78 def GetList(self):
79 """Return a list of available boards.
80
81 Returns:
82 List of Board objects
83 """
84 return self._boards
85
86 def GetDict(self):
87 """Build a dictionary containing all the boards.
88
89 Returns:
90 Dictionary:
91 key is board.target
92 value is board
93 """
94 board_dict = {}
95 for board in self._boards:
96 board_dict[board.target] = board
97 return board_dict
98
99 def GetSelectedDict(self):
100 """Return a dictionary containing the selected boards
101
102 Returns:
103 List of Board objects that are marked selected
104 """
105 board_dict = {}
106 for board in self._boards:
107 if board.build_it:
108 board_dict[board.target] = board
109 return board_dict
110
111 def GetSelected(self):
112 """Return a list of selected boards
113
114 Returns:
115 List of Board objects that are marked selected
116 """
117 return [board for board in self._boards if board.build_it]
118
119 def GetSelectedNames(self):
120 """Return a list of selected boards
121
122 Returns:
123 List of board names that are marked selected
124 """
125 return [board.target for board in self._boards if board.build_it]
126
127 def SelectBoards(self, args):
128 """Mark boards selected based on args
129
130 Args:
131 List of strings specifying boards to include, either named, or
132 by their target, architecture, cpu, vendor or soc. If empty, all
133 boards are selected.
134
135 Returns:
136 Dictionary which holds the number of boards which were selected
137 due to each argument, arranged by argument.
138 """
139 result = {}
Stephen Warren8426d8b2013-10-10 10:00:20 -0600140 argres = {}
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000141 for arg in args:
142 result[arg] = 0
Stephen Warren8426d8b2013-10-10 10:00:20 -0600143 argres[arg] = re.compile(arg)
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000144 result['all'] = 0
145
146 for board in self._boards:
147 if args:
148 for arg in args:
Stephen Warren8426d8b2013-10-10 10:00:20 -0600149 argre = argres[arg]
150 match = False
151 for prop in board.props:
152 match = argre.match(prop)
153 if match:
154 break
155 if match:
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000156 if not board.build_it:
157 board.build_it = True
158 result[arg] += 1
159 result['all'] += 1
160 else:
161 board.build_it = True
162 result['all'] += 1
163
164 return result