-
Notifications
You must be signed in to change notification settings - Fork 40
/
build.py
executable file
·74 lines (62 loc) · 2.42 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
#!/usr/bin/env python
import argparse
import os
all_targets = ['iccad19gr']
run_files = 'scripts/*.py ispd18eval ispd19eval drcu'
def run(command):
if args.print_commands:
print(command)
if os.system(command) is not 0:
if not args.print_commands:
print(command)
quit()
# cmake & copy run files
# for sanitize, need to remove -static from src/CMakeLists.txt
mode_cmake_options = {
None: '',
'debug': '-DCMAKE_BUILD_TYPE=Debug',
'release': '-DCMAKE_BUILD_TYPE=Release',
'profile': '-DCMAKE_CXX_FLAGS=-pg',
'release_profile': '-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=-pg',
'asan': '-DCMAKE_CXX_FLAGS=-fsanitize=address',
'debug_asan': '-DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS=-fsanitize=address',
'tsan': '-DCMAKE_CXX_FLAGS=-fsanitize=thread',
'debug_tsan': '-DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS=-fsanitize=thread'
}
# argparse
parser = argparse.ArgumentParser(description='Build iccad19gr in Linux')
parser.add_argument('-t', '--targets', choices=all_targets, nargs='+')
parser.add_argument('-o', '--mode', choices=mode_cmake_options.keys())
parser.add_argument('-c', '--cmake_options', default='')
parser.add_argument('-m', '--make_options', default='-j 6')
parser.add_argument('-u', '--unittest', action='store_true')
parser.add_argument('-p', '--print_commands', action='store_true')
parser.add_argument('-b', '--build_dir', default='build')
parser.add_argument('-r', '--run_dir', default='run')
args = parser.parse_args()
# targets
if args.unittest:
build_targets = ['unittest_salt']
elif args.targets is None:
build_targets = ['']
else:
build_targets = args.targets
run('cmake src -B{} {} {}'.format(args.build_dir,
mode_cmake_options[args.mode], args.cmake_options))
run('mkdir -p {}'.format(args.run_dir))
run('cp -u -R {} {}'.format(run_files, args.run_dir))
# make
for target in build_targets:
run('cmake --build {} --target {} -- {}'.format(args.build_dir,
target, args.make_options))
cp_targets = all_targets if build_targets == [''] else build_targets
for target in cp_targets:
run('cp -u {}/{} {}'.format(args.build_dir, target, args.run_dir))
# flute LUT
run('cp src/flute/*.dat {}'.format(args.run_dir))
# unit test
if args.unittest:
root_dir = os.path.curdir
os.chdir(args.run_dir)
run('./{}'.format('unittest_salt'))
os.chdir(root_dir)