entrypoint.py
1.75 KB
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
import argparse
import os
import sys
from subprocess import call, check_call, CalledProcessError
from time import sleep
from typing import List, Tuple
def main():
settings, rest = parse_arguments()
if settings.wait:
wait()
if settings.build_llvm or settings.build_llvm_only:
build_llvm()
if settings.build_llvm_only:
return
sys.exit(test(rest))
def wait():
# It is an easy on CPU way of keeping the docker container running
# while the user has a terminal session in that container.
while True:
sleep(3600)
def parse_arguments() -> Tuple[argparse.Namespace, List[str]]:
parser = argparse.ArgumentParser()
parser.add_argument('--wait', action='store_true')
parser.add_argument('--build-llvm', action='store_true')
parser.add_argument('--build-llvm-only', action='store_true')
return parser.parse_known_args()
def build_llvm():
os.chdir('/build')
try:
if is_cmake_needed():
cmake()
ninja()
except CalledProcessError:
print("Build failed!")
sys.exit(1)
def is_cmake_needed():
return "build.ninja" not in os.listdir()
CMAKE_COMMAND = "cmake -G Ninja -DCMAKE_BUILD_TYPE=Release " \
"-DCMAKE_INSTALL_PREFIX=/analyzer -DLLVM_TARGETS_TO_BUILD=X86 " \
"-DLLVM_ENABLE_PROJECTS=\"clang;openmp\" -DLLVM_BUILD_RUNTIME=OFF " \
"-DLLVM_ENABLE_TERMINFO=OFF -DCLANG_ENABLE_ARCMT=OFF " \
"-DCLANG_ENABLE_STATIC_ANALYZER=ON"
def cmake():
check_call(CMAKE_COMMAND + ' /llvm-project/llvm', shell=True)
def ninja():
check_call("ninja install", shell=True)
def test(args: List[str]) -> int:
os.chdir("/projects")
return call("/scripts/SATest.py " + " ".join(args), shell=True)
if __name__ == '__main__':
main()