Anna Zaks | 1b41716 | 2011-10-06 23:26:27 +0000 | [diff] [blame^] | 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 | # Add a new project for testing: build it and add to the Project Map file. |
| 26 | # Params: |
| 27 | # Dir is the directory where the sources are. |
| 28 | # ID is a short string used to identify a project. |
| 29 | def addNewProject(ID) : |
| 30 | CurDir = os.path.abspath(os.curdir) |
| 31 | Dir = SATestBuild.getProjectDir(ID) |
| 32 | if not os.path.exists(Dir): |
| 33 | print "Error: Project directory is missing: %s" % Dir |
| 34 | sys.exit(-1) |
| 35 | |
| 36 | # Build the project. |
| 37 | SATestBuild.testProject(ID, True, Dir) |
| 38 | |
| 39 | # Add the project ID to the project map. |
| 40 | ProjectMapPath = os.path.join(CurDir, SATestBuild.ProjectMapFile) |
| 41 | if os.path.exists(ProjectMapPath): |
| 42 | PMapFile = open(ProjectMapPath, "r+b") |
| 43 | else: |
| 44 | print "Warning: Creating the Project Map file!!" |
| 45 | PMapFile = open(ProjectMapPath, "w+b") |
| 46 | try: |
| 47 | PMapReader = csv.reader(PMapFile) |
| 48 | for I in PMapReader: |
| 49 | IID = I[0] |
| 50 | if ID == IID: |
| 51 | print >> sys.stderr, 'Warning: Project with ID \'', ID, \ |
| 52 | '\' already exists.' |
| 53 | sys.exit(-1) |
| 54 | |
| 55 | PMapWriter = csv.writer(PMapFile) |
| 56 | PMapWriter.writerow( (ID, Dir) ); |
| 57 | finally: |
| 58 | PMapFile.close() |
| 59 | |
| 60 | print "The project map is updated: ", ProjectMapPath |
| 61 | |
| 62 | |
| 63 | # TODO: Add an option not to build. |
| 64 | # TODO: Set the path to the Repository directory. |
| 65 | if __name__ == '__main__': |
| 66 | if len(sys.argv) < 2: |
| 67 | print >> sys.stderr, 'Usage: ', sys.argv[0],\ |
| 68 | '[project ID]' |
| 69 | sys.exit(-1) |
| 70 | |
| 71 | addNewProject(sys.argv[1]) |