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,
|
|
|
|
run the the download script to download
|
|
|
|
the project to CachedSource, copy the
|
|
|
|
CachedSource to another directory (for
|
2017-10-03 01:59:12 +08:00
|
|
|
example, PatchedSource) and make any
|
|
|
|
needed modifications to the the copied
|
|
|
|
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
|
|
|
|
|
|
|
|
import os
|
|
|
|
import csv
|
|
|
|
import sys
|
|
|
|
|
2017-10-03 01:59:12 +08:00
|
|
|
|
|
|
|
def isExistingProject(PMapFile, projectID):
|
2011-11-09 06:41:22 +08:00
|
|
|
PMapReader = csv.reader(PMapFile)
|
|
|
|
for I in PMapReader:
|
|
|
|
if projectID == I[0]:
|
|
|
|
return True
|
2015-09-08 11:50:52 +08:00
|
|
|
return False
|
2011-11-09 06:41:22 +08:00
|
|
|
|
2017-10-03 01:59:12 +08:00
|
|
|
|
|
|
|
def addNewProject(ID, BuildMode):
|
|
|
|
"""
|
|
|
|
Add a new project for testing: build it and add to the Project Map file.
|
|
|
|
:param ID: is a short string used to identify a project.
|
|
|
|
"""
|
|
|
|
|
2011-10-07 07:26:27 +08:00
|
|
|
CurDir = os.path.abspath(os.curdir)
|
|
|
|
Dir = SATestBuild.getProjectDir(ID)
|
|
|
|
if not os.path.exists(Dir):
|
|
|
|
print "Error: Project directory is missing: %s" % Dir
|
|
|
|
sys.exit(-1)
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2011-10-07 07:26:27 +08:00
|
|
|
# Build the project.
|
2017-09-22 09:41:16 +08:00
|
|
|
SATestBuild.testProject(ID, BuildMode, IsReferenceBuild=True)
|
2011-10-07 07:26:27 +08:00
|
|
|
|
|
|
|
# Add the project ID to the project map.
|
|
|
|
ProjectMapPath = os.path.join(CurDir, SATestBuild.ProjectMapFile)
|
2017-10-03 01:59:12 +08:00
|
|
|
|
2011-10-07 07:26:27 +08:00
|
|
|
if os.path.exists(ProjectMapPath):
|
2017-10-03 01:59:12 +08:00
|
|
|
FileMode = "r+b"
|
2011-10-07 07:26:27 +08:00
|
|
|
else:
|
|
|
|
print "Warning: Creating the Project Map file!!"
|
2017-10-03 01:59:12 +08:00
|
|
|
FileMode = "w+b"
|
|
|
|
|
|
|
|
with open(ProjectMapPath, FileMode) as PMapFile:
|
|
|
|
if (isExistingProject(PMapFile, ID)):
|
2011-11-09 06:41:22 +08:00
|
|
|
print >> sys.stdout, 'Warning: Project with ID \'', ID, \
|
|
|
|
'\' already exists.'
|
|
|
|
print >> sys.stdout, "Reference output has been regenerated."
|
2015-09-08 11:50:52 +08:00
|
|
|
else:
|
2011-11-09 06:41:22 +08:00
|
|
|
PMapWriter = csv.writer(PMapFile)
|
2017-10-03 01:59:12 +08:00
|
|
|
PMapWriter.writerow((ID, int(BuildMode)))
|
2011-11-09 06:41:22 +08:00
|
|
|
print "The project map is updated: ", ProjectMapPath
|
2011-10-07 07:26:27 +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.
|
|
|
|
if __name__ == '__main__':
|
2017-09-22 05:47:33 +08:00
|
|
|
if len(sys.argv) < 2 or sys.argv[1] in ('-h', '--help'):
|
2017-10-03 01:59:12 +08:00
|
|
|
print >> sys.stderr, 'Add a new project for testing to the analyzer'\
|
2017-09-22 05:47:33 +08:00
|
|
|
'\nUsage: ', sys.argv[0],\
|
|
|
|
'project_ID <mode>\n' \
|
|
|
|
'mode: 0 for single file project, ' \
|
|
|
|
'1 for scan_build, ' \
|
2012-09-07 07:30:27 +08:00
|
|
|
'2 for single file c++11 project'
|
2011-10-07 07:26:27 +08:00
|
|
|
sys.exit(-1)
|
2015-09-08 11:50:52 +08:00
|
|
|
|
|
|
|
BuildMode = 1
|
2011-11-05 13:20:48 +08:00
|
|
|
if (len(sys.argv) >= 3):
|
2015-09-08 11:50:52 +08:00
|
|
|
BuildMode = int(sys.argv[2])
|
2012-09-07 07:30:27 +08:00
|
|
|
assert((BuildMode == 0) | (BuildMode == 1) | (BuildMode == 2))
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2012-09-07 07:30:27 +08:00
|
|
|
addNewProject(sys.argv[1], BuildMode)
|