blob: 28050fddb819dd12fca9c417f4e0ca5cef1adc3a [file] [log] [blame]
Anna Zaksf0c41162011-10-06 23:26:27 +00001#!/usr/bin/env python
2
3"""
Ted Kremenek3a0678e2015-09-08 03:50:52 +00004Static Analyzer qualification infrastructure: adding a new project to
Anna Zaksf0c41162011-10-06 23:26:27 +00005the 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.
Ted Kremenek3a0678e2015-09-08 03:50:52 +00009 The project directory should be added inside the Repository Directory and
Anna Zaksf0c41162011-10-06 23:26:27 +000010 have the same name as the project ID
Ted Kremenek3a0678e2015-09-08 03:50:52 +000011
Anna Zaksf0c41162011-10-06 23:26:27 +000012 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.
Ted Kremenek3a0678e2015-09-08 03:50:52 +000017 Choose from: configure, make, xcodebuild
Anna Zaksf0c41162011-10-06 23:26:27 +000018"""
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
Ted Kremenek3a0678e2015-09-08 03:50:52 +000030 return False
Anna Zaksa1b56e22011-11-08 22:41:22 +000031
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)
Ted Kremenek3a0678e2015-09-08 03:50:52 +000042
Anna Zaksf0c41162011-10-06 23:26:27 +000043 # 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:
Ted Kremenek3a0678e2015-09-08 03:50:52 +000054 if (isExistingProject(PMapFile, ID)) :
Anna Zaksa1b56e22011-11-08 22:41:22 +000055 print >> sys.stdout, 'Warning: Project with ID \'', ID, \
56 '\' already exists.'
57 print >> sys.stdout, "Reference output has been regenerated."
Ted Kremenek3a0678e2015-09-08 03:50:52 +000058 else:
Anna Zaksa1b56e22011-11-08 22:41:22 +000059 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
Ted Kremenek3a0678e2015-09-08 03:50:52 +000065
66# TODO: Add an option not to build.
Anna Zaksf0c41162011-10-06 23:26:27 +000067# 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)
Ted Kremenek3a0678e2015-09-08 03:50:52 +000076
77 BuildMode = 1
Anna Zaks4720a732011-11-05 05:20:48 +000078 if (len(sys.argv) >= 3):
Ted Kremenek3a0678e2015-09-08 03:50:52 +000079 BuildMode = int(sys.argv[2])
Anna Zaksa2f970b2012-09-06 23:30:27 +000080 assert((BuildMode == 0) | (BuildMode == 1) | (BuildMode == 2))
Ted Kremenek3a0678e2015-09-08 03:50:52 +000081
Anna Zaksa2f970b2012-09-06 23:30:27 +000082 addNewProject(sys.argv[1], BuildMode)