SATestAdd.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env python
  2. """
  3. Static Analyzer qualification infrastructure: adding a new project to
  4. the Repository Directory.
  5. Add a new project for testing: build it and add to the Project Map file.
  6. Assumes it's being run from the Repository Directory.
  7. The project directory should be added inside the Repository Directory and
  8. have the same name as the project ID
  9. The project should use the following files for set up:
  10. - pre_run_static_analyzer.sh - prepare the build environment.
  11. Ex: make clean can be a part of it.
  12. - run_static_analyzer.cmd - a list of commands to run through scan-build.
  13. Each command should be on a separate line.
  14. Choose from: configure, make, xcodebuild
  15. """
  16. import SATestBuild
  17. import os
  18. import csv
  19. import sys
  20. def isExistingProject(PMapFile, projectID) :
  21. PMapReader = csv.reader(PMapFile)
  22. for I in PMapReader:
  23. if projectID == I[0]:
  24. return True
  25. return False
  26. # Add a new project for testing: build it and add to the Project Map file.
  27. # Params:
  28. # Dir is the directory where the sources are.
  29. # ID is a short string used to identify a project.
  30. def addNewProject(ID, BuildMode) :
  31. CurDir = os.path.abspath(os.curdir)
  32. Dir = SATestBuild.getProjectDir(ID)
  33. if not os.path.exists(Dir):
  34. print "Error: Project directory is missing: %s" % Dir
  35. sys.exit(-1)
  36. # Build the project.
  37. SATestBuild.testProject(ID, BuildMode, IsReferenceBuild=True, Dir=Dir)
  38. # Add the project ID to the project map.
  39. ProjectMapPath = os.path.join(CurDir, SATestBuild.ProjectMapFile)
  40. if os.path.exists(ProjectMapPath):
  41. PMapFile = open(ProjectMapPath, "r+b")
  42. else:
  43. print "Warning: Creating the Project Map file!!"
  44. PMapFile = open(ProjectMapPath, "w+b")
  45. try:
  46. if (isExistingProject(PMapFile, ID)) :
  47. print >> sys.stdout, 'Warning: Project with ID \'', ID, \
  48. '\' already exists.'
  49. print >> sys.stdout, "Reference output has been regenerated."
  50. else:
  51. PMapWriter = csv.writer(PMapFile)
  52. PMapWriter.writerow( (ID, int(BuildMode)) );
  53. print "The project map is updated: ", ProjectMapPath
  54. finally:
  55. PMapFile.close()
  56. # TODO: Add an option not to build.
  57. # TODO: Set the path to the Repository directory.
  58. if __name__ == '__main__':
  59. if len(sys.argv) < 2:
  60. print >> sys.stderr, 'Usage: ', sys.argv[0],\
  61. 'project_ID <mode>' \
  62. 'mode - 0 for single file project; ' \
  63. '1 for scan_build; ' \
  64. '2 for single file c++11 project'
  65. sys.exit(-1)
  66. BuildMode = 1
  67. if (len(sys.argv) >= 3):
  68. BuildMode = int(sys.argv[2])
  69. assert((BuildMode == 0) | (BuildMode == 1) | (BuildMode == 2))
  70. addNewProject(sys.argv[1], BuildMode)