2011-10-07 07:26:27 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
2015-09-08 11:50:52 +08:00
|
|
|
Static Analyzer qualification infrastructure: adding a new project to
|
2011-10-07 07:26:27 +08:00
|
|
|
the Repository Directory.
|
|
|
|
|
|
|
|
Add a new project for testing: build it and add to the Project Map file.
|
|
|
|
Assumes it's being run from the Repository Directory.
|
2015-09-08 11:50:52 +08:00
|
|
|
The project directory should be added inside the Repository Directory and
|
2011-10-07 07:26:27 +08:00
|
|
|
have the same name as the project ID
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2011-10-07 07:26:27 +08:00
|
|
|
The project should use the following files for set up:
|
2015-11-08 02:27:35 +08:00
|
|
|
- cleanup_run_static_analyzer.sh - prepare the build environment.
|
2011-10-07 07:26:27 +08:00
|
|
|
Ex: make clean can be a part of it.
|
|
|
|
- run_static_analyzer.cmd - a list of commands to run through scan-build.
|
|
|
|
Each command should be on a separate line.
|
2015-09-08 11:50:52 +08:00
|
|
|
Choose from: configure, make, xcodebuild
|
2015-11-08 02:27:35 +08:00
|
|
|
- download_project.sh - download the project into the CachedSource/
|
|
|
|
directory. For example, download a zip of
|
|
|
|
the project source from GitHub, unzip it,
|
|
|
|
and rename the unzipped directory to
|
|
|
|
'CachedSource'. This script is not called
|
|
|
|
when 'CachedSource' is already present,
|
|
|
|
so an alternative is to check the
|
|
|
|
'CachedSource' directory into the
|
|
|
|
repository directly.
|
|
|
|
- CachedSource/ - An optional directory containing the source of the
|
|
|
|
project being analyzed. If present,
|
|
|
|
download_project.sh will not be called.
|
2017-10-03 01:59:12 +08:00
|
|
|
- changes_for_analyzer.patch - An optional patch file for any local
|
|
|
|
changes
|
2015-11-08 02:27:35 +08:00
|
|
|
(e.g., to adapt to newer version of clang)
|
|
|
|
that should be applied to CachedSource
|
|
|
|
before analysis. To construct this patch,
|
2018-01-22 15:44:38 +08:00
|
|
|
run the download script to download
|
2015-11-08 02:27:35 +08:00
|
|
|
the project to CachedSource, copy the
|
|
|
|
CachedSource to another directory (for
|
2017-10-03 01:59:12 +08:00
|
|
|
example, PatchedSource) and make any
|
2018-01-22 15:44:38 +08:00
|
|
|
needed modifications to the copied
|
2017-10-03 01:59:12 +08:00
|
|
|
source.
|
2015-11-08 02:27:35 +08:00
|
|
|
Then run:
|
|
|
|
diff -ur CachedSource PatchedSource \
|
|
|
|
> changes_for_analyzer.patch
|
2011-10-07 07:26:27 +08:00
|
|
|
"""
|
|
|
|
import SATestBuild
|
2020-06-01 22:15:38 +08:00
|
|
|
from ProjectMap import ProjectMap, ProjectInfo
|
2011-10-07 07:26:27 +08:00
|
|
|
|
2020-05-21 23:28:36 +08:00
|
|
|
import os
|
2011-10-07 07:26:27 +08:00
|
|
|
import sys
|
|
|
|
|
2011-11-09 06:41:22 +08:00
|
|
|
|
2020-06-02 23:21:45 +08:00
|
|
|
def add_new_project(project: ProjectInfo):
|
2017-10-03 01:59:12 +08:00
|
|
|
"""
|
|
|
|
Add a new project for testing: build it and add to the Project Map file.
|
2020-05-21 23:28:36 +08:00
|
|
|
:param name: is a short string used to identify a project.
|
2017-10-03 01:59:12 +08:00
|
|
|
"""
|
|
|
|
|
2020-06-02 23:21:45 +08:00
|
|
|
test_info = SATestBuild.TestInfo(project,
|
2020-06-01 22:15:38 +08:00
|
|
|
is_reference_build=True)
|
|
|
|
tester = SATestBuild.ProjectTester(test_info)
|
2020-05-21 23:28:36 +08:00
|
|
|
|
|
|
|
project_dir = tester.get_project_dir()
|
|
|
|
if not os.path.exists(project_dir):
|
|
|
|
print(f"Error: Project directory is missing: {project_dir}")
|
2011-10-07 07:26:27 +08:00
|
|
|
sys.exit(-1)
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2011-10-07 07:26:27 +08:00
|
|
|
# Build the project.
|
2020-05-21 23:28:36 +08:00
|
|
|
tester.test()
|
2011-10-07 07:26:27 +08:00
|
|
|
|
2020-05-21 23:28:36 +08:00
|
|
|
# Add the project name to the project map.
|
2020-06-01 22:15:38 +08:00
|
|
|
project_map = ProjectMap(should_exist=False)
|
2017-10-03 01:59:12 +08:00
|
|
|
|
2020-06-02 23:21:45 +08:00
|
|
|
if is_existing_project(project_map, project):
|
|
|
|
print(f"Warning: Project with name '{project.name}' already exists.",
|
2020-06-01 22:15:38 +08:00
|
|
|
file=sys.stdout)
|
|
|
|
print("Reference output has been regenerated.", file=sys.stdout)
|
2011-10-07 07:26:27 +08:00
|
|
|
else:
|
2020-06-02 23:21:45 +08:00
|
|
|
project_map.projects.append(project)
|
2020-06-01 22:15:38 +08:00
|
|
|
project_map.save()
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2020-05-21 23:28:36 +08:00
|
|
|
|
2020-06-02 23:21:45 +08:00
|
|
|
def is_existing_project(project_map: ProjectMap, project: ProjectInfo) -> bool:
|
|
|
|
return any(existing_project.name == project.name
|
2020-06-01 22:15:38 +08:00
|
|
|
for existing_project in project_map.projects)
|
2020-05-21 23:28:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-06-03 20:29:42 +08:00
|
|
|
print("SATestAdd.py should not be used on its own.")
|
|
|
|
print("Please use 'SATest.py add' instead")
|
|
|
|
sys.exit(1)
|