source: mainline/tools/checkers/stanse.py@ f1380b7

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since f1380b7 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: 3.6 KB
RevLine 
[8786aa5]1#!/usr/bin/env python
2#
3# Copyright (c) 2010 Martin Decky
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9#
10# - Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# - Redistributions in binary form must reproduce the above copyright
13# notice, this list of conditions and the following disclaimer in the
14# documentation and/or other materials provided with the distribution.
15# - The name of the author may not be used to endorse or promote products
16# derived from this software without specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29"""
30Wrapper for Stanse static checker
31"""
32
33import sys
34import os
35import subprocess
[6064dab]36import jobfile
[8786aa5]37
38jobs = [
39 "kernel/kernel.job",
40 "uspace/srv/clip/clip.job"
41]
42
43def usage(prname):
44 "Print usage syntax"
[28f4adb]45 print(prname + " <ROOT>")
[8786aa5]46
47def stanse(root, job):
48 "Run Stanse on a jobfile"
[a35b458]49
[8786aa5]50 # Convert generic jobfile to Stanse-specific jobfile format
[a35b458]51
[8786aa5]52 inname = os.path.join(root, job)
53 outname = os.path.join(root, "_%s" % os.path.basename(job))
[a35b458]54
[8786aa5]55 if (not os.path.isfile(inname)):
[28f4adb]56 print("Unable to open %s" % inname)
57 print("Did you run \"make precheck\" on the source tree?")
[8786aa5]58 return False
[a35b458]59
[28f4adb]60 inf = open(inname, "r")
[8786aa5]61 records = inf.read().splitlines()
62 inf.close()
[a35b458]63
[8786aa5]64 output = []
65 for record in records:
[6064dab]66 arg = jobfile.parse_arg(record)
[8786aa5]67 if (not arg):
68 return False
[a35b458]69
[8786aa5]70 if (len(arg) < 6):
[f4057f5]71 print("Not enough jobfile record arguments")
[8786aa5]72 return False
[a35b458]73
[8786aa5]74 srcfname = arg[0]
75 tgtfname = arg[1]
[958de16]76 tool = arg[2]
77 category = arg[3]
[8786aa5]78 base = arg[4]
79 options = arg[5]
[a35b458]80
[8786aa5]81 srcfqname = os.path.join(base, srcfname)
82 if (not os.path.isfile(srcfqname)):
[28f4adb]83 print("Source %s not found" % srcfqname)
[8786aa5]84 return False
[a35b458]85
[8786aa5]86 # Only C files are interesting for us
[958de16]87 if (tool != "cc"):
[8786aa5]88 continue
[a35b458]89
[8786aa5]90 output.append([srcfname, tgtfname, base, options])
[a35b458]91
[28f4adb]92 outf = open(outname, "w")
[8786aa5]93 for record in output:
94 outf.write("{%s},{%s},{%s},{%s}\n" % (record[0], record[1], record[2], record[3]))
95 outf.close()
[a35b458]96
[8786aa5]97 # Run Stanse
[a35b458]98
[8786aa5]99 retval = subprocess.Popen(['stanse', '--checker', 'ReachabilityChecker', '--jobfile', outname]).wait()
[a35b458]100
[8786aa5]101 # Cleanup
[a35b458]102
[8786aa5]103 os.remove(outname)
104 for record in output:
105 tmpfile = os.path.join(record[2], "%s.preproc" % record[1])
106 if (os.path.isfile(tmpfile)):
107 os.remove(tmpfile)
[a35b458]108
[8786aa5]109 if (retval == 0):
110 return True
[a35b458]111
[8786aa5]112 return False
113
114def main():
115 if (len(sys.argv) < 2):
116 usage(sys.argv[0])
117 return
[a35b458]118
[8786aa5]119 rootdir = os.path.abspath(sys.argv[1])
120 config = os.path.join(rootdir, "HelenOS.config")
[a35b458]121
[8786aa5]122 if (not os.path.isfile(config)):
[28f4adb]123 print("%s not found." % config)
124 print("Please specify the path to HelenOS build tree root as the first argument.")
[8786aa5]125 return
[a35b458]126
[8786aa5]127 for job in jobs:
128 if (not stanse(rootdir, job)):
[6582b36]129 print()
[28f4adb]130 print("Failed job: %s" % job)
[8786aa5]131 return
[a35b458]132
[8786aa5]133 print
[28f4adb]134 print("All jobs passed")
[8786aa5]135
136if __name__ == '__main__':
137 main()
Note: See TracBrowser for help on using the repository browser.