source: mainline/tools/checkers/vcc.py@ 86018c1

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

add more Vcc compatibility preprocessing (by Ondrej Sery)

  • Property mode set to 100755
File size: 4.1 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
38
39jobs = [
40 "kernel/kernel.job",
41 "uspace/srv/clip/clip.job"
42]
43
44def usage(prname):
45 "Print usage syntax"
46 print prname + " <ROOT>"
47
48def cygpath(upath):
49 "Convert Unix (Cygwin) path to Windows path"
50
51 return subprocess.Popen(['cygpath', '--windows', '--absolute', upath], stdout = subprocess.PIPE).communicate()[0].strip()
52
53def preprocess(srcfname, tmpfname, base, options):
54 "Preprocess source using GCC preprocessor and compatibility tweaks"
55
56 args = ['gcc', '-E']
57 args.extend(options.split())
58 args.append(srcfname)
59
60 # Change working directory
61
62 cwd = os.getcwd()
63 os.chdir(base)
64
65 preproc = subprocess.Popen(args, stdout = subprocess.PIPE).communicate()[0]
66
67 tmpf = file(tmpfname, "w")
68
69 for line in preproc.splitlines():
70 # Ignore preprocessor directives
71 if (line.startswith('#')):
72 continue
73
74 tmpf.write("%s\n" % line)
75
76 tmpf.close()
77
78 os.chdir(cwd)
79
80 return True
81
82def vcc(root, job):
83 "Run Vcc on a jobfile"
84
85 # Parse jobfile
86
87 inname = os.path.join(root, job)
88
89 if (not os.path.isfile(inname)):
90 print "Unable to open %s" % inname
91 print "Did you run \"make precheck\" on the source tree?"
92 return False
93
94 inf = file(inname, "r")
95 records = inf.read().splitlines()
96 inf.close()
97
98 for record in records:
99 arg = jobfile.parse_arg(record)
100 if (not arg):
101 return False
102
103 if (len(arg) < 6):
104 print "Not enought jobfile record arguments"
105 return False
106
107 srcfname = arg[0]
108 tgtfname = arg[1]
109 base = arg[4]
110 options = arg[5]
111
112 srcfqname = os.path.join(base, srcfname)
113 if (not os.path.isfile(srcfqname)):
114 print "Source %s not found" % srcfqname
115 return False
116
117 tmpfname = "%s.preproc" % srcfname
118 tmpfqname = os.path.join(base, tmpfname)
119
120 # Only C files are interesting for us
121 if (arg[2] != "cc"):
122 continue
123
124 # Preprocess sources
125
126 if (not preprocess(srcfname, tmpfname, base, options)):
127 return False
128
129 # Run Vcc
130
131 retval = subprocess.Popen(['vcc', cygpath(tmpfqname)]).wait()
132
133 # Cleanup
134
135 if (os.path.isfile(tmpfqname)):
136 os.remove(tmpfqname)
137
138 if (retval != 0):
139 return False
140
141 return True
142
143def main():
144 if (len(sys.argv) < 2):
145 usage(sys.argv[0])
146 return
147
148 rootdir = os.path.abspath(sys.argv[1])
149 config = os.path.join(rootdir, "HelenOS.config")
150
151 if (not os.path.isfile(config)):
152 print "%s not found." % config
153 print "Please specify the path to HelenOS build tree root as the first argument."
154 return
155
156 for job in jobs:
157 if (not vcc(rootdir, job)):
158 print
159 print "Failed job: %s" % job
160 return
161
162 print
163 print "All jobs passed"
164
165if __name__ == '__main__':
166 main()
Note: See TracBrowser for help on using the repository browser.