1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
import fileinput
import re
import subprocess
import sys
"""
source/organizer/aboutdialog.h should add these lines:
#include <QObject> // for Q_OBJECT, slots
#include <QString> // for QString
class QListWidgetItem;
class QWidget;
source/organizer/aboutdialog.h should remove these lines:
- #include <QListWidgetItem> // lines 25-25
- #include <utility> // lines 28-28
- #include <vector> // lines 27-27
- class DownloadManager; // lines 47-47
The full include-list for source/organizer/aboutdialog.h:
#include <QDialog> // for QDialog
#include <QObject> // for Q_OBJECT, slots
#include <QString> // for QString
#include <map> // for map
class QListWidgetItem;
class QWidget;
namespace Ui { class AboutDialog; } // lines 31-31
---
"""
removing = None
includes = dict
foundline = 0
def process_next_line(line):
""" 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
"""
global removing
global includes
global foundline
line = line.rstrip()
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.
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))
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))
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.
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)
print line
if line.endswith(' should remove these lines:'):
removing = (line.split(' '))[0]
elif line.endswith(' should add these lines:'):
adding = (line.split(' '))[0]
# also process the other lines
# added lines should come after the first entry with a line number.
process = subprocess.Popen(sys.argv[1:],
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)
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
|