source: mainline/tools/checkers/vcc.py@ 4ca26c9b

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4ca26c9b 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
RevLine 
[8786aa5]1#!/usr/bin/env python
2#
3# Copyright (c) 2010 Martin Decky
[ed63298]4# Copyright (c) 2010 Ondrej Sery
[8786aa5]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"""
[6064dab]31Wrapper for Vcc checker
[8786aa5]32"""
33
34import sys
35import os
36import subprocess
[6064dab]37import jobfile
[4ca26c9b]38import re
[8786aa5]39
40jobs = [
[4ca26c9b]41 "kernel/kernel.job"
[8786aa5]42]
43
[4ca26c9b]44re_attribute = re.compile("__attribute__\s*\(\(.*\)\)")
45re_va_list = re.compile("__builtin_va_list")
46
[8786aa5]47def usage(prname):
48 "Print usage syntax"
[4ca26c9b]49 print prname + " <ROOT> [VCC_PATH]"
[8786aa5]50
[679c361]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):
[ed63298]57 "Preprocess source using GCC preprocessor and compatibility tweaks"
[679c361]58
59 args = ['gcc', '-E']
60 args.extend(options.split())
[ed63298]61 args.append(srcfname)
62
63 # Change working directory
[679c361]64
65 cwd = os.getcwd()
66 os.chdir(base)
67
[ed63298]68 preproc = subprocess.Popen(args, stdout = subprocess.PIPE).communicate()[0]
69
70 tmpf = file(tmpfname, "w")
71
72 for line in preproc.splitlines():
[4ca26c9b]73
[ed63298]74 # Ignore preprocessor directives
[4ca26c9b]75
[ed63298]76 if (line.startswith('#')):
[958de16]77 continue
[ed63298]78
[4ca26c9b]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
[ed63298]89 tmpf.write("%s\n" % line)
90
91 tmpf.close()
92
93 os.chdir(cwd)
[679c361]94
95 return True
96
[4ca26c9b]97def vcc(vcc_path, root, job):
[6064dab]98 "Run Vcc on a jobfile"
[8786aa5]99
[6064dab]100 # Parse jobfile
[8786aa5]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:
[6064dab]114 arg = jobfile.parse_arg(record)
[8786aa5]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]
[958de16]124 tool = arg[2]
125 category = arg[3]
[8786aa5]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
[679c361]134 tmpfname = "%s.preproc" % srcfname
135 tmpfqname = os.path.join(base, tmpfname)
136
[4ca26c9b]137 vccfname = "%s.i" % srcfname
138 vccfqname = os.path.join(base, vccfname);
139
[8786aa5]140 # Only C files are interesting for us
[958de16]141 if (tool != "cc"):
[8786aa5]142 continue
143
[679c361]144 # Preprocess sources
145
146 if (not preprocess(srcfname, tmpfname, base, options)):
147 return False
148
149 # Run Vcc
[4ca26c9b]150 print " -- %s --" % srcfname
151 retval = subprocess.Popen([vcc_path, cygpath(tmpfqname)]).wait()
[679c361]152
[4ca26c9b]153 if (retval != 0):
154 return False
[679c361]155
[4ca26c9b]156 # Cleanup, but only if verification was successful
157 # (to be able to examine the preprocessed file)
[6064dab]158
[679c361]159 if (os.path.isfile(tmpfqname)):
160 os.remove(tmpfqname)
[4ca26c9b]161 os.remove(vccfqname)
[8786aa5]162
[679c361]163 return True
[8786aa5]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])
[4ca26c9b]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
[8786aa5]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:
[4ca26c9b]189 if (not vcc(vcc_path, rootdir, job)):
[8786aa5]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.