[clang-format] Fix a bug in aligning comments above PPDirective (#72791)
[llvm-project.git] / clang / utils / analyzer / entrypoint.py
blobff877060bad69e909e906a55b59f73d1ae35b88e
1 import argparse
2 import os
3 import sys
5 from subprocess import call, check_call, CalledProcessError
6 from time import sleep
7 from typing import List, Tuple
10 def main():
11 settings, rest = parse_arguments()
12 cmake_opts = ["-D" + cmd for cmd in settings.D]
13 if settings.wait:
14 wait()
15 if settings.build_llvm or settings.build_llvm_only:
16 build_llvm(cmake_opts)
17 if settings.build_llvm_only:
18 return
19 sys.exit(test(rest))
22 def wait():
23 # It is an easy on CPU way of keeping the docker container running
24 # while the user has a terminal session in that container.
25 while True:
26 sleep(3600)
29 def parse_arguments() -> Tuple[argparse.Namespace, List[str]]:
30 parser = argparse.ArgumentParser()
31 parser.add_argument("--wait", action="store_true")
32 parser.add_argument("--build-llvm", action="store_true")
33 parser.add_argument("--build-llvm-only", action="store_true")
34 parser.add_argument("-D", action="append", default=[])
35 return parser.parse_known_args()
38 def build_llvm(cmake_options):
39 os.chdir("/build")
40 try:
41 if is_cmake_needed():
42 cmake(cmake_options)
43 ninja()
44 except CalledProcessError:
45 print("Build failed!")
46 sys.exit(1)
49 def is_cmake_needed():
50 return "build.ninja" not in os.listdir()
53 CMAKE_COMMAND = (
54 "cmake -G Ninja -DCMAKE_BUILD_TYPE=Release "
55 "-DCMAKE_INSTALL_PREFIX=/analyzer -DLLVM_TARGETS_TO_BUILD=X86 "
56 '-DLLVM_ENABLE_PROJECTS="clang;openmp" -DLLVM_BUILD_RUNTIME=OFF '
57 "-DLLVM_ENABLE_TERMINFO=OFF -DCLANG_ENABLE_ARCMT=OFF "
58 "-DCLANG_ENABLE_STATIC_ANALYZER=ON"
62 def cmake(cmake_options):
63 check_call(
64 CMAKE_COMMAND + " ".join(cmake_options) + " /llvm-project/llvm", shell=True
68 def ninja():
69 check_call("ninja install", shell=True)
72 def test(args: List[str]) -> int:
73 os.chdir("/projects")
74 return call("/scripts/SATest.py " + " ".join(args), shell=True)
77 if __name__ == "__main__":
78 main()