-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev.py
69 lines (55 loc) · 1.53 KB
/
dev.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
import sys
import shutil
import os
import subprocess
def run(fp, command):
with subprocess.Popen(
command, stdout=subprocess.PIPE, text=True, bufsize=1, universal_newlines=True
) as proc:
for line in proc.stdout:
print(line, end="")
fp.write(line)
proc.wait()
if proc.returncode != 0:
raise subprocess.CalledProcessError(proc.returncode, command)
def clean():
if os.path.exists("build"):
shutil.rmtree("build")
if os.path.exists("local"):
shutil.rmtree("local")
def build():
with open("build.log", "w") as f:
run(
f,
[
"cmake",
"-S",
".",
"-B",
"build",
"-G",
"Ninja",
"-DCMAKE_BUILD_TYPE=Debug",
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON",
f"-DCMAKE_INSTALL_PREFIX={os.path.join(os.getcwd(), 'local')}",
],
)
run(f, ["cmake", "--build", "build"])
run(f, ["cmake", "--install", "build"])
def print_help():
print("Usage: python dev.py <command>")
print("Commands:")
print(" clean - Clean the project")
print(" build - Build the project")
def main():
args = sys.argv[1:]
command = args[0] if args else "help"
if command == "clean":
clean()
elif command == "build":
build()
else:
print_help()
sys.exit(1)
if __name__ == "__main__":
main()