2022-07-12 01:04:03 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
|
|
|
# Copyright (c) 2012 The Chromium OS Authors.
|
2022-07-12 01:04:04 +00:00
|
|
|
# Author: Simon Glass <sjg@chromium.org>
|
|
|
|
# Author: Masahiro Yamada <yamada.m@jp.panasonic.com>
|
2022-07-12 01:04:03 +00:00
|
|
|
|
|
|
|
"""Maintains a list of boards and allows them to be selected"""
|
|
|
|
|
|
|
|
from collections import OrderedDict
|
2022-07-12 01:04:04 +00:00
|
|
|
import errno
|
|
|
|
import fnmatch
|
|
|
|
import glob
|
|
|
|
import multiprocessing
|
|
|
|
import os
|
2022-07-12 01:04:03 +00:00
|
|
|
import re
|
2022-07-12 01:04:04 +00:00
|
|
|
import sys
|
|
|
|
import tempfile
|
|
|
|
import time
|
2022-07-12 01:04:03 +00:00
|
|
|
|
|
|
|
from buildman import board
|
2022-07-12 01:04:04 +00:00
|
|
|
from buildman import kconfiglib
|
|
|
|
|
|
|
|
|
|
|
|
### constant variables ###
|
|
|
|
OUTPUT_FILE = 'boards.cfg'
|
|
|
|
CONFIG_DIR = 'configs'
|
|
|
|
SLEEP_TIME = 0.03
|
2022-07-12 01:04:05 +00:00
|
|
|
COMMENT_BLOCK = f'''#
|
2022-07-12 01:04:04 +00:00
|
|
|
# List of boards
|
2022-07-12 01:04:05 +00:00
|
|
|
# Automatically generated by {__file__}: don't edit
|
2022-07-12 01:04:04 +00:00
|
|
|
#
|
2022-07-12 01:04:06 +00:00
|
|
|
# Status, Arch, CPU, SoC, Vendor, Board, Target, Config, Maintainers
|
2022-07-12 01:04:04 +00:00
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
'''
|
2022-07-12 01:04:04 +00:00
|
|
|
|
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
def try_remove(fname):
|
|
|
|
"""Remove a file ignoring 'No such file or directory' error.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
fname (str): Filename to remove
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
OSError: output file exists but could not be removed
|
|
|
|
"""
|
2022-07-12 01:04:04 +00:00
|
|
|
try:
|
2022-07-12 01:04:05 +00:00
|
|
|
os.remove(fname)
|
2022-07-12 01:04:04 +00:00
|
|
|
except OSError as exception:
|
|
|
|
# Ignore 'No such file or directory' error
|
|
|
|
if exception.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
|
|
def output_is_new(output):
|
|
|
|
"""Check if the output file is up to date.
|
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
Looks at defconfig and Kconfig files to make sure none is newer than the
|
|
|
|
output file. Also ensures that the boards.cfg does not mention any removed
|
|
|
|
boards.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
output (str): Filename to check
|
|
|
|
|
2022-07-12 01:04:04 +00:00
|
|
|
Returns:
|
2022-07-12 01:04:05 +00:00
|
|
|
True if the given output file exists and is newer than any of
|
|
|
|
*_defconfig, MAINTAINERS and Kconfig*. False otherwise.
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
OSError: output file exists but could not be opened
|
2022-07-12 01:04:04 +00:00
|
|
|
"""
|
2022-07-12 01:04:05 +00:00
|
|
|
# pylint: disable=too-many-branches
|
2022-07-12 01:04:04 +00:00
|
|
|
try:
|
|
|
|
ctime = os.path.getctime(output)
|
|
|
|
except OSError as exception:
|
|
|
|
if exception.errno == errno.ENOENT:
|
|
|
|
# return False on 'No such file or directory' error
|
|
|
|
return False
|
2022-07-12 01:04:05 +00:00
|
|
|
raise
|
2022-07-12 01:04:04 +00:00
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
for (dirpath, _, filenames) in os.walk(CONFIG_DIR):
|
2022-07-12 01:04:04 +00:00
|
|
|
for filename in fnmatch.filter(filenames, '*_defconfig'):
|
|
|
|
if fnmatch.fnmatch(filename, '.*'):
|
|
|
|
continue
|
|
|
|
filepath = os.path.join(dirpath, filename)
|
|
|
|
if ctime < os.path.getctime(filepath):
|
|
|
|
return False
|
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
for (dirpath, _, filenames) in os.walk('.'):
|
2022-07-12 01:04:04 +00:00
|
|
|
for filename in filenames:
|
|
|
|
if (fnmatch.fnmatch(filename, '*~') or
|
|
|
|
not fnmatch.fnmatch(filename, 'Kconfig*') and
|
|
|
|
not filename == 'MAINTAINERS'):
|
|
|
|
continue
|
|
|
|
filepath = os.path.join(dirpath, filename)
|
|
|
|
if ctime < os.path.getctime(filepath):
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Detect a board that has been removed since the current board database
|
|
|
|
# was generated
|
2022-07-12 01:04:05 +00:00
|
|
|
with open(output, encoding="utf-8") as inf:
|
|
|
|
for line in inf:
|
2022-07-12 01:04:06 +00:00
|
|
|
if 'Options,' in line:
|
|
|
|
return False
|
2022-07-12 01:04:04 +00:00
|
|
|
if line[0] == '#' or line == '\n':
|
|
|
|
continue
|
|
|
|
defconfig = line.split()[6] + '_defconfig'
|
|
|
|
if not os.path.exists(os.path.join(CONFIG_DIR, defconfig)):
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
2022-07-12 01:04:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Expr:
|
|
|
|
"""A single regular expression for matching boards to build"""
|
|
|
|
|
|
|
|
def __init__(self, expr):
|
|
|
|
"""Set up a new Expr object.
|
|
|
|
|
|
|
|
Args:
|
2022-07-12 01:04:05 +00:00
|
|
|
expr (str): String cotaining regular expression to store
|
2022-07-12 01:04:03 +00:00
|
|
|
"""
|
|
|
|
self._expr = expr
|
|
|
|
self._re = re.compile(expr)
|
|
|
|
|
|
|
|
def matches(self, props):
|
|
|
|
"""Check if any of the properties match the regular expression.
|
|
|
|
|
|
|
|
Args:
|
2022-07-12 01:04:05 +00:00
|
|
|
props (list of str): List of properties to check
|
2022-07-12 01:04:03 +00:00
|
|
|
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:
|
2022-07-12 01:04:05 +00:00
|
|
|
expr (Expr): New Expr object to add to the list of those that must
|
2022-07-12 01:04:03 +00:00
|
|
|
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:
|
2022-07-12 01:04:05 +00:00
|
|
|
props (list of str): List of properties to check
|
2022-07-12 01:04:03 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2022-07-12 01:04:04 +00:00
|
|
|
class KconfigScanner:
|
|
|
|
|
|
|
|
"""Kconfig scanner."""
|
|
|
|
|
|
|
|
### constant variable only used in this class ###
|
|
|
|
_SYMBOL_TABLE = {
|
|
|
|
'arch' : 'SYS_ARCH',
|
|
|
|
'cpu' : 'SYS_CPU',
|
|
|
|
'soc' : 'SYS_SOC',
|
|
|
|
'vendor' : 'SYS_VENDOR',
|
|
|
|
'board' : 'SYS_BOARD',
|
|
|
|
'config' : 'SYS_CONFIG_NAME',
|
2022-07-12 01:04:06 +00:00
|
|
|
# 'target' is added later
|
2022-07-12 01:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""Scan all the Kconfig files and create a Kconfig object."""
|
|
|
|
# Define environment variables referenced from Kconfig
|
|
|
|
os.environ['srctree'] = os.getcwd()
|
|
|
|
os.environ['UBOOTVERSION'] = 'dummy'
|
|
|
|
os.environ['KCONFIG_OBJDIR'] = ''
|
2022-07-12 01:04:05 +00:00
|
|
|
self._tmpfile = None
|
2022-07-12 01:04:04 +00:00
|
|
|
self._conf = kconfiglib.Kconfig(warn=False)
|
|
|
|
|
|
|
|
def __del__(self):
|
|
|
|
"""Delete a leftover temporary file before exit.
|
|
|
|
|
|
|
|
The scan() method of this class creates a temporay file and deletes
|
|
|
|
it on success. If scan() method throws an exception on the way,
|
|
|
|
the temporary file might be left over. In that case, it should be
|
|
|
|
deleted in this destructor.
|
|
|
|
"""
|
2022-07-12 01:04:05 +00:00
|
|
|
if self._tmpfile:
|
2022-07-12 01:04:04 +00:00
|
|
|
try_remove(self._tmpfile)
|
|
|
|
|
|
|
|
def scan(self, defconfig):
|
|
|
|
"""Load a defconfig file to obtain board parameters.
|
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
Args:
|
|
|
|
defconfig (str): path to the defconfig file to be processed
|
2022-07-12 01:04:04 +00:00
|
|
|
|
|
|
|
Returns:
|
2022-07-12 01:04:06 +00:00
|
|
|
A dictionary of board parameters. It has a form of:
|
2022-07-12 01:04:05 +00:00
|
|
|
{
|
|
|
|
'arch': <arch_name>,
|
|
|
|
'cpu': <cpu_name>,
|
|
|
|
'soc': <soc_name>,
|
|
|
|
'vendor': <vendor_name>,
|
|
|
|
'board': <board_name>,
|
|
|
|
'target': <target_name>,
|
|
|
|
'config': <config_header_name>,
|
|
|
|
}
|
2022-07-12 01:04:04 +00:00
|
|
|
"""
|
|
|
|
# strip special prefixes and save it in a temporary file
|
2022-07-12 01:04:05 +00:00
|
|
|
outfd, self._tmpfile = tempfile.mkstemp()
|
|
|
|
with os.fdopen(outfd, 'w') as outf:
|
|
|
|
with open(defconfig, encoding='utf-8') as inf:
|
|
|
|
for line in inf:
|
|
|
|
colon = line.find(':CONFIG_')
|
|
|
|
if colon == -1:
|
|
|
|
outf.write(line)
|
|
|
|
else:
|
|
|
|
outf.write(line[colon + 1:])
|
2022-07-12 01:04:04 +00:00
|
|
|
|
|
|
|
self._conf.load_config(self._tmpfile)
|
|
|
|
try_remove(self._tmpfile)
|
|
|
|
self._tmpfile = None
|
|
|
|
|
|
|
|
params = {}
|
|
|
|
|
|
|
|
# Get the value of CONFIG_SYS_ARCH, CONFIG_SYS_CPU, ... etc.
|
|
|
|
# Set '-' if the value is empty.
|
|
|
|
for key, symbol in list(self._SYMBOL_TABLE.items()):
|
|
|
|
value = self._conf.syms.get(symbol).str_value
|
|
|
|
if value:
|
|
|
|
params[key] = value
|
|
|
|
else:
|
|
|
|
params[key] = '-'
|
|
|
|
|
|
|
|
defconfig = os.path.basename(defconfig)
|
|
|
|
params['target'], match, rear = defconfig.partition('_defconfig')
|
2022-07-12 01:04:05 +00:00
|
|
|
assert match and not rear, f'{defconfig} : invalid defconfig'
|
2022-07-12 01:04:04 +00:00
|
|
|
|
|
|
|
# fix-up for aarch64
|
|
|
|
if params['arch'] == 'arm' and params['cpu'] == 'armv8':
|
|
|
|
params['arch'] = 'aarch64'
|
|
|
|
|
2022-10-03 16:07:53 +00:00
|
|
|
# fix-up for riscv
|
|
|
|
if params['arch'] == 'riscv':
|
|
|
|
try:
|
|
|
|
value = self._conf.syms.get('ARCH_RV32I').str_value
|
|
|
|
except:
|
|
|
|
value = ''
|
|
|
|
if value == 'y':
|
|
|
|
params['arch'] = 'riscv32'
|
|
|
|
else:
|
|
|
|
params['arch'] = 'riscv64'
|
|
|
|
|
2022-07-12 01:04:04 +00:00
|
|
|
return params
|
|
|
|
|
|
|
|
|
|
|
|
class MaintainersDatabase:
|
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
"""The database of board status and maintainers.
|
|
|
|
|
|
|
|
Properties:
|
|
|
|
database: dict:
|
|
|
|
key: Board-target name (e.g. 'snow')
|
|
|
|
value: tuple:
|
|
|
|
str: Board status (e.g. 'Active')
|
|
|
|
str: List of maintainers, separated by :
|
2022-07-12 01:04:08 +00:00
|
|
|
warnings (list of str): List of warnings due to missing status, etc.
|
2022-07-12 01:04:05 +00:00
|
|
|
"""
|
2022-07-12 01:04:04 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""Create an empty database."""
|
|
|
|
self.database = {}
|
2022-07-12 01:04:08 +00:00
|
|
|
self.warnings = []
|
2022-07-12 01:04:04 +00:00
|
|
|
|
|
|
|
def get_status(self, target):
|
|
|
|
"""Return the status of the given board.
|
|
|
|
|
|
|
|
The board status is generally either 'Active' or 'Orphan'.
|
|
|
|
Display a warning message and return '-' if status information
|
|
|
|
is not found.
|
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
Args:
|
|
|
|
target (str): Build-target name
|
|
|
|
|
2022-07-12 01:04:04 +00:00
|
|
|
Returns:
|
2022-07-12 01:04:05 +00:00
|
|
|
str: 'Active', 'Orphan' or '-'.
|
2022-07-12 01:04:04 +00:00
|
|
|
"""
|
|
|
|
if not target in self.database:
|
2022-07-12 01:04:08 +00:00
|
|
|
self.warnings.append(f"WARNING: no status info for '{target}'")
|
2022-07-12 01:04:04 +00:00
|
|
|
return '-'
|
|
|
|
|
|
|
|
tmp = self.database[target][0]
|
|
|
|
if tmp.startswith('Maintained'):
|
|
|
|
return 'Active'
|
2022-07-12 01:04:05 +00:00
|
|
|
if tmp.startswith('Supported'):
|
2022-07-12 01:04:04 +00:00
|
|
|
return 'Active'
|
2022-07-12 01:04:05 +00:00
|
|
|
if tmp.startswith('Orphan'):
|
2022-07-12 01:04:04 +00:00
|
|
|
return 'Orphan'
|
2022-07-12 01:04:08 +00:00
|
|
|
self.warnings.append(f"WARNING: {tmp}: unknown status for '{target}'")
|
2022-07-12 01:04:05 +00:00
|
|
|
return '-'
|
2022-07-12 01:04:04 +00:00
|
|
|
|
|
|
|
def get_maintainers(self, target):
|
|
|
|
"""Return the maintainers of the given board.
|
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
Args:
|
|
|
|
target (str): Build-target name
|
|
|
|
|
2022-07-12 01:04:04 +00:00
|
|
|
Returns:
|
2022-07-12 01:04:05 +00:00
|
|
|
str: Maintainers of the board. If the board has two or more
|
|
|
|
maintainers, they are separated with colons.
|
2022-07-12 01:04:04 +00:00
|
|
|
"""
|
|
|
|
if not target in self.database:
|
2022-07-12 01:04:08 +00:00
|
|
|
self.warnings.append(f"WARNING: no maintainers for '{target}'")
|
2022-07-12 01:04:04 +00:00
|
|
|
return ''
|
|
|
|
|
|
|
|
return ':'.join(self.database[target][1])
|
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
def parse_file(self, fname):
|
2022-07-12 01:04:04 +00:00
|
|
|
"""Parse a MAINTAINERS file.
|
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
Parse a MAINTAINERS file and accumulate board status and maintainers
|
|
|
|
information in the self.database dict.
|
2022-07-12 01:04:04 +00:00
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
Args:
|
|
|
|
fname (str): MAINTAINERS file to be parsed
|
2022-07-12 01:04:04 +00:00
|
|
|
"""
|
|
|
|
targets = []
|
|
|
|
maintainers = []
|
|
|
|
status = '-'
|
2022-07-12 01:04:05 +00:00
|
|
|
with open(fname, encoding="utf-8") as inf:
|
|
|
|
for line in inf:
|
|
|
|
# Check also commented maintainers
|
|
|
|
if line[:3] == '#M:':
|
|
|
|
line = line[1:]
|
|
|
|
tag, rest = line[:2], line[2:].strip()
|
|
|
|
if tag == 'M:':
|
|
|
|
maintainers.append(rest)
|
|
|
|
elif tag == 'F:':
|
|
|
|
# expand wildcard and filter by 'configs/*_defconfig'
|
|
|
|
for item in glob.glob(rest):
|
|
|
|
front, match, rear = item.partition('configs/')
|
|
|
|
if not front and match:
|
|
|
|
front, match, rear = rear.rpartition('_defconfig')
|
|
|
|
if match and not rear:
|
|
|
|
targets.append(front)
|
|
|
|
elif tag == 'S:':
|
|
|
|
status = rest
|
2022-10-11 14:15:37 +00:00
|
|
|
elif tag == 'N:':
|
|
|
|
# Just scan the configs directory since that's all we care
|
|
|
|
# about
|
|
|
|
for dirpath, _, fnames in os.walk('configs'):
|
|
|
|
for fname in fnames:
|
|
|
|
path = os.path.join(dirpath, fname)
|
|
|
|
front, match, rear = path.partition('configs/')
|
|
|
|
if not front and match:
|
|
|
|
front, match, rear = rear.rpartition('_defconfig')
|
|
|
|
if match and not rear:
|
|
|
|
targets.append(front)
|
2022-07-12 01:04:05 +00:00
|
|
|
elif line == '\n':
|
|
|
|
for target in targets:
|
|
|
|
self.database[target] = (status, maintainers)
|
|
|
|
targets = []
|
|
|
|
maintainers = []
|
|
|
|
status = '-'
|
2022-07-12 01:04:04 +00:00
|
|
|
if targets:
|
|
|
|
for target in targets:
|
|
|
|
self.database[target] = (status, maintainers)
|
|
|
|
|
|
|
|
|
2022-07-12 01:04:03 +00:00
|
|
|
class Boards:
|
|
|
|
"""Manage a list of boards."""
|
|
|
|
def __init__(self):
|
|
|
|
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:
|
2022-07-12 01:04:05 +00:00
|
|
|
brd (Board): board to add
|
2022-07-12 01:04:03 +00:00
|
|
|
"""
|
|
|
|
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:
|
2022-07-12 01:04:05 +00:00
|
|
|
fname (str): Filename of boards.cfg file
|
2022-07-12 01:04:03 +00:00
|
|
|
"""
|
|
|
|
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:
|
2022-07-12 01:04:05 +00:00
|
|
|
args (list of str): List of command line arguments
|
|
|
|
|
2022-07-12 01:04:03 +00:00
|
|
|
Returns:
|
2022-07-12 01:04:05 +00:00
|
|
|
list of Term: A list of Term objects
|
2022-07-12 01:04:03 +00:00
|
|
|
"""
|
|
|
|
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:
|
2022-07-12 01:04:05 +00:00
|
|
|
args (list of str): 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 str): List of boards to exclude, regardless of
|
|
|
|
'args', or None for none
|
|
|
|
brds (list of Board): List of boards to build, or None/[] for all
|
2022-07-12 01:04:03 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
Tuple
|
|
|
|
Dictionary which holds the list of boards which were selected
|
|
|
|
due to each argument, arranged by argument.
|
|
|
|
List of errors found
|
|
|
|
"""
|
2022-07-12 01:04:05 +00:00
|
|
|
def _check_board(brd):
|
|
|
|
"""Check whether to include or exclude a board
|
2022-07-12 01:04:03 +00:00
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
Checks the various terms and decide whether to build it or not (the
|
|
|
|
'build_it' variable).
|
2022-07-12 01:04:03 +00:00
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
If it is built, add the board to the result[term] list so we know
|
|
|
|
which term caused it to be built. Add it to result['all'] also.
|
2022-07-12 01:04:03 +00:00
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
Keep a list of boards we found in 'found', so we can report boards
|
|
|
|
which appear in self._boards but not in brds.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
brd (Board): Board to check
|
|
|
|
"""
|
2022-07-12 01:04:03 +00:00
|
|
|
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)
|
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
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:
|
|
|
|
_check_board(brd)
|
|
|
|
|
2022-07-12 01:04:03 +00:00
|
|
|
if brds:
|
|
|
|
remaining = set(brds) - set(found)
|
|
|
|
if remaining:
|
|
|
|
warnings.append(f"Boards not found: {', '.join(remaining)}\n")
|
|
|
|
|
|
|
|
return result, warnings
|
2022-07-12 01:04:04 +00:00
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
@classmethod
|
|
|
|
def scan_defconfigs_for_multiprocess(cls, queue, defconfigs):
|
2022-07-12 01:04:04 +00:00
|
|
|
"""Scan defconfig files and queue their board parameters
|
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
This function is intended to be passed to multiprocessing.Process()
|
|
|
|
constructor.
|
2022-07-12 01:04:04 +00:00
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
Args:
|
|
|
|
queue (multiprocessing.Queue): The resulting board parameters are
|
|
|
|
written into this.
|
|
|
|
defconfigs (sequence of str): A sequence of defconfig files to be
|
|
|
|
scanned.
|
2022-07-12 01:04:04 +00:00
|
|
|
"""
|
|
|
|
kconf_scanner = KconfigScanner()
|
|
|
|
for defconfig in defconfigs:
|
|
|
|
queue.put(kconf_scanner.scan(defconfig))
|
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
@classmethod
|
|
|
|
def read_queues(cls, queues, params_list):
|
2022-07-12 01:04:04 +00:00
|
|
|
"""Read the queues and append the data to the paramers list"""
|
2022-07-12 01:04:05 +00:00
|
|
|
for que in queues:
|
|
|
|
while not que.empty():
|
|
|
|
params_list.append(que.get())
|
2022-07-12 01:04:04 +00:00
|
|
|
|
|
|
|
def scan_defconfigs(self, jobs=1):
|
|
|
|
"""Collect board parameters for all defconfig files.
|
|
|
|
|
|
|
|
This function invokes multiple processes for faster processing.
|
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
Args:
|
|
|
|
jobs (int): The number of jobs to run simultaneously
|
2022-07-12 01:04:04 +00:00
|
|
|
"""
|
|
|
|
all_defconfigs = []
|
2022-07-12 01:04:05 +00:00
|
|
|
for (dirpath, _, filenames) in os.walk(CONFIG_DIR):
|
2022-07-12 01:04:04 +00:00
|
|
|
for filename in fnmatch.filter(filenames, '*_defconfig'):
|
|
|
|
if fnmatch.fnmatch(filename, '.*'):
|
|
|
|
continue
|
|
|
|
all_defconfigs.append(os.path.join(dirpath, filename))
|
|
|
|
|
|
|
|
total_boards = len(all_defconfigs)
|
|
|
|
processes = []
|
|
|
|
queues = []
|
|
|
|
for i in range(jobs):
|
|
|
|
defconfigs = all_defconfigs[total_boards * i // jobs :
|
|
|
|
total_boards * (i + 1) // jobs]
|
2022-07-12 01:04:05 +00:00
|
|
|
que = multiprocessing.Queue(maxsize=-1)
|
|
|
|
proc = multiprocessing.Process(
|
2022-07-12 01:04:04 +00:00
|
|
|
target=self.scan_defconfigs_for_multiprocess,
|
2022-07-12 01:04:05 +00:00
|
|
|
args=(que, defconfigs))
|
|
|
|
proc.start()
|
|
|
|
processes.append(proc)
|
|
|
|
queues.append(que)
|
2022-07-12 01:04:04 +00:00
|
|
|
|
|
|
|
# The resulting data should be accumulated to this list
|
|
|
|
params_list = []
|
|
|
|
|
|
|
|
# Data in the queues should be retrieved preriodically.
|
|
|
|
# Otherwise, the queues would become full and subprocesses would get stuck.
|
2022-07-12 01:04:05 +00:00
|
|
|
while any(p.is_alive() for p in processes):
|
2022-07-12 01:04:04 +00:00
|
|
|
self.read_queues(queues, params_list)
|
|
|
|
# sleep for a while until the queues are filled
|
|
|
|
time.sleep(SLEEP_TIME)
|
|
|
|
|
|
|
|
# Joining subprocesses just in case
|
|
|
|
# (All subprocesses should already have been finished)
|
2022-07-12 01:04:05 +00:00
|
|
|
for proc in processes:
|
|
|
|
proc.join()
|
2022-07-12 01:04:04 +00:00
|
|
|
|
|
|
|
# retrieve leftover data
|
|
|
|
self.read_queues(queues, params_list)
|
|
|
|
|
|
|
|
return params_list
|
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
@classmethod
|
|
|
|
def insert_maintainers_info(cls, params_list):
|
2022-07-12 01:04:04 +00:00
|
|
|
"""Add Status and Maintainers information to the board parameters list.
|
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
Args:
|
|
|
|
params_list (list of dict): A list of the board parameters
|
2022-07-12 01:04:08 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
list of str: List of warnings collected due to missing status, etc.
|
2022-07-12 01:04:04 +00:00
|
|
|
"""
|
|
|
|
database = MaintainersDatabase()
|
2022-07-12 01:04:05 +00:00
|
|
|
for (dirpath, _, filenames) in os.walk('.'):
|
2022-07-12 01:04:04 +00:00
|
|
|
if 'MAINTAINERS' in filenames:
|
|
|
|
database.parse_file(os.path.join(dirpath, 'MAINTAINERS'))
|
|
|
|
|
|
|
|
for i, params in enumerate(params_list):
|
|
|
|
target = params['target']
|
|
|
|
params['status'] = database.get_status(target)
|
|
|
|
params['maintainers'] = database.get_maintainers(target)
|
|
|
|
params_list[i] = params
|
2022-07-12 01:04:08 +00:00
|
|
|
return database.warnings
|
2022-07-12 01:04:04 +00:00
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
@classmethod
|
|
|
|
def format_and_output(cls, params_list, output):
|
2022-07-12 01:04:04 +00:00
|
|
|
"""Write board parameters into a file.
|
|
|
|
|
|
|
|
Columnate the board parameters, sort lines alphabetically,
|
|
|
|
and then write them to a file.
|
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
Args:
|
|
|
|
params_list (list of dict): The list of board parameters
|
|
|
|
output (str): The path to the output file
|
2022-07-12 01:04:04 +00:00
|
|
|
"""
|
2022-07-12 01:04:05 +00:00
|
|
|
fields = ('status', 'arch', 'cpu', 'soc', 'vendor', 'board', 'target',
|
2022-07-12 01:04:06 +00:00
|
|
|
'config', 'maintainers')
|
2022-07-12 01:04:04 +00:00
|
|
|
|
|
|
|
# First, decide the width of each column
|
2022-07-12 01:04:05 +00:00
|
|
|
max_length = {f: 0 for f in fields}
|
2022-07-12 01:04:04 +00:00
|
|
|
for params in params_list:
|
2022-07-12 01:04:05 +00:00
|
|
|
for field in fields:
|
|
|
|
max_length[field] = max(max_length[field], len(params[field]))
|
2022-07-12 01:04:04 +00:00
|
|
|
|
|
|
|
output_lines = []
|
|
|
|
for params in params_list:
|
|
|
|
line = ''
|
2022-07-12 01:04:05 +00:00
|
|
|
for field in fields:
|
2022-07-12 01:04:04 +00:00
|
|
|
# insert two spaces between fields like column -t would
|
2022-07-12 01:04:05 +00:00
|
|
|
line += ' ' + params[field].ljust(max_length[field])
|
2022-07-12 01:04:04 +00:00
|
|
|
output_lines.append(line.strip())
|
|
|
|
|
|
|
|
# ignore case when sorting
|
|
|
|
output_lines.sort(key=str.lower)
|
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
with open(output, 'w', encoding="utf-8") as outf:
|
|
|
|
outf.write(COMMENT_BLOCK + '\n'.join(output_lines) + '\n')
|
2022-07-12 01:04:04 +00:00
|
|
|
|
|
|
|
def ensure_board_list(self, output, jobs=1, force=False, quiet=False):
|
|
|
|
"""Generate a board database file if needed.
|
|
|
|
|
2022-07-12 01:04:05 +00:00
|
|
|
Args:
|
|
|
|
output (str): The name of the output file
|
|
|
|
jobs (int): The number of jobs to run simultaneously
|
|
|
|
force (bool): Force to generate the output even if it is new
|
|
|
|
quiet (bool): True to avoid printing a message if nothing needs doing
|
2022-07-12 01:04:08 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
bool: True if all is well, False if there were warnings
|
2022-07-12 01:04:04 +00:00
|
|
|
"""
|
|
|
|
if not force and output_is_new(output):
|
|
|
|
if not quiet:
|
2022-07-12 01:04:05 +00:00
|
|
|
print(f'{output} is up to date. Nothing to do.')
|
2022-07-12 01:04:08 +00:00
|
|
|
return True
|
2022-07-12 01:04:04 +00:00
|
|
|
params_list = self.scan_defconfigs(jobs)
|
2022-07-12 01:04:08 +00:00
|
|
|
warnings = self.insert_maintainers_info(params_list)
|
|
|
|
for warn in warnings:
|
|
|
|
print(warn, file=sys.stderr)
|
2022-07-12 01:04:04 +00:00
|
|
|
self.format_and_output(params_list, output)
|
2022-07-12 01:04:08 +00:00
|
|
|
return not warnings
|