blob: 64ff4ff65683f7fcae4e64faf07352abb2d1570a [file] [log] [blame]
Anna Zaksf0c41162011-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 Zaksa1b56e22011-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 Zaksf0c41162011-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 Zaksa2f970b2012-09-06 23:30:27 +000036def addNewProject(ID, BuildMode) :
Anna Zaksf0c41162011-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 Zaksa2f970b2012-09-06 23:30:27 +000044 SATestBuild.testProject(ID, BuildMode, IsReferenceBuild=True, Dir=Dir)
Anna Zaksf0c41162011-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 Zaksa1b56e22011-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)
Anna Zaksa2f970b2012-09-06 23:30:27 +000060 PMapWriter.writerow( (ID, int(BuildMode)) );
Anna Zaksa1b56e22011-11-08 22:41:22 +000061 print "The project map is updated: ", ProjectMapPath
Anna Zaksf0c41162011-10-06 23:26:27 +000062 finally:
63 PMapFile.close()
Anna Zaksf0c41162011-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 Zaks4720a732011-11-05 05:20:48 +000071 'project_ID <mode>' \
Anna Zaksa2f970b2012-09-06 23:30:27 +000072 'mode - 0 for single file project; ' \
73 '1 for scan_build; ' \
74 '2 for single file c++11 project'
Anna Zaksf0c41162011-10-06 23:26:27 +000075 sys.exit(-1)
Anna Zaks4720a732011-11-05 05:20:48 +000076
Anna Zaksa2f970b2012-09-06 23:30:27 +000077 BuildMode = 1
Anna Zaks4720a732011-11-05 05:20:48 +000078 if (len(sys.argv) >= 3):
Anna Zaksa2f970b2012-09-06 23:30:27 +000079 BuildMode = int(sys.argv[2])
80 assert((BuildMode == 0) | (BuildMode == 1) | (BuildMode == 2))
Anna Zaksf0c41162011-10-06 23:26:27 +000081
Anna Zaksa2f970b2012-09-06 23:30:27 +000082 addNewProject(sys.argv[1], BuildMode)