123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import errno
- import re
- import os
- import sys
- import subprocess
- allowed_warnings = set([
- "core.c:144",
- "inet_connection_sock.c:430",
- "inet_connection_sock.c:467",
- "inet6_connection_sock.c:89",
- ])
- ofile = None
- warning_re = re.compile(r'''(.*/|)([^/]+\.[a-z]+:\d+):(\d+:)? warning:''')
- def interpret_warning(line):
- """Decode the message from gcc. The messages we care about have a filename, and a warning"""
- line = line.rstrip('\n')
- m = warning_re.match(line)
- if m and m.group(2) not in allowed_warnings:
- print >> sys.stderr, "error, forbidden warning:", m.group(2)
-
- if ofile:
- try:
- os.remove(ofile)
- except OSError:
- pass
- sys.exit(1)
- def run_gcc():
- args = sys.argv[1:]
-
- try:
- i = args.index('-o')
- global ofile
- ofile = args[i+1]
- except (ValueError, IndexError):
- pass
- compiler = sys.argv[0]
- try:
- proc = subprocess.Popen(args, stderr=subprocess.PIPE)
- for line in proc.stderr:
- print >> sys.stderr, line,
- interpret_warning(line)
- result = proc.wait()
- except OSError as e:
- result = e.errno
- if result == errno.ENOENT:
- print >> sys.stderr, args[0] + ':',e.strerror
- print >> sys.stderr, 'Is your PATH set correctly?'
- else:
- print >> sys.stderr, ' '.join(args), str(e)
- return result
- if __name__ == '__main__':
- status = run_gcc()
- sys.exit(status)
|