Skip to content

Commit 9a18524

Browse files
committed
simplify circuitpy_mpconfig with enable-if-any, -all
and make corresponding simplifications in shared-bindings-matrix, but directly using the final defines from CFLAGS instead of the status quo. The net changes are to disable audiocore & audiomixer on some espressif devices that have no audio output at all. Other than that, the shared-bindings-matrix seems to be identical.
1 parent fd60ccc commit 9a18524

File tree

3 files changed

+27
-71
lines changed

3 files changed

+27
-71
lines changed

docs/shared_bindings_matrix.py

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
161151
def 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

201172
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
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"],
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
@@ -280,7 +251,7 @@ def frozen_modules_from_dirs(frozen_mpy_dirs, withurl):
280251
"""
281252
frozen_modules = []
282253
for frozen_path in filter(lambda x: x, frozen_mpy_dirs.split(" ")):
283-
source_dir = get_circuitpython_root_dir() / frozen_path[7:]
254+
source_dir = get_circuitpython_root_dir() / frozen_path[6:]
284255
url_repository = get_repository_url(source_dir)
285256
for sub in source_dir.glob("*"):
286257
if sub.name in FROZEN_EXCLUDES:

ports/espressif/mpconfigport.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ CIRCUITPY_FULL_BUILD ?= 1
1414
CIRCUITPY_ALARM ?= 1
1515
CIRCUITPY_ANALOGBUFIO ?= 1
1616
CIRCUITPY_AUDIOBUSIO ?= 1
17-
CIRCUITPY_AUDIOBUSIO_I2SOUT ?= 1
1817
CIRCUITPY_AUDIOBUSIO_PDMIN ?= 0
1918
CIRCUITPY_AUDIOIO ?= 0
2019
CIRCUITPY_AUDIOMP3 ?= 0

py/circuitpy_mpconfig.mk

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@
2626
# Boards default to all modules enabled (with exceptions)
2727
# Manually disable by overriding in #mpconfigboard.mk
2828

29+
enable-if-any=$(lastword $(sort $(1) 0))
30+
enable-if-all=$(firstword $(sort $(1) 1))
31+
32+
#$(info enable-if-any 0 1 -> $(call enable-if-any,0 1))
33+
#$(info enable-if-any 1 0 -> $(call enable-if-any,1 0))
34+
#$(info enable-if-any 1 1 -> $(call enable-if-any,1 1))
35+
#$(info enable-if-any 0 0 -> $(call enable-if-any,0 0))
36+
#$(info enable-if-all 0 1 -> $(call enable-if-all,0 1))
37+
#$(info enable-if-all 1 0 -> $(call enable-if-all,1 0))
38+
#$(info enable-if-all 1 1 -> $(call enable-if-all,1 1))
39+
#$(info enable-if-all 0 0 -> $(call enable-if-all,0 0))
40+
2941
# Always on. Present here to help generate documentation module support matrix for "builtins".
3042
CIRCUITPY = 1
3143
CFLAGS += -DCIRCUITPY=$(CIRCUITPY)
@@ -95,13 +107,7 @@ CFLAGS += -DCIRCUITPY_AUDIOIO=$(CIRCUITPY_AUDIOIO)
95107
CIRCUITPY_AUDIOPWMIO ?= 0
96108
CFLAGS += -DCIRCUITPY_AUDIOPWMIO=$(CIRCUITPY_AUDIOPWMIO)
97109

98-
ifndef CIRCUITPY_AUDIOCORE
99-
ifeq ($(CIRCUITPY_AUDIOPWMIO),1)
100-
CIRCUITPY_AUDIOCORE = $(CIRCUITPY_AUDIOPWMIO)
101-
else
102-
CIRCUITPY_AUDIOCORE = $(CIRCUITPY_AUDIOIO)
103-
endif
104-
endif
110+
CIRCUITPY_AUDIOCORE ?= $(call enable-if-any,$(CIRCUITPY_AUDIOPWMIO) $(CIRCUITPY_AUDIOIO) $(CIRCUITPY_AUDIOBUSIO))
105111
CFLAGS += -DCIRCUITPY_AUDIOCORE=$(CIRCUITPY_AUDIOCORE)
106112

107113
CIRCUITPY_AUDIOMIXER ?= $(CIRCUITPY_AUDIOCORE)
@@ -112,13 +118,7 @@ CIRCUITPY_AUDIOCORE_DEBUG ?= 0
112118
endif
113119
CFLAGS += -DCIRCUITPY_AUDIOCORE_DEBUG=$(CIRCUITPY_AUDIOCORE_DEBUG)
114120

115-
ifndef CIRCUITPY_AUDIOMP3
116-
ifeq ($(CIRCUITPY_FULL_BUILD),1)
117-
CIRCUITPY_AUDIOMP3 = $(CIRCUITPY_AUDIOCORE)
118-
else
119-
CIRCUITPY_AUDIOMP3 = 0
120-
endif
121-
endif
121+
CIRCUITPY_AUDIOMP3 ?= $(call enable-if-all,$(CIRCUITPY_FULL_BUILD) $(CIRCUITPY_AUDIOCORE))
122122
CFLAGS += -DCIRCUITPY_AUDIOMP3=$(CIRCUITPY_AUDIOMP3)
123123

124124
CIRCUITPY_BINASCII ?= $(CIRCUITPY_FULL_BUILD)
@@ -200,15 +200,9 @@ endif
200200
CFLAGS += -DCIRCUITPY_PARALLELDISPLAY=$(CIRCUITPY_PARALLELDISPLAY)
201201

202202
# bitmaptools and framebufferio rely on displayio
203-
ifeq ($(CIRCUITPY_DISPLAYIO),1)
204-
CIRCUITPY_BITMAPTOOLS ?= $(CIRCUITPY_FULL_BUILD)
205-
CIRCUITPY_FRAMEBUFFERIO ?= $(CIRCUITPY_FULL_BUILD)
206-
CIRCUITPY_VECTORIO ?= 1
207-
else
208-
CIRCUITPY_BITMAPTOOLS ?= 0
209-
CIRCUITPY_FRAMEBUFFERIO ?= 0
210-
CIRCUITPY_VECTORIO ?= 0
211-
endif
203+
CIRCUITPY_BITMAPTOOLS ?= $(call enable-if-all,$(CIRCUITPY_FULL_BUILD) $(CIRCUITPY_DISPLAYIO))
204+
CIRCUITPY_FRAMEBUFFERIO ?= $(call enable-if-all,$(CIRCUITPY_FULL_BUILD) $(CIRCUITPY_DISPLAYIO))
205+
CIRCUITPY_VECTORIO ?= $(CIRCUITPY_DISPLAYIO)
212206
CFLAGS += -DCIRCUITPY_BITMAPTOOLS=$(CIRCUITPY_BITMAPTOOLS)
213207
CFLAGS += -DCIRCUITPY_FRAMEBUFFERIO=$(CIRCUITPY_FRAMEBUFFERIO)
214208
CFLAGS += -DCIRCUITPY_VECTORIO=$(CIRCUITPY_VECTORIO)
@@ -255,12 +249,7 @@ CFLAGS += -DCIRCUITPY_FUTURE=$(CIRCUITPY_FUTURE)
255249
CIRCUITPY_GETPASS ?= $(CIRCUITPY_FULL_BUILD)
256250
CFLAGS += -DCIRCUITPY_GETPASS=$(CIRCUITPY_GETPASS)
257251

258-
ifeq ($(CIRCUITPY_DISPLAYIO),1)
259-
#CIRCUITPY_GIFIO ?= $(CIRCUITPY_CAMERA)
260-
CIRCUITPY_GIFIO ?= 1
261-
else
262-
CIRCUITPY_GIFIO ?= 0
263-
endif
252+
CIRCUITPY_GIFIO ?= $(call enable-if-any,$(CIRCUITPY_DISPLAYIO) $(CIRCUITPY_CAMERA))
264253
CFLAGS += -DCIRCUITPY_GIFIO=$(CIRCUITPY_GIFIO)
265254

266255
CIRCUITPY_GNSS ?= 0
@@ -468,10 +457,7 @@ CFLAGS += -DCIRCUITPY_SYS=$(CIRCUITPY_SYS)
468457
CIRCUITPY_TERMINALIO ?= $(CIRCUITPY_DISPLAYIO)
469458
CFLAGS += -DCIRCUITPY_TERMINALIO=$(CIRCUITPY_TERMINALIO)
470459

471-
ifeq ($(CIRCUITPY_DISPLAYIO),1)
472-
CIRCUITPY_FONTIO ?= $(CIRCUITPY_TERMINALIO)
473-
endif
474-
CFLAGS += -DCIRCUITPY_FONTIO=$(CIRCUITPY_FONTIO)
460+
CIRCUITPY_FONTIO ?= $(call enable-if-all,$(CIRCUITPY_DISPLAYIO) $(CIRCUITPY_TERMINALIO))
475461

476462
CIRCUITPY_TIME ?= 1
477463
CFLAGS += -DCIRCUITPY_TIME=$(CIRCUITPY_TIME)

0 commit comments

Comments
 (0)