1*e038c9c4Sjoergimport argparse 2*e038c9c4Sjoergimport os 3*e038c9c4Sjoergimport sys 4*e038c9c4Sjoerg 5*e038c9c4Sjoergfrom subprocess import call, check_call, CalledProcessError 6*e038c9c4Sjoergfrom time import sleep 7*e038c9c4Sjoergfrom typing import List, Tuple 8*e038c9c4Sjoerg 9*e038c9c4Sjoerg 10*e038c9c4Sjoergdef main(): 11*e038c9c4Sjoerg settings, rest = parse_arguments() 12*e038c9c4Sjoerg if settings.wait: 13*e038c9c4Sjoerg wait() 14*e038c9c4Sjoerg if settings.build_llvm or settings.build_llvm_only: 15*e038c9c4Sjoerg build_llvm() 16*e038c9c4Sjoerg if settings.build_llvm_only: 17*e038c9c4Sjoerg return 18*e038c9c4Sjoerg sys.exit(test(rest)) 19*e038c9c4Sjoerg 20*e038c9c4Sjoerg 21*e038c9c4Sjoergdef wait(): 22*e038c9c4Sjoerg # It is an easy on CPU way of keeping the docker container running 23*e038c9c4Sjoerg # while the user has a terminal session in that container. 24*e038c9c4Sjoerg while True: 25*e038c9c4Sjoerg sleep(3600) 26*e038c9c4Sjoerg 27*e038c9c4Sjoerg 28*e038c9c4Sjoergdef parse_arguments() -> Tuple[argparse.Namespace, List[str]]: 29*e038c9c4Sjoerg parser = argparse.ArgumentParser() 30*e038c9c4Sjoerg parser.add_argument('--wait', action='store_true') 31*e038c9c4Sjoerg parser.add_argument('--build-llvm', action='store_true') 32*e038c9c4Sjoerg parser.add_argument('--build-llvm-only', action='store_true') 33*e038c9c4Sjoerg return parser.parse_known_args() 34*e038c9c4Sjoerg 35*e038c9c4Sjoerg 36*e038c9c4Sjoergdef build_llvm(): 37*e038c9c4Sjoerg os.chdir('/build') 38*e038c9c4Sjoerg try: 39*e038c9c4Sjoerg if is_cmake_needed(): 40*e038c9c4Sjoerg cmake() 41*e038c9c4Sjoerg ninja() 42*e038c9c4Sjoerg except CalledProcessError: 43*e038c9c4Sjoerg print("Build failed!") 44*e038c9c4Sjoerg sys.exit(1) 45*e038c9c4Sjoerg 46*e038c9c4Sjoerg 47*e038c9c4Sjoergdef is_cmake_needed(): 48*e038c9c4Sjoerg return "build.ninja" not in os.listdir() 49*e038c9c4Sjoerg 50*e038c9c4Sjoerg 51*e038c9c4SjoergCMAKE_COMMAND = "cmake -G Ninja -DCMAKE_BUILD_TYPE=Release " \ 52*e038c9c4Sjoerg "-DCMAKE_INSTALL_PREFIX=/analyzer -DLLVM_TARGETS_TO_BUILD=X86 " \ 53*e038c9c4Sjoerg "-DLLVM_ENABLE_PROJECTS=\"clang;openmp\" -DLLVM_BUILD_RUNTIME=OFF " \ 54*e038c9c4Sjoerg "-DLLVM_ENABLE_TERMINFO=OFF -DCLANG_ENABLE_ARCMT=OFF " \ 55*e038c9c4Sjoerg "-DCLANG_ENABLE_STATIC_ANALYZER=ON" 56*e038c9c4Sjoerg 57*e038c9c4Sjoerg 58*e038c9c4Sjoergdef cmake(): 59*e038c9c4Sjoerg check_call(CMAKE_COMMAND + ' /llvm-project/llvm', shell=True) 60*e038c9c4Sjoerg 61*e038c9c4Sjoerg 62*e038c9c4Sjoergdef ninja(): 63*e038c9c4Sjoerg check_call("ninja install", shell=True) 64*e038c9c4Sjoerg 65*e038c9c4Sjoerg 66*e038c9c4Sjoergdef test(args: List[str]) -> int: 67*e038c9c4Sjoerg os.chdir("/projects") 68*e038c9c4Sjoerg return call("/scripts/SATest.py " + " ".join(args), shell=True) 69*e038c9c4Sjoerg 70*e038c9c4Sjoerg 71*e038c9c4Sjoergif __name__ == '__main__': 72*e038c9c4Sjoerg main() 73