blob: ea3ec21d642cd1cf8657cbc9aad397415d7f84b1 [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
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.
Anna Zaks4720a732011-11-05 05:20:48 +000029def addNewProject(ID, IsScanBuild) :
Anna Zaksf0c41162011-10-06 23:26:27 +000030 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.
Anna Zaks4720a732011-11-05 05:20:48 +000037 SATestBuild.testProject(ID, True, IsScanBuild, Dir)
Anna Zaksf0c41162011-10-06 23:26:27 +000038
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)
Anna Zaks4720a732011-11-05 05:20:48 +000056 PMapWriter.writerow( (ID, int(IsScanBuild)) );
Anna Zaksf0c41162011-10-06 23:26:27 +000057 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.
65if __name__ == '__main__':
66 if len(sys.argv) < 2:
67 print >> sys.stderr, 'Usage: ', sys.argv[0],\
Anna Zaks4720a732011-11-05 05:20:48 +000068 'project_ID <mode>' \
69 'mode - 0 for single file project; 1 for scan_build'
Anna Zaksf0c41162011-10-06 23:26:27 +000070 sys.exit(-1)
Anna Zaks4720a732011-11-05 05:20:48 +000071
72 IsScanBuild = 1
73 if (len(sys.argv) >= 3):
74 IsScanBuild = int(sys.argv[2])
75 assert((IsScanBuild == 0) | (IsScanBuild == 1))
Anna Zaksf0c41162011-10-06 23:26:27 +000076
Anna Zaks4720a732011-11-05 05:20:48 +000077 addNewProject(sys.argv[1], IsScanBuild)