-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathversion_increment_pre.py
76 lines (68 loc) · 2.98 KB
/
version_increment_pre.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
""" Create version header and tracker file if missing """
import datetime
import os
Import("env")
## DO NOT EDIT THIS FILE, edit version file if you want to start from a different version
#
# version_increment_pre.py - Simple versioning script for Platformio
#
# Copyright (C) 2022 Davide Perini
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# You should have received a copy of the MIT License along with this program.
# If not, see <https://opensource.org/licenses/MIT/>.
#
VERSION_FILE = 'version'
VERSION_HEADER = 'Version.h'
VERSION_PREFIX = '0.1.'
VERSION_PATCH_NUMBER = 0
if not os.path.exists(".version_no_increment"):
try:
with open(VERSION_FILE) as FILE:
VERSION_PATCH_NUMBER = FILE.readline()
VERSION_PREFIX = VERSION_PATCH_NUMBER[0:VERSION_PATCH_NUMBER.rindex('.')+1]
VERSION_PATCH_NUMBER = int(VERSION_PATCH_NUMBER[VERSION_PATCH_NUMBER.rindex('.')+1:])
if not os.path.exists(".version_no_increment_update_date"):
VERSION_PATCH_NUMBER = VERSION_PATCH_NUMBER + 1
except:
print('No version file found or incorrect data in it. Starting from 0.1.0')
VERSION_PATCH_NUMBER = 0
with open(VERSION_FILE, 'w+') as FILE:
FILE.write(VERSION_PREFIX + str(VERSION_PATCH_NUMBER))
print('Build number: {}'.format(VERSION_PREFIX + str(VERSION_PATCH_NUMBER)))
HEADER_FILE = """
// AUTO GENERATED FILE, DO NOT EDIT
#ifndef VERSION
#define VERSION "{}"
#endif
#ifndef BUILD_TIMESTAMP
#define BUILD_TIMESTAMP "{}"
#endif
""".format(VERSION_PREFIX + str(VERSION_PATCH_NUMBER), datetime.datetime.now())
if os.environ.get('PLATFORMIO_INCLUDE_DIR') is not None:
VERSION_HEADER = os.environ.get('PLATFORMIO_INCLUDE_DIR') + os.sep + VERSION_HEADER
elif os.path.exists("include"):
VERSION_HEADER = "include" + os.sep + VERSION_HEADER
else:
PROJECT_DIR = env.subst("$PROJECT_DIR")
os.mkdir(PROJECT_DIR + os.sep + "include")
VERSION_HEADER = "include" + os.sep + VERSION_HEADER
with open(VERSION_HEADER, 'w+') as FILE:
FILE.write(HEADER_FILE)
open('.version_no_increment', 'a').close()
else:
if os.path.exists("version"):
FILE = open(VERSION_FILE)
VERSION_NUMBER = FILE.readline()
print('Build number: {} (waiting for upload before next increment)'.format(str(VERSION_NUMBER)))
else:
print('No version file found or incorrect data in it!!')