-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild_versioning.py
35 lines (31 loc) · 916 Bytes
/
build_versioning.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# copied from https://stackoverflow.com/questions/56923895/auto-increment-build-number-using-platformio
FILENAME_BUILDNO = 'versioning'
FILENAME_VERSION_H = 'include/version.h'
version = 'GIT_VERSION'
import datetime
build_no = 0
try:
with open(FILENAME_BUILDNO) as f:
build_no = int(f.readline()) + 1
except:
print('Starting build number from 1..')
build_no = 1
with open(FILENAME_BUILDNO, 'w+') as f:
f.write(str(build_no))
print('Build number: {}'.format(build_no))
hf = """
#ifndef GIT_VERSION
#define GIT_VERSION "git n/a"
#endif
#ifndef BUILD_NUMBER
#define BUILD_NUMBER "{}"
#endif
#ifndef VERSION
#define VERSION {}".{}-{}"
#endif
#ifndef VERSION_SHORT
#define VERSION_SHORT {}".{}"
#endif
""".format(build_no, version,str(build_no), datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S"), version,str(build_no))
with open(FILENAME_VERSION_H, 'w+') as f:
f.write(hf)