1 # Copyright (c) 2012 The Chromium OS Authors.
3 # SPDX-License-Identifier: GPL-2.0+
9 """A single regular expression for matching boards to build"""
11 def __init__(self, expr):
12 """Set up a new Expr object.
15 expr: String cotaining regular expression to store
18 self._re = re.compile(expr)
20 def Matches(self, props):
21 """Check if any of the properties match the regular expression.
24 props: List of properties to check
26 True if any of the properties match the regular expression
29 if self._re.match(prop):
37 """A list of expressions each of which must match with properties.
39 This provides a list of 'AND' expressions, meaning that each must
40 match the board properties for that board to be built.
46 def AddExpr(self, expr):
47 """Add an Expr object to the list to check.
50 expr: New Expr object to add to the list of those that must
51 match for a board to be built.
53 self._expr_list.append(Expr(expr))
56 """Return some sort of useful string describing the term"""
57 return '&'.join([str(expr) for expr in self._expr_list])
59 def Matches(self, props):
60 """Check if any of the properties match this term
62 Each of the expressions in the term is checked. All must match.
65 props: List of properties to check
67 True if all of the expressions in the Term match, else False
69 for expr in self._expr_list:
70 if not expr.Matches(props):
75 """A particular board that we can build"""
76 def __init__(self, status, arch, cpu, soc, vendor, board_name, target, options):
77 """Create a new board type.
80 status: define whether the board is 'Active' or 'Orphaned'
81 arch: Architecture name (e.g. arm)
82 cpu: Cpu name (e.g. arm1136)
83 soc: Name of SOC, or '' if none (e.g. mx31)
84 vendor: Name of vendor (e.g. armltd)
85 board_name: Name of board (e.g. integrator)
86 target: Target name (use make <target>_defconfig to configure)
87 options: board-specific options (e.g. integratorcp:CM1136)
92 self.board_name = board_name
95 self.props = [self.target, self.arch, self.cpu, self.board_name,
96 self.vendor, self.soc]
97 self.options = options
102 """Manage a list of boards."""
104 # Use a simple list here, sinc OrderedDict requires Python 2.7
107 def AddBoard(self, board):
108 """Add a new board to the list.
110 The board's target member must not already exist in the board list.
115 self._boards.append(board)
117 def ReadBoards(self, fname):
118 """Read a list of boards from a board file.
120 Create a board object for each and add it to our _boards list.
123 fname: Filename of boards.cfg file
125 with open(fname, 'r') as fd:
129 fields = line.split()
132 for upto in range(len(fields)):
133 if fields[upto] == '-':
135 while len(fields) < 8:
140 board = Board(*fields)
145 """Return a list of available boards.
148 List of Board objects
153 """Build a dictionary containing all the boards.
161 for board in self._boards:
162 board_dict[board.target] = board
165 def GetSelectedDict(self):
166 """Return a dictionary containing the selected boards
169 List of Board objects that are marked selected
172 for board in self._boards:
174 board_dict[board.target] = board
177 def GetSelected(self):
178 """Return a list of selected boards
181 List of Board objects that are marked selected
183 return [board for board in self._boards if board.build_it]
185 def GetSelectedNames(self):
186 """Return a list of selected boards
189 List of board names that are marked selected
191 return [board.target for board in self._boards if board.build_it]
193 def _BuildTerms(self, args):
194 """Convert command line arguments to a list of terms.
196 This deals with parsing of the arguments. It handles the '&'
197 operator, which joins several expressions into a single Term.
200 ['arm & freescale sandbox', 'tegra']
202 will produce 3 Terms containing expressions as follows:
207 The first Term has two expressions, both of which must match for
208 a board to be selected.
211 args: List of command line arguments
213 A list of Term objects
217 for word in arg.split():
219 for term in word.split('&'):
221 sym_build.append(term)
222 sym_build.append('&')
223 syms += sym_build[:-1]
242 def SelectBoards(self, args):
243 """Mark boards selected based on args
246 List of strings specifying boards to include, either named, or
247 by their target, architecture, cpu, vendor or soc. If empty, all
251 Dictionary which holds the number of boards which were selected
252 due to each argument, arranged by argument.
255 terms = self._BuildTerms(args)
259 result[str(term)] = 0
261 for board in self._boards:
265 if term.Matches(board.props):
266 board.build_it = True
267 result[str(term)] += 1
271 board.build_it = True