1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2012 The Chromium OS Authors.
7 """A single regular expression for matching boards to build"""
9 def __init__(self, expr):
10 """Set up a new Expr object.
13 expr: String cotaining regular expression to store
16 self._re = re.compile(expr)
18 def Matches(self, props):
19 """Check if any of the properties match the regular expression.
22 props: List of properties to check
24 True if any of the properties match the regular expression
27 if self._re.match(prop):
35 """A list of expressions each of which must match with properties.
37 This provides a list of 'AND' expressions, meaning that each must
38 match the board properties for that board to be built.
44 def AddExpr(self, expr):
45 """Add an Expr object to the list to check.
48 expr: New Expr object to add to the list of those that must
49 match for a board to be built.
51 self._expr_list.append(Expr(expr))
54 """Return some sort of useful string describing the term"""
55 return '&'.join([str(expr) for expr in self._expr_list])
57 def Matches(self, props):
58 """Check if any of the properties match this term
60 Each of the expressions in the term is checked. All must match.
63 props: List of properties to check
65 True if all of the expressions in the Term match, else False
67 for expr in self._expr_list:
68 if not expr.Matches(props):
73 """A particular board that we can build"""
74 def __init__(self, status, arch, cpu, soc, vendor, board_name, target, options):
75 """Create a new board type.
78 status: define whether the board is 'Active' or 'Orphaned'
79 arch: Architecture name (e.g. arm)
80 cpu: Cpu name (e.g. arm1136)
81 soc: Name of SOC, or '' if none (e.g. mx31)
82 vendor: Name of vendor (e.g. armltd)
83 board_name: Name of board (e.g. integrator)
84 target: Target name (use make <target>_defconfig to configure)
85 options: board-specific options (e.g. integratorcp:CM1136)
90 self.board_name = board_name
93 self.options = options
94 self.props = [self.target, self.arch, self.cpu, self.board_name,
95 self.vendor, self.soc, self.options]
100 """Manage a list of boards."""
102 # Use a simple list here, sinc OrderedDict requires Python 2.7
105 def AddBoard(self, board):
106 """Add a new board to the list.
108 The board's target member must not already exist in the board list.
113 self._boards.append(board)
115 def ReadBoards(self, fname):
116 """Read a list of boards from a board file.
118 Create a board object for each and add it to our _boards list.
121 fname: Filename of boards.cfg file
123 with open(fname, 'r') as fd:
127 fields = line.split()
130 for upto in range(len(fields)):
131 if fields[upto] == '-':
133 while len(fields) < 8:
138 board = Board(*fields)
143 """Return a list of available boards.
146 List of Board objects
151 """Build a dictionary containing all the boards.
159 for board in self._boards:
160 board_dict[board.target] = board
163 def GetSelectedDict(self):
164 """Return a dictionary containing the selected boards
167 List of Board objects that are marked selected
170 for board in self._boards:
172 board_dict[board.target] = board
175 def GetSelected(self):
176 """Return a list of selected boards
179 List of Board objects that are marked selected
181 return [board for board in self._boards if board.build_it]
183 def GetSelectedNames(self):
184 """Return a list of selected boards
187 List of board names that are marked selected
189 return [board.target for board in self._boards if board.build_it]
191 def _BuildTerms(self, args):
192 """Convert command line arguments to a list of terms.
194 This deals with parsing of the arguments. It handles the '&'
195 operator, which joins several expressions into a single Term.
198 ['arm & freescale sandbox', 'tegra']
200 will produce 3 Terms containing expressions as follows:
205 The first Term has two expressions, both of which must match for
206 a board to be selected.
209 args: List of command line arguments
211 A list of Term objects
215 for word in arg.split():
217 for term in word.split('&'):
219 sym_build.append(term)
220 sym_build.append('&')
221 syms += sym_build[:-1]
240 def SelectBoards(self, args, exclude=[]):
241 """Mark boards selected based on args
244 args: List of strings specifying boards to include, either named,
245 or by their target, architecture, cpu, vendor or soc. If
246 empty, all boards are selected.
247 exclude: List of boards to exclude, regardless of 'args'
250 Dictionary which holds the list of boards which were selected
251 due to each argument, arranged by argument.
254 terms = self._BuildTerms(args)
258 result[str(term)] = []
262 exclude_list.append(Expr(expr))
264 for board in self._boards:
270 if term.Matches(board.props):
271 matching_term = str(term)
277 # Check that it is not specifically excluded
278 for expr in exclude_list:
279 if expr.Matches(board.props):
284 board.build_it = True
286 result[matching_term].append(board.target)
287 result['all'].append(board.target)