@@ -148,66 +148,36 @@ def get_board_mapping():
148148 return boards
149149
150150
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-
161151def build_module_map ():
162152 """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.
167154 """
168155 base = dict ()
169156 modules = get_bindings ()
170- configs = read_mpconfig ()
171- full_build = False
172157 for module in modules :
173158 full_name = module
174159 if module in ADDITIONAL_MODULES :
175160 search_identifier = ADDITIONAL_MODULES [module ]
176161 else :
177162 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"
189163
190164 base [module ] = {
191165 "name" : full_name ,
192- "full_build" : str (full_build ),
193- "default_value" : default_val ,
194- "excluded" : {},
195166 "key" : search_identifier ,
196167 }
197168
198169 return base
199170
200171
201172def 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
204174
205175 This means that the effect of all Makefile directives is taken
206176 into account, without having to re-encode the logic that sets them
207177 in this script, something that has proved error-prone
208178 """
209179 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 " ],
211181 encoding = "utf-8" ,
212182 errors = "replace" ,
213183 stdout = subprocess .PIPE ,
@@ -223,9 +193,10 @@ def get_settings_from_makefile(port_dir, board_name):
223193
224194 settings = {}
225195 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 ):
229200 settings [m .group (1 )] = m .group (2 )
230201
231202 return settings
@@ -268,6 +239,10 @@ def get_repository_url(directory):
268239 repository_urls [directory ] = path
269240 return path
270241
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 )
271246
272247def frozen_modules_from_dirs (frozen_mpy_dirs , withurl ):
273248 """
@@ -280,7 +255,8 @@ def frozen_modules_from_dirs(frozen_mpy_dirs, withurl):
280255 """
281256 frozen_modules = []
282257 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
284260 url_repository = get_repository_url (source_dir )
285261 for sub in source_dir .glob ("*" ):
286262 if sub .name in FROZEN_EXCLUDES :
0 commit comments