@@ -148,66 +148,36 @@ def get_board_mapping():
148
148
return boards
149
149
150
150
151
- def read_mpconfig ():
152
- """Open 'circuitpy_mpconfig.mk' and return the contents."""
153
- configs = []
154
- cpy_mpcfg = get_circuitpython_root_dir () / "py" / "circuitpy_mpconfig.mk"
155
- with open (cpy_mpcfg ) as mpconfig :
156
- configs = mpconfig .read ()
157
-
158
- return configs
159
-
160
-
161
151
def build_module_map ():
162
152
"""Establish the base of the JSON file, based on the contents from
163
- `configs`. Base will contain module names, if they're part of
164
- the `FULL_BUILD`, or their default value (0, 1, or a list of
165
- modules that determine default [see audiocore, audiomixer, etc.]).
166
-
153
+ `configs`. Base contains the module name and the controlling C macro name.
167
154
"""
168
155
base = dict ()
169
156
modules = get_bindings ()
170
- configs = read_mpconfig ()
171
- full_build = False
172
157
for module in modules :
173
158
full_name = module
174
159
if module in ADDITIONAL_MODULES :
175
160
search_identifier = ADDITIONAL_MODULES [module ]
176
161
else :
177
162
search_identifier = "CIRCUITPY_" + module .lstrip ("_" ).upper ()
178
- re_pattern = f"{ re .escape (search_identifier )} \s*\??=\s*(.+)"
179
- find_config = re .findall (re_pattern , configs )
180
- if not find_config :
181
- continue
182
- find_config = ", " .join ([x .strip ("$()" ) for x in find_config ])
183
-
184
- full_build = int ("CIRCUITPY_FULL_BUILD" in find_config )
185
- if not full_build :
186
- default_val = find_config
187
- else :
188
- default_val = "None"
189
163
190
164
base [module ] = {
191
165
"name" : full_name ,
192
- "full_build" : str (full_build ),
193
- "default_value" : default_val ,
194
- "excluded" : {},
195
166
"key" : search_identifier ,
196
167
}
197
168
198
169
return base
199
170
200
171
201
172
def get_settings_from_makefile (port_dir , board_name ):
202
- """Invoke make in a mode which prints the database, then parse it for
203
- settings.
173
+ """Invoke make to print the value of critical build settings
204
174
205
175
This means that the effect of all Makefile directives is taken
206
176
into account, without having to re-encode the logic that sets them
207
177
in this script, something that has proved error-prone
208
178
"""
209
179
contents = subprocess .run (
210
- ["make" , "-C" , port_dir , f" BOARD={ board_name } " , "-qp " , "print-CC " ],
180
+ ["make" , "-C" , port_dir , "-f" , "Makefile" , f" BOARD={ board_name } " , "print-CFLAGS " , "print-CIRCUITPY_BUILD_EXTENSIONS" , "print-FROZEN_MPY_DIRS" , "print-SRC_PATTERNS " ],
211
181
encoding = "utf-8" ,
212
182
errors = "replace" ,
213
183
stdout = subprocess .PIPE ,
@@ -223,9 +193,10 @@ def get_settings_from_makefile(port_dir, board_name):
223
193
224
194
settings = {}
225
195
for line in contents .stdout .split ("\n " ):
226
- # Handle both = and := definitions.
227
- m = re .match (r"^([A-Z][A-Z0-9_]*) :?= (.*)$" , line )
228
- if m :
196
+ if line .startswith ('CFLAGS =' ):
197
+ for m in re .findall ('-D([A-Z][A-Z0-9_]*)=(\d+)' , line ):
198
+ settings [m [0 ]] = m [1 ]
199
+ elif m := re .match (r"^([A-Z][A-Z0-9_]*) = (.*)$" , line ):
229
200
settings [m .group (1 )] = m .group (2 )
230
201
231
202
return settings
@@ -268,6 +239,10 @@ def get_repository_url(directory):
268
239
repository_urls [directory ] = path
269
240
return path
270
241
242
+ def remove_prefix (s , prefix ):
243
+ if not s .startswith (prefix ):
244
+ raise ValueError (f"{ s = } does not start with { prefix = } " )
245
+ return s .removeprefix (prefix )
271
246
272
247
def frozen_modules_from_dirs (frozen_mpy_dirs , withurl ):
273
248
"""
@@ -280,7 +255,8 @@ def frozen_modules_from_dirs(frozen_mpy_dirs, withurl):
280
255
"""
281
256
frozen_modules = []
282
257
for frozen_path in filter (lambda x : x , frozen_mpy_dirs .split (" " )):
283
- source_dir = get_circuitpython_root_dir () / frozen_path [7 :]
258
+ frozen_path = remove_prefix (frozen_path , '../../' )
259
+ source_dir = get_circuitpython_root_dir () / frozen_path
284
260
url_repository = get_repository_url (source_dir )
285
261
for sub in source_dir .glob ("*" ):
286
262
if sub .name in FROZEN_EXCLUDES :
0 commit comments