py/modsys: Add sys.implementation._build entry.

For a given MicroPython firmware/executable it can be sometimes important
to know how it was built, which variant/board configuration it came from.

This commit adds a new field `sys.implementation._build` that can help
identify the configuration that MicroPython was built with.

For now it's either:
* <VARIANT> for unix, webassembly and windows ports
* <BOARD>-<VARIANT> for microcontroller ports (the variant is optional)

In the future additional elements may be added to this string, separated by
a hyphen.

Resolves issue #16498.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2025-03-02 23:52:13 +11:00
parent b4cf82b2d6
commit f5b4545761
5 changed files with 61 additions and 4 deletions

View File

@@ -27,6 +27,17 @@ OBJ_EXTRA_ORDER_DEPS += $(HEADER_BUILD)/compressed.data.h
CFLAGS += -DMICROPY_ROM_TEXT_COMPRESSION=1
endif
# Set the variant or board name.
ifneq ($(VARIANT),)
CFLAGS += -DMICROPY_BOARD_BUILD_NAME=\"$(VARIANT)\"
else ifneq ($(BOARD),)
ifeq ($(BOARD_VARIANT),)
CFLAGS += -DMICROPY_BOARD_BUILD_NAME=\"$(BOARD)\"
else
CFLAGS += -DMICROPY_BOARD_BUILD_NAME=\"$(BOARD)-$(BOARD_VARIANT)\"
endif
endif
# QSTR generation uses the same CFLAGS, with these modifications.
QSTR_GEN_FLAGS = -DNO_QSTR
# Note: := to force evaluation immediately.