-
Notifications
You must be signed in to change notification settings - Fork 6
/
CoverPositionsCompile.py
55 lines (44 loc) · 1.32 KB
/
CoverPositionsCompile.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
#!/bin/env python3
import glob
import os.path
import sys
def c_string(s):
return 'R"us5lhvaf({})us5lhvaf"'.format(s)
configs = {}
for fn in glob.glob("_defaultConfigs/*.js"):
basename = os.path.basename(fn)
if basename[0] == '_':
continue
with open(fn) as f:
configs[basename[:-3]] = f.read()
if 'Default' not in configs:
sys.exit("Default config missing")
config_count = len(configs)
configs = "\n\n".join(
"//{:/^116}//\n{},\n{},".format(
" {} ".format(k),
c_string(k + " (build-in)"),
c_string(v.strip().replace(" ", "\t")))
for k, v in sorted(configs.items()))
template = """/// This file is auto-generated by {me}
static const char* configs[{array_len}] = {{
{configs}
nullptr }};
const char** builtInCoverConfigArray = static_cast<const char**>(configs);
"""
new_content = template.format(me=__file__,
configs=configs,
array_len=config_count * 2 + 1)
made_changes = False
out_file = 'lib/cover_configs.cpp'
with open(out_file, "r+", newline="\n") as f:
old_content = f.read()
if old_content != new_content:
made_changes = True
f.seek(0)
f.truncate()
f.write(new_content)
if made_changes:
print("cover configs updated")
else:
print("cover configs unchanged")