Skip to content

Commit 4c5f847

Browse files
committed
py/mkrules.mk: Add MICROPY_PREVIEW_VERSION_2_X.
This provides a way to enable features and changes slated for MicroPython 2.x, by running `make MICROPY_PREVIEW_VERSION_2_X=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_X` is enabled, the REPL banner is amended to say "MicroPython (with 2.x preview) vX.Y.Z", and sys.implementation gets a new field `_2x` set to `True`. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
1 parent 5f0bd33 commit 4c5f847

File tree

8 files changed

+85
-11
lines changed

8 files changed

+85
-11
lines changed

.github/workflows/ports_unix.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ jobs:
5555
if: failure()
5656
run: tests/run-tests.py --print-failures
5757

58+
standard_2x:
59+
runs-on: ubuntu-latest
60+
steps:
61+
- uses: actions/checkout@v4
62+
- name: Build
63+
run: source tools/ci.sh && ci_unix_standard_2x_build
64+
- name: Run main test suite
65+
run: source tools/ci.sh && ci_unix_standard_2x_run_tests
66+
- name: Print failures
67+
if: failure()
68+
run: tests/run-tests.py --print-failures
69+
5870
coverage:
5971
runs-on: ubuntu-latest
6072
steps:

ports/esp32/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ ifdef BOARD_VARIANT
5252
IDFPY_FLAGS += -D MICROPY_BOARD_VARIANT=$(BOARD_VARIANT)
5353
endif
5454

55+
ifdef MICROPY_PREVIEW_VERSION_2_X
56+
IDFPY_FLAGS += -D MICROPY_PREVIEW_VERSION_2_X=1
57+
endif
58+
5559
HELP_BUILD_ERROR ?= "See \033[1;31mhttps://github.com/micropython/micropython/wiki/Build-Troubleshooting\033[0m"
5660

5761
define RUN_IDF_PY

ports/rp2/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ ifdef BOARD_VARIANT
4848
CMAKE_ARGS += -DMICROPY_BOARD_VARIANT=$(BOARD_VARIANT)
4949
endif
5050

51+
ifdef MICROPY_PREVIEW_VERSION_2_X
52+
CMAKE_ARGS += -DMICROPY_PREVIEW_VERSION_2_X=1
53+
endif
54+
5155
HELP_BUILD_ERROR ?= "See \033[1;31mhttps://github.com/micropython/micropython/wiki/Build-Troubleshooting\033[0m"
5256

5357
all:

py/mkrules.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ set(MICROPY_ROOT_POINTERS_SPLIT "${MICROPY_GENHDR_DIR}/root_pointers.split")
1515
set(MICROPY_ROOT_POINTERS_COLLECTED "${MICROPY_GENHDR_DIR}/root_pointers.collected")
1616
set(MICROPY_ROOT_POINTERS "${MICROPY_GENHDR_DIR}/root_pointers.h")
1717

18+
if(NOT MICROPY_PREVIEW_VERSION_2_X)
19+
set(MICROPY_PREVIEW_VERSION_2_X 0)
20+
endif()
21+
1822
# Need to do this before extracting MICROPY_CPP_DEF below. Rest of frozen
1923
# manifest handling is at the end of this file.
2024
if(MICROPY_FROZEN_MANIFEST)
@@ -24,6 +28,12 @@ if(MICROPY_FROZEN_MANIFEST)
2428
)
2529
endif()
2630

31+
if(MICROPY_PREVIEW_VERSION_2_X)
32+
target_compile_definitions(${MICROPY_TARGET} PUBLIC
33+
MICROPY_PREVIEW_VERSION_2_X=\(1\)
34+
)
35+
endif()
36+
2737
# Provide defaults for preprocessor flags if not already defined
2838
if(NOT MICROPY_CPP_FLAGS)
2939
get_target_property(MICROPY_CPP_INC ${MICROPY_TARGET} INCLUDE_DIRECTORIES)

py/mkrules.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ THIS_MAKEFILE = $(lastword $(MAKEFILE_LIST))
44
include $(dir $(THIS_MAKEFILE))mkenv.mk
55
endif
66

7+
# Enable in-progress/breaking changes that are slated for MicroPython 2.x.
8+
MICROPY_PREVIEW_VERSION_2_X ?= 0
9+
10+
ifeq ($(MICROPY_PREVIEW_VERSION_2_X),1)
11+
CFLAGS += -DMICROPY_PREVIEW_VERSION_2_X=1
12+
endif
13+
714
HELP_BUILD_ERROR ?= "See \033[1;31mhttps://github.com/micropython/micropython/wiki/Build-Troubleshooting\033[0m"
815
HELP_MPY_LIB_SUBMODULE ?= "\033[1;31mError: micropython-lib submodule is not initialized.\033[0m Run 'make submodules'"
916

