1#!/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 - cleanup_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 - download_project.sh - download the project into the CachedSource/ 19 directory. For example, download a zip of 20 the project source from GitHub, unzip it, 21 and rename the unzipped directory to 22 'CachedSource'. This script is not called 23 when 'CachedSource' is already present, 24 so an alternative is to check the 25 'CachedSource' directory into the 26 repository directly. 27 - CachedSource/ - An optional directory containing the source of the 28 project being analyzed. If present, 29 download_project.sh will not be called. 30 - changes_for_analyzer.patch - An optional patch file for any local 31 changes 32 (e.g., to adapt to newer version of clang) 33 that should be applied to CachedSource 34 before analysis. To construct this patch, 35 run the download script to download 36 the project to CachedSource, copy the 37 CachedSource to another directory (for 38 example, PatchedSource) and make any 39 needed modifications to the copied 40 source. 41 Then run: 42 diff -ur CachedSource PatchedSource \ 43 > changes_for_analyzer.patch 44""" 45import SATestBuild 46from ProjectMap import ProjectMap, ProjectInfo 47 48import os 49import sys 50 51 52def add_new_project(project: ProjectInfo): 53 """ 54 Add a new project for testing: build it and add to the Project Map file. 55 :param name: is a short string used to identify a project. 56 """ 57 58 test_info = SATestBuild.TestInfo(project, 59 is_reference_build=True) 60 tester = SATestBuild.ProjectTester(test_info) 61 62 project_dir = tester.get_project_dir() 63 if not os.path.exists(project_dir): 64 print(f"Error: Project directory is missing: {project_dir}") 65 sys.exit(-1) 66 67 # Build the project. 68 tester.test() 69 70 # Add the project name to the project map. 71 project_map = ProjectMap(should_exist=False) 72 73 if is_existing_project(project_map, project): 74 print(f"Warning: Project with name '{project.name}' already exists.", 75 file=sys.stdout) 76 print("Reference output has been regenerated.", file=sys.stdout) 77 else: 78 project_map.projects.append(project) 79 project_map.save() 80 81 82def is_existing_project(project_map: ProjectMap, project: ProjectInfo) -> bool: 83 return any(existing_project.name == project.name 84 for existing_project in project_map.projects) 85 86 87if __name__ == "__main__": 88 print("SATestAdd.py should not be used on its own.") 89 print("Please use 'SATest.py add' instead") 90 sys.exit(1) 91