[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] | 31 | Wrapper for Vcc checker
|
---|
[8786aa5] | 32 | """
|
---|
| 33 |
|
---|
| 34 | import sys
|
---|
| 35 | import os
|
---|
| 36 | import subprocess
|
---|
[6064dab] | 37 | import jobfile
|
---|
[8786aa5] | 38 |
|
---|
| 39 | jobs = [
|
---|
| 40 | "kernel/kernel.job",
|
---|
| 41 | "uspace/srv/clip/clip.job"
|
---|
| 42 | ]
|
---|
| 43 |
|
---|
| 44 | def usage(prname):
|
---|
| 45 | "Print usage syntax"
|
---|
| 46 | print prname + " <ROOT>"
|
---|
| 47 |
|
---|
[679c361] | 48 | def 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 |
|
---|
| 53 | def preprocess(srcfname, tmpfname, base, options):
|
---|
[ed63298] | 54 | "Preprocess source using GCC preprocessor and compatibility tweaks"
|
---|
[679c361] | 55 |
|
---|
| 56 | args = ['gcc', '-E']
|
---|
| 57 | args.extend(options.split())
|
---|
[ed63298] | 58 | args.append(srcfname)
|
---|
| 59 |
|
---|
| 60 | # Change working directory
|
---|
[679c361] | 61 |
|
---|
| 62 | cwd = os.getcwd()
|
---|
| 63 | os.chdir(base)
|
---|
| 64 |
|
---|
[ed63298] | 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('#')):
|
---|
[958de16] | 72 | continue
|
---|
[ed63298] | 73 |
|
---|
| 74 | tmpf.write("%s\n" % line)
|
---|
| 75 |
|
---|
| 76 | tmpf.close()
|
---|
| 77 |
|
---|
| 78 | os.chdir(cwd)
|
---|
[679c361] | 79 |
|
---|
| 80 | return True
|
---|
| 81 |
|
---|
[6064dab] | 82 | def vcc(root, job):
|
---|
| 83 | "Run Vcc on a jobfile"
|
---|
[8786aa5] | 84 |
|
---|
[6064dab] | 85 | # Parse jobfile
|
---|
[8786aa5] | 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:
|
---|
[6064dab] | 99 | arg = jobfile.parse_arg(record)
|
---|
[8786aa5] | 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]
|
---|
[958de16] | 109 | tool = arg[2]
|
---|
| 110 | category = arg[3]
|
---|
[8786aa5] | 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 |
|
---|
[679c361] | 119 | tmpfname = "%s.preproc" % srcfname
|
---|
| 120 | tmpfqname = os.path.join(base, tmpfname)
|
---|
| 121 |
|
---|
[8786aa5] | 122 | # Only C files are interesting for us
|
---|
[958de16] | 123 | if (tool != "cc"):
|
---|
[8786aa5] | 124 | continue
|
---|
| 125 |
|
---|
[679c361] | 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
|
---|
[6064dab] | 136 |
|
---|
[679c361] | 137 | if (os.path.isfile(tmpfqname)):
|
---|
| 138 | os.remove(tmpfqname)
|
---|
[6064dab] | 139 |
|
---|
| 140 | if (retval != 0):
|
---|
| 141 | return False
|
---|
[8786aa5] | 142 |
|
---|
[679c361] | 143 | return True
|
---|
[8786aa5] | 144 |
|
---|
| 145 | def 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:
|
---|
[6064dab] | 159 | if (not vcc(rootdir, job)):
|
---|
[8786aa5] | 160 | print
|
---|
| 161 | print "Failed job: %s" % job
|
---|
| 162 | return
|
---|
| 163 |
|
---|
| 164 | print
|
---|
| 165 | print "All jobs passed"
|
---|
| 166 |
|
---|
| 167 | if __name__ == '__main__':
|
---|
| 168 | main()
|
---|