12
12
base branch while pushes will compare to the current ref. We override this
13
13
for the adafruit/circuitpython repo so we build all docs/boards for pushes.
14
14
15
+ When making changes to the script it is useful to manually test it.
16
+ You can for instance run
17
+ ```shell
18
+ tools/ci_set_matrix ports/raspberrypi/common-hal/socket/SSLSocket.c
19
+ ```
20
+ and (at the time this comment was written) get a series of messages indicating
21
+ that only the single board raspberry_pi_pico_w would be built.
15
22
"""
16
23
17
24
import re
18
25
import os
19
26
import sys
20
27
import json
21
28
import yaml
29
+ import pathlib
30
+ from concurrent .futures import ThreadPoolExecutor
31
+
32
+ tools_dir = pathlib .Path (__file__ ).resolve ().parent
33
+ top_dir = tools_dir .parent
34
+
35
+ sys .path .insert (0 , str (tools_dir / "adabot" ))
36
+ sys .path .insert (0 , str (top_dir / "docs" ))
22
37
23
38
import build_board_info
24
- from shared_bindings_matrix import get_settings_from_makefile
39
+ from shared_bindings_matrix import (
40
+ get_settings_from_makefile ,
41
+ SUPPORTED_PORTS ,
42
+ all_ports_all_boards ,
43
+ )
25
44
26
45
PORT_TO_ARCH = {
27
46
"atmel-samd" : "arm" ,
40
59
"tools/ci_check_duplicate_usb_vid_pid.py" ,
41
60
]
42
61
43
- changed_files = {}
44
- try :
45
- changed_files = json .loads (os .environ ["CHANGED_FILES" ])
46
- except json .decoder .JSONDecodeError as exc :
47
- if exc .msg != "Expecting value" :
48
- raise
62
+ if len (sys .argv ) > 1 :
63
+ print ("Using files list on commandline" )
64
+ changed_files = sys .argv [1 :]
65
+ else :
66
+ c = os .environ ["CHANGED_FILES" ]
67
+ if c == "" :
68
+ print ("CHANGED_FILES is in environment, but value is empty" )
69
+ changed_files = []
70
+ else :
71
+ print ("Using files list in CHANGED_FILES" )
72
+ changed_files = json .loads (os .environ ["CHANGED_FILES" ])
49
73
50
74
51
75
def set_output (name , value ):
@@ -74,13 +98,29 @@ def set_boards_to_build(build_all):
74
98
port_to_boards [port ].add (board_id )
75
99
board_to_port [board_id ] = port
76
100
101
+ def compute_board_settings (boards ):
102
+ need = set (boards ) - set (board_settings .keys ())
103
+ if not need :
104
+ return
105
+
106
+ def get_settings (board ):
107
+ return (
108
+ board ,
109
+ get_settings_from_makefile (str (top_dir / "ports" / board_to_port [board ]), board ),
110
+ )
111
+
112
+ with ThreadPoolExecutor (max_workers = os .cpu_count ()) as ex :
113
+ board_settings .update (ex .map (get_settings , need ))
114
+
77
115
boards_to_build = all_board_ids
78
116
79
117
if not build_all :
80
118
boards_to_build = set ()
81
119
board_pattern = re .compile (r"^ports/[^/]+/boards/([^/]+)/" )
82
120
port_pattern = re .compile (r"^ports/([^/]+)/" )
83
- module_pattern = re .compile (r"^(ports/[^/]+/shared-bindings|shared-module)/([^/]+)/" )
121
+ module_pattern = re .compile (
122
+ r"^(ports/[^/]+/(?:common-hal|bindings)|shared-bindings|shared-module)/([^/]+)/"
123
+ )
84
124
for p in changed_files :
85
125
# See if it is board specific
86
126
board_matches = board_pattern .search (p )
@@ -91,9 +131,9 @@ def set_boards_to_build(build_all):
91
131
92
132
# See if it is port specific
93
133
port_matches = port_pattern .search (p )
134
+ port = port_matches .group (1 ) if port_matches else None
94
135
module_matches = module_pattern .search (p )
95
- if port_matches and not module_matches :
96
- port = port_matches .group (1 )
136
+ if port and not module_matches :
97
137
if port != "unix" :
98
138
boards_to_build .update (port_to_boards [port ])
99
139
continue
@@ -109,11 +149,12 @@ def set_boards_to_build(build_all):
109
149
# As a (nearly) last resort, for some certain files, we compute the settings from the
110
150
# makefile for each board and determine whether to build them that way.
111
151
if p .startswith ("frozen" ) or p .startswith ("supervisor" ) or module_matches :
112
- for board in all_board_ids :
113
- if board not in board_settings :
114
- board_settings [board ] = get_settings_from_makefile (
115
- "../ports/" + board_to_port [board ], board
116
- )
152
+ if port :
153
+ board_ids = port_to_boards [port ]
154
+ else :
155
+ board_ids = all_board_ids
156
+ compute_board_settings (board_ids )
157
+ for board in board_ids :
117
158
settings = board_settings [board ]
118
159
119
160
# Check frozen files to see if they are in each board.
0 commit comments