-
Notifications
You must be signed in to change notification settings - Fork 3
/
version.py
67 lines (58 loc) · 2.17 KB
/
version.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
versionDefines = [
"#define SIGNALSMITH_DSP_VERSION_MAJOR ",
"#define SIGNALSMITH_DSP_VERSION_MINOR ",
"#define SIGNALSMITH_DSP_VERSION_PATCH "
]
versionStringDefine = "#define SIGNALSMITH_DSP_VERSION_STRING \"%s\""
version = [0, 0, 0]
# Read existing version from `#define`s
with open("dsp/common.h") as commonH:
for line in commonH:
for i in range(3):
if line.startswith(versionDefines[i]):
version[i] = int(line[len(versionDefines[i]):])
startVersion = list(version)
import sys
if len(sys.argv) > 1:
action = sys.argv[1]
if action == "bump-patch":
version[2] += 1
elif action == "bump-minor":
version[1] += 1
version[2] = 0
elif action == "bump-major":
version[0] += 1
version[1] = 0
version[2] = 0
else:
print("Unrecognised action: " + action)
exit(1)
oldVersion = ".".join([str(x) for x in startVersion])
newVersion = ".".join([str(x) for x in version])
def fileReplace(filename, fromText, toText):
text = ""
with open(filename) as textfile:
text = textfile.read()
if len(text) == 0:
return
text = text.replace(fromText, toText)
with open(filename, 'w') as textfile:
textfile.write(text)
for i in range(3):
fileReplace("dsp/common.h", versionDefines[i] + str(startVersion[i]), versionDefines[i] + str(version[i]))
fileReplace("dsp/common.h", versionStringDefine%oldVersion, versionStringDefine%newVersion)
exactVersionCheck = "SIGNALSMITH_DSP_VERSION_MAJOR == %i && SIGNALSMITH_DSP_VERSION_MINOR == %i && SIGNALSMITH_DSP_VERSION_PATCH == %i";
fileReplace("dsp/common.h",
exactVersionCheck%tuple(startVersion),
exactVersionCheck%tuple(version))
fileReplace("dsp/README.md",
"SIGNALSMITH_DSP_VERSION_CHECK(%i, %i, %i)"%tuple(startVersion),
"SIGNALSMITH_DSP_VERSION_CHECK(%i, %i, %i)"%tuple(version))
fileReplace("Doxyfile", "PROJECT_NUMBER = " + oldVersion, "PROJECT_NUMBER = " + newVersion)
fileReplace("tests/common/version.cpp",
"SIGNALSMITH_DSP_VERSION_CHECK(%i, %i, %i)"%tuple(startVersion),
"SIGNALSMITH_DSP_VERSION_CHECK(%i, %i, %i)"%tuple(version))
fileReplace("tests/common/version.cpp",
"static_assert(signalsmith::version(%i, %i, %i)"%tuple(startVersion),
"static_assert(signalsmith::version(%i, %i, %i)"%tuple(version))
print(newVersion)