source: mainline/tools/checkers/vcc.py@ 9c40b834

Last change on this file since 9c40b834 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100755
File size: 5.3 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
[33c4f72]47specification = ""
48
[8786aa5]49def usage(prname):
50 "Print usage syntax"
[28f4adb]51 print(prname + " <ROOT> [VCC_PATH]")
[8786aa5]52
[679c361]53def cygpath(upath):
54 "Convert Unix (Cygwin) path to Windows path"
[a35b458]55
[679c361]56 return subprocess.Popen(['cygpath', '--windows', '--absolute', upath], stdout = subprocess.PIPE).communicate()[0].strip()
57
58def preprocess(srcfname, tmpfname, base, options):
[ed63298]59 "Preprocess source using GCC preprocessor and compatibility tweaks"
[a35b458]60
[33c4f72]61 global specification
[a35b458]62
[679c361]63 args = ['gcc', '-E']
64 args.extend(options.split())
[09a0bd4a]65 args.extend(['-DCONFIG_VERIFY_VCC=1', srcfname])
[a35b458]66
[ed63298]67 # Change working directory
[a35b458]68
[679c361]69 cwd = os.getcwd()
70 os.chdir(base)
[a35b458]71
[ed63298]72 preproc = subprocess.Popen(args, stdout = subprocess.PIPE).communicate()[0]
[a35b458]73
[28f4adb]74 tmpf = open(tmpfname, "w")
[33c4f72]75 tmpf.write(specification)
[a35b458]76
[ed63298]77 for line in preproc.splitlines():
[a35b458]78
[ed63298]79 # Ignore preprocessor directives
[a35b458]80
[ed63298]81 if (line.startswith('#')):
[958de16]82 continue
[a35b458]83
[4ca26c9b]84 # Remove __attribute__((.*)) GCC extension
[a35b458]85
[4ca26c9b]86 line = re.sub(re_attribute, "", line)
[a35b458]87
[4ca26c9b]88 # Ignore unsupported __builtin_va_list type
89 # (a better solution replacing __builrin_va_list with
90 # an emulated implementation is needed)
[a35b458]91
[4ca26c9b]92 line = re.sub(re_va_list, "void *", line)
[a35b458]93
[ed63298]94 tmpf.write("%s\n" % line)
[a35b458]95
[ed63298]96 tmpf.close()
[a35b458]97
[ed63298]98 os.chdir(cwd)
[a35b458]99
[679c361]100 return True
101
[4ca26c9b]102def vcc(vcc_path, root, job):
[6064dab]103 "Run Vcc on a jobfile"
[a35b458]104
[6064dab]105 # Parse jobfile
[a35b458]106
[8786aa5]107 inname = os.path.join(root, job)
[a35b458]108
[8786aa5]109 if (not os.path.isfile(inname)):
[28f4adb]110 print("Unable to open %s" % inname)
111 print("Did you run \"make precheck\" on the source tree?")
[8786aa5]112 return False
[a35b458]113
[28f4adb]114 inf = open(inname, "r")
[8786aa5]115 records = inf.read().splitlines()
116 inf.close()
[a35b458]117
[8786aa5]118 for record in records:
[6064dab]119 arg = jobfile.parse_arg(record)
[8786aa5]120 if (not arg):
121 return False
[a35b458]122
[8786aa5]123 if (len(arg) < 6):
[f4057f5]124 print("Not enough jobfile record arguments")
[8786aa5]125 return False
[a35b458]126
[8786aa5]127 srcfname = arg[0]
128 tgtfname = arg[1]
[958de16]129 tool = arg[2]
130 category = arg[3]
[8786aa5]131 base = arg[4]
132 options = arg[5]
[a35b458]133
[8786aa5]134 srcfqname = os.path.join(base, srcfname)
135 if (not os.path.isfile(srcfqname)):
[28f4adb]136 print("Source %s not found" % srcfqname)
[8786aa5]137 return False
[a35b458]138
[679c361]139 tmpfname = "%s.preproc" % srcfname
140 tmpfqname = os.path.join(base, tmpfname)
[a35b458]141
[4ca26c9b]142 vccfname = "%s.i" % srcfname
143 vccfqname = os.path.join(base, vccfname);
[a35b458]144
[8786aa5]145 # Only C files are interesting for us
[958de16]146 if (tool != "cc"):
[8786aa5]147 continue
[a35b458]148
[679c361]149 # Preprocess sources
[a35b458]150
[679c361]151 if (not preprocess(srcfname, tmpfname, base, options)):
152 return False
[a35b458]153
[679c361]154 # Run Vcc
[28f4adb]155 print(" -- %s --" % srcfname)
[33c4f72]156 retval = subprocess.Popen([vcc_path, '/pointersize:32', '/newsyntax', cygpath(tmpfqname)]).wait()
[a35b458]157
[4ca26c9b]158 if (retval != 0):
159 return False
[a35b458]160
[4ca26c9b]161 # Cleanup, but only if verification was successful
162 # (to be able to examine the preprocessed file)
[a35b458]163
[679c361]164 if (os.path.isfile(tmpfqname)):
165 os.remove(tmpfqname)
[4ca26c9b]166 os.remove(vccfqname)
[a35b458]167
[679c361]168 return True
[8786aa5]169
170def main():
[33c4f72]171 global specification
[a35b458]172
[8786aa5]173 if (len(sys.argv) < 2):
174 usage(sys.argv[0])
175 return
[a35b458]176
[8786aa5]177 rootdir = os.path.abspath(sys.argv[1])
[4ca26c9b]178 if (len(sys.argv) > 2):
179 vcc_path = sys.argv[2]
180 else:
181 vcc_path = "/cygdrive/c/Program Files (x86)/Microsoft Research/Vcc/Binaries/vcc"
[a35b458]182
[4ca26c9b]183 if (not os.path.isfile(vcc_path)):
[28f4adb]184 print("%s is not a binary." % vcc_path)
185 print("Please supply the full Cygwin path to Vcc as the second argument.")
[4ca26c9b]186 return
[a35b458]187
[8786aa5]188 config = os.path.join(rootdir, "HelenOS.config")
[a35b458]189
[8786aa5]190 if (not os.path.isfile(config)):
[28f4adb]191 print("%s not found." % config)
192 print("Please specify the path to HelenOS build tree root as the first argument.")
[8786aa5]193 return
[a35b458]194
[33c4f72]195 specpath = os.path.join(rootdir, "tools/checkers/vcc.h")
196 if (not os.path.isfile(specpath)):
[28f4adb]197 print("%s not found." % config)
[33c4f72]198 return
[a35b458]199
[33c4f72]200 specfile = file(specpath, "r")
201 specification = specfile.read()
202 specfile.close()
[a35b458]203
[8786aa5]204 for job in jobs:
[4ca26c9b]205 if (not vcc(vcc_path, rootdir, job)):
[6582b36]206 print()
[28f4adb]207 print("Failed job: %s" % job)
[8786aa5]208 return
[a35b458]209
[6582b36]210 print()
[28f4adb]211 print("All jobs passed")
[8786aa5]212
213if __name__ == '__main__':
214 main()
Note: See TracBrowser for help on using the repository browser.