From a284cbf232f34cc1a83b85ec45baafc1ce6518ec Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Mon, 9 Nov 2015 18:16:58 +0000 Subject: Yet more changes for include what you use, including a moderate hack for compiling stackdata with clang --- massage_messages.py | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'massage_messages.py') diff --git a/massage_messages.py b/massage_messages.py index 708c09cc..249068ba 100644 --- a/massage_messages.py +++ b/massage_messages.py @@ -34,7 +34,9 @@ includes = dict foundline = 0 -def process_next_line(line): +errors = False + +def process_next_line(line, outfile): """ Read a line of output/error from include-what-you use Turn clang errors into a form QT creator recognises Raise warnings for unneeded includes @@ -42,37 +44,48 @@ def process_next_line(line): global removing global includes global foundline + global errors line = line.rstrip() + print >> outfile, line if removing: if line == '': removing = None print return else: - # Really we should stash these so that if we get a 'class xxx' in the - # add lines we can print it here. also we could do the case fixing. + # Really we should stash these so that if we get a 'class xxx' in + # the add lines we can print it here. also we could do the case + # fixing. m = re.match(r'- #include [<"](.*)[">] +// lines (.*)-', line) if m: # If there is an added line with the same class, print it here - print '%s(%s) : warning I0001: Unnecessary include of %s' % (removing, m.group(2), m.group(1)) + print '%s(%s) : warning I0001: Unnecessary include of %s' %\ + (removing, m.group(2), m.group(1)) foundline = m.group(1) else: m = re.match(r'- (.*) +// lines (.*)-', line) if m: - print '%s(%s) : warning I0002: Unnecessary forward ref of %s' % (removing, m.group(2), m.group(1)) + print '%s(%s) : warning I0002: '\ + 'Unnecessary forward ref of %s' %\ + (removing, m.group(2), m.group(1)) foundline = m.group(1) else: print '********* I got confused **********' if line.startswith('In file included from'): - line = re.sub(r'^(In file included from)(.*):(\d+):', r' \2(\3) : \1 here', line) - # Note This doesnt appear to work if you get a string of them, not sure why. + line = re.sub(r'^(In file included from)(.*):(\d+):', + r' \2(\3) : \1 here', + line) + # Note; QT Creator seems to be unwilling to let you double click the + # line to select the code in question if you get a string of these, not + # sure why. elif ': note:' in line: line = ' ' + re.sub(r':(\d+):\d+: note:', r'(\1) : note:', line) else: # Replace clang :line:column: type: with ms (line) : type nnnn: line = re.sub(r':(\d+):\d+: ([^:]*):', r'(\1) : \2 I1234:', line) - + if ' : error I1234:' in line: + errors = True print line if line.endswith(' should remove these lines:'): @@ -84,16 +97,20 @@ def process_next_line(line): # added lines should come after the first entry with a line number. -process = subprocess.Popen(sys.argv[1:], +outfile = open(sys.argv[1], 'w') +process = subprocess.Popen(sys.argv[2:], stdout = subprocess.PIPE, stderr = subprocess.STDOUT) while True: output = process.stdout.readline() if output == '' and process.poll() is not None: break if output: - process_next_line(output) + process_next_line(output, outfile) + rc = process.poll() # The return code you get appears to be more to do with the amount of output -# generated than any real error. We should error if any ': error:' lines are -# detected +# generated than any real error, so instead we should error if any ': error:' +# lines are detected +if errors: + sys.exit(1) -- cgit v1.3.1