py/mkrules.mk: Add MICROPY_PREVIEW_VERSION_2.

This provides a way to enable features and changes slated for MicroPython
2.x, by running `make MICROPY_PREVIEW_VERSION_2=1`. Also supported for
the cmake ports (except Zephyr).

This is an alternative to having a 2.x development branch (or equivalently,
keeping a 1.x release branch). Any feature or change that needs to be
"hidden" until 2.x can use this flag (either in the Makefile or the
preprocessor).

A good example is changing function arguments or other public API features,
in particular to aid in improving consistency between ports.

When `MICROPY_PREVIEW_VERSION_2` is enabled, the REPL banner is amended to
say "MicroPython (with v2.0 preview) vX.Y.Z", and sys.implementation gets a
new field `_v2` set to `True`.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
Jim Mussared
2023-10-10 16:50:28 +11:00
committed by Damien George
parent 3e2706a18d
commit 3bf70f16e9
8 changed files with 85 additions and 11 deletions

View File

@@ -15,6 +15,10 @@ set(MICROPY_ROOT_POINTERS_SPLIT "${MICROPY_GENHDR_DIR}/root_pointers.split")
set(MICROPY_ROOT_POINTERS_COLLECTED "${MICROPY_GENHDR_DIR}/root_pointers.collected")
set(MICROPY_ROOT_POINTERS "${MICROPY_GENHDR_DIR}/root_pointers.h")
if(NOT MICROPY_PREVIEW_VERSION_2)
set(MICROPY_PREVIEW_VERSION_2 0)
endif()
# Need to do this before extracting MICROPY_CPP_DEF below. Rest of frozen
# manifest handling is at the end of this file.
if(MICROPY_FROZEN_MANIFEST)
@@ -24,6 +28,12 @@ if(MICROPY_FROZEN_MANIFEST)
)
endif()
if(MICROPY_PREVIEW_VERSION_2)
target_compile_definitions(${MICROPY_TARGET} PUBLIC
MICROPY_PREVIEW_VERSION_2=\(1\)
)
endif()
# Provide defaults for preprocessor flags if not already defined
if(NOT MICROPY_CPP_FLAGS)
get_target_property(MICROPY_CPP_INC ${MICROPY_TARGET} INCLUDE_DIRECTORIES)