1 | #!/usr/bin/env python |
2 | |
3 | """ |
4 | Update reference results for static analyzer. |
5 | """ |
6 | from __future__ import absolute_import, division, print_function |
7 | |
8 | import SATestBuild |
9 | |
10 | from subprocess import check_call |
11 | import os |
12 | import sys |
13 | |
14 | Verbose = 0 |
15 | |
16 | |
17 | def runCmd(Command, **kwargs): |
18 | if Verbose: |
19 | print("Executing %s" % Command) |
20 | check_call(Command, shell=True, **kwargs) |
21 | |
22 | |
23 | def updateReferenceResults(ProjName, ProjBuildMode): |
24 | ProjDir = SATestBuild.getProjectDir(ProjName) |
25 | |
26 | RefResultsPath = os.path.join( |
27 | ProjDir, |
28 | SATestBuild.getSBOutputDirName(IsReferenceBuild=True)) |
29 | CreatedResultsPath = os.path.join( |
30 | ProjDir, |
31 | SATestBuild.getSBOutputDirName(IsReferenceBuild=False)) |
32 | |
33 | if not os.path.exists(CreatedResultsPath): |
34 | print("New results not found, was SATestBuild.py "\ |
35 | "previously run?", file=sys.stderr) |
36 | sys.exit(1) |
37 | |
38 | BuildLogPath = SATestBuild.getBuildLogPath(RefResultsPath) |
39 | Dirname = os.path.dirname(os.path.abspath(BuildLogPath)) |
40 | runCmd("mkdir -p '%s'" % Dirname) |
41 | with open(BuildLogPath, "wb+") as PBuildLogFile: |
42 | # Remove reference results: in git, and then again for a good measure |
43 | # with rm, as git might not remove things fully if there are empty |
44 | # directories involved. |
45 | runCmd('git rm -r -q "%s"' % (RefResultsPath,), stdout=PBuildLogFile) |
46 | runCmd('rm -rf "%s"' % (RefResultsPath,), stdout=PBuildLogFile) |
47 | |
48 | # Replace reference results with a freshly computed once. |
49 | runCmd('cp -r "%s" "%s"' % (CreatedResultsPath, RefResultsPath,), |
50 | stdout=PBuildLogFile) |
51 | |
52 | # Run cleanup script. |
53 | SATestBuild.runCleanupScript(ProjDir, PBuildLogFile) |
54 | |
55 | SATestBuild.normalizeReferenceResults( |
56 | ProjDir, RefResultsPath, ProjBuildMode) |
57 | |
58 | # Clean up the generated difference results. |
59 | SATestBuild.cleanupReferenceResults(RefResultsPath) |
60 | |
61 | runCmd('git add "%s"' % (RefResultsPath,), stdout=PBuildLogFile) |
62 | |
63 | |
64 | def main(argv): |
65 | if len(argv) == 2 and argv[1] in ('-h', '--help'): |
66 | print("Update static analyzer reference results based "\ |
67 | "\non the previous run of SATestBuild.py.\n"\ |
68 | "\nN.B.: Assumes that SATestBuild.py was just run", file=sys.stderr) |
69 | sys.exit(1) |
70 | |
71 | with SATestBuild.projectFileHandler() as f: |
72 | for (ProjName, ProjBuildMode) in SATestBuild.iterateOverProjects(f): |
73 | updateReferenceResults(ProjName, int(ProjBuildMode)) |
74 | |
75 | |
76 | if __name__ == '__main__': |
77 | main(sys.argv) |
78 | |