17330f729Sjoerg#!/usr/bin/env python 27330f729Sjoerg 37330f729Sjoerg""" 47330f729SjoergStatic Analyzer qualification infrastructure: adding a new project to 57330f729Sjoergthe Repository Directory. 67330f729Sjoerg 77330f729Sjoerg Add a new project for testing: build it and add to the Project Map file. 87330f729Sjoerg Assumes it's being run from the Repository Directory. 97330f729Sjoerg The project directory should be added inside the Repository Directory and 107330f729Sjoerg have the same name as the project ID 117330f729Sjoerg 127330f729Sjoerg The project should use the following files for set up: 137330f729Sjoerg - cleanup_run_static_analyzer.sh - prepare the build environment. 147330f729Sjoerg Ex: make clean can be a part of it. 157330f729Sjoerg - run_static_analyzer.cmd - a list of commands to run through scan-build. 167330f729Sjoerg Each command should be on a separate line. 177330f729Sjoerg Choose from: configure, make, xcodebuild 187330f729Sjoerg - download_project.sh - download the project into the CachedSource/ 197330f729Sjoerg directory. For example, download a zip of 207330f729Sjoerg the project source from GitHub, unzip it, 217330f729Sjoerg and rename the unzipped directory to 227330f729Sjoerg 'CachedSource'. This script is not called 237330f729Sjoerg when 'CachedSource' is already present, 247330f729Sjoerg so an alternative is to check the 257330f729Sjoerg 'CachedSource' directory into the 267330f729Sjoerg repository directly. 277330f729Sjoerg - CachedSource/ - An optional directory containing the source of the 287330f729Sjoerg project being analyzed. If present, 297330f729Sjoerg download_project.sh will not be called. 307330f729Sjoerg - changes_for_analyzer.patch - An optional patch file for any local 317330f729Sjoerg changes 327330f729Sjoerg (e.g., to adapt to newer version of clang) 337330f729Sjoerg that should be applied to CachedSource 347330f729Sjoerg before analysis. To construct this patch, 357330f729Sjoerg run the download script to download 367330f729Sjoerg the project to CachedSource, copy the 377330f729Sjoerg CachedSource to another directory (for 387330f729Sjoerg example, PatchedSource) and make any 397330f729Sjoerg needed modifications to the copied 407330f729Sjoerg source. 417330f729Sjoerg Then run: 427330f729Sjoerg diff -ur CachedSource PatchedSource \ 437330f729Sjoerg > changes_for_analyzer.patch 447330f729Sjoerg""" 457330f729Sjoergimport SATestBuild 46*e038c9c4Sjoergfrom ProjectMap import ProjectMap, ProjectInfo 477330f729Sjoerg 487330f729Sjoergimport os 497330f729Sjoergimport sys 507330f729Sjoerg 517330f729Sjoerg 52*e038c9c4Sjoergdef add_new_project(project: ProjectInfo): 537330f729Sjoerg """ 547330f729Sjoerg Add a new project for testing: build it and add to the Project Map file. 55*e038c9c4Sjoerg :param name: is a short string used to identify a project. 567330f729Sjoerg """ 577330f729Sjoerg 58*e038c9c4Sjoerg test_info = SATestBuild.TestInfo(project, 59*e038c9c4Sjoerg is_reference_build=True) 60*e038c9c4Sjoerg tester = SATestBuild.ProjectTester(test_info) 61*e038c9c4Sjoerg 62*e038c9c4Sjoerg project_dir = tester.get_project_dir() 63*e038c9c4Sjoerg if not os.path.exists(project_dir): 64*e038c9c4Sjoerg print(f"Error: Project directory is missing: {project_dir}") 657330f729Sjoerg sys.exit(-1) 667330f729Sjoerg 677330f729Sjoerg # Build the project. 68*e038c9c4Sjoerg tester.test() 697330f729Sjoerg 70*e038c9c4Sjoerg # Add the project name to the project map. 71*e038c9c4Sjoerg project_map = ProjectMap(should_exist=False) 727330f729Sjoerg 73*e038c9c4Sjoerg if is_existing_project(project_map, project): 74*e038c9c4Sjoerg print(f"Warning: Project with name '{project.name}' already exists.", 75*e038c9c4Sjoerg file=sys.stdout) 767330f729Sjoerg print("Reference output has been regenerated.", file=sys.stdout) 777330f729Sjoerg else: 78*e038c9c4Sjoerg project_map.projects.append(project) 79*e038c9c4Sjoerg project_map.save() 807330f729Sjoerg 817330f729Sjoerg 82*e038c9c4Sjoergdef is_existing_project(project_map: ProjectMap, project: ProjectInfo) -> bool: 83*e038c9c4Sjoerg return any(existing_project.name == project.name 84*e038c9c4Sjoerg for existing_project in project_map.projects) 857330f729Sjoerg 867330f729Sjoerg 87*e038c9c4Sjoergif __name__ == "__main__": 88*e038c9c4Sjoerg print("SATestAdd.py should not be used on its own.") 89*e038c9c4Sjoerg print("Please use 'SATest.py add' instead") 90*e038c9c4Sjoerg sys.exit(1) 91