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