2121import yaml
2222
2323import build_board_info
24+ from shared_bindings_matrix import get_settings_from_makefile
2425
2526PORT_TO_ARCH = {
2627 "atmel-samd" : "arm" ,
@@ -53,6 +54,7 @@ def set_boards_to_build(build_all):
5354 all_board_ids = set ()
5455 port_to_boards = {}
5556 board_to_port = {}
57+ board_settings = {}
5658 for board_id in boards_info_json :
5759 info = boards_info_json [board_id ]
5860 if info .get ("alias" , False ):
@@ -70,6 +72,9 @@ def set_boards_to_build(build_all):
7072 boards_to_build = set ()
7173 board_pattern = re .compile (r"^ports/[^/]+/boards/([^/]+)/" )
7274 port_pattern = re .compile (r"^ports/([^/]+)/" )
75+ module_pattern = re .compile (
76+ r"^(ports/[^/]+/common-hal|shared-bindings|shared-module)/([^/]+)/"
77+ )
7378 for p in changed_files :
7479 # See if it is board specific
7580 board_matches = board_pattern .search (p )
@@ -80,7 +85,8 @@ def set_boards_to_build(build_all):
8085
8186 # See if it is port specific
8287 port_matches = port_pattern .search (p )
83- if port_matches :
88+ module_matches = module_pattern .search (p )
89+ if port_matches and not module_matches :
8490 port = port_matches .group (1 )
8591 if port != "unix" :
8692 boards_to_build .update (port_to_boards [port ])
@@ -94,14 +100,56 @@ def set_boards_to_build(build_all):
94100 if p .startswith ("tests" ):
95101 continue
96102
103+ # As a (nearly) last resort, for some certain files, we compute the settings from the
104+ # makefile for each board and determine whether to build them that way.
105+ if p .startswith ("frozen" ) or p .startswith ("supervisor" ) or module_matches :
106+ for board in all_board_ids :
107+ if board not in board_settings :
108+ board_settings [board ] = get_settings_from_makefile (
109+ "../ports/" + board_to_port [board ], board
110+ )
111+ settings = board_settings [board ]
112+
113+ # Check frozen files to see if they are in each board.
114+ frozen = settings .get ("FROZEN_MPY_DIRS" , "" )
115+ if frozen and p .startswith ("frozen" ) and p in frozen :
116+ boards_to_build .add (board )
117+ continue
118+
119+ # Check supervisor files. This is useful for limiting workflow changes to the
120+ # relevant boards.
121+ supervisor = settings ["SRC_SUPERVISOR" ]
122+ if p .startswith ("supervisor" ):
123+ if p in supervisor :
124+ boards_to_build .add (board )
125+ continue
126+
127+ web_workflow = settings ["CIRCUITPY_WEB_WORKFLOW" ]
128+ while web_workflow .startswith ("$(" ):
129+ web_workflow = settings [web_workflow [2 :- 1 ]]
130+ if (
131+ p .startswith ("supervisor/shared/web_workflow/static/" )
132+ and web_workflow != "0"
133+ ):
134+ boards_to_build .add (board )
135+ continue
136+
137+ # Check module matches
138+ if module_matches :
139+ module = module_matches .group (2 ) + "/"
140+ if module in settings ["SRC_PATTERNS" ]:
141+ boards_to_build .add (board )
142+ continue
143+ continue
144+
97145 # Otherwise build it all
98146 boards_to_build = all_board_ids
99147 break
100148
101149 # Split boards by architecture.
102150 print ("Building boards:" )
103151 arch_to_boards = {"aarch" : [], "arm" : [], "riscv" : [], "espressif" : []}
104- for board in boards_to_build :
152+ for board in sorted ( boards_to_build ) :
105153 print (" " , board )
106154 port = board_to_port .get (board )
107155 # A board can appear due to its _deletion_ (rare)
0 commit comments