[clang-format] Fix a bug in aligning comments above PPDirective (#72791)
[llvm-project.git] / clang / utils / analyzer / SATestAdd.py
blob84e6d44b4282230cc772bbf0e735c14365704f5f
1 #!/usr/bin/env python
3 """
4 Static Analyzer qualification infrastructure: adding a new project to
5 the Repository Directory.
7 Add a new project for testing: build it and add to the Project Map file.
8 Assumes it's being run from the Repository Directory.
9 The project directory should be added inside the Repository Directory and
10 have the same name as the project ID
12 The project should use the following files for set up:
13 - cleanup_run_static_analyzer.sh - prepare the build environment.
14 Ex: make clean can be a part of it.
15 - run_static_analyzer.cmd - a list of commands to run through scan-build.
16 Each command should be on a separate line.
17 Choose from: configure, make, xcodebuild
18 - download_project.sh - download the project into the CachedSource/
19 directory. For example, download a zip of
20 the project source from GitHub, unzip it,
21 and rename the unzipped directory to
22 'CachedSource'. This script is not called
23 when 'CachedSource' is already present,
24 so an alternative is to check the
25 'CachedSource' directory into the
26 repository directly.
27 - CachedSource/ - An optional directory containing the source of the
28 project being analyzed. If present,
29 download_project.sh will not be called.
30 - changes_for_analyzer.patch - An optional patch file for any local
31 changes
32 (e.g., to adapt to newer version of clang)
33 that should be applied to CachedSource
34 before analysis. To construct this patch,
35 run the download script to download
36 the project to CachedSource, copy the
37 CachedSource to another directory (for
38 example, PatchedSource) and make any
39 needed modifications to the copied
40 source.
41 Then run:
42 diff -ur CachedSource PatchedSource \
43 > changes_for_analyzer.patch
44 """
45 import SATestBuild
46 from ProjectMap import ProjectMap, ProjectInfo
48 import os
49 import sys
52 def add_new_project(project: ProjectInfo):
53 """
54 Add a new project for testing: build it and add to the Project Map file.
55 :param name: is a short string used to identify a project.
56 """
58 test_info = SATestBuild.TestInfo(project, is_reference_build=True)
59 tester = SATestBuild.ProjectTester(test_info)
61 project_dir = tester.get_project_dir()
62 if not os.path.exists(project_dir):
63 print(f"Error: Project directory is missing: {project_dir}")
64 sys.exit(-1)
66 # Build the project.
67 tester.test()
69 # Add the project name to the project map.
70 project_map = ProjectMap(should_exist=False)
72 if is_existing_project(project_map, project):
73 print(
74 f"Warning: Project with name '{project.name}' already exists.",
75 file=sys.stdout,
77 print("Reference output has been regenerated.", file=sys.stdout)
78 else:
79 project_map.projects.append(project)
80 project_map.save()
83 def is_existing_project(project_map: ProjectMap, project: ProjectInfo) -> bool:
84 return any(
85 existing_project.name == project.name
86 for existing_project in project_map.projects
90 if __name__ == "__main__":
91 print("SATestAdd.py should not be used on its own.")
92 print("Please use 'SATest.py add' instead")
93 sys.exit(1)