source: mainline/tools/checkers/vcc.py@ fdaad75d

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since fdaad75d was 4ca26c9b, checked in by Martin Decky <martin@…>, 15 years ago

improve support for Vcc, add basic source preprocessing (thx to Ondrej Sery)

  • Property mode set to 100755
File size: 5.0 KB
Line 
1#!/usr/bin/env python
2#
3# Copyright (c) 2010 Martin Decky
4# Copyright (c) 2010 Ondrej Sery
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10#
11# - Redistributions of source code must retain the above copyright
12# notice, this list of conditions and the following disclaimer.
13# - Redistributions in binary form must reproduce the above copyright
14# notice, this list of conditions and the following disclaimer in the
15# documentation and/or other materials provided with the distribution.
16# - The name of the author may not be used to endorse or promote products
17# derived from this software without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29#
30"""
31Wrapper for Vcc checker
32"""
33
34import sys
35import os
36import subprocess
37import jobfile
38import re
39
40jobs = [
41 "kernel/kernel.job"
42]
43
44re_attribute = re.compile("__attribute__\s*\(\(.*\)\)")
45re_va_list = re.compile("__builtin_va_list")
46
47def usage(prname):
48 "Print usage syntax"
49 print prname + " <ROOT> [VCC_PATH]"
50
51def cygpath(upath):
52 "Convert Unix (Cygwin) path to Windows path"
53
54 return subprocess.Popen(['cygpath', '--windows', '--absolute', upath], stdout = subprocess.PIPE).communicate()[0].strip()
55
56def preprocess(srcfname, tmpfname, base, options):
57 "Preprocess source using GCC preprocessor and compatibility tweaks"
58
59 args = ['gcc', '-E']
60 args.extend(options.split())
61 args.append(srcfname)
62
63 # Change working directory
64
65 cwd = os.getcwd()
66 os.chdir(base)
67
68 preproc = subprocess.Popen(args, stdout = subprocess.PIPE).communicate()[0]
69
70 tmpf = file(tmpfname, "w")
71
72 for line in preproc.splitlines():
73
74 # Ignore preprocessor directives
75
76 if (line.startswith('#')):
77 continue
78
79 # Remove __attribute__((.*)) GCC extension
80
81 line = re.sub(re_attribute, "", line)
82
83 # Ignore unsupported __builtin_va_list type
84 # (a better solution replacing __builrin_va_list with
85 # an emulated implementation is needed)
86
87 line = re.sub(re_va_list, "void *", line)
88
89 tmpf.write("%s\n" % line)
90
91 tmpf.close()
92
93 os.chdir(cwd)
94
95 return True
96
97def vcc(vcc_path, root, job):
98 "Run Vcc on a jobfile"
99
100 # Parse jobfile
101
102 inname = os.path.join(root, job)
103
104 if (not os.path.isfile(inname)):
105 print "Unable to open %s" % inname
106 print "Did you run \"make precheck\" on the source tree?"
107 return False
108
109 inf = file(inname, "r")
110 records = inf.read().splitlines()
111 inf.close()
112
113 for record in records:
114 arg = jobfile.parse_arg(record)
115 if (not arg):
116 return False
117
118 if (len(arg) < 6):
119 print "Not enought jobfile record arguments"
120 return False
121
122 srcfname = arg[0]
123 tgtfname = arg[1]
124 tool = arg[2]
125 category = arg[3]
126 base = arg[4]
127 options = arg[5]
128
129 srcfqname = os.path.join(base, srcfname)
130 if (not os.path.isfile(srcfqname)):
131 print "Source %s not found" % srcfqname
132 return False
133
134 tmpfname = "%s.preproc" % srcfname
135 tmpfqname = os.path.join(base, tmpfname)
136
137 vccfname = "%s.i" % srcfname
138 vccfqname = os.path.join(base, vccfname);
139
140 # Only C files are interesting for us
141 if (tool != "cc"):
142 continue
143
144 # Preprocess sources
145
146 if (not preprocess(srcfname, tmpfname, base, options)):
147 return False
148
149 # Run Vcc
150 print " -- %s --" % srcfname
151 retval = subprocess.Popen([vcc_path, cygpath(tmpfqname)]).wait()
152
153 if (retval != 0):
154 return False
155
156 # Cleanup, but only if verification was successful
157 # (to be able to examine the preprocessed file)
158
159 if (os.path.isfile(tmpfqname)):
160 os.remove(tmpfqname)
161 os.remove(vccfqname)
162
163 return True
164
165def main():
166 if (len(sys.argv) < 2):
167 usage(sys.argv[0])
168 return
169
170 rootdir = os.path.abspath(sys.argv[1])
171 if (len(sys.argv) > 2):
172 vcc_path = sys.argv[2]
173 else:
174 vcc_path = "/cygdrive/c/Program Files (x86)/Microsoft Research/Vcc/Binaries/vcc"
175
176 if (not os.path.isfile(vcc_path)):
177 print "%s is not a binary." % vcc_path
178 print "Please supply the full Cygwin path to Vcc as the second argument."
179 return
180
181 config = os.path.join(rootdir, "HelenOS.config")
182
183 if (not os.path.isfile(config)):
184 print "%s not found." % config
185 print "Please specify the path to HelenOS build tree root as the first argument."
186 return
187
188 for job in jobs:
189 if (not vcc(vcc_path, rootdir, job)):
190 print
191 print "Failed job: %s" % job
192 return
193
194 print
195 print "All jobs passed"
196
197if __name__ == '__main__':
198 main()
Note: See TracBrowser for help on using the repository browser.