8000 py/mpconfig: Move MICROPY_VERSION macros to static ones in mpconfig.h. · msuszko/micropython@7cd59c5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7cd59c5

Browse files
committed
py/mpconfig: Move MICROPY_VERSION macros to static ones in mpconfig.h.
It's more robust to have the version defined statically in a header file, rather than dynamically generating it via git using a git tag. In case git doesn't exist, or a different source control tool is used, it's important to still have the uPy version number available.
1 parent ce0c581 commit 7cd59c5

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

extmod/modwebrepl.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include "py/mphal.h"
3636
#endif
3737
#include "extmod/modwebsocket.h"
38-
#include "genhdr/mpversion.h"
3938

4039
#if MICROPY_PY_WEBREPL
4140

py/makeversionhdr.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,15 @@ def get_version_info_from_git():
4646
except OSError:
4747
return None
4848

49-
# Try to extract MicroPython version from git tag
50-
if git_tag.startswith("v"):
51-
ver = git_tag[1:].split("-")[0].split(".")
52-
if len(ver) == 2:
53-
ver.append("0")
54-
else:
55-
ver = ["0", "0", "1"]
56-
57-
return git_tag, git_hash, ver
49+
return git_tag, git_hash
5850

5951
def get_version_info_from_docs_conf():
6052
with open(os.path.join(os.path.dirname(sys.argv[0]), "..", "docs", "conf.py")) as f:
6153
for line in f:
6254
if line.startswith("version = release = '"):
6355
ver = line.strip().split(" = ")[2].strip("'")
6456
git_tag = "v" + ver
65-
ver = ver.split(".")
66-
if len(ver) == 2:
67-
ver.append("0")
68-
return git_tag, "<no hash>", ver
57+
return git_tag, "<no hash>"
6958
return None
7059

7160
def make_version_header(filename):
@@ -74,20 +63,15 @@ def make_version_header(filename):
7463
if info is None:
7564
info = get_version_info_from_docs_conf()
7665

77-
git_tag, git_hash, ver = info
66+
git_tag, git_hash = info
7867

7968
# Generate the file with the git and version info
8069
file_data = """\
8170
// This file was generated by py/makeversionhdr.py
8271
#define MICROPY_GIT_TAG "%s"
8372
#define MICROPY_GIT_HASH "%s"
8473
#define MICROPY_BUILD_DATE "%s"
85-
#define MICROPY_VERSION_MAJOR (%s)
86-
#define MICROPY_VERSION_MINOR (%s)
87-
#define MICROPY_VERSION_MICRO (%s)
88-
#define MICROPY_VERSION_STRING "%s.%s.%s"
89-
""" % (git_tag, git_hash, datetime.date.today().strftime("%Y-%m-%d"),
90-
ver[0], ver[1], ver[2], ver[0], ver[1], ver[2])
74+
""" % (git_tag, git_hash, datetime.date.today().strftime("%Y-%m-%d"))
9175

9276
# Check if the file contents changed from last time
9377
write_file = True

py/modsys.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737

3838
#if MICROPY_PY_SYS
3939

40-
#include "genhdr/mpversion.h"
41-
4240
// defined per port; type of these is irrelevant, just need pointer
4341
extern struct _mp_dummy_t mp_sys_stdin_obj;
4442
extern struct _mp_dummy_t mp_sys_stdout_obj;

py/mpconfig.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@
2626
#ifndef MICROPY_INCLUDED_PY_MPCONFIG_H
2727
#define MICROPY_INCLUDED_PY_MPCONFIG_H
2828

29+
// Current version of MicroPython
30+
#define MICROPY_VERSION_MAJOR (1)
31+
#define MICROPY_VERSION_MINOR (9)
32+
#define MICROPY_VERSION_MICRO (4)
33+
34+
// Combined version as a 32-bit number for convenience
35+
#define MICROPY_VERSION ( \
36+
MICROPY_VERSION_MAJOR << 16 \
37+
| MICROPY_VERSION_MINOR << 8 \
38+
| MICROPY_VERSION_MICRO)
39+
40+
// String version
41+
#define MICROPY_VERSION_STRING \
42+
MP_STRINGIFY(MICROPY_VERSION_MAJOR) "." \
43+
MP_STRINGIFY(MICROPY_VERSION_MINOR) "." \
44+
MP_STRINGIFY(MICROPY_VERSION_MICRO)
45+
2946
// This file contains default configuration settings for MicroPython.
3047
// You can override any of the options below using mpconfigport.h file
3148
// located in a directory of your port.

0 commit comments

Comments
 (0)
0