-
Notifications
You must be signed in to change notification settings - Fork 62
/
setup_container.py
106 lines (88 loc) · 3.84 KB
/
setup_container.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/python
import os
import sys
import shlex
import subprocess
from colorama import Fore
from colorama import Style
LLVM_VERSION = "3.6.2"
LAVA_DIR = os.path.dirname(os.path.abspath(sys.argv[0]))
os.chdir(LAVA_DIR)
PANDA_DIR = os.path.abspath(os.path.join(LAVA_DIR, "panda/src"))
PANDA_BUILD_DIR = os.path.join(PANDA_DIR, '../build')
PANDA_MAK = """
# This is an autogenerated file from lava/setup.py.
PANDA_SRC_PATH := {PANDA_DIR}
PANDA_BUILD_DIR := {PANDA_DIR}/../build
"""
LLVM_MAK = """
# This is an autogenerated file from lava/setup.py.
LLVM_SRC_PATH := {LLVM_SRC_PATH}
LLVM_BUILD_PATH := {LLVM_BUILD_PATH}
LLVM_BIN_PATH := $(LLVM_BUILD_PATH)/install/bin
"""
def progress(msg):
print('')
# PANDA_UBUNTU = "https://goo.gl/GNMNmJ"
print(Fore.GREEN + '[setup.py] ' + Fore.RESET + Style.BRIGHT
+ msg + Style.RESET_ALL)
def error(msg):
print('')
print(Fore.RED + '[setup.py] ' + Fore.RESET + Style.BRIGHT
+ msg + Style.RESET_ALL)
sys.exit(1)
def cmd_to_list(cmd):
cmd_args = shlex.split(cmd) if isinstance(cmd, str) else cmd
cmd = subprocess.list2cmdline(cmd_args)
return cmd, cmd_args
def run(cmd):
cmd, cmd_args = cmd_to_list(cmd)
try:
progress("Running [{}] . . . ".format(cmd))
subprocess.check_call(cmd_args)
except subprocess.CalledProcessError:
error("[{}] cmd did not execute properly.".format(cmd))
raise
if __name__ == '__main__':
# Compile btrace
compile_cmd = ['cd', os.path.join(LAVA_DIR, 'tools', 'btrace'),
'&&', 'bash', 'compile.sh']
run(['bash', '-c', subprocess.list2cmdline(compile_cmd)])
# Compile lavaTool inside the docker container.
progress("Creating $LAVA_DIR/tools/lavaTool/config.mak")
with open("tools/lavaTool/config.mak", "w") as f:
LLVM_DOCKER_DIR = '/llvm-{}'.format(LLVM_VERSION)
f.write(LLVM_MAK.format(LLVM_BUILD_PATH=LLVM_DOCKER_DIR,
LLVM_SRC_PATH=LLVM_DOCKER_DIR))
run(['rm', '-rf', os.path.join(LAVA_DIR, 'tools/build')])
run(['mkdir', '-p', os.path.join(LAVA_DIR, 'tools/build')])
run(['mkdir', '-p', os.path.join(LAVA_DIR, 'tools/install')])
run(['cmake', '-B{}'.format(os.path.join(LAVA_DIR, 'tools/build')),
'-H{}'.format(os.path.join(LAVA_DIR, 'tools')),
'-DCMAKE_INSTALL_PREFIX={}'.format(os.path.join(LAVA_DIR,
'tools/install'))])
run(['make','--no-print-directory','-j4', 'install', '-C',
os.path.join(LAVA_DIR, 'tools/build/lavaTool')])
# -----------Beginning .mak file stuff -------------------
# I think this would be useful, but i'm seperating it out
# in case anyone thinks it's a bad idea
# the idea is that if someone wants llvm and panda installed in certain
# locations, they can make their lava.mak ahead of time
# then setup.py will parse it and configure the environmet to those specs
os.chdir(LAVA_DIR)
if not os.path.isfile(os.path.join(LAVA_DIR, "fbi", "panda.mak")):
progress("Creating $LAVA_DIR/tools/fbi/panda.mak")
with open(os.path.join(LAVA_DIR, "tools/fbi/panda.mak"), "w") as f:
f.write(PANDA_MAK.format(PANDA_DIR=PANDA_DIR))
if not os.path.isfile(os.path.join(LAVA_DIR, "lava.mak")):
progress("Creating $LAVA_DIR/lava.mak")
with open("lava.mak", 'w') as f:
f.write(PANDA_MAK.format(PANDA_DIR=PANDA_DIR))
f.write(LLVM_MAK.format(LLVM_BUILD_PATH=LLVM_DOCKER_DIR,
LLVM_SRC_PATH=LLVM_DOCKER_DIR))
# ----------------End .mak file stuff ---------------------
progress("Making each component of lava, fbi and lavaTool")
progress("Compiling fbi")
os.chdir(os.path.join(LAVA_DIR, "tools/build"))
run("make --no-print-directory -j4 -C fbi install")
os.chdir(LAVA_DIR)