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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
import os
import sys
import optparse
import platform
import json
import shutil
import re
import os, re, json, xml.etree.ElementTree
from optparse import OptionParser
def system(cmd):
if os.system(cmd) != 0:
sys.exit(1)
def build(clean, verbose = False):
if platform.system() == "Windows":
# configure
system("cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -G \"Ninja\"")
# build
system("ninja")
else:
# configure
system("cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -G \"Unix Makefiles\"")
if clean:
system("make clean")
# build
if verbose:
system("make -j 10 VERBOSE=1")
else:
system("make -j 10")
def read_json(fn):
json_file = ""
with open(fn) as f:
json_file = f.read()
return json.loads(json_file)
def checkgit():
stat = os.popen('git status --porcelain').read().strip()
if stat != "":
print("Missing checkin in", os.getcwd(), "\n" + stat)
exit(1)
def read_config():
codal = read_json("codal.json")
targetdir = codal['target']['name']
target = read_json("libraries/" + targetdir + "/target.json")
return (codal, targetdir, target)
def update(allow_detached=False):
(codal, targetdir, target) = read_config()
dirname = os.getcwd()
for ln in target['libraries']:
os.chdir(dirname + "/libraries/" + ln['name'])
system("git checkout " + ln['branch'])
system("git pull")
os.chdir(dirname + "/libraries/" + targetdir)
if ("HEAD detached" in os.popen('git branch').read().strip() and
allow_detached == False):
system("git checkout master")
system("git pull")
os.chdir(dirname)
def revision(rev):
(codal, targetdir, target) = read_config()
dirname = os.getcwd()
os.chdir("libraries/" + targetdir)
system("git checkout " + rev)
os.chdir(dirname)
update(True)
def printstatus():
print("\n***%s" % os.getcwd())
system("git status -s")
system("git rev-parse HEAD")
system("git branch")
def status():
(codal, targetdir, target) = read_config()
dirname = os.getcwd()
for ln in target['libraries']:
os.chdir(dirname + "/libraries/" + ln['name'])
printstatus()
os.chdir(dirname + "/libraries/" + targetdir)
printstatus()
os.chdir(dirname)
printstatus()
def get_next_version(options):
if options.version:
return options.version
log = os.popen('git log -n 100').read().strip()
m = re.search('Snapshot v(\d+)\.(\d+)\.(\d+)(-([\w\-]+).(\d+))?', log)
if m is None:
print("Cannot determine next version from git log")
exit(1)
v0 = int(m.group(1))
v1 = int(m.group(2))
v2 = int(m.group(3))
vB = -1
branchName = os.popen('git rev-parse --abbrev-ref HEAD').read().strip()
if not options.branch and branchName != "master":
print("On non-master branch use -l -b")
exit(1)
suff = ""
if options.branch:
if m.group(4) and branchName == m.group(5):
vB = int(m.group(6))
suff = "-%s.%d" % (branchName, vB + 1)
elif options.update_major:
v0 += 1
v1 = 0
v2 = 0
elif options.update_minor:
v1 += 1
v2 = 0
else:
v2 += 1
return "v%d.%d.%d%s" % (v0, v1, v2, suff)
def lock(options):
(codal, targetdir, target) = read_config()
dirname = os.getcwd()
for ln in target['libraries']:
os.chdir(dirname + "/libraries/" + ln['name'])
checkgit()
stat = os.popen('git status --porcelain -b').read().strip()
if "ahead" in stat:
print("Missing push in", os.getcwd())
exit(1)
sha = os.popen('git rev-parse HEAD').read().strip()
ln['branch'] = sha
print(ln['name'], sha)
os.chdir(dirname + "/libraries/" + targetdir)
ver = get_next_version(options)
print("Creating snaphot", ver)
system("git checkout target-locked.json")
checkgit()
target["snapshot_version"] = ver
with open("target-locked.json", "w") as f:
f.write(json.dumps(target, indent=4, sort_keys=True))
system("git commit -am \"Snapshot %s\"" % ver) # must match get_next_version() regex
sha = os.popen('git rev-parse HEAD').read().strip()
system("git tag %s" % ver)
system("git pull")
system("git push")
system("git push --tags")
os.chdir(dirname)
print("\nNew snapshot: %s [%s]" % (ver, sha))
def delete_build_folder(in_folder = True):
if in_folder:
os.chdir("..")
shutil.rmtree('./build')
os.mkdir("./build")
if in_folder:
os.chdir("./build")
def generate_docs():
from doc_gen.doxygen_extractor import DoxygenExtractor
from doc_gen.md_converter import MarkdownConverter
from doc_gen.system_utils import SystemUtils
from doc_gen.doc_gen import generate_mkdocs
os.chdir("..")
(codal, targetdir, target) = read_config()
lib_dir = os.getcwd() + "/libraries/"
libraries = [lib_dir + targetdir]
for l in target["libraries"]:
libraries = libraries + [ lib_dir + l["name"]]
os.chdir(lib_dir + targetdir)
generate_mkdocs(libraries)
|