shared_bindings_matrix: Run in parallel
.. this makes it take a fraction of the time, at least on systems with a lot of CPU threads. Even on my old laptop with a 2-core CPU it reduces the time from 55s to 27s.
This commit is contained in:
parent
5755160720
commit
5422dd682c
@ -28,6 +28,7 @@ import re
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
SUPPORTED_PORTS = ['atmel-samd', 'esp32s2', 'litex', 'mimxrt10xx', 'nrf', 'stm']
|
SUPPORTED_PORTS = ['atmel-samd', 'esp32s2', 'litex', 'mimxrt10xx', 'nrf', 'stm']
|
||||||
|
|
||||||
@ -131,38 +132,44 @@ def lookup_setting(settings, key, default=''):
|
|||||||
key = value[2:-1]
|
key = value[2:-1]
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
def all_ports_all_boards(ports=SUPPORTED_PORTS):
|
||||||
|
for port in ports:
|
||||||
|
|
||||||
|
port_dir = get_circuitpython_root_dir() / "ports" / port
|
||||||
|
for entry in (port_dir / "boards").iterdir():
|
||||||
|
if not entry.is_dir():
|
||||||
|
continue
|
||||||
|
yield (port, entry)
|
||||||
|
|
||||||
def support_matrix_by_board(use_branded_name=True):
|
def support_matrix_by_board(use_branded_name=True):
|
||||||
""" Compiles a list of the available core modules available for each
|
""" Compiles a list of the available core modules available for each
|
||||||
board.
|
board.
|
||||||
"""
|
"""
|
||||||
base = build_module_map()
|
base = build_module_map()
|
||||||
|
|
||||||
boards = dict()
|
def support_matrix(arg):
|
||||||
for port in SUPPORTED_PORTS:
|
port, entry = arg
|
||||||
|
|
||||||
port_dir = get_circuitpython_root_dir() / "ports" / port
|
port_dir = get_circuitpython_root_dir() / "ports" / port
|
||||||
for entry in (port_dir / "boards").iterdir():
|
settings = get_settings_from_makefile(str(port_dir), entry.name)
|
||||||
if not entry.is_dir():
|
|
||||||
continue
|
|
||||||
board_modules = []
|
|
||||||
board_name = entry.name
|
|
||||||
|
|
||||||
settings = get_settings_from_makefile(str(port_dir), entry.name)
|
if use_branded_name:
|
||||||
|
with open(entry / "mpconfigboard.h") as get_name:
|
||||||
|
board_contents = get_name.read()
|
||||||
|
board_name_re = re.search(r"(?<=MICROPY_HW_BOARD_NAME)\s+(.+)",
|
||||||
|
board_contents)
|
||||||
|
if board_name_re:
|
||||||
|
board_name = board_name_re.group(1).strip('"')
|
||||||
|
|
||||||
if use_branded_name:
|
board_modules = []
|
||||||
with open(entry / "mpconfigboard.h") as get_name:
|
for module in base:
|
||||||
board_contents = get_name.read()
|
key = f'CIRCUITPY_{module.upper()}'
|
||||||
board_name_re = re.search(r"(?<=MICROPY_HW_BOARD_NAME)\s+(.+)",
|
if int(lookup_setting(settings, key, '0')):
|
||||||
board_contents)
|
board_modules.append(base[module]['name'])
|
||||||
if board_name_re:
|
|
||||||
board_name = board_name_re.group(1).strip('"')
|
|
||||||
|
|
||||||
board_modules = []
|
return (board_name, sorted(board_modules))
|
||||||
for module in base:
|
|
||||||
key = f'CIRCUITPY_{module.upper()}'
|
executor = ThreadPoolExecutor(max_workers=os.cpu_count())
|
||||||
if int(lookup_setting(settings, key, '0')):
|
boards = dict(sorted(executor.map(support_matrix, all_ports_all_boards())))
|
||||||
board_modules.append(base[module]['name'])
|
|
||||||
boards[board_name] = sorted(board_modules)
|
|
||||||
|
|
||||||
#print(json.dumps(boards, indent=2))
|
#print(json.dumps(boards, indent=2))
|
||||||
return boards
|
return boards
|
||||||
|
Loading…
x
Reference in New Issue
Block a user