[analyzer] SATest: Add option to specify projects to test
Differential Revision: https://reviews.llvm.org/D81569
diff --git a/clang/utils/analyzer/ProjectMap.py b/clang/utils/analyzer/ProjectMap.py
index 62b7e48..3daa701 100644
--- a/clang/utils/analyzer/ProjectMap.py
+++ b/clang/utils/analyzer/ProjectMap.py
@@ -28,6 +28,20 @@
commit: str = ""
enabled: bool = True
+ def with_fields(self, **kwargs) -> "ProjectInfo":
+ """
+ Create a copy of this project info with customized fields.
+ NamedTuple is immutable and this is a way to create modified copies.
+
+ info.enabled = True
+ info.mode = 1
+
+ can be done as follows:
+
+ modified = info.with_fields(enbled=True, mode=1)
+ """
+ return ProjectInfo(**{**self._asdict(), **kwargs})
+
class ProjectMap:
"""
diff --git a/clang/utils/analyzer/SATest.py b/clang/utils/analyzer/SATest.py
index 4fb7bf7..f45f593 100755
--- a/clang/utils/analyzer/SATest.py
+++ b/clang/utils/analyzer/SATest.py
@@ -28,7 +28,29 @@
def build(parser, args):
SATestBuild.VERBOSE = args.verbose
- tester = SATestBuild.RegressionTester(args.jobs, args.override_compiler,
+
+ project_map = ProjectMap()
+ projects = project_map.projects
+
+ if args.projects:
+ projects_arg = args.projects.split(",")
+ available_projects = [project.name
+ for project in projects]
+
+ # validate that given projects are present in the project map file
+ for manual_project in projects_arg:
+ if manual_project not in available_projects:
+ parser.error("Project '{project}' is not found in "
+ "the project map file. Available projects are "
+ "{all}.".format(project=manual_project,
+ all=available_projects))
+
+ projects = [project.with_fields(enabled=project.name in projects_arg)
+ for project in projects]
+
+ tester = SATestBuild.RegressionTester(args.jobs,
+ projects,
+ args.override_compiler,
args.extra_analyzer_config,
args.regenerate,
args.strictness)
@@ -111,6 +133,8 @@
dest="extra_analyzer_config", type=str,
default="",
help="Arguments passed to to -analyzer-config")
+ build_parser.add_argument("--projects", action="store", default="",
+ help="Comma-separated list of projects to test")
build_parser.add_argument("-v", "--verbose", action="count", default=0)
build_parser.set_defaults(func=build)
diff --git a/clang/utils/analyzer/SATestBuild.py b/clang/utils/analyzer/SATestBuild.py
index d5b0710..d83ff1e 100644
--- a/clang/utils/analyzer/SATestBuild.py
+++ b/clang/utils/analyzer/SATestBuild.py
@@ -44,7 +44,7 @@
"""
import CmpRuns
import SATestUtils
-from ProjectMap import DownloadType, ProjectInfo, ProjectMap
+from ProjectMap import DownloadType, ProjectInfo
import glob
import logging
@@ -225,10 +225,11 @@
"""
A component aggregating all of the project testing.
"""
- def __init__(self, jobs: int, override_compiler: bool,
- extra_analyzer_config: str, regenerate: bool,
- strictness: bool):
+ def __init__(self, jobs: int, projects: List[ProjectInfo],
+ override_compiler: bool, extra_analyzer_config: str,
+ regenerate: bool, strictness: bool):
self.jobs = jobs
+ self.projects = projects
self.override_compiler = override_compiler
self.extra_analyzer_config = extra_analyzer_config
self.regenerate = regenerate
@@ -237,10 +238,8 @@
def test_all(self) -> bool:
projects_to_test: List[TestInfo] = []
- project_map = ProjectMap()
-
# Test the projects.
- for project in project_map.projects:
+ for project in self.projects:
projects_to_test.append(
TestInfo(project,
self.override_compiler,