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:
|
|
|
|
- pre_run_static_analyzer.sh - prepare the build environment.
|
|
|
|
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
|
2011-10-07 07:26:27 +08:00
|
|
|
"""
|
|
|
|
import SATestBuild
|
|
|
|
|
|
|
|
import os
|
|
|
|
import csv
|
|
|
|
import sys
|
|
|
|
|
2011-11-09 06:41:22 +08:00
|
|
|
def isExistingProject(PMapFile, projectID) :
|
|
|
|
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
|
|
|
|
2011-10-07 07:26:27 +08:00
|
|
|
# Add a new project for testing: build it and add to the Project Map file.
|
|
|
|
# Params:
|
|
|
|
# Dir is the directory where the sources are.
|
|
|
|
# ID is a short string used to identify a project.
|
2012-09-07 07:30:27 +08:00
|
|
|
def addNewProject(ID, BuildMode) :
|
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.
|
2012-09-07 07:30:27 +08:00
|
|
|
SATestBuild.testProject(ID, BuildMode, IsReferenceBuild=True, Dir=Dir)
|
2011-10-07 07:26:27 +08:00
|
|
|
|
|
|
|
# Add the project ID to the project map.
|
|
|
|
ProjectMapPath = os.path.join(CurDir, SATestBuild.ProjectMapFile)
|
|
|
|
if os.path.exists(ProjectMapPath):
|
|
|
|
PMapFile = open(ProjectMapPath, "r+b")
|
|
|
|
else:
|
|
|
|
print "Warning: Creating the Project Map file!!"
|
|
|
|
PMapFile = open(ProjectMapPath, "w+b")
|
|
|
|
try:
|
2015-09-08 11:50:52 +08:00
|
|
|
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)
|
2012-09-07 07:30:27 +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
|
|
|
finally:
|
|
|
|
PMapFile.close()
|
|
|
|
|
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__':
|
|
|
|
if len(sys.argv) < 2:
|
|
|
|
print >> sys.stderr, 'Usage: ', sys.argv[0],\
|
2011-11-05 13:20:48 +08:00
|
|
|
'project_ID <mode>' \
|
2012-09-07 07:30:27 +08:00
|
|
|
'mode - 0 for single file project; ' \
|
|
|
|
'1 for scan_build; ' \
|
|
|
|
'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)
|