2626import pathlib
2727import re
2828import subprocess
29-
29+ import tomllib
3030
3131from concurrent .futures import ThreadPoolExecutor
3232
4343 "renode" ,
4444 "silabs" ,
4545 "stm" ,
46+ "zephyr-cp" ,
4647]
4748
4849ALIASES_BY_BOARD = {
@@ -130,21 +131,29 @@ def get_board_mapping():
130131 boards = {}
131132 for port in SUPPORTED_PORTS :
132133 board_path = root_dir / "ports" / port / "boards"
133- for board_path in os .scandir (board_path ):
134+ # Zephyr port has vendor specific subdirectories to match zephyr (and
135+ # clean up the boards folder.)
136+ g = "*/*" if port == "zephyr-cp" else "*"
137+ for board_path in board_path .glob (g ):
134138 if board_path .is_dir ():
135139 board_id = board_path .name
140+ if port == "zephyr-cp" :
141+ vendor = board_path .parent .name
142+ board_id = f"{ vendor } _{ board_id } "
136143 aliases = ALIASES_BY_BOARD .get (board_path .name , [])
137144 boards [board_id ] = {
138145 "port" : port ,
139146 "download_count" : 0 ,
140147 "aliases" : aliases ,
148+ "directory" : board_path ,
141149 }
142150 for alias in aliases :
143151 boards [alias ] = {
144152 "port" : port ,
145153 "download_count" : 0 ,
146154 "alias" : True ,
147155 "aliases" : [],
156+ "directory" : board_path ,
148157 }
149158 return boards
150159
@@ -295,15 +304,6 @@ def lookup_setting(settings, key, default=""):
295304 return value
296305
297306
298- def all_ports_all_boards (ports = SUPPORTED_PORTS ):
299- for port in ports :
300- port_dir = get_circuitpython_root_dir () / "ports" / port
301- for entry in (port_dir / "boards" ).iterdir ():
302- if not entry .is_dir ():
303- continue
304- yield (port , entry )
305-
306-
307307def support_matrix_by_board (use_branded_name = True , withurl = True ,
308308 add_port = False , add_chips = False ,
309309 add_pins = False , add_branded_name = False ):
@@ -313,29 +313,44 @@ def support_matrix_by_board(use_branded_name=True, withurl=True,
313313 base = build_module_map ()
314314
315315 def support_matrix (arg ):
316- port , entry = arg
317- port_dir = get_circuitpython_root_dir () / "ports" / port
318- settings = get_settings_from_makefile (str (port_dir ), entry .name )
316+ board_id , board_info = arg
317+ port = board_info ["port" ]
318+ board_directory = board_info ["directory" ]
319+ port_dir = board_directory .parent .parent
320+ if port != "zephyr-cp" :
321+ settings = get_settings_from_makefile (str (port_dir ), board_directory .name )
322+ autogen_board_info = None
323+ else :
324+ circuitpython_toml_fn = board_directory / "circuitpython.toml"
325+ with circuitpython_toml_fn .open ("rb" ) as f :
326+ settings = tomllib .load (f )
327+
328+ autogen_board_info_fn = board_directory / "autogen_board_info.toml"
329+ with autogen_board_info_fn .open ("rb" ) as f :
330+ autogen_board_info = tomllib .load (f )
319331
320332 if use_branded_name or add_branded_name :
321- with open (entry / "mpconfigboard.h" ) as get_name :
322- board_contents = get_name .read ()
323- board_name_re = re .search (
324- r"(?<=MICROPY_HW_BOARD_NAME)\s+(.+)" , board_contents
325- )
326- if board_name_re :
327- branded_name = board_name_re .group (1 ).strip ('"' )
328- if '"' in branded_name : # sometimes the closing " is not at line end
329- branded_name = branded_name [:branded_name .index ('"' )]
330- board_name = branded_name
333+ if autogen_board_info :
334+ branded_name = autogen_board_info ["name" ]
335+ else :
336+ with open (board_directory / "mpconfigboard.h" ) as get_name :
337+ board_contents = get_name .read ()
338+ board_name_re = re .search (
339+ r"(?<=MICROPY_HW_BOARD_NAME)\s+(.+)" , board_contents
340+ )
341+ if board_name_re :
342+ branded_name = board_name_re .group (1 ).strip ('"' )
343+ if '"' in branded_name : # sometimes the closing " is not at line end
344+ branded_name = branded_name [:branded_name .index ('"' )]
345+ board_name = branded_name
331346
332347 if use_branded_name :
333348 board_name = branded_name
334349 else :
335- board_name = entry .name
350+ board_name = board_directory .name
336351
337352 if add_chips :
338- with open (entry / "mpconfigboard.h" ) as get_name :
353+ with open (board_directory / "mpconfigboard.h" ) as get_name :
339354 board_contents = get_name .read ()
340355 mcu_re = re .search (
341356 r'(?<=MICROPY_HW_MCU_NAME)\s+(.+)' , board_contents
@@ -346,7 +361,7 @@ def support_matrix(arg):
346361 mcu = mcu [:mcu .index ('"' )]
347362 else :
348363 mcu = ""
349- with open (entry / "mpconfigboard.mk" ) as get_name :
364+ with open (board_directory / "mpconfigboard.mk" ) as get_name :
350365 board_contents = get_name .read ()
351366 flash_re = re .search (
352367 r'(?<=EXTERNAL_FLASH_DEVICES)\s+=\s+(.+)' , board_contents
@@ -363,7 +378,7 @@ def support_matrix(arg):
363378 if add_pins :
364379 pins = []
365380 try :
366- with open (entry / "pins.c" ) as get_name :
381+ with open (board_directory / "pins.c" ) as get_name :
367382 pin_lines = get_name .readlines ()
368383 except FileNotFoundError : # silabs boards have no pins.c
369384 pass
@@ -376,17 +391,25 @@ def support_matrix(arg):
376391 pins .append ((board_pin , chip_pin ))
377392
378393 board_modules = []
379- for module in base :
380- key = base [module ]["key" ]
381- if int (lookup_setting (settings , key , "0" )):
382- board_modules .append (base [module ]["name" ])
394+ if autogen_board_info :
395+ autogen_modules = autogen_board_info ["modules" ]
396+ for k in autogen_modules :
397+ if autogen_modules [k ]:
398+ board_modules .append (k )
399+ else :
400+ for module in base :
401+ key = base [module ]["key" ]
402+ if int (lookup_setting (settings , key , "0" )):
403+ board_modules .append (base [module ]["name" ])
383404 board_modules .sort ()
384405
385406 if "CIRCUITPY_BUILD_EXTENSIONS" in settings :
386- board_extensions = [
387- extension .strip ()
388- for extension in settings ["CIRCUITPY_BUILD_EXTENSIONS" ].split ("," )
389- ]
407+ board_extensions = settings ["CIRCUITPY_BUILD_EXTENSIONS" ]
408+ if isinstance (board_extensions , str ):
409+ board_extensions = [
410+ extension .strip ()
411+ for extension in board_extensions .split ("," )
412+ ]
390413 else :
391414 raise OSError (f"Board extensions undefined: { board_name } ." )
392415
@@ -420,8 +443,8 @@ def support_matrix(arg):
420443 board_info
421444 )
422445 ]
423- if entry . name in ALIASES_BY_BOARD :
424- for alias in ALIASES_BY_BOARD [entry . name ]:
446+ if board_id in ALIASES_BY_BOARD :
447+ for alias in ALIASES_BY_BOARD [board_id ]:
425448 if use_branded_name :
426449 if alias in ALIASES_BRAND_NAMES :
427450 alias = ALIASES_BRAND_NAMES [alias ]
@@ -450,8 +473,14 @@ def support_matrix(arg):
450473
451474 return board_matrix # this is now a list of (board,modules)
452475
476+
477+ board_mapping = get_board_mapping ()
478+ real_boards = []
479+ for board in board_mapping :
480+ if not board_mapping [board ].get ("alias" , False ):
481+ real_boards .append ((board , board_mapping [board ]))
453482 executor = ThreadPoolExecutor (max_workers = os .cpu_count ())
454- mapped_exec = executor .map (support_matrix , all_ports_all_boards () )
483+ mapped_exec = executor .map (support_matrix , real_boards )
455484 # flatmap with comprehensions
456485 boards = dict (
457486 sorted (
0 commit comments