source: mainline/tools/checkers/stanse.py@ 27dd0e6

Last change on this file since 27dd0e6 was 4dd3912, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago

Update python scripts

  • Property mode set to 100755
File size: 2.3 KB
RevLine 
[8786aa5]1#!/usr/bin/env python
2#
[4dd3912]3# SPDX-FileCopyrightText: 2010 Martin Decky
[8786aa5]4#
[4dd3912]5# SPDX-License-Identifier: BSD-3-Clause
[8786aa5]6#
7"""
8Wrapper for Stanse static checker
9"""
10
11import sys
12import os
13import subprocess
[6064dab]14import jobfile
[8786aa5]15
16jobs = [
17 "kernel/kernel.job",
18 "uspace/srv/clip/clip.job"
19]
20
21def usage(prname):
22 "Print usage syntax"
[28f4adb]23 print(prname + " <ROOT>")
[8786aa5]24
25def stanse(root, job):
26 "Run Stanse on a jobfile"
[a35b458]27
[8786aa5]28 # Convert generic jobfile to Stanse-specific jobfile format
[a35b458]29
[8786aa5]30 inname = os.path.join(root, job)
31 outname = os.path.join(root, "_%s" % os.path.basename(job))
[a35b458]32
[8786aa5]33 if (not os.path.isfile(inname)):
[28f4adb]34 print("Unable to open %s" % inname)
35 print("Did you run \"make precheck\" on the source tree?")
[8786aa5]36 return False
[a35b458]37
[28f4adb]38 inf = open(inname, "r")
[8786aa5]39 records = inf.read().splitlines()
40 inf.close()
[a35b458]41
[8786aa5]42 output = []
43 for record in records:
[6064dab]44 arg = jobfile.parse_arg(record)
[8786aa5]45 if (not arg):
46 return False
[a35b458]47
[8786aa5]48 if (len(arg) < 6):
[f4057f5]49 print("Not enough jobfile record arguments")
[8786aa5]50 return False
[a35b458]51
[8786aa5]52 srcfname = arg[0]
53 tgtfname = arg[1]
[958de16]54 tool = arg[2]
55 category = arg[3]
[8786aa5]56 base = arg[4]
57 options = arg[5]
[a35b458]58
[8786aa5]59 srcfqname = os.path.join(base, srcfname)
60 if (not os.path.isfile(srcfqname)):
[28f4adb]61 print("Source %s not found" % srcfqname)
[8786aa5]62 return False
[a35b458]63
[8786aa5]64 # Only C files are interesting for us
[958de16]65 if (tool != "cc"):
[8786aa5]66 continue
[a35b458]67
[8786aa5]68 output.append([srcfname, tgtfname, base, options])
[a35b458]69
[28f4adb]70 outf = open(outname, "w")
[8786aa5]71 for record in output:
72 outf.write("{%s},{%s},{%s},{%s}\n" % (record[0], record[1], record[2], record[3]))
73 outf.close()
[a35b458]74
[8786aa5]75 # Run Stanse
[a35b458]76
[8786aa5]77 retval = subprocess.Popen(['stanse', '--checker', 'ReachabilityChecker', '--jobfile', outname]).wait()
[a35b458]78
[8786aa5]79 # Cleanup
[a35b458]80
[8786aa5]81 os.remove(outname)
82 for record in output:
83 tmpfile = os.path.join(record[2], "%s.preproc" % record[1])
84 if (os.path.isfile(tmpfile)):
85 os.remove(tmpfile)
[a35b458]86
[8786aa5]87 if (retval == 0):
88 return True
[a35b458]89
[8786aa5]90 return False
91
92def main():
93 if (len(sys.argv) < 2):
94 usage(sys.argv[0])
95 return
[a35b458]96
[8786aa5]97 rootdir = os.path.abspath(sys.argv[1])
98 config = os.path.join(rootdir, "HelenOS.config")
[a35b458]99
[8786aa5]100 if (not os.path.isfile(config)):
[28f4adb]101 print("%s not found." % config)
102 print("Please specify the path to HelenOS build tree root as the first argument.")
[8786aa5]103 return
[a35b458]104
[8786aa5]105 for job in jobs:
106 if (not stanse(rootdir, job)):
[6582b36]107 print()
[28f4adb]108 print("Failed job: %s" % job)
[8786aa5]109 return
[a35b458]110
[8786aa5]111 print
[28f4adb]112 print("All jobs passed")
[8786aa5]113
114if __name__ == '__main__':
115 main()
Note: See TracBrowser for help on using the repository browser.