George Karpenkov | aff3338 | 2017-09-22 01:43:12 +0000 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | """ |
| 4 | Update reference results for static analyzer. |
| 5 | """ |
| 6 | |
| 7 | from subprocess import check_call, check_output, CalledProcessError |
| 8 | import csv |
| 9 | import os |
| 10 | import sys |
| 11 | |
| 12 | Verbose = 1 |
| 13 | def runCmd(Command): |
| 14 | if Verbose: |
| 15 | print "Executing %s" % Command |
| 16 | check_call(Command, shell=True) |
| 17 | |
| 18 | def updateReferenceResults(ProjName, ProjBuildMode): |
| 19 | ProjDir = SATestBuild.getProjectDir(ProjName) |
| 20 | |
| 21 | RefResultsPath = os.path.join(ProjDir, |
| 22 | SATestBuild.getSBOutputDirName(IsReferenceBuild=True)) |
| 23 | CreatedResultsPath = os.path.join(ProjDir, |
| 24 | SATestBuild.getSBOutputDirName(IsReferenceBuild=False)) |
| 25 | |
| 26 | if not os.path.exists(CreatedResultsPath): |
| 27 | print >> sys.stderr, "New results not found, was SATestBuild.py "\ |
| 28 | "previously run?" |
| 29 | sys.exit(-1) |
| 30 | |
| 31 | # Remove reference results. |
| 32 | runCmd('git rm -r "%s"' % (RefResultsPath,)) |
| 33 | |
| 34 | # Replace reference results with a freshly computed once. |
| 35 | runCmd('cp -r "%s" "%s"' % (CreatedResultsPath, RefResultsPath,)) |
| 36 | |
| 37 | # Run cleanup script. |
| 38 | with open(SATestBuild.getBuildLogPath(RefResultsPath), "wb+") |
| 39 | as PBuildLogFile: |
| 40 | SATestBuild.runCleanupScript(ProjDir, PBuildLogFile) |
| 41 | |
| 42 | SATestBuild.normalizeReferenceResults(ProjDir, RefResultsPath, ProjBuildMode) |
| 43 | |
| 44 | # Clean up the generated difference results. |
| 45 | SATestBuild.cleanupReferenceResults(RefResultsPath) |
| 46 | |
| 47 | # Remove the created .diffs file before adding. |
| 48 | runCmd('rm -f "%s/*/%s"' % (RefResultsPath, SATestBuild.DiffsSummaryFileName)) |
| 49 | |
| 50 | runCmd('git add "%s"' % (RefResultsPath,)) |
| 51 | |
| 52 | def main(argv): |
| 53 | if len(argv) == 2 and argv[1] in ('-h', '--help'): |
| 54 | print >> sys.stderr, "Update static analyzer reference results based "\ |
| 55 | "\non the previous run of SATestBuild.py.\n" |
| 56 | "\nN.B.: Assumes that SATestBuild.py was just run." |
| 57 | sys.exit(-1) |
| 58 | |
| 59 | with SATestBuild.projectFileHandler() as f: |
| 60 | for (ProjName, ProjBuildMode) in SATestBuild.iterateOverProjects(f): |
| 61 | updateReferenceResults(ProjName, int(ProjBuildMode)) |
| 62 | |
| 63 | if __name__ == '__main__': |
| 64 | main(sys.argv) |