brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.0 KiB · 84e6d44 Raw
94 lines · python
1#!/usr/bin/env python2 3"""4Static Analyzer qualification infrastructure: adding a new project to5the 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 and10   have the same name as the project ID11 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, xcodebuild18      - download_project.sh - download the project into the CachedSource/19                                     directory. For example, download a zip of20                                     the project source from GitHub, unzip it,21                                     and rename the unzipped directory to22                                     'CachedSource'. This script is not called23                                     when 'CachedSource' is already present,24                                     so an alternative is to check the25                                     'CachedSource' directory into the26                                     repository directly.27      - CachedSource/ - An optional directory containing the source of the28                                     project being analyzed. If present,29                                     download_project.sh will not be called.30      - changes_for_analyzer.patch - An optional patch file for any local31                                     changes32                                     (e.g., to adapt to newer version of clang)33                                     that should be applied to CachedSource34                                     before analysis. To construct this patch,35                                     run the download script to download36                                     the project to CachedSource, copy the37                                     CachedSource to another directory (for38                                     example, PatchedSource) and make any39                                     needed modifications to the copied40                                     source.41                                     Then run:42                                          diff -ur CachedSource PatchedSource \43                                              > changes_for_analyzer.patch44"""45import SATestBuild46from ProjectMap import ProjectMap, ProjectInfo47 48import os49import sys50 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, is_reference_build=True)59    tester = SATestBuild.ProjectTester(test_info)60 61    project_dir = tester.get_project_dir()62    if not os.path.exists(project_dir):63        print(f"Error: Project directory is missing: {project_dir}")64        sys.exit(-1)65 66    # Build the project.67    tester.test()68 69    # Add the project name to the project map.70    project_map = ProjectMap(should_exist=False)71 72    if is_existing_project(project_map, project):73        print(74            f"Warning: Project with name '{project.name}' already exists.",75            file=sys.stdout,76        )77        print("Reference output has been regenerated.", file=sys.stdout)78    else:79        project_map.projects.append(project)80        project_map.save()81 82 83def is_existing_project(project_map: ProjectMap, project: ProjectInfo) -> bool:84    return any(85        existing_project.name == project.name86        for existing_project in project_map.projects87    )88 89 90if __name__ == "__main__":91    print("SATestAdd.py should not be used on its own.")92    print("Please use 'SATest.py add' instead")93    sys.exit(1)94