[clang] 3770f5c - [analyzer] SATest: Add convenience 'docker' command
Valeriy Savchenko via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 25 02:28:46 PDT 2020
Author: Valeriy Savchenko
Date: 2020-06-25T12:28:22+03:00
New Revision: 3770f5c9b98c5bae2f099f5c24e05eb4a0cca1d0
URL: https://github.com/llvm/llvm-project/commit/3770f5c9b98c5bae2f099f5c24e05eb4a0cca1d0
DIFF: https://github.com/llvm/llvm-project/commit/3770f5c9b98c5bae2f099f5c24e05eb4a0cca1d0.diff
LOG: [analyzer] SATest: Add convenience 'docker' command
Summary:
It provides a simpler interface for testing within docker.
This way the user is not required to no how to use `docker run` and
its options.
Differential Revision: https://reviews.llvm.org/D81572
Added:
Modified:
clang/utils/analyzer/SATest.py
Removed:
################################################################################
diff --git a/clang/utils/analyzer/SATest.py b/clang/utils/analyzer/SATest.py
index f45f593d08ec..f7cf5146566d 100755
--- a/clang/utils/analyzer/SATest.py
+++ b/clang/utils/analyzer/SATest.py
@@ -9,6 +9,16 @@
import argparse
import sys
+import os
+
+from subprocess import check_call
+
+SCRIPTS_DIR = os.path.dirname(os.path.realpath(__file__))
+PROJECTS_DIR = os.path.join(SCRIPTS_DIR, "projects")
+DEFAULT_LLVM_DIR = os.path.realpath(os.path.join(SCRIPTS_DIR,
+ os.path.pardir,
+ os.path.pardir,
+ os.path.pardir))
def add(parser, args):
@@ -78,6 +88,37 @@ def update(parser, args):
SATestUpdateDiffs.update_reference_results(project)
+def docker(parser, args):
+ if len(args.rest) > 0:
+ if args.rest[0] != "--":
+ parser.error("REST arguments should start with '--'")
+ args.rest = args.rest[1:]
+
+ if args.build_image:
+ docker_build_image()
+ else:
+ docker_run(args)
+
+
+def docker_build_image():
+ check_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)
+
+
def main():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()
@@ -180,6 +221,27 @@ def main():
# TODO: add option to decide whether we should use git
upd_parser.set_defaults(func=update)
+ # docker subcommand
+ dock_parser = subparsers.add_parser(
+ "docker",
+ help="Run regression system in the docker.")
+
+ dock_parser.add_argument("--build-image", action="store_true",
+ help="Build docker image for running tests.")
+ dock_parser.add_argument("--llvm-project-dir", action="store",
+ default=DEFAULT_LLVM_DIR,
+ help="Path to LLVM source code. Defaults "
+ "to the repo where this script is located. ")
+ dock_parser.add_argument("--build-dir", action="store", default="",
+ help="Path to a directory where docker should "
+ "build LLVM code.")
+ dock_parser.add_argument("--clang-dir", action="store", default="",
+ help="Path to find/install LLVM installation.")
+ dock_parser.add_argument("rest", nargs=argparse.REMAINDER, default=[],
+ help="Additionall args that will be forwarded "
+ "to the docker's entrypoint.")
+ dock_parser.set_defaults(func=docker)
+
args = parser.parse_args()
args.func(parser, args)
More information about the cfe-commits
mailing list