brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 1c5ffaa Raw
76 lines · python
1#!/usr/bin/env python2 3"""4Update reference results for static analyzer.5"""6import SATestBuild7from ProjectMap import ProjectInfo, ProjectMap8 9import os10import shutil11import sys12 13from subprocess import check_call14 15Verbose = 016 17 18def update_reference_results(project: ProjectInfo, git: bool = False):19    test_info = SATestBuild.TestInfo(project)20    tester = SATestBuild.ProjectTester(test_info)21    project_dir = tester.get_project_dir()22 23    tester.is_reference_build = True24    ref_results_path = tester.get_output_dir()25 26    tester.is_reference_build = False27    created_results_path = tester.get_output_dir()28 29    if not os.path.exists(created_results_path):30        print(31            f"Skipping project '{project.name}', " f"it doesn't have newer results.",32            file=sys.stderr,33        )34        return35 36    build_log_path = SATestBuild.get_build_log_path(ref_results_path)37    build_log_dir = os.path.dirname(os.path.abspath(build_log_path))38 39    os.makedirs(build_log_dir)40 41    with open(build_log_path, "w+") as build_log_file:42 43        def run_cmd(command: str):44            if Verbose:45                print(f"Executing {command}")46            check_call(command, shell=True, stdout=build_log_file)47 48        # Remove reference results: in git, and then again for a good measure49        # with rm, as git might not remove things fully if there are empty50        # directories involved.51        if git:52            run_cmd(f"git rm -r -q '{ref_results_path}'")53        shutil.rmtree(ref_results_path)54 55        # Replace reference results with a freshly computed once.56        shutil.copytree(created_results_path, ref_results_path, symlinks=True)57 58        # Run cleanup script.59        SATestBuild.run_cleanup_script(project_dir, build_log_file)60 61        SATestBuild.normalize_reference_results(62            project_dir, ref_results_path, project.mode63        )64 65        # Clean up the generated difference results.66        SATestBuild.cleanup_reference_results(ref_results_path)67 68        if git:69            run_cmd(f"git add '{ref_results_path}'")70 71 72if __name__ == "__main__":73    print("SATestUpdateDiffs.py should not be used on its own.")74    print("Please use 'SATest.py update' instead")75    sys.exit(1)76