-
Notifications
You must be signed in to change notification settings - Fork 12
/
build.py
executable file
·89 lines (71 loc) · 2.91 KB
/
build.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
import os.path
import subprocess
import argparse
import platform
os_name = platform.system()
def which(program):
import os
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ['PATH'].split(os.pathsep):
path = path.strip("'")
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
parser = argparse.ArgumentParser(description='Build chipmachine')
parser.add_argument('actions', choices=['build', 'clean', 'run', 'config'], default='build',
nargs='*', help='Actions to perform')
parser.add_argument('--buildsystem', choices=['ninja', 'make', 'xcode'], default='ninja',
help='Build system to use')
parser.add_argument('--config', choices=['release', 'debug', 'usan', 'asan', 'tsan', 'msan'], default='release',
help='Release or Debug config')
parser.add_argument('--output', default='builds',
help='Output directory')
parser.add_argument('--target', choices=['native', 'raspberry', 'windows', 'android'], default='native',
help='(Cross) compilation target')
args = parser.parse_args()
configs = { 'release' : [ 'release', ['-DCMAKE_BUILD_TYPE=Release'] ],
'debug' : [ 'debug', ['-DCMAKE_BUILD_TYPE=Debug'] ],
'usan' : [ 'usan', ['-DCMAKE_BUILD_TYPE=Debug', '-DSAN=undefined'] ],
'asan' : [ 'asan', ['-DCMAKE_BUILD_TYPE=Debug', '-DSAN=address'] ],
'msan' : [ 'msan', ['-DCMAKE_BUILD_TYPE=Debug', '-DSAN=memory'] ],
'tsan' : [ 'tsan', ['-DCMAKE_BUILD_TYPE=Debug', '-DSAN=thread'] ]
}
buildsystems = { 'make' : ['-GUnix Makefiles'],
'ninja' : [ '-GNinja', ]
}
buildTool = args.buildsystem;
buildArgs = []
buildArgs += configs[args.config][1]
buildArgs.append(buildsystems[args.buildsystem][0])
#buildArgs.append('-DCMAKE_TOOLCHAIN_FILE=clang.cmake')
outputDir = os.path.join(args.output, configs[args.config][0])
try :
os.makedirs(outputDir)
except :
pass
if args.actions == 'build' :
args.actions = [ 'build' ]
for a in args.actions :
a = a.strip()
if a == 'build' :
if not os.path.isfile(os.path.join(outputDir, 'build.ninja')) :
subprocess.call(['cmake', '-B' + outputDir, '-H.'] + buildArgs)
args = [buildTool, '-C', outputDir]
if buildTool == 'make' :
args.append('-j8')
subprocess.call(args)
elif a == 'config' :
subprocess.call(['cmake', '-B' + outputDir, '-H.'] + buildArgs)
elif a == 'clean' :
subprocess.call([buildTool, '-C', outputDir, 'clean'])
elif a == 'run' :
exe = os.path.join(outputDir, 'chipmachine')
os.system(exe + ' -d')