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.
This commit is contained in:
Jeff Epler 2023-07-25 18:25:59 -05:00
parent fd60cccb06
commit 9a18524c30
No known key found for this signature in database
GPG Key ID: D5BF15AB975AB4DE
3 changed files with 27 additions and 71 deletions

View File

@ -148,50 +148,21 @@ def get_board_mapping():
return boards return boards
def read_mpconfig():
"""Open 'circuitpy_mpconfig.mk' and return the contents."""
configs = []
cpy_mpcfg = get_circuitpython_root_dir() / "py" / "circuitpy_mpconfig.mk"
with open(cpy_mpcfg) as mpconfig:
configs = mpconfig.read()
return configs
def build_module_map(): def build_module_map():
"""Establish the base of the JSON file, based on the contents from """Establish the base of the JSON file, based on the contents from
`configs`. Base will contain module names, if they're part of `configs`. Base contains the module name and the controlling C macro name.
the `FULL_BUILD`, or their default value (0, 1, or a list of
modules that determine default [see audiocore, audiomixer, etc.]).
""" """
base = dict() base = dict()
modules = get_bindings() modules = get_bindings()
configs = read_mpconfig()
full_build = False
for module in modules: for module in modules:
full_name = module full_name = module
if module in ADDITIONAL_MODULES: if module in ADDITIONAL_MODULES:
search_identifier = ADDITIONAL_MODULES[module] search_identifier = ADDITIONAL_MODULES[module]
else: else:
search_identifier = "CIRCUITPY_" + module.lstrip("_").upper() search_identifier = "CIRCUITPY_" + module.lstrip("_").upper()
re_pattern = f"{re.escape(search_identifier)}\s*\??=\s*(.+)"
find_config = re.findall(re_pattern, configs)
if not find_config:
continue
find_config = ", ".join([x.strip("$()") for x in find_config])
full_build = int("CIRCUITPY_FULL_BUILD" in find_config)
if not full_build:
default_val = find_config
else:
default_val = "None"
base[module] = { base[module] = {
"name": full_name, "name": full_name,
"full_build": str(full_build),
"default_value": default_val,
"excluded": {},
"key": search_identifier, "key": search_identifier,
} }
@ -199,15 +170,14 @@ def build_module_map():
def get_settings_from_makefile(port_dir, board_name): def get_settings_from_makefile(port_dir, board_name):
"""Invoke make in a mode which prints the database, then parse it for """Invoke make to print the value of critical build settings
settings.
This means that the effect of all Makefile directives is taken This means that the effect of all Makefile directives is taken
into account, without having to re-encode the logic that sets them into account, without having to re-encode the logic that sets them
in this script, something that has proved error-prone in this script, something that has proved error-prone
""" """
contents = subprocess.run( contents = subprocess.run(
["make", "-C", port_dir, f"BOARD={board_name}", "-qp", "print-CC"], ["make", "-C", port_dir, "-f", "Makefile", f"BOARD={board_name}", "print-CFLAGS", "print-CIRCUITPY_BUILD_EXTENSIONS", "print-FROZEN_MPY_DIRS"],
encoding="utf-8", encoding="utf-8",
errors="replace", errors="replace",
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
@ -223,9 +193,10 @@ def get_settings_from_makefile(port_dir, board_name):
settings = {} settings = {}
for line in contents.stdout.split("\n"): for line in contents.stdout.split("\n"):
# Handle both = and := definitions. if line.startswith('CFLAGS ='):
m = re.match(r"^([A-Z][A-Z0-9_]*) :?= (.*)$", line) for m in re.findall('-D([A-Z][A-Z0-9_]*)=(\d+)', line):
if m: settings[m[0]] = m[1]
elif m := re.match(r"^([A-Z][A-Z0-9_]*) = (.*)$", line):
settings[m.group(1)] = m.group(2) settings[m.group(1)] = m.group(2)
return settings return settings
@ -280,7 +251,7 @@ def frozen_modules_from_dirs(frozen_mpy_dirs, withurl):
""" """
frozen_modules = [] frozen_modules = []
for frozen_path in filter(lambda x: x, frozen_mpy_dirs.split(" ")): for frozen_path in filter(lambda x: x, frozen_mpy_dirs.split(" ")):
source_dir = get_circuitpython_root_dir() / frozen_path[7:] source_dir = get_circuitpython_root_dir() / frozen_path[6:]
url_repository = get_repository_url(source_dir) url_repository = get_repository_url(source_dir)
for sub in source_dir.glob("*"): for sub in source_dir.glob("*"):
if sub.name in FROZEN_EXCLUDES: if sub.name in FROZEN_EXCLUDES:

View File

@ -14,7 +14,6 @@ CIRCUITPY_FULL_BUILD ?= 1
CIRCUITPY_ALARM ?= 1 CIRCUITPY_ALARM ?= 1
CIRCUITPY_ANALOGBUFIO ?= 1 CIRCUITPY_ANALOGBUFIO ?= 1
CIRCUITPY_AUDIOBUSIO ?= 1 CIRCUITPY_AUDIOBUSIO ?= 1
CIRCUITPY_AUDIOBUSIO_I2SOUT ?= 1
CIRCUITPY_AUDIOBUSIO_PDMIN ?= 0 CIRCUITPY_AUDIOBUSIO_PDMIN ?= 0
CIRCUITPY_AUDIOIO ?= 0 CIRCUITPY_AUDIOIO ?= 0
CIRCUITPY_AUDIOMP3 ?= 0 CIRCUITPY_AUDIOMP3 ?= 0

View File

@ -26,6 +26,18 @@
# Boards default to all modules enabled (with exceptions) # Boards default to all modules enabled (with exceptions)
# Manually disable by overriding in #mpconfigboard.mk # Manually disable by overriding in #mpconfigboard.mk
enable-if-any=$(lastword $(sort $(1) 0))
enable-if-all=$(firstword $(sort $(1) 1))
#$(info enable-if-any 0 1 -> $(call enable-if-any,0 1))
#$(info enable-if-any 1 0 -> $(call enable-if-any,1 0))
#$(info enable-if-any 1 1 -> $(call enable-if-any,1 1))
#$(info enable-if-any 0 0 -> $(call enable-if-any,0 0))
#$(info enable-if-all 0 1 -> $(call enable-if-all,0 1))
#$(info enable-if-all 1 0 -> $(call enable-if-all,1 0))
#$(info enable-if-all 1 1 -> $(call enable-if-all,1 1))
#$(info enable-if-all 0 0 -> $(call enable-if-all,0 0))
# Always on. Present here to help generate documentation module support matrix for "builtins". # Always on. Present here to help generate documentation module support matrix for "builtins".
CIRCUITPY = 1 CIRCUITPY = 1
CFLAGS += -DCIRCUITPY=$(CIRCUITPY) CFLAGS += -DCIRCUITPY=$(CIRCUITPY)
@ -95,13 +107,7 @@ CFLAGS += -DCIRCUITPY_AUDIOIO=$(CIRCUITPY_AUDIOIO)
CIRCUITPY_AUDIOPWMIO ?= 0 CIRCUITPY_AUDIOPWMIO ?= 0
CFLAGS += -DCIRCUITPY_AUDIOPWMIO=$(CIRCUITPY_AUDIOPWMIO) CFLAGS += -DCIRCUITPY_AUDIOPWMIO=$(CIRCUITPY_AUDIOPWMIO)
ifndef CIRCUITPY_AUDIOCORE CIRCUITPY_AUDIOCORE ?= $(call enable-if-any,$(CIRCUITPY_AUDIOPWMIO) $(CIRCUITPY_AUDIOIO) $(CIRCUITPY_AUDIOBUSIO))
ifeq ($(CIRCUITPY_AUDIOPWMIO),1)
CIRCUITPY_AUDIOCORE = $(CIRCUITPY_AUDIOPWMIO)
else
CIRCUITPY_AUDIOCORE = $(CIRCUITPY_AUDIOIO)
endif
endif
CFLAGS += -DCIRCUITPY_AUDIOCORE=$(CIRCUITPY_AUDIOCORE) CFLAGS += -DCIRCUITPY_AUDIOCORE=$(CIRCUITPY_AUDIOCORE)
CIRCUITPY_AUDIOMIXER ?= $(CIRCUITPY_AUDIOCORE) CIRCUITPY_AUDIOMIXER ?= $(CIRCUITPY_AUDIOCORE)
@ -112,13 +118,7 @@ CIRCUITPY_AUDIOCORE_DEBUG ?= 0
endif endif
CFLAGS += -DCIRCUITPY_AUDIOCORE_DEBUG=$(CIRCUITPY_AUDIOCORE_DEBUG) CFLAGS += -DCIRCUITPY_AUDIOCORE_DEBUG=$(CIRCUITPY_AUDIOCORE_DEBUG)
ifndef CIRCUITPY_AUDIOMP3 CIRCUITPY_AUDIOMP3 ?= $(call enable-if-all,$(CIRCUITPY_FULL_BUILD) $(CIRCUITPY_AUDIOCORE))
ifeq ($(CIRCUITPY_FULL_BUILD),1)
CIRCUITPY_AUDIOMP3 = $(CIRCUITPY_AUDIOCORE)
else
CIRCUITPY_AUDIOMP3 = 0
endif
endif
CFLAGS += -DCIRCUITPY_AUDIOMP3=$(CIRCUITPY_AUDIOMP3) CFLAGS += -DCIRCUITPY_AUDIOMP3=$(CIRCUITPY_AUDIOMP3)
CIRCUITPY_BINASCII ?= $(CIRCUITPY_FULL_BUILD) CIRCUITPY_BINASCII ?= $(CIRCUITPY_FULL_BUILD)
@ -200,15 +200,9 @@ endif
CFLAGS += -DCIRCUITPY_PARALLELDISPLAY=$(CIRCUITPY_PARALLELDISPLAY) CFLAGS += -DCIRCUITPY_PARALLELDISPLAY=$(CIRCUITPY_PARALLELDISPLAY)
# bitmaptools and framebufferio rely on displayio # bitmaptools and framebufferio rely on displayio
ifeq ($(CIRCUITPY_DISPLAYIO),1) CIRCUITPY_BITMAPTOOLS ?= $(call enable-if-all,$(CIRCUITPY_FULL_BUILD) $(CIRCUITPY_DISPLAYIO))
CIRCUITPY_BITMAPTOOLS ?= $(CIRCUITPY_FULL_BUILD) CIRCUITPY_FRAMEBUFFERIO ?= $(call enable-if-all,$(CIRCUITPY_FULL_BUILD) $(CIRCUITPY_DISPLAYIO))
CIRCUITPY_FRAMEBUFFERIO ?= $(CIRCUITPY_FULL_BUILD) CIRCUITPY_VECTORIO ?= $(CIRCUITPY_DISPLAYIO)
CIRCUITPY_VECTORIO ?= 1
else
CIRCUITPY_BITMAPTOOLS ?= 0
CIRCUITPY_FRAMEBUFFERIO ?= 0
CIRCUITPY_VECTORIO ?= 0
endif
CFLAGS += -DCIRCUITPY_BITMAPTOOLS=$(CIRCUITPY_BITMAPTOOLS) CFLAGS += -DCIRCUITPY_BITMAPTOOLS=$(CIRCUITPY_BITMAPTOOLS)
CFLAGS += -DCIRCUITPY_FRAMEBUFFERIO=$(CIRCUITPY_FRAMEBUFFERIO) CFLAGS += -DCIRCUITPY_FRAMEBUFFERIO=$(CIRCUITPY_FRAMEBUFFERIO)
CFLAGS += -DCIRCUITPY_VECTORIO=$(CIRCUITPY_VECTORIO) CFLAGS += -DCIRCUITPY_VECTORIO=$(CIRCUITPY_VECTORIO)
@ -255,12 +249,7 @@ CFLAGS += -DCIRCUITPY_FUTURE=$(CIRCUITPY_FUTURE)
CIRCUITPY_GETPASS ?= $(CIRCUITPY_FULL_BUILD) CIRCUITPY_GETPASS ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_GETPASS=$(CIRCUITPY_GETPASS) CFLAGS += -DCIRCUITPY_GETPASS=$(CIRCUITPY_GETPASS)
ifeq ($(CIRCUITPY_DISPLAYIO),1) CIRCUITPY_GIFIO ?= $(call enable-if-any,$(CIRCUITPY_DISPLAYIO) $(CIRCUITPY_CAMERA))
#CIRCUITPY_GIFIO ?= $(CIRCUITPY_CAMERA)
CIRCUITPY_GIFIO ?= 1
else
CIRCUITPY_GIFIO ?= 0
endif
CFLAGS += -DCIRCUITPY_GIFIO=$(CIRCUITPY_GIFIO) CFLAGS += -DCIRCUITPY_GIFIO=$(CIRCUITPY_GIFIO)
CIRCUITPY_GNSS ?= 0 CIRCUITPY_GNSS ?= 0
@ -468,10 +457,7 @@ CFLAGS += -DCIRCUITPY_SYS=$(CIRCUITPY_SYS)
CIRCUITPY_TERMINALIO ?= $(CIRCUITPY_DISPLAYIO) CIRCUITPY_TERMINALIO ?= $(CIRCUITPY_DISPLAYIO)
CFLAGS += -DCIRCUITPY_TERMINALIO=$(CIRCUITPY_TERMINALIO) CFLAGS += -DCIRCUITPY_TERMINALIO=$(CIRCUITPY_TERMINALIO)
ifeq ($(CIRCUITPY_DISPLAYIO),1) CIRCUITPY_FONTIO ?= $(call enable-if-all,$(CIRCUITPY_DISPLAYIO) $(CIRCUITPY_TERMINALIO))
CIRCUITPY_FONTIO ?= $(CIRCUITPY_TERMINALIO)
endif
CFLAGS += -DCIRCUITPY_FONTIO=$(CIRCUITPY_FONTIO)
CIRCUITPY_TIME ?= 1 CIRCUITPY_TIME ?= 1
CFLAGS += -DCIRCUITPY_TIME=$(CIRCUITPY_TIME) CFLAGS += -DCIRCUITPY_TIME=$(CIRCUITPY_TIME)