py/modsys.c

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,39 +79,57 @@ STATIC const mp_rom_obj_tuple_t mp_sys_implementation_version_info_obj = {
7979
}
8080
};
8181
STATIC const MP_DEFINE_STR_OBJ(mp_sys_implementation_machine_obj, MICROPY_BANNER_MACHINE);
82-
#if MICROPY_PERSISTENT_CODE_LOAD
83-
#define SYS_IMPLEMENTATION_ELEMS \
84-
MP_ROM_QSTR(MP_QSTR_micropython), \
85-
MP_ROM_PTR(&mp_sys_implementation_version_info_obj), \
86-
MP_ROM_PTR(&mp_sys_implementation_machine_obj), \
87-
MP_ROM_INT(MPY_FILE_HEADER_INT)
88-
#else
89-
#define SYS_IMPLEMENTATION_ELEMS \
82+
#define SYS_IMPLEMENTATION_ELEMS_BASE \
9083
MP_ROM_QSTR(MP_QSTR_micropython), \
9184
MP_ROM_PTR(&mp_sys_implementation_version_info_obj), \
9285
MP_ROM_PTR(&mp_sys_implementation_machine_obj)
86+
87+
#if MICROPY_PERSISTENT_CODE_LOAD
88+
#define SYS_IMPLEMENTATION_ELEMS__MPY \
89+
, MP_ROM_INT(MPY_FILE_HEADER_INT)
90+
#else
91+
#define SYS_IMPLEMENTATION_ELEMS__MPY
9392
#endif
93+
9494
#if MICROPY_PY_ATTRTUPLE
95+
#if MICROPY_PREVIEW_VERSION_2_X
96+
#define SYS_IMPLEMENTATION_ELEMS__2X \
97+
, MP_ROM_TRUE
98+
#else
99+
#define SYS_IMPLEMENTATION_ELEMS__2X
100+
#endif
101+
95102
STATIC const qstr impl_fields[] = {
96103
MP_QSTR_name,
97104
MP_QSTR_version,
98105
MP_QSTR__machine,
99106
#if MICROPY_PERSISTENT_CODE_LOAD
100107
MP_QSTR__mpy,
101108
#endif
109+
#if MICROPY_PREVIEW_VERSION_2_X
110+
MP_QSTR__2x,
111+
#endif
102112
};
103113
STATIC MP_DEFINE_ATTRTUPLE(
104114
mp_sys_implementation_obj,
105115
impl_fields,
106-
3 + MICROPY_PERSISTENT_CODE_LOAD,
107-
SYS_IMPLEMENTATION_ELEMS
116+
3 + MICROPY_PERSISTENT_CODE_LOAD + MICROPY_PREVIEW_VERSION_2_X,
117+
SYS_IMPLEMENTATION_ELEMS_BASE
118+
SYS_IMPLEMENTATION_ELEMS__MPY
119+
SYS_IMPLEMENTATION_ELEMS__2X
108120
);
109121
#else
110122
STATIC const mp_rom_obj_tuple_t mp_sys_implementation_obj = {
111123
{&mp_type_tuple},
112124
3 + MICROPY_PERSISTENT_CODE_LOAD,
113125
{
114-
SYS_IMPLEMENTATION_ELEMS
126+
SYS_IMPLEMENTATION_ELEMS_BASE
127+
SYS_IMPLEMENTATION_ELEMS__MPY
128+
// Do not include SYS_IMPLEMENTATION_ELEMS__2X because
129+
// SYS_IMPLEMENTATION_ELEMS__MPY may be empty if
130+
// MICROPY_PERSISTENT_CODE_LOAD is disabled, which means they'll share
131+
// the same index. Cannot query _2x if MICROPY_PY_ATTRTUPLE is
132+
// disabled.
115133
}
116134
};
117135
#endif

py/mpconfig.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@
5353
#define MICROPY_VERSION_STRING MICROPY_VERSION_STRING_BASE
5454
#endif
5555

56+
// If this is enabled, then in-progress/breaking changes slated for the 2.x
57+
// release will be enabled.
58+
#ifndef MICROPY_PREVIEW_VERSION_2_X
59+
#define MICROPY_PREVIEW_VERSION_2_X (0)
60+
#endif
61+
5662
// This file contains default configuration settings for MicroPython.
5763
// You can override any of the options below using mpconfigport.h file
5864
// located in a directory of your port.
@@ -1828,8 +1834,12 @@ typedef double mp_float_t;
18281834

18291835
// String used for the banner, and sys.version additional information
18301836
#ifndef MICROPY_BANNER_NAME_AND_VERSION
1837+
#if MICROPY_PREVIEW_VERSION_2_X
1838+
#define MICROPY_BANNER_NAME_AND_VERSION "MicroPython (with 2.x preview) " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE
1839+
#else
18311840
#define MICROPY_BANNER_NAME_AND_VERSION "MicroPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE
18321841
#endif
1842+
#endif
18331843

18341844
// String used for the second part of the banner, and sys.implementation._machine
18351845
#ifndef MICROPY_BANNER_MACHINE

tools/ci.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,15 @@ function ci_unix_standard_run_tests {
462462
ci_unix_run_tests_full_helper standard
463463
}
464464

465+
function ci_unix_standard_2x_build {
466+
ci_unix_build_helper VARIANT=standard MICROPY_PREVIEW_VERSION_2_X=1
467+
ci_unix_build_ffi_lib_helper gcc
468+
}
469+
470+
function ci_unix_standard_2x_run_tests {
471+
ci_unix_run_tests_full_helper standard
472+
}
473+
465474
function ci_unix_coverage_setup {
466475
sudo pip3 install setuptools
467476
sudo pip3 install pyelftools

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy