[analyzer] SATest: Make docker interfaces transparent
authorValeriy Savchenko <vsavchenko@apple.com>
Fri, 5 Jun 2020 08:47:35 +0000 (11:47 +0300)
committerValeriy Savchenko <vsavchenko@apple.com>
Thu, 25 Jun 2020 09:28:22 +0000 (12:28 +0300)
Summary:
Forward results of every command executed in docker.  The actual commands
and their error codes are more informative than python stacktraces.

Differential Revision: https://reviews.llvm.org/D81593

clang/utils/analyzer/SATest.py
clang/utils/analyzer/entrypoint.py

index f7cf514..100d01a 100755 (executable)
@@ -11,7 +11,7 @@ import argparse
 import sys
 import os
 
-from subprocess import check_call
+from subprocess import call
 
 SCRIPTS_DIR = os.path.dirname(os.path.realpath(__file__))
 PROJECTS_DIR = os.path.join(SCRIPTS_DIR, "projects")
@@ -101,22 +101,25 @@ def docker(parser, args):
 
 
 def docker_build_image():
-    check_call("docker build --tag satest-image {}".format(SCRIPTS_DIR),
-               shell=True)
+    sys.exit(call("docker build --tag satest-image {}".format(SCRIPTS_DIR),
+                  shell=True))
 
 
 def docker_run(args):
-    check_call("docker run --rm --name satest "
-               "-v {llvm}:/llvm-project "
-               "-v {build}:/build "
-               "-v {clang}:/analyzer "
-               "-v {scripts}:/scripts "
-               "-v {projects}:/projects "
-               "satest-image:latest {args}"
-               .format(llvm=args.llvm_project_dir, build=args.build_dir,
-                       clang=args.clang_dir, scripts=SCRIPTS_DIR,
-                       projects=PROJECTS_DIR, args=' '.join(args.rest)),
-               shell=True)
+    sys.exit(call("docker run --rm --name satest "
+                  "-v {llvm}:/llvm-project "
+                  "-v {build}:/build "
+                  "-v {clang}:/analyzer "
+                  "-v {scripts}:/scripts "
+                  "-v {projects}:/projects "
+                  "satest-image:latest {args}"
+                  .format(llvm=args.llvm_project_dir,
+                          build=args.build_dir,
+                          clang=args.clang_dir,
+                          scripts=SCRIPTS_DIR,
+                          projects=PROJECTS_DIR,
+                          args=' '.join(args.rest)),
+                  shell=True))
 
 
 def main():
index 3b85628..8a1f59e 100644 (file)
@@ -1,9 +1,10 @@
 import argparse
 import os
+import sys
 
 from typing import List, Tuple
 
-from subprocess import check_call
+from subprocess import call, check_call, CalledProcessError
 
 
 def main():
@@ -12,7 +13,7 @@ def main():
         build_llvm()
     if settings.build_llvm_only:
         return
-    test(rest)
+    sys.exit(test(rest))
 
 
 def parse_arguments() -> Tuple[argparse.Namespace, List[str]]:
@@ -24,8 +25,12 @@ def parse_arguments() -> Tuple[argparse.Namespace, List[str]]:
 
 def build_llvm() -> None:
     os.chdir('/build')
-    cmake()
-    ninja()
+    try:
+        cmake()
+        ninja()
+    except CalledProcessError:
+        print("Build failed!")
+        sys.exit(1)
 
 
 CMAKE_COMMAND = "cmake -G Ninja -DCMAKE_BUILD_TYPE=Release " \
@@ -43,9 +48,9 @@ def ninja():
     check_call("ninja install", shell=True)
 
 
-def test(args: List[str]):
+def test(args: List[str]) -> int:
     os.chdir("/projects")
-    check_call("/scripts/SATest.py " + " ".join(args), shell=True)
+    return call("/scripts/SATest.py " + " ".join(args), shell=True)
 
 
 if __name__ == '__main__':