annotate clang/utils/analyzer/SATestUpdateDiffs.py @ 225:f7655407a6ba

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