author | timothy.murphy@nokia.com |
Fri, 12 Feb 2010 15:41:09 +0200 | |
branch | fix |
changeset 205 | ce7b587b436c |
parent 203 | faed4203d5c6 |
child 294 | 660607a4d589 |
permissions | -rw-r--r-- |
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 |
||
114
35ed82e9d574
Strip epocroot off whatcomp filter output.
timothy.murphy@nokia.com
parents:
100
diff
changeset
|
25 |
def __init__(self): |
125 | 26 |
super(filter_interface.Filter,self).__init__() |
114
35ed82e9d574
Strip epocroot off whatcomp filter output.
timothy.murphy@nokia.com
parents:
100
diff
changeset
|
27 |
self.path_prefix_to_strip = None |
115
5869e06bf2ac
Cause whatcomp output to use the incoming epocroot value. i.e. if epocroot is relative then so is the what output.
timothy.murphy@nokia.com
parents:
114
diff
changeset
|
28 |
self.path_prefix_to_add_on = None |
199
3776a92b44bb
Tests cor check and whatTests cor check and what
timothy.murphy@nokia.com
parents:
198
diff
changeset
|
29 |
self.check = False |
3 | 30 |
|
31 |
def print_file(self, line, start, end): |
|
32 |
"Ensure DOS slashes on Windows" |
|
33 |
||
34 |
"""Use chars between enclosing tags ("<>", "''", etc) |
|
35 |
start = opening tag, so the line we need |
|
36 |
actually starts at 'start + 1' """ |
|
203
faed4203d5c6
Fix up file testing with checkwhatcomp and make epocroot driveletter stripping case insensitive.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
199
diff
changeset
|
37 |
|
faed4203d5c6
Fix up file testing with checkwhatcomp and make epocroot driveletter stripping case insensitive.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
199
diff
changeset
|
38 |
abs_filename = line[(start + 1):end] |
205
ce7b587b436c
fix: filterwhatcomp and filtercheckcomp - correctly strip absolute directory and replace with EPOCROOT on windows.
timothy.murphy@nokia.com
parents:
203
diff
changeset
|
39 |
filename = abs_filename |
203
faed4203d5c6
Fix up file testing with checkwhatcomp and make epocroot driveletter stripping case insensitive.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
199
diff
changeset
|
40 |
|
205
ce7b587b436c
fix: filterwhatcomp and filtercheckcomp - correctly strip absolute directory and replace with EPOCROOT on windows.
timothy.murphy@nokia.com
parents:
203
diff
changeset
|
41 |
# Adjust drive letters for case insensitivity on windows |
203
faed4203d5c6
Fix up file testing with checkwhatcomp and make epocroot driveletter stripping case insensitive.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
199
diff
changeset
|
42 |
|
faed4203d5c6
Fix up file testing with checkwhatcomp and make epocroot driveletter stripping case insensitive.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
199
diff
changeset
|
43 |
path_prefix_to_strip = self.path_prefix_to_strip |
3 | 44 |
if "win" in self.buildparameters.platform: |
203
faed4203d5c6
Fix up file testing with checkwhatcomp and make epocroot driveletter stripping case insensitive.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
199
diff
changeset
|
45 |
filename = filename[0].upper()+filename[1:] |
faed4203d5c6
Fix up file testing with checkwhatcomp and make epocroot driveletter stripping case insensitive.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
199
diff
changeset
|
46 |
filename = filename.replace("/","\\") |
114
35ed82e9d574
Strip epocroot off whatcomp filter output.
timothy.murphy@nokia.com
parents:
100
diff
changeset
|
47 |
|
203
faed4203d5c6
Fix up file testing with checkwhatcomp and make epocroot driveletter stripping case insensitive.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
199
diff
changeset
|
48 |
if path_prefix_to_strip: |
faed4203d5c6
Fix up file testing with checkwhatcomp and make epocroot driveletter stripping case insensitive.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
199
diff
changeset
|
49 |
if "win" in self.buildparameters.platform: |
205
ce7b587b436c
fix: filterwhatcomp and filtercheckcomp - correctly strip absolute directory and replace with EPOCROOT on windows.
timothy.murphy@nokia.com
parents:
203
diff
changeset
|
50 |
path_prefix_to_strip = path_prefix_to_strip[0].upper()+path_prefix_to_strip[1:].replace("/","\\") |
203
faed4203d5c6
Fix up file testing with checkwhatcomp and make epocroot driveletter stripping case insensitive.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
199
diff
changeset
|
51 |
if filename.startswith(path_prefix_to_strip): |
faed4203d5c6
Fix up file testing with checkwhatcomp and make epocroot driveletter stripping case insensitive.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
199
diff
changeset
|
52 |
filename = filename[len(path_prefix_to_strip):] |
115
5869e06bf2ac
Cause whatcomp output to use the incoming epocroot value. i.e. if epocroot is relative then so is the what output.
timothy.murphy@nokia.com
parents:
114
diff
changeset
|
53 |
if self.path_prefix_to_add_on != None: |
117
ecf683438dc6
Don't mess around with EPOCROOT until actually entering raptor so we know what the original was
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
115
diff
changeset
|
54 |
filename = self.path_prefix_to_add_on + filename |
3 | 55 |
|
56 |
if self.check: |
|
203
faed4203d5c6
Fix up file testing with checkwhatcomp and make epocroot driveletter stripping case insensitive.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
199
diff
changeset
|
57 |
if not os.path.isfile(abs_filename): |
3 | 58 |
print "MISSING:", filename |
59 |
self.ok = False |
|
60 |
else: |
|
61 |
self.outfile.write(filename+"\n") |
|
62 |
||
9 | 63 |
self.prints += 1 |
93
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
64 |
|
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
65 |
def start_bldinf(self, bldinf): |
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
66 |
pass |
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
67 |
|
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
68 |
def end_bldinf(self): |
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
69 |
pass |
9 | 70 |
|
3 | 71 |
|
72 |
def open(self, build_parameters): |
|
73 |
"initialise" |
|
74 |
||
203
faed4203d5c6
Fix up file testing with checkwhatcomp and make epocroot driveletter stripping case insensitive.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
199
diff
changeset
|
75 |
|
3 | 76 |
self.buildparameters = build_parameters |
198
53dd6a549481
fix: make filters work with new default python
timothy.murphy@nokia.com
parents:
125
diff
changeset
|
77 |
if build_parameters.doCheck: |
53dd6a549481
fix: make filters work with new default python
timothy.murphy@nokia.com
parents:
125
diff
changeset
|
78 |
self.check = True |
3 | 79 |
self.what = build_parameters.doWhat |
80 |
||
81 |
self.outfile = sys.stdout |
|
82 |
self.outfile_close = False |
|
83 |
||
84 |
if "FILTERWHAT_FILE" in os.environ: |
|
85 |
try: |
|
86 |
self.outfile = open(os.environ['FILTERWHAT_FILE'],"w+") |
|
87 |
self.outfile_close = True |
|
88 |
except Exception,e: |
|
89 |
raise Exception("The 'What Filter' could not open the output file specified in the FILTER_WHAT environment variable: " + os.environ['FILTERWHAT_FILE']) |
|
90 |
||
91 |
# repetitions is for tracking repeated lines in the output log |
|
92 |
# when --check and --what are called |
|
93 |
self.repetitions = {} |
|
94 |
||
95 |
"Regex for old what output" |
|
96 |
if "win" in self.buildparameters.platform: |
|
97 |
self.regex = re.compile("^[a-zA-Z]:\S+$") |
|
98 |
else: |
|
99 |
self.regex = re.compile("^/\S+$") |
|
100 |
||
101 |
"Regex for targets" |
|
102 |
self.target_regex = re.compile("^<(build|stringtable|resource|bitmap)>.*") |
|
103 |
||
104 |
"Regex for exports" |
|
105 |
self.export_regex = re.compile("^<export destination.*") |
|
106 |
||
107 |
"Regex for zip exports" |
|
108 |
self.zip_export_regex = re.compile("^<member>.*") |
|
93
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
109 |
|
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
110 |
"Regex for determining bld.inf name" |
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
111 |
self.whatlog_regex = re.compile("^<whatlog *bldinf='(?P<bldinf>[^']*)'.*") |
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
112 |
self.current_bldinf = '' |
3 | 113 |
|
9 | 114 |
self.prints = 0 |
3 | 115 |
self.ok = True |
116 |
return self.ok |
|
117 |
||
118 |
def write(self, text): |
|
119 |
"process some log text" |
|
120 |
||
121 |
for line in text.splitlines(): |
|
122 |
line = line.rstrip() |
|
123 |
||
9 | 124 |
# we are normally the ONLY filter running so we have to pass on |
125 |
# any errors and warnings that emerge |
|
126 |
# |
|
127 |
if line.startswith("<error"): |
|
128 |
sys.stderr.write(self.formatError(line)) |
|
129 |
self.ok = False |
|
130 |
continue |
|
131 |
if line.startswith("<warning"): |
|
132 |
sys.stderr.write(self.formatWarning(line)) |
|
133 |
continue |
|
134 |
||
3 | 135 |
if not line in self.repetitions: |
136 |
self.repetitions[line] = 0 |
|
137 |
||
138 |
if self.repetitions[line] == 0: |
|
93
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
139 |
|
3 | 140 |
if self.regex.match(line) and (self.what or self.check): |
141 |
"Print the whole line" |
|
142 |
self.print_file(line, (-1), len(line)) |
|
143 |
||
144 |
if self.target_regex.match(line): |
|
145 |
"Grab the filename between <build> and </build>" |
|
146 |
start = line.find(">") |
|
147 |
end = line.rfind("<") |
|
148 |
||
149 |
self.print_file(line, start, end) |
|
150 |
||
151 |
elif self.export_regex.match(line): |
|
152 |
"Grab the filename between the first set of '' chars" |
|
153 |
start = line.find("'") |
|
154 |
end = line.find("'", (start + 1)) |
|
155 |
||
156 |
self.print_file(line, start, end) |
|
157 |
||
158 |
elif self.zip_export_regex.match(line): |
|
159 |
"Grab the filename between <member> and </member>" |
|
160 |
start = line.find(">") |
|
161 |
end = line.rfind("<") |
|
162 |
||
163 |
self.print_file(line, start, end) |
|
93
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
164 |
|
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
165 |
else: |
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
166 |
"work out what the 'current' bldinf file is" |
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
167 |
m = self.whatlog_regex.match(line) |
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
168 |
if m: |
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
169 |
bi = m.groupdict()['bldinf'] |
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
170 |
if self.current_bldinf != bi: |
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
171 |
if self.current_bldinf != '': |
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
172 |
self.end_bldinf() |
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
173 |
self.current_bldinf = bi |
100 | 174 |
if bi != '': |
175 |
self.start_bldinf(bi) |
|
93
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
176 |
|
572b3909c72f
RELEASE NOTE: Added new launchers for the sbs_filter program so that there is no longer a need to manually set the HOSTPLATFORM variable
timothy.murphy@nokia.com
parents:
9
diff
changeset
|
177 |
|
3 | 178 |
|
179 |
self.repetitions[line] += 1 |
|
180 |
||
181 |
return self.ok |
|
182 |
||
9 | 183 |
def summary(self): |
184 |
if self.prints == 0: |
|
185 |
if self.what: |
|
186 |
message = "no WHAT information found" |
|
187 |
else: |
|
188 |
message = "no CHECK information found" |
|
189 |
||
190 |
sys.stderr.write(self.formatError(message)) |
|
191 |
self.ok = False |
|
192 |
return self.ok |
|
193 |
||
3 | 194 |
def close(self): |
195 |
if self.outfile_close: |
|
196 |
self.outfile.close() |
|
197 |
return self.ok |
|
198 |
||
199 |