source: mainline/tools/checkers/stanse.py@ 04c3a21f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 04c3a21f was 6064dab, checked in by U-ALPHA\Administrator <Administrator@…>, 15 years ago

move checker tools one directory up
initial (dummy) support for Vcc

  • Property mode set to 100755
File size: 3.6 KB
Line 
1#!/usr/bin/env python
2#
3# Copyright (c) 2010 Martin Decky
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9#
10# - Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# - Redistributions in binary form must reproduce the above copyright
13# notice, this list of conditions and the following disclaimer in the
14# documentation and/or other materials provided with the distribution.
15# - The name of the author may not be used to endorse or promote products
16# derived from this software without specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29"""
30Wrapper for Stanse static checker
31"""
32
33import sys
34import os
35import subprocess
36import jobfile
37
38jobs = [
39 "kernel/kernel.job",
40 "uspace/srv/clip/clip.job"
41]
42
43def usage(prname):
44 "Print usage syntax"
45 print prname + " <ROOT>"
46
47def stanse(root, job):
48 "Run Stanse on a jobfile"
49
50 # Convert generic jobfile to Stanse-specific jobfile format
51
52 inname = os.path.join(root, job)
53 outname = os.path.join(root, "_%s" % os.path.basename(job))
54
55 if (not os.path.isfile(inname)):
56 print "Unable to open %s" % inname
57 print "Did you run \"make precheck\" on the source tree?"
58 return False
59
60 inf = file(inname, "r")
61 records = inf.read().splitlines()
62 inf.close()
63
64 output = []
65 for record in records:
66 arg = jobfile.parse_arg(record)
67 if (not arg):
68 return False
69
70 if (len(arg) < 6):
71 print "Not enought jobfile record arguments"
72 return False
73
74 srcfname = arg[0]
75 tgtfname = arg[1]
76 base = arg[4]
77 options = arg[5]
78
79 srcfqname = os.path.join(base, srcfname)
80 if (not os.path.isfile(srcfqname)):
81 print "Source %s not found" % srcfqname
82 return False
83
84 # Only C files are interesting for us
85 if (arg[2] != "cc"):
86 continue
87
88 output.append([srcfname, tgtfname, base, options])
89
90 outf = file(outname, "w")
91 for record in output:
92 outf.write("{%s},{%s},{%s},{%s}\n" % (record[0], record[1], record[2], record[3]))
93 outf.close()
94
95 # Run Stanse
96
97 retval = subprocess.Popen(['stanse', '--checker', 'ReachabilityChecker', '--jobfile', outname]).wait()
98
99 # Cleanup
100
101 os.remove(outname)
102 for record in output:
103 tmpfile = os.path.join(record[2], "%s.preproc" % record[1])
104 if (os.path.isfile(tmpfile)):
105 os.remove(tmpfile)
106
107 if (retval == 0):
108 return True
109
110 return False
111
112def main():
113 if (len(sys.argv) < 2):
114 usage(sys.argv[0])
115 return
116
117 rootdir = os.path.abspath(sys.argv[1])
118 config = os.path.join(rootdir, "HelenOS.config")
119
120 if (not os.path.isfile(config)):
121 print "%s not found." % config
122 print "Please specify the path to HelenOS build tree root as the first argument."
123 return
124
125 for job in jobs:
126 if (not stanse(rootdir, job)):
127 print
128 print "Failed job: %s" % job
129 return
130
131 print
132 print "All jobs passed"
133
134if __name__ == '__main__':
135 main()
Note: See TracBrowser for help on using the repository browser.