source: mainline/tools/checkers/stanse.py@ 77578e8

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