3
|
1 |
#
|
|
2 |
# Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
# Filter class for doing --what and --check operations
|
|
16 |
#
|
|
17 |
|
|
18 |
import os
|
|
19 |
import sys
|
|
20 |
import re
|
|
21 |
import filter_interface
|
|
22 |
|
|
23 |
class FilterWhat(filter_interface.Filter):
|
|
24 |
|
|
25 |
|
|
26 |
def print_file(self, line, start, end):
|
|
27 |
"Ensure DOS slashes on Windows"
|
|
28 |
|
|
29 |
"""Use chars between enclosing tags ("<>", "''", etc)
|
|
30 |
start = opening tag, so the line we need
|
|
31 |
actually starts at 'start + 1' """
|
|
32 |
if "win" in self.buildparameters.platform:
|
|
33 |
filename = line[(start + 1):end].replace("/","\\")
|
|
34 |
else:
|
|
35 |
filename = line[(start + 1):end]
|
|
36 |
|
|
37 |
if self.check:
|
|
38 |
if not os.path.isfile(filename):
|
|
39 |
print "MISSING:", filename
|
|
40 |
self.ok = False
|
|
41 |
else:
|
|
42 |
self.outfile.write(filename+"\n")
|
|
43 |
|
9
|
44 |
self.prints += 1
|
|
45 |
|
3
|
46 |
|
|
47 |
def open(self, build_parameters):
|
|
48 |
"initialise"
|
|
49 |
|
|
50 |
self.buildparameters = build_parameters
|
|
51 |
self.check = build_parameters.doCheck
|
|
52 |
self.what = build_parameters.doWhat
|
|
53 |
|
|
54 |
self.outfile = sys.stdout
|
|
55 |
self.outfile_close = False
|
|
56 |
|
|
57 |
if "FILTERWHAT_FILE" in os.environ:
|
|
58 |
try:
|
|
59 |
self.outfile = open(os.environ['FILTERWHAT_FILE'],"w+")
|
|
60 |
self.outfile_close = True
|
|
61 |
except Exception,e:
|
|
62 |
raise Exception("The 'What Filter' could not open the output file specified in the FILTER_WHAT environment variable: " + os.environ['FILTERWHAT_FILE'])
|
|
63 |
|
|
64 |
# repetitions is for tracking repeated lines in the output log
|
|
65 |
# when --check and --what are called
|
|
66 |
self.repetitions = {}
|
|
67 |
|
|
68 |
"Regex for old what output"
|
|
69 |
if "win" in self.buildparameters.platform:
|
|
70 |
self.regex = re.compile("^[a-zA-Z]:\S+$")
|
|
71 |
else:
|
|
72 |
self.regex = re.compile("^/\S+$")
|
|
73 |
|
|
74 |
"Regex for targets"
|
|
75 |
self.target_regex = re.compile("^<(build|stringtable|resource|bitmap)>.*")
|
|
76 |
|
|
77 |
"Regex for exports"
|
|
78 |
self.export_regex = re.compile("^<export destination.*")
|
|
79 |
|
|
80 |
"Regex for zip exports"
|
|
81 |
self.zip_export_regex = re.compile("^<member>.*")
|
|
82 |
|
9
|
83 |
self.prints = 0
|
3
|
84 |
self.ok = True
|
|
85 |
return self.ok
|
|
86 |
|
|
87 |
def write(self, text):
|
|
88 |
"process some log text"
|
|
89 |
|
|
90 |
for line in text.splitlines():
|
|
91 |
line = line.rstrip()
|
|
92 |
|
9
|
93 |
# we are normally the ONLY filter running so we have to pass on
|
|
94 |
# any errors and warnings that emerge
|
|
95 |
#
|
|
96 |
if line.startswith("<error"):
|
|
97 |
sys.stderr.write(self.formatError(line))
|
|
98 |
self.ok = False
|
|
99 |
continue
|
|
100 |
if line.startswith("<warning"):
|
|
101 |
sys.stderr.write(self.formatWarning(line))
|
|
102 |
continue
|
|
103 |
|
3
|
104 |
if not line in self.repetitions:
|
|
105 |
self.repetitions[line] = 0
|
|
106 |
|
|
107 |
if self.repetitions[line] == 0:
|
|
108 |
if self.regex.match(line) and (self.what or self.check):
|
|
109 |
"Print the whole line"
|
|
110 |
self.print_file(line, (-1), len(line))
|
|
111 |
|
|
112 |
if self.target_regex.match(line):
|
|
113 |
"Grab the filename between <build> and </build>"
|
|
114 |
start = line.find(">")
|
|
115 |
end = line.rfind("<")
|
|
116 |
|
|
117 |
self.print_file(line, start, end)
|
|
118 |
|
|
119 |
elif self.export_regex.match(line):
|
|
120 |
"Grab the filename between the first set of '' chars"
|
|
121 |
start = line.find("'")
|
|
122 |
end = line.find("'", (start + 1))
|
|
123 |
|
|
124 |
self.print_file(line, start, end)
|
|
125 |
|
|
126 |
elif self.zip_export_regex.match(line):
|
|
127 |
"Grab the filename between <member> and </member>"
|
|
128 |
start = line.find(">")
|
|
129 |
end = line.rfind("<")
|
|
130 |
|
|
131 |
self.print_file(line, start, end)
|
|
132 |
|
|
133 |
self.repetitions[line] += 1
|
|
134 |
|
|
135 |
return self.ok
|
|
136 |
|
9
|
137 |
def summary(self):
|
|
138 |
if self.prints == 0:
|
|
139 |
if self.what:
|
|
140 |
message = "no WHAT information found"
|
|
141 |
else:
|
|
142 |
message = "no CHECK information found"
|
|
143 |
|
|
144 |
sys.stderr.write(self.formatError(message))
|
|
145 |
self.ok = False
|
|
146 |
return self.ok
|
|
147 |
|
3
|
148 |
def close(self):
|
|
149 |
if self.outfile_close:
|
|
150 |
self.outfile.close()
|
|
151 |
return self.ok
|
|
152 |
|
|
153 |
|