-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnbuild.py
67 lines (57 loc) · 1.73 KB
/
nbuild.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
try:
import configparser
except ImportError:
import ConfigParser as configparser
import glob
import os
import re
# Read the platformio ini file
config = configparser.ConfigParser()
config.read("platformio.ini")
# Update nbuild
def get_nbuild():
# nbuild file handler
nbuild = 0
# Check if nbuild file exists
if os.path.exists('nbuild'):
# Read it
nbfile = open('nbuild', 'r')
nbuild = int(nbfile.read())
nbfile.close()
# Incrmeent build number
nbuild = nbuild + 1
# Rewrite nbuild file
nbfile = open('nbuild', 'w')
nbfile.write(str(nbuild))
nbfile.close()
# Return
return nbuild
# Make header
def mk_header():
# Get relevant data
path = config.get("codegen:versioning", "header")
version = config.get("codegen:versioning", "version")
nbuild = get_nbuild()
# Open file
mainfile = open(path, 'wt')
# Make header
mainfile.write('#ifndef __VERSION_NBUILD\n')
mainfile.write('#define __VERSION_NBUILD\n \n')
# Add defines
mainfile.write('\t#define BUILD_N %d \n\n' % (nbuild))
mainfile.write('\t/* Debug mode */\n')
mainfile.write('\t#ifdef BUILD_CONFIG_DEBUG\n')
mainfile.write('\t\t#define BUILD_VERSION "%sD" \n' % version)
mainfile.write('\t\t#define BUILD_VERSION_NBUILD "%s#%dD" \n' % (version, nbuild))
mainfile.write('\t/* Release mode */\n')
mainfile.write('\t#else\n')
mainfile.write('\t\t#define BUILD_VERSION "%s" \n' % version)
mainfile.write('\t\t#define BUILD_VERSION_NBUILD "%s#%d" \n' % (version, nbuild))
mainfile.write('\t#endif\n\n')
# Close it
mainfile.write('#endif')
mainfile.close()
# Do !
mk_header()
# OK
print("Regenerated version file !")