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