1 #!/usr/bin/env python 2 3 """ 4 Static Analyzer qualification infrastructure: adding a new project to 5 the Repository Directory. 6 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 11 12 The project should use the following files for set up: 13 - pre_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 """ 19 import SATestBuild 20 21 import os 22 import csv 23 import sys 24 25 def isExistingProject(PMapFile, projectID) : 26 PMapReader = csv.reader(PMapFile) 27 for I in PMapReader: 28 if projectID == I[0]: 29 return True 30 return False 31 32 # Add a new project for testing: build it and add to the Project Map file. 33 # Params: 34 # Dir is the directory where the sources are. 35 # ID is a short string used to identify a project. 36 def addNewProject(ID, IsScanBuild) : 37 CurDir = os.path.abspath(os.curdir) 38 Dir = SATestBuild.getProjectDir(ID) 39 if not os.path.exists(Dir): 40 print "Error: Project directory is missing: %s" % Dir 41 sys.exit(-1) 42 43 # Build the project. 44 SATestBuild.testProject(ID, True, IsScanBuild, Dir) 45 46 # Add the project ID to the project map. 47 ProjectMapPath = os.path.join(CurDir, SATestBuild.ProjectMapFile) 48 if os.path.exists(ProjectMapPath): 49 PMapFile = open(ProjectMapPath, "r+b") 50 else: 51 print "Warning: Creating the Project Map file!!" 52 PMapFile = open(ProjectMapPath, "w+b") 53 try: 54 if (isExistingProject(PMapFile, ID)) : 55 print >> sys.stdout, 'Warning: Project with ID \'', ID, \ 56 '\' already exists.' 57 print >> sys.stdout, "Reference output has been regenerated." 58 else: 59 PMapWriter = csv.writer(PMapFile) 60 PMapWriter.writerow( (ID, int(IsScanBuild)) ); 61 print "The project map is updated: ", ProjectMapPath 62 finally: 63 PMapFile.close() 64 65 66 # TODO: Add an option not to build. 67 # TODO: Set the path to the Repository directory. 68 if __name__ == '__main__': 69 if len(sys.argv) < 2: 70 print >> sys.stderr, 'Usage: ', sys.argv[0],\ 71 'project_ID <mode>' \ 72 'mode - 0 for single file project; 1 for scan_build' 73 sys.exit(-1) 74 75 IsScanBuild = 1 76 if (len(sys.argv) >= 3): 77 IsScanBuild = int(sys.argv[2]) 78 assert((IsScanBuild == 0) | (IsScanBuild == 1)) 79 80 addNewProject(sys.argv[1], IsScanBuild) 81