26
26
import pathlib
27
27
import re
28
28
import subprocess
29
-
29
+ import tomllib
30
30
31
31
from concurrent .futures import ThreadPoolExecutor
32
32
43
43
"renode" ,
44
44
"silabs" ,
45
45
"stm" ,
46
+ "zephyr-cp" ,
46
47
]
47
48
48
49
ALIASES_BY_BOARD = {
@@ -130,21 +131,29 @@ def get_board_mapping():
130
131
boards = {}
131
132
for port in SUPPORTED_PORTS :
132
133
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 ):
134
138
if board_path .is_dir ():
135
139
board_id = board_path .name
140
+ if port == "zephyr-cp" :
141
+ vendor = board_path .parent .name
142
+ board_id = f"{ vendor } _{ board_id } "
136
143
aliases = ALIASES_BY_BOARD .get (board_path .name , [])
137
144
boards [board_id ] = {
138
145
"port" : port ,
139
146
"download_count" : 0 ,
140
147
"aliases" : aliases ,
148
+ "directory" : board_path ,
141
149
}
142
150
for alias in aliases :
143
151
boards [alias ] = {
144
152
"port" : port ,
145
153
"download_count" : 0 ,
146
154
"alias" : True ,
147
155
"aliases" : [],
156
+ "directory" : board_path ,
148
157
}
149
158
return boards
150
159
@@ -295,15 +304,6 @@ def lookup_setting(settings, key, default=""):
295
304
return value
296
305
297
306
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
-
307
307
def support_matrix_by_board (use_branded_name = True , withurl = True ,
308
308
add_port = False , add_chips = False ,
309
309
add_pins = False , add_branded_name = False ):
@@ -313,29 +313,44 @@ def support_matrix_by_board(use_branded_name=True, withurl=True,
313
313
base = build_module_map ()
314
314
315
315
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 )
319
331
320
332
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
331
346
332
347
if use_branded_name :
333
348
board_name = branded_name
334
349
else :
335
- board_name = entry .name
350
+ board_name = board_directory .name
336
351
337
352
if add_chips :
338
- with open (entry / "mpconfigboard.h" ) as get_name :
353
+ with open (board_directory / "mpconfigboard.h" ) as get_name :
339
354
board_contents = get_name .read ()
340
355
mcu_re = re .search (
341
356
r'(?<=MICROPY_HW_MCU_NAME)\s+(.+)' , board_contents
@@ -346,7 +361,7 @@ def support_matrix(arg):
346
361
mcu = mcu [:mcu .index ('"' )]
347
362
else :
348
363
mcu = ""
349
- with open (entry / "mpconfigboard.mk" ) as get_name :
364
+ with open (board_directory / "mpconfigboard.mk" ) as get_name :
350
365
board_contents = get_name .read ()
351
366
flash_re = re .search (
352
367
r'(?<=EXTERNAL_FLASH_DEVICES)\s+=\s+(.+)' , board_contents
@@ -363,7 +378,7 @@ def support_matrix(arg):
363
378
if add_pins :
364
379
pins = []
365
380
try :
366
- with open (entry / "pins.c" ) as get_name :
381
+ with open (board_directory / "pins.c" ) as get_name :
367
382
pin_lines = get_name .readlines ()
368
383
except FileNotFoundError : # silabs boards have no pins.c
369
384
pass
@@ -376,17 +391,25 @@ def support_matrix(arg):
376
391
pins .append ((board_pin , chip_pin ))
377
392
378
393
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" ])
383
404
board_modules .sort ()
384
405
385
406
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
+ ]
390
413
else :
391
414
raise OSError (f"Board extensions undefined: { board_name } ." )
392
415
@@ -420,8 +443,8 @@ def support_matrix(arg):
420
443
board_info
421
444
)
422
445
]
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 ]:
425
448
if use_branded_name :
426
449
if alias in ALIASES_BRAND_NAMES :
427
450
alias = ALIASES_BRAND_NAMES [alias ]
@@ -450,8 +473,14 @@ def support_matrix(arg):
450
473
451
474
return board_matrix # this is now a list of (board,modules)
452
475
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 ]))
453
482
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 )
455
484
# flatmap with comprehensions
456
485
boards = dict (
457
486
sorted (
0 commit comments