From f4ed4706ef6668890bfc906ea3071429fb7f8990 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 11 Jul 2022 19:03:57 -0600 Subject: buildman: Avoid using board as a variable We have a module called 'board'. Sometimes buildman uses 'brd' as an instance variable but sometimes it uses 'board', which is confusing and can mess with the module handling. Update the code to use 'brd' consistently, making it easier for tools to determine when the module is being referenced. Signed-off-by: Simon Glass --- tools/buildman/board.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'tools/buildman/board.py') diff --git a/tools/buildman/board.py b/tools/buildman/board.py index 447aaabea8..08771b3f15 100644 --- a/tools/buildman/board.py +++ b/tools/buildman/board.py @@ -103,15 +103,15 @@ class Boards: # Use a simple list here, sinc OrderedDict requires Python 2.7 self._boards = [] - def AddBoard(self, board): + def AddBoard(self, brd): """Add a new board to the list. The board's target member must not already exist in the board list. Args: - board: board to add + brd: board to add """ - self._boards.append(board) + self._boards.append(brd) def ReadBoards(self, fname): """Read a list of boards from a board file. @@ -136,8 +136,8 @@ class Boards: if len(fields) > 8: fields = fields[:8] - board = Board(*fields) - self.AddBoard(board) + brd = Board(*fields) + self.AddBoard(brd) def GetList(self): @@ -157,8 +157,8 @@ class Boards: value is board """ board_dict = OrderedDict() - for board in self._boards: - board_dict[board.target] = board + for brd in self._boards: + board_dict[brd.target] = brd return board_dict def GetSelectedDict(self): @@ -168,9 +168,9 @@ class Boards: List of Board objects that are marked selected """ board_dict = OrderedDict() - for board in self._boards: - if board.build_it: - board_dict[board.target] = board + for brd in self._boards: + if brd.build_it: + board_dict[brd.target] = brd return board_dict def GetSelected(self): @@ -179,7 +179,7 @@ class Boards: Returns: List of Board objects that are marked selected """ - return [board for board in self._boards if board.build_it] + return [brd for brd in self._boards if brd.build_it] def GetSelectedNames(self): """Return a list of selected boards @@ -187,7 +187,7 @@ class Boards: Returns: List of board names that are marked selected """ - return [board.target for board in self._boards if board.build_it] + return [brd.target for brd in self._boards if brd.build_it] def _BuildTerms(self, args): """Convert command line arguments to a list of terms. @@ -273,34 +273,34 @@ class Boards: exclude_list.append(Expr(expr)) found = [] - for board in self._boards: + for brd in self._boards: matching_term = None build_it = False if terms: match = False for term in terms: - if term.Matches(board.props): + if term.Matches(brd.props): matching_term = str(term) build_it = True break elif boards: - if board.target in boards: + if brd.target in boards: build_it = True - found.append(board.target) + found.append(brd.target) else: build_it = True # Check that it is not specifically excluded for expr in exclude_list: - if expr.Matches(board.props): + if expr.Matches(brd.props): build_it = False break if build_it: - board.build_it = True + brd.build_it = True if matching_term: - result[matching_term].append(board.target) - result['all'].append(board.target) + result[matching_term].append(brd.target) + result['all'].append(brd.target) if boards: remaining = set(boards) - set(found) -- cgit v1.2.3 From fb5cb07abe9856eac2089ed175e08e115db01f2b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 11 Jul 2022 19:04:01 -0600 Subject: buildman: Drop use of 'board' in board module Use brds instead so that we can reserve 'boards' and 'board' as module names. Signed-off-by: Simon Glass --- tools/buildman/board.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'tools/buildman/board.py') diff --git a/tools/buildman/board.py b/tools/buildman/board.py index 08771b3f15..8de71e487e 100644 --- a/tools/buildman/board.py +++ b/tools/buildman/board.py @@ -116,7 +116,7 @@ class Boards: def ReadBoards(self, fname): """Read a list of boards from a board file. - Create a board object for each and add it to our _boards list. + Create a Board object for each and add it to our _boards list. Args: fname: Filename of boards.cfg file @@ -238,21 +238,21 @@ class Boards: terms.append(term) return terms - def SelectBoards(self, args, exclude=[], boards=None): + def SelectBoards(self, args, exclude=[], brds=None): """Mark boards selected based on args Normally either boards (an explicit list of boards) or args (a list of terms to match against) is used. It is possible to specify both, in which case they are additive. - If boards and args are both empty, all boards are selected. + If brds and args are both empty, all boards are selected. Args: args: List of strings specifying boards to include, either named, or by their target, architecture, cpu, vendor or soc. If empty, all boards are selected. exclude: List of boards to exclude, regardless of 'args' - boards: List of boards to build + brds: List of boards to build Returns: Tuple @@ -283,8 +283,8 @@ class Boards: matching_term = str(term) build_it = True break - elif boards: - if brd.target in boards: + elif brds: + if brd.target in brds: build_it = True found.append(brd.target) else: @@ -302,8 +302,8 @@ class Boards: result[matching_term].append(brd.target) result['all'].append(brd.target) - if boards: - remaining = set(boards) - set(found) + if brds: + remaining = set(brds) - set(found) if remaining: warnings.append('Boards not found: %s\n' % ', '.join(remaining)) -- cgit v1.2.3 From 6014db68d39cd2b0760c50093b6529d7ebf9afe8 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 11 Jul 2022 19:04:02 -0600 Subject: buildman: Convert camel case in board.py Convert this file to snake case and update all files which use it. Signed-off-by: Simon Glass --- tools/buildman/board.py | 38 +++++++++++++++++++------------------- tools/buildman/control.py | 12 ++++++------ tools/buildman/func_test.py | 10 +++++----- tools/buildman/test.py | 24 ++++++++++++------------ 4 files changed, 42 insertions(+), 42 deletions(-) (limited to 'tools/buildman/board.py') diff --git a/tools/buildman/board.py b/tools/buildman/board.py index 8de71e487e..ebb9d6f67d 100644 --- a/tools/buildman/board.py +++ b/tools/buildman/board.py @@ -16,7 +16,7 @@ class Expr: self._expr = expr self._re = re.compile(expr) - def Matches(self, props): + def matches(self, props): """Check if any of the properties match the regular expression. Args: @@ -42,7 +42,7 @@ class Term: self._expr_list = [] self._board_count = 0 - def AddExpr(self, expr): + def add_expr(self, expr): """Add an Expr object to the list to check. Args: @@ -55,7 +55,7 @@ class Term: """Return some sort of useful string describing the term""" return '&'.join([str(expr) for expr in self._expr_list]) - def Matches(self, props): + def matches(self, props): """Check if any of the properties match this term Each of the expressions in the term is checked. All must match. @@ -66,7 +66,7 @@ class Term: True if all of the expressions in the Term match, else False """ for expr in self._expr_list: - if not expr.Matches(props): + if not expr.matches(props): return False return True @@ -103,7 +103,7 @@ class Boards: # Use a simple list here, sinc OrderedDict requires Python 2.7 self._boards = [] - def AddBoard(self, brd): + def add_board(self, brd): """Add a new board to the list. The board's target member must not already exist in the board list. @@ -113,7 +113,7 @@ class Boards: """ self._boards.append(brd) - def ReadBoards(self, fname): + def read_boards(self, fname): """Read a list of boards from a board file. Create a Board object for each and add it to our _boards list. @@ -137,10 +137,10 @@ class Boards: fields = fields[:8] brd = Board(*fields) - self.AddBoard(brd) + self.add_board(brd) - def GetList(self): + def get_list(self): """Return a list of available boards. Returns: @@ -148,7 +148,7 @@ class Boards: """ return self._boards - def GetDict(self): + def get_dict(self): """Build a dictionary containing all the boards. Returns: @@ -161,7 +161,7 @@ class Boards: board_dict[brd.target] = brd return board_dict - def GetSelectedDict(self): + def get_selected_dict(self): """Return a dictionary containing the selected boards Returns: @@ -173,7 +173,7 @@ class Boards: board_dict[brd.target] = brd return board_dict - def GetSelected(self): + def get_selected(self): """Return a list of selected boards Returns: @@ -181,7 +181,7 @@ class Boards: """ return [brd for brd in self._boards if brd.build_it] - def GetSelectedNames(self): + def get_selected_names(self): """Return a list of selected boards Returns: @@ -189,7 +189,7 @@ class Boards: """ return [brd.target for brd in self._boards if brd.build_it] - def _BuildTerms(self, args): + def _build_terms(self, args): """Convert command line arguments to a list of terms. This deals with parsing of the arguments. It handles the '&' @@ -227,18 +227,18 @@ class Boards: if sym == '&': oper = sym elif oper: - term.AddExpr(sym) + term.add_expr(sym) oper = None else: if term: terms.append(term) term = Term() - term.AddExpr(sym) + term.add_expr(sym) if term: terms.append(term) return terms - def SelectBoards(self, args, exclude=[], brds=None): + def select_boards(self, args, exclude=[], brds=None): """Mark boards selected based on args Normally either boards (an explicit list of boards) or args (a list of @@ -262,7 +262,7 @@ class Boards: """ result = OrderedDict() warnings = [] - terms = self._BuildTerms(args) + terms = self._build_terms(args) result['all'] = [] for term in terms: @@ -279,7 +279,7 @@ class Boards: if terms: match = False for term in terms: - if term.Matches(brd.props): + if term.matches(brd.props): matching_term = str(term) build_it = True break @@ -292,7 +292,7 @@ class Boards: # Check that it is not specifically excluded for expr in exclude_list: - if expr.Matches(brd.props): + if expr.matches(brd.props): build_it = False break diff --git a/tools/buildman/control.py b/tools/buildman/control.py index c4dfc2af57..a5c1c2e51c 100644 --- a/tools/buildman/control.py +++ b/tools/buildman/control.py @@ -100,7 +100,7 @@ def ShowToolchainPrefix(brds, toolchains): Return: None on success, string error message otherwise """ - board_selected = brds.GetSelectedDict() + board_selected = brds.get_selected_dict() tc_set = set() for brd in board_selected.values(): tc_set.add(toolchains.Select(brd.arch)) @@ -198,7 +198,7 @@ def DoBuildman(options, args, toolchains=None, make_func=None, brds=None, sys.exit("Failed to generate boards.cfg") brds = board.Boards() - brds.ReadBoards(board_file) + brds.read_boards(board_file) exclude = [] if options.exclude: @@ -211,9 +211,9 @@ def DoBuildman(options, args, toolchains=None, make_func=None, brds=None, requested_boards += b.split(',') else: requested_boards = None - why_selected, board_warnings = brds.SelectBoards(args, exclude, - requested_boards) - selected = brds.GetSelected() + why_selected, board_warnings = brds.select_boards(args, exclude, + requested_boards) + selected = brds.get_selected() if not len(selected): sys.exit(col.build(col.RED, 'No matching boards found')) @@ -349,7 +349,7 @@ def DoBuildman(options, args, toolchains=None, make_func=None, brds=None, builder.in_tree = options.in_tree # Work out which boards to build - board_selected = brds.GetSelectedDict() + board_selected = brds.get_selected_dict() if series: commits = series.commits diff --git a/tools/buildman/func_test.py b/tools/buildman/func_test.py index 23627f3b0f..6806ea7fbe 100644 --- a/tools/buildman/func_test.py +++ b/tools/buildman/func_test.py @@ -189,7 +189,7 @@ class TestFunctional(unittest.TestCase): self._toolchains.Add('powerpc-gcc', test=False) self._boards = board.Boards() for brd in BOARDS: - self._boards.AddBoard(board.Board(*brd)) + self._boards.add_board(board.Board(*brd)) # Directories where the source been cloned self._clone_dirs = [] @@ -476,7 +476,7 @@ class TestFunctional(unittest.TestCase): self.assertEqual(ret_code, 100) for commit in range(self._commits): - for brd in self._boards.GetList(): + for brd in self._boards.get_list(): if brd.arch != 'sandbox': errfile = self._builder.GetErrFile(commit, brd.target) fd = open(errfile) @@ -581,7 +581,7 @@ class TestFunctional(unittest.TestCase): def testWorkInOutput(self): """Test the -w option which should write directly to the output dir""" board_list = board.Boards() - board_list.AddBoard(board.Board(*BOARDS[0])) + board_list.add_board(board.Board(*BOARDS[0])) self._RunControl('-o', self._output_dir, '-w', clean_dir=False, brds=board_list) self.assertTrue( @@ -600,14 +600,14 @@ class TestFunctional(unittest.TestCase): os.path.exists(os.path.join(self._output_dir, 'u-boot'))) board_list = board.Boards() - board_list.AddBoard(board.Board(*BOARDS[0])) + board_list.add_board(board.Board(*BOARDS[0])) with self.assertRaises(SystemExit) as e: self._RunControl('-b', self._test_branch, '-o', self._output_dir, '-w', clean_dir=False, brds=board_list) self.assertIn("single commit", str(e.exception)) board_list = board.Boards() - board_list.AddBoard(board.Board(*BOARDS[0])) + board_list.add_board(board.Board(*BOARDS[0])) with self.assertRaises(SystemExit) as e: self._RunControl('-w', clean_dir=False) self.assertIn("specify -o", str(e.exception)) diff --git a/tools/buildman/test.py b/tools/buildman/test.py index 6c09cb7fad..d7306fb4df 100644 --- a/tools/buildman/test.py +++ b/tools/buildman/test.py @@ -133,8 +133,8 @@ class TestBuild(unittest.TestCase): # Set up boards to build self.brds = board.Boards() for brd in BOARDS: - self.brds.AddBoard(board.Board(*brd)) - self.brds.SelectBoards([]) + self.brds.add_board(board.Board(*brd)) + self.brds.select_boards([]) # Add some test settings bsettings.Setup(None) @@ -203,7 +203,7 @@ class TestBuild(unittest.TestCase): build = builder.Builder(self.toolchains, self.base_dir, None, threads, 2, checkout=False, show_unknown=False) build.do_make = self.Make - board_selected = self.brds.GetSelectedDict() + board_selected = self.brds.get_selected_dict() # Build the boards for the pre-defined commits and warnings/errors # associated with each. This calls our Make() to inject the fake output. @@ -468,18 +468,18 @@ class TestBuild(unittest.TestCase): def testBoardSingle(self): """Test single board selection""" - self.assertEqual(self.brds.SelectBoards(['sandbox']), + self.assertEqual(self.brds.select_boards(['sandbox']), ({'all': ['board4'], 'sandbox': ['board4']}, [])) def testBoardArch(self): """Test single board selection""" - self.assertEqual(self.brds.SelectBoards(['arm']), + self.assertEqual(self.brds.select_boards(['arm']), ({'all': ['board0', 'board1'], 'arm': ['board0', 'board1']}, [])) def testBoardArchSingle(self): """Test single board selection""" - self.assertEqual(self.brds.SelectBoards(['arm sandbox']), + self.assertEqual(self.brds.select_boards(['arm sandbox']), ({'sandbox': ['board4'], 'all': ['board0', 'board1', 'board4'], 'arm': ['board0', 'board1']}, [])) @@ -487,20 +487,20 @@ class TestBuild(unittest.TestCase): def testBoardArchSingleMultiWord(self): """Test single board selection""" - self.assertEqual(self.brds.SelectBoards(['arm', 'sandbox']), + self.assertEqual(self.brds.select_boards(['arm', 'sandbox']), ({'sandbox': ['board4'], 'all': ['board0', 'board1', 'board4'], 'arm': ['board0', 'board1']}, [])) def testBoardSingleAnd(self): """Test single board selection""" - self.assertEqual(self.brds.SelectBoards(['Tester & arm']), + self.assertEqual(self.brds.select_boards(['Tester & arm']), ({'Tester&arm': ['board0', 'board1'], 'all': ['board0', 'board1']}, [])) def testBoardTwoAnd(self): """Test single board selection""" - self.assertEqual(self.brds.SelectBoards(['Tester', '&', 'arm', + self.assertEqual(self.brds.select_boards(['Tester', '&', 'arm', 'Tester' '&', 'powerpc', 'sandbox']), ({'sandbox': ['board4'], @@ -511,19 +511,19 @@ class TestBuild(unittest.TestCase): def testBoardAll(self): """Test single board selection""" - self.assertEqual(self.brds.SelectBoards([]), + self.assertEqual(self.brds.select_boards([]), ({'all': ['board0', 'board1', 'board2', 'board3', 'board4']}, [])) def testBoardRegularExpression(self): """Test single board selection""" - self.assertEqual(self.brds.SelectBoards(['T.*r&^Po']), + self.assertEqual(self.brds.select_boards(['T.*r&^Po']), ({'all': ['board2', 'board3'], 'T.*r&^Po': ['board2', 'board3']}, [])) def testBoardDuplicate(self): """Test single board selection""" - self.assertEqual(self.brds.SelectBoards(['sandbox sandbox', + self.assertEqual(self.brds.select_boards(['sandbox sandbox', 'sandbox']), ({'all': ['board4'], 'sandbox': ['board4']}, [])) def CheckDirs(self, build, dirname): -- cgit v1.2.3 From c52bd22539f3bb009f73cc1608b155813f7e48a0 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 11 Jul 2022 19:04:03 -0600 Subject: buildman: Split out Boards into its own file Use a separate file for the Boards class so that its name matches the module name. Fix up the function names to match the pylint style and fix some other warnings. Signed-off-by: Simon Glass --- tools/buildman/board.py | 281 +----------------------------------------- tools/buildman/boards.py | 290 ++++++++++++++++++++++++++++++++++++++++++++ tools/buildman/control.py | 4 +- tools/buildman/func_test.py | 11 +- tools/buildman/test.py | 3 +- 5 files changed, 301 insertions(+), 288 deletions(-) create mode 100644 tools/buildman/boards.py (limited to 'tools/buildman/board.py') diff --git a/tools/buildman/board.py b/tools/buildman/board.py index ebb9d6f67d..3268b39e35 100644 --- a/tools/buildman/board.py +++ b/tools/buildman/board.py @@ -1,74 +1,8 @@ # SPDX-License-Identifier: GPL-2.0+ # Copyright (c) 2012 The Chromium OS Authors. -from collections import OrderedDict -import re -class Expr: - """A single regular expression for matching boards to build""" - - def __init__(self, expr): - """Set up a new Expr object. - - Args: - expr: String cotaining regular expression to store - """ - self._expr = expr - self._re = re.compile(expr) - - def matches(self, props): - """Check if any of the properties match the regular expression. - - Args: - props: List of properties to check - Returns: - True if any of the properties match the regular expression - """ - for prop in props: - if self._re.match(prop): - return True - return False - - def __str__(self): - return self._expr - -class Term: - """A list of expressions each of which must match with properties. - - This provides a list of 'AND' expressions, meaning that each must - match the board properties for that board to be built. - """ - def __init__(self): - self._expr_list = [] - self._board_count = 0 - - def add_expr(self, expr): - """Add an Expr object to the list to check. - - Args: - expr: New Expr object to add to the list of those that must - match for a board to be built. - """ - self._expr_list.append(Expr(expr)) - - def __str__(self): - """Return some sort of useful string describing the term""" - return '&'.join([str(expr) for expr in self._expr_list]) - - def matches(self, props): - """Check if any of the properties match this term - - Each of the expressions in the term is checked. All must match. - - Args: - props: List of properties to check - Returns: - True if all of the expressions in the Term match, else False - """ - for expr in self._expr_list: - if not expr.matches(props): - return False - return True +"""A single board which can be selected and built""" class Board: """A particular board that we can build""" @@ -95,216 +29,3 @@ class Board: self.props = [self.target, self.arch, self.cpu, self.board_name, self.vendor, self.soc, self.options] self.build_it = False - - -class Boards: - """Manage a list of boards.""" - def __init__(self): - # Use a simple list here, sinc OrderedDict requires Python 2.7 - self._boards = [] - - def add_board(self, brd): - """Add a new board to the list. - - The board's target member must not already exist in the board list. - - Args: - brd: board to add - """ - self._boards.append(brd) - - def read_boards(self, fname): - """Read a list of boards from a board file. - - Create a Board object for each and add it to our _boards list. - - Args: - fname: Filename of boards.cfg file - """ - with open(fname, 'r', encoding='utf-8') as fd: - for line in fd: - if line[0] == '#': - continue - fields = line.split() - if not fields: - continue - for upto in range(len(fields)): - if fields[upto] == '-': - fields[upto] = '' - while len(fields) < 8: - fields.append('') - if len(fields) > 8: - fields = fields[:8] - - brd = Board(*fields) - self.add_board(brd) - - - def get_list(self): - """Return a list of available boards. - - Returns: - List of Board objects - """ - return self._boards - - def get_dict(self): - """Build a dictionary containing all the boards. - - Returns: - Dictionary: - key is board.target - value is board - """ - board_dict = OrderedDict() - for brd in self._boards: - board_dict[brd.target] = brd - return board_dict - - def get_selected_dict(self): - """Return a dictionary containing the selected boards - - Returns: - List of Board objects that are marked selected - """ - board_dict = OrderedDict() - for brd in self._boards: - if brd.build_it: - board_dict[brd.target] = brd - return board_dict - - def get_selected(self): - """Return a list of selected boards - - Returns: - List of Board objects that are marked selected - """ - return [brd for brd in self._boards if brd.build_it] - - def get_selected_names(self): - """Return a list of selected boards - - Returns: - List of board names that are marked selected - """ - return [brd.target for brd in self._boards if brd.build_it] - - def _build_terms(self, args): - """Convert command line arguments to a list of terms. - - This deals with parsing of the arguments. It handles the '&' - operator, which joins several expressions into a single Term. - - For example: - ['arm & freescale sandbox', 'tegra'] - - will produce 3 Terms containing expressions as follows: - arm, freescale - sandbox - tegra - - The first Term has two expressions, both of which must match for - a board to be selected. - - Args: - args: List of command line arguments - Returns: - A list of Term objects - """ - syms = [] - for arg in args: - for word in arg.split(): - sym_build = [] - for term in word.split('&'): - if term: - sym_build.append(term) - sym_build.append('&') - syms += sym_build[:-1] - terms = [] - term = None - oper = None - for sym in syms: - if sym == '&': - oper = sym - elif oper: - term.add_expr(sym) - oper = None - else: - if term: - terms.append(term) - term = Term() - term.add_expr(sym) - if term: - terms.append(term) - return terms - - def select_boards(self, args, exclude=[], brds=None): - """Mark boards selected based on args - - Normally either boards (an explicit list of boards) or args (a list of - terms to match against) is used. It is possible to specify both, in - which case they are additive. - - If brds and args are both empty, all boards are selected. - - Args: - args: List of strings specifying boards to include, either named, - or by their target, architecture, cpu, vendor or soc. If - empty, all boards are selected. - exclude: List of boards to exclude, regardless of 'args' - brds: List of boards to build - - Returns: - Tuple - Dictionary which holds the list of boards which were selected - due to each argument, arranged by argument. - List of errors found - """ - result = OrderedDict() - warnings = [] - terms = self._build_terms(args) - - result['all'] = [] - for term in terms: - result[str(term)] = [] - - exclude_list = [] - for expr in exclude: - exclude_list.append(Expr(expr)) - - found = [] - for brd in self._boards: - matching_term = None - build_it = False - if terms: - match = False - for term in terms: - if term.matches(brd.props): - matching_term = str(term) - build_it = True - break - elif brds: - if brd.target in brds: - build_it = True - found.append(brd.target) - else: - build_it = True - - # Check that it is not specifically excluded - for expr in exclude_list: - if expr.matches(brd.props): - build_it = False - break - - if build_it: - brd.build_it = True - if matching_term: - result[matching_term].append(brd.target) - result['all'].append(brd.target) - - if brds: - remaining = set(brds) - set(found) - if remaining: - warnings.append('Boards not found: %s\n' % ', '.join(remaining)) - - return result, warnings diff --git a/tools/buildman/boards.py b/tools/buildman/boards.py new file mode 100644 index 0000000000..ec143f9e0f --- /dev/null +++ b/tools/buildman/boards.py @@ -0,0 +1,290 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2012 The Chromium OS Authors. + +"""Maintains a list of boards and allows them to be selected""" + +from collections import OrderedDict +import re + +from buildman import board + + +class Expr: + """A single regular expression for matching boards to build""" + + def __init__(self, expr): + """Set up a new Expr object. + + Args: + expr: String cotaining regular expression to store + """ + self._expr = expr + self._re = re.compile(expr) + + def matches(self, props): + """Check if any of the properties match the regular expression. + + Args: + props: List of properties to check + Returns: + True if any of the properties match the regular expression + """ + for prop in props: + if self._re.match(prop): + return True + return False + + def __str__(self): + return self._expr + +class Term: + """A list of expressions each of which must match with properties. + + This provides a list of 'AND' expressions, meaning that each must + match the board properties for that board to be built. + """ + def __init__(self): + self._expr_list = [] + self._board_count = 0 + + def add_expr(self, expr): + """Add an Expr object to the list to check. + + Args: + expr: New Expr object to add to the list of those that must + match for a board to be built. + """ + self._expr_list.append(Expr(expr)) + + def __str__(self): + """Return some sort of useful string describing the term""" + return '&'.join([str(expr) for expr in self._expr_list]) + + def matches(self, props): + """Check if any of the properties match this term + + Each of the expressions in the term is checked. All must match. + + Args: + props: List of properties to check + Returns: + True if all of the expressions in the Term match, else False + """ + for expr in self._expr_list: + if not expr.matches(props): + return False + return True + + +class Boards: + """Manage a list of boards.""" + def __init__(self): + # Use a simple list here, sinc OrderedDict requires Python 2.7 + self._boards = [] + + def add_board(self, brd): + """Add a new board to the list. + + The board's target member must not already exist in the board list. + + Args: + brd: board to add + """ + self._boards.append(brd) + + def read_boards(self, fname): + """Read a list of boards from a board file. + + Create a Board object for each and add it to our _boards list. + + Args: + fname: Filename of boards.cfg file + """ + with open(fname, 'r', encoding='utf-8') as inf: + for line in inf: + if line[0] == '#': + continue + fields = line.split() + if not fields: + continue + for upto, field in enumerate(fields): + if field == '-': + fields[upto] = '' + while len(fields) < 8: + fields.append('') + if len(fields) > 8: + fields = fields[:8] + + brd = board.Board(*fields) + self.add_board(brd) + + + def get_list(self): + """Return a list of available boards. + + Returns: + List of Board objects + """ + return self._boards + + def get_dict(self): + """Build a dictionary containing all the boards. + + Returns: + Dictionary: + key is board.target + value is board + """ + board_dict = OrderedDict() + for brd in self._boards: + board_dict[brd.target] = brd + return board_dict + + def get_selected_dict(self): + """Return a dictionary containing the selected boards + + Returns: + List of Board objects that are marked selected + """ + board_dict = OrderedDict() + for brd in self._boards: + if brd.build_it: + board_dict[brd.target] = brd + return board_dict + + def get_selected(self): + """Return a list of selected boards + + Returns: + List of Board objects that are marked selected + """ + return [brd for brd in self._boards if brd.build_it] + + def get_selected_names(self): + """Return a list of selected boards + + Returns: + List of board names that are marked selected + """ + return [brd.target for brd in self._boards if brd.build_it] + + @classmethod + def _build_terms(cls, args): + """Convert command line arguments to a list of terms. + + This deals with parsing of the arguments. It handles the '&' + operator, which joins several expressions into a single Term. + + For example: + ['arm & freescale sandbox', 'tegra'] + + will produce 3 Terms containing expressions as follows: + arm, freescale + sandbox + tegra + + The first Term has two expressions, both of which must match for + a board to be selected. + + Args: + args: List of command line arguments + Returns: + A list of Term objects + """ + syms = [] + for arg in args: + for word in arg.split(): + sym_build = [] + for term in word.split('&'): + if term: + sym_build.append(term) + sym_build.append('&') + syms += sym_build[:-1] + terms = [] + term = None + oper = None + for sym in syms: + if sym == '&': + oper = sym + elif oper: + term.add_expr(sym) + oper = None + else: + if term: + terms.append(term) + term = Term() + term.add_expr(sym) + if term: + terms.append(term) + return terms + + def select_boards(self, args, exclude=None, brds=None): + """Mark boards selected based on args + + Normally either boards (an explicit list of boards) or args (a list of + terms to match against) is used. It is possible to specify both, in + which case they are additive. + + If brds and args are both empty, all boards are selected. + + Args: + args: List of strings specifying boards to include, either named, + or by their target, architecture, cpu, vendor or soc. If + empty, all boards are selected. + exclude: List of boards to exclude, regardless of 'args' + brds: List of boards to build + + Returns: + Tuple + Dictionary which holds the list of boards which were selected + due to each argument, arranged by argument. + List of errors found + """ + result = OrderedDict() + warnings = [] + terms = self._build_terms(args) + + result['all'] = [] + for term in terms: + result[str(term)] = [] + + exclude_list = [] + if exclude: + for expr in exclude: + exclude_list.append(Expr(expr)) + + found = [] + for brd in self._boards: + matching_term = None + build_it = False + if terms: + for term in terms: + if term.matches(brd.props): + matching_term = str(term) + build_it = True + break + elif brds: + if brd.target in brds: + build_it = True + found.append(brd.target) + else: + build_it = True + + # Check that it is not specifically excluded + for expr in exclude_list: + if expr.matches(brd.props): + build_it = False + break + + if build_it: + brd.build_it = True + if matching_term: + result[matching_term].append(brd.target) + result['all'].append(brd.target) + + if brds: + remaining = set(brds) - set(found) + if remaining: + warnings.append(f"Boards not found: {', '.join(remaining)}\n") + + return result, warnings diff --git a/tools/buildman/control.py b/tools/buildman/control.py index a5c1c2e51c..8d3e781d51 100644 --- a/tools/buildman/control.py +++ b/tools/buildman/control.py @@ -8,7 +8,7 @@ import shutil import subprocess import sys -from buildman import board +from buildman import boards from buildman import bsettings from buildman import cfgutil from buildman import toolchain @@ -197,7 +197,7 @@ def DoBuildman(options, args, toolchains=None, make_func=None, brds=None, if status != 0: sys.exit("Failed to generate boards.cfg") - brds = board.Boards() + brds = boards.Boards() brds.read_boards(board_file) exclude = [] diff --git a/tools/buildman/func_test.py b/tools/buildman/func_test.py index 6806ea7fbe..f12e996634 100644 --- a/tools/buildman/func_test.py +++ b/tools/buildman/func_test.py @@ -9,6 +9,7 @@ import tempfile import unittest from buildman import board +from buildman import boards from buildman import bsettings from buildman import cmdline from buildman import control @@ -187,7 +188,7 @@ class TestFunctional(unittest.TestCase): self.setupToolchains() self._toolchains.Add('arm-gcc', test=False) self._toolchains.Add('powerpc-gcc', test=False) - self._boards = board.Boards() + self._boards = boards.Boards() for brd in BOARDS: self._boards.add_board(board.Board(*brd)) @@ -442,7 +443,7 @@ class TestFunctional(unittest.TestCase): def testNoBoards(self): """Test that buildman aborts when there are no boards""" - self._boards = board.Boards() + self._boards = boards.Boards() with self.assertRaises(SystemExit): self._RunControl() @@ -580,7 +581,7 @@ class TestFunctional(unittest.TestCase): def testWorkInOutput(self): """Test the -w option which should write directly to the output dir""" - board_list = board.Boards() + board_list = boards.Boards() board_list.add_board(board.Board(*BOARDS[0])) self._RunControl('-o', self._output_dir, '-w', clean_dir=False, brds=board_list) @@ -599,14 +600,14 @@ class TestFunctional(unittest.TestCase): self.assertFalse( os.path.exists(os.path.join(self._output_dir, 'u-boot'))) - board_list = board.Boards() + board_list = boards.Boards() board_list.add_board(board.Board(*BOARDS[0])) with self.assertRaises(SystemExit) as e: self._RunControl('-b', self._test_branch, '-o', self._output_dir, '-w', clean_dir=False, brds=board_list) self.assertIn("single commit", str(e.exception)) - board_list = board.Boards() + board_list = boards.Boards() board_list.add_board(board.Board(*BOARDS[0])) with self.assertRaises(SystemExit) as e: self._RunControl('-w', clean_dir=False) diff --git a/tools/buildman/test.py b/tools/buildman/test.py index d7306fb4df..daf5467503 100644 --- a/tools/buildman/test.py +++ b/tools/buildman/test.py @@ -10,6 +10,7 @@ import time import unittest from buildman import board +from buildman import boards from buildman import bsettings from buildman import builder from buildman import cfgutil @@ -131,7 +132,7 @@ class TestBuild(unittest.TestCase): self.commits.append(comm) # Set up boards to build - self.brds = board.Boards() + self.brds = boards.Boards() for brd in BOARDS: self.brds.add_board(board.Board(*brd)) self.brds.select_boards([]) -- cgit v1.2.3 From 256126c29434a93584b6043b1c1d1c6dbbc340db Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 11 Jul 2022 19:04:06 -0600 Subject: buildman: Replace the Options column with config name This appears in boards.cfg but we want to remove it. Drop support for generating it and reading it. Detect an old boards.cfg file that has this field and regenerate it, to avoid problems. Instead, add the config name in that place. This fixes a subtle bug in the generation code, since it uses 'target' for the config name and then overwrites the value in scan() by setting params['target'] to the name of the defconfig. The defconfig name is not the same as the SYS_CONFIG_NAME variable. With this change, we still have the config name and it can be searched by buildman, e.g. with: buildman -nv sun5i Signed-off-by: Simon Glass Reported-by: Tom Rini --- tools/buildman/board.py | 8 ++++---- tools/buildman/boards.py | 19 ++++++------------- 2 files changed, 10 insertions(+), 17 deletions(-) (limited to 'tools/buildman/board.py') diff --git a/tools/buildman/board.py b/tools/buildman/board.py index 3268b39e35..8ef905b8ce 100644 --- a/tools/buildman/board.py +++ b/tools/buildman/board.py @@ -6,7 +6,7 @@ class Board: """A particular board that we can build""" - def __init__(self, status, arch, cpu, soc, vendor, board_name, target, options): + def __init__(self, status, arch, cpu, soc, vendor, board_name, target, cfg_name): """Create a new board type. Args: @@ -17,7 +17,7 @@ class Board: vendor: Name of vendor (e.g. armltd) board_name: Name of board (e.g. integrator) target: Target name (use make _defconfig to configure) - options: board-specific options (e.g. integratorcp:CM1136) + cfg_name: Config name """ self.target = target self.arch = arch @@ -25,7 +25,7 @@ class Board: self.board_name = board_name self.vendor = vendor self.soc = soc - self.options = options + self.cfg_name = cfg_name self.props = [self.target, self.arch, self.cpu, self.board_name, - self.vendor, self.soc, self.options] + self.vendor, self.soc, self.cfg_name] self.build_it = False diff --git a/tools/buildman/boards.py b/tools/buildman/boards.py index e16f3268ab..8832e40cd5 100644 --- a/tools/buildman/boards.py +++ b/tools/buildman/boards.py @@ -28,7 +28,7 @@ COMMENT_BLOCK = f'''# # List of boards # Automatically generated by {__file__}: don't edit # -# Status, Arch, CPU, SoC, Vendor, Board, Target, Options, Maintainers +# Status, Arch, CPU, SoC, Vendor, Board, Target, Config, Maintainers ''' @@ -98,6 +98,8 @@ def output_is_new(output): # was generated with open(output, encoding="utf-8") as inf: for line in inf: + if 'Options,' in line: + return False if line[0] == '#' or line == '\n': continue defconfig = line.split()[6] + '_defconfig' @@ -186,7 +188,7 @@ class KconfigScanner: 'vendor' : 'SYS_VENDOR', 'board' : 'SYS_BOARD', 'config' : 'SYS_CONFIG_NAME', - 'options' : 'SYS_EXTRA_OPTIONS' + # 'target' is added later } def __init__(self): @@ -216,7 +218,7 @@ class KconfigScanner: defconfig (str): path to the defconfig file to be processed Returns: - Dictionary of board parameters. It has a form: + A dictionary of board parameters. It has a form of: { 'arch': , 'cpu': , @@ -225,7 +227,6 @@ class KconfigScanner: 'board': , 'target': , 'config': , - 'options': } """ # strip special prefixes and save it in a temporary file @@ -262,14 +263,6 @@ class KconfigScanner: if params['arch'] == 'arm' and params['cpu'] == 'armv8': params['arch'] = 'aarch64' - # fix-up options field. It should have the form: - # [:comma separated config options] - if params['options'] != '-': - params['options'] = params['config'] + ':' + \ - params['options'].replace(r'\"', '"') - elif params['config'] != params['target']: - params['options'] = params['config'] - return params @@ -708,7 +701,7 @@ class Boards: output (str): The path to the output file """ fields = ('status', 'arch', 'cpu', 'soc', 'vendor', 'board', 'target', - 'options', 'maintainers') + 'config', 'maintainers') # First, decide the width of each column max_length = {f: 0 for f in fields} -- cgit v1.2.3