blob: ce64bc82f756fdd4bbd5e8b6904dfaacc8fc18a6 [file] [log] [blame]
Anna Zaks1b417162011-10-06 23:26:27 +00001#!/usr/bin/env python
2
3"""
4Static Analyzer qualification infrastructure: adding a new project to
5the 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"""
19import SATestBuild
20
21import os
22import csv
23import sys
24
Anna Zaks86f14ab2011-11-08 22:41:22 +000025def 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
Anna Zaks1b417162011-10-06 23:26:27 +000032# 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.
Anna Zaks45518b12011-11-05 05:20:48 +000036def addNewProject(ID, IsScanBuild) :
Anna Zaks1b417162011-10-06 23:26:27 +000037 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.
Anna Zaks45518b12011-11-05 05:20:48 +000044 SATestBuild.testProject(ID, True, IsScanBuild, Dir)
Anna Zaks1b417162011-10-06 23:26:27 +000045
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:
Anna Zaks86f14ab2011-11-08 22:41:22 +000054 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
Anna Zaks1b417162011-10-06 23:26:27 +000062 finally:
63 PMapFile.close()
Anna Zaks1b417162011-10-06 23:26:27 +000064
65
66# TODO: Add an option not to build.
67# TODO: Set the path to the Repository directory.
68if __name__ == '__main__':
69 if len(sys.argv) < 2:
70 print >> sys.stderr, 'Usage: ', sys.argv[0],\
Anna Zaks45518b12011-11-05 05:20:48 +000071 'project_ID <mode>' \
72 'mode - 0 for single file project; 1 for scan_build'
Anna Zaks1b417162011-10-06 23:26:27 +000073 sys.exit(-1)
Anna Zaks45518b12011-11-05 05:20:48 +000074
75 IsScanBuild = 1
76 if (len(sys.argv) >= 3):
77 IsScanBuild = int(sys.argv[2])
78 assert((IsScanBuild == 0) | (IsScanBuild == 1))
Anna Zaks1b417162011-10-06 23:26:27 +000079
Anna Zaks45518b12011-11-05 05:20:48 +000080 addNewProject(sys.argv[1], IsScanBuild)