Skip to content

Commit c3dda7c

Browse files
committed
add parsing for 'MINIMAL/DEFAULT'; process inclusion when determined by another module
1 parent 7f1bc48 commit c3dda7c

1 file changed

Lines changed: 55 additions & 10 deletions

File tree

docs/shared_bindings_matrix.py

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ def read_mpconfig():
8787
def build_module_map():
8888
""" Establish the base of the JSON file, based on the contents from
8989
`configs`. Base will contain module names, if they're part of
90-
the `FULL_BUILD`, or their default value (0 | 1).
90+
the `FULL_BUILD`, or their default value (0, 1, or a list of
91+
modules that determine default [see audiocore, audiomixer, etc.]).
9192
9293
"""
9394
base = dict()
@@ -98,23 +99,25 @@ def build_module_map():
9899
full_name = module
99100
search_name = module.lstrip("_")
100101
re_pattern = "CIRCUITPY_{}\s=\s(.+)".format(search_name.upper())
101-
find_config = re.search(re_pattern, configs)
102-
#print(module, "|", find_config)
102+
find_config = re.findall(re_pattern, configs)
103103
if not find_config:
104104
continue
105-
full_build = int("FULL_BUILD" in find_config.group(0))
106-
#print(find_config[1])
105+
find_config = ", ".join([x.strip("$()") for x in find_config])
106+
107+
full_build = int("CIRCUITPY_FULL_BUILD" in find_config)
107108
if not full_build:
108-
default_val = find_config.group(1)
109+
default_val = find_config
109110
else:
110111
default_val = "None"
112+
111113
base[search_name] = {
112114
"name": full_name,
113115
"full_build": str(full_build),
114116
"default_value": default_val,
115117
"excluded": {}
116118
}
117119

120+
#print(base)
118121
return base
119122

120123

@@ -166,21 +169,40 @@ def get_excluded_boards(base):
166169
if board_chip in port_config:
167170
contents += "\n" + "\n".join(port_config[board_chip])
168171

172+
check_dependent_modules = dict()
169173
for module in modules:
170174
board_is_excluded = False
171175
# check if board uses `SMALL_BUILD`. if yes, and current
172176
# module is marked as `FULL_BUILD`, board is excluded
173177
small_build = re.search("CIRCUITPY_SMALL_BUILD = 1", contents)
174178
if small_build and base[module]["full_build"] == "1":
175179
board_is_excluded = True
180+
181+
# check if board uses `MINIMAL_BUILD`. if yes, and current
182+
# module is marked as `DEFAULT_BUILD`, board is excluded
183+
min_build = re.search("CIRCUITPY_MINIMAL_BUILD = 1", contents)
184+
if min_build and base[module]["default_value"] == "CIRCUITPY_DEFAULT_BUILD":
185+
board_is_excluded = True
186+
176187
# check if module is specifically disabled for this board
177188
re_pattern = "CIRCUITPY_{}\s=\s(\w)".format(module.upper())
178189
find_module = re.search(re_pattern, contents)
179190
if not find_module:
180-
# check if default inclusion is off ('0'). if the board doesn't
181-
# have it explicitly enabled, its excluded.
182-
if base[module]["default_value"] == "0":
183-
board_is_excluded = True
191+
if base[module]["default_value"].isdigit():
192+
# check if default inclusion is off ('0'). if the board doesn't
193+
# have it explicitly enabled, its excluded.
194+
if base[module]["default_value"] == "0":
195+
board_is_excluded = True
196+
else:
197+
# this module is dependent on another module. add it
198+
# to the list to check after processing all other modules.
199+
# only need to check exclusion if it isn't already excluded.
200+
if (not board_is_excluded and
201+
base[module]["default_value"] not in [
202+
"None",
203+
"CIRCUITPY_DEFAULT_BUILD"
204+
]):
205+
check_dependent_modules[module] = base[module]["default_value"]
184206
else:
185207
if (find_module.group(1) == "0" and
186208
find_module.group(1) != base[module]["default_value"]):
@@ -191,6 +213,29 @@ def get_excluded_boards(base):
191213
base[module]["excluded"][board_chip].append(entry.name)
192214
else:
193215
base[module]["excluded"][board_chip] = [entry.name]
216+
217+
for module in check_dependent_modules:
218+
depend_results = set()
219+
220+
parents = check_dependent_modules[module].split("CIRCUITPY_")
221+
parents = [item.strip(", ").lower() for item in parents if item]
222+
223+
for parent in parents:
224+
if parent in base:
225+
if (board_chip in base[parent]["excluded"] and
226+
entry.name in base[parent]["excluded"][board_chip]):
227+
depend_results.add(False)
228+
else:
229+
depend_results.add(True)
230+
231+
# only exclude the module if there were zero parents enabled
232+
# as determined by the 'depend_results' set.
233+
if (len(depend_results) == 1 and False in depend_results):
234+
if board_chip in base[module]["excluded"]:
235+
base[module]["excluded"][board_chip].append(entry.name)
236+
else:
237+
base[module]["excluded"][board_chip] = [entry.name]
238+
194239
#print(json.dumps(base, indent=2))
195240
return base
196241

0 commit comments

Comments
 (0)