source: mainline/tools/checkers/vcc.py@ 6b80696

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

slightly better code

  • 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 tool = arg[2]
110 category = arg[3]
111 base = arg[4]
112 options = arg[5]
113
114 srcfqname = os.path.join(base, srcfname)
115 if (not os.path.isfile(srcfqname)):
116 print "Source %s not found" % srcfqname
117 return False
118
119 tmpfname = "%s.preproc" % srcfname
120 tmpfqname = os.path.join(base, tmpfname)
121
122 # Only C files are interesting for us
123 if (tool != "cc"):
124 continue
125
126 # Preprocess sources
127
128 if (not preprocess(srcfname, tmpfname, base, options)):
129 return False
130
131 # Run Vcc
132
133 retval = subprocess.Popen(['vcc', cygpath(tmpfqname)]).wait()
134
135 # Cleanup
136
137 if (os.path.isfile(tmpfqname)):
138 os.remove(tmpfqname)
139
140 if (retval != 0):
141 return False
142
143 return True
144
145def main():
146 if (len(sys.argv) < 2):
147 usage(sys.argv[0])
148 return
149
150 rootdir = os.path.abspath(sys.argv[1])
151 config = os.path.join(rootdir, "HelenOS.config")
152
153 if (not os.path.isfile(config)):
154 print "%s not found." % config
155 print "Please specify the path to HelenOS build tree root as the first argument."
156 return
157
158 for job in jobs:
159 if (not vcc(rootdir, job)):
160 print
161 print "Failed job: %s" % job
162 return
163
164 print
165 print "All jobs passed"
166
167if __name__ == '__main__':
168 main()
Note: See TracBrowser for help on using the repository browser.