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-06-02 23:21:45 +08:00
|
|
|
import argparse
|
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
|
|
|
|
|
|
|
|
2015-09-08 11:50:52 +08:00
|
|
|
# TODO: Add an option not to build.
|
2011-10-07 07:26:27 +08:00
|
|
|
# TODO: Set the path to the Repository directory.
|
2020-05-21 23:28:36 +08:00
|
|
|
if __name__ == "__main__":
|
2020-06-02 23:21:45 +08:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
|
|
|
parser.add_argument("name", nargs=1, help="Name of the new project")
|
|
|
|
parser.add_argument("--mode", action="store", default=1, type=int,
|
|
|
|
choices=[0, 1, 2],
|
|
|
|
help="Build mode: 0 for single file project, "
|
|
|
|
"1 for scan_build, "
|
|
|
|
"2 for single file c++11 project")
|
|
|
|
parser.add_argument("--source", action="store", default="script",
|
|
|
|
choices=["script", "git", "zip"],
|
|
|
|
help=f"Source type of the new project: "
|
|
|
|
f"'git' for getting from git "
|
|
|
|
f"(please provide --origin and --commit), "
|
|
|
|
f"'zip' for unpacking source from a zip file, "
|
|
|
|
f"'script' for downloading source by running "
|
|
|
|
f"a custom script {SATestBuild.DOWNLOAD_SCRIPT}")
|
|
|
|
parser.add_argument("--origin", action="store", default="",
|
|
|
|
help="Origin link for a git repository")
|
|
|
|
parser.add_argument("--commit", action="store", default="",
|
|
|
|
help="Git hash for a commit to checkout")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if args.source == "git" and (args.origin == "" or args.commit == ""):
|
|
|
|
parser.error(
|
|
|
|
"Please provide both --origin and --commit if source is 'git'")
|
|
|
|
|
|
|
|
if args.source != "git" and (args.origin != "" or args.commit != ""):
|
|
|
|
parser.error("Options --origin and --commit don't make sense when "
|
|
|
|
"source is not 'git'")
|
|
|
|
|
|
|
|
project = ProjectInfo(args.name[0], args.mode, args.source, args.origin,
|
|
|
|
args.commit)
|
|
|
|
|
|
|
|
add_new_project(project)
|