author | timothy.murphy@nokia.com |
Wed, 16 Dec 2009 15:25:49 +0000 | |
branch | wip |
changeset 114 | 35ed82e9d574 |
parent 100 | 55250667c668 |
child 115 | 5869e06bf2ac |
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): |
35ed82e9d574
Strip epocroot off whatcomp filter output.
timothy.murphy@nokia.com
parents:
100
diff
changeset
|
26 |
super(filter_interface.Filter,self).__init__(self) |
35ed82e9d574
Strip epocroot off whatcomp filter output.
timothy.murphy@nokia.com
parents:
100
diff
changeset
|
27 |
self.path_prefix_to_strip = None |
35ed82e9d574
Strip epocroot off whatcomp filter output.
timothy.murphy@nokia.com
parents:
100
diff
changeset
|
28 |
print "HELLO=------" |
3 | 29 |
|
30 |
def print_file(self, line, start, end): |
|
31 |
"Ensure DOS slashes on Windows" |
|
32 |
||
33 |
"""Use chars between enclosing tags ("<>", "''", etc) |
|
34 |
start = opening tag, so the line we need |
|
35 |
actually starts at 'start + 1' """ |
|
36 |
if "win" in self.buildparameters.platform: |
|
37 |
filename = line[(start + 1):end].replace("/","\\") |
|
38 |
else: |
|
39 |
filename = line[(start + 1):end] |
|
114
35ed82e9d574
Strip epocroot off whatcomp filter output.
timothy.murphy@nokia.com
parents:
100
diff
changeset
|
40 |
|
35ed82e9d574
Strip epocroot off whatcomp filter output.
timothy.murphy@nokia.com
parents:
100
diff
changeset
|
41 |
if self.path_prefix_to_strip: |
35ed82e9d574
Strip epocroot off whatcomp filter output.
timothy.murphy@nokia.com
parents:
100
diff
changeset
|
42 |
if filename.startswith(self.path_prefix_to_strip): |
35ed82e9d574
Strip epocroot off whatcomp filter output.
timothy.murphy@nokia.com
parents:
100
diff
changeset
|
43 |
filename = filename[len(self.path_prefix_to_strip):] |
3 | 44 |
|
45 |
if self.check: |
|
46 |
if not os.path.isfile(filename): |
|
47 |
print "MISSING:", filename |
|
48 |
self.ok = False |
|
49 |
else: |
|
50 |
self.outfile.write(filename+"\n") |
|
51 |
||
9 | 52 |
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
|
53 |
|
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
|
54 |
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
|
55 |
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
|
56 |
|
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
|
57 |
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
|
58 |
pass |
9 | 59 |
|
3 | 60 |
|
61 |
def open(self, build_parameters): |
|
62 |
"initialise" |
|
63 |
||
64 |
self.buildparameters = build_parameters |
|
65 |
self.check = build_parameters.doCheck |
|
66 |
self.what = build_parameters.doWhat |
|
67 |
||
68 |
self.outfile = sys.stdout |
|
69 |
self.outfile_close = False |
|
70 |
||
71 |
if "FILTERWHAT_FILE" in os.environ: |
|
72 |
try: |
|
73 |
self.outfile = open(os.environ['FILTERWHAT_FILE'],"w+") |
|
74 |
self.outfile_close = True |
|
75 |
except Exception,e: |
|
76 |
raise Exception("The 'What Filter' could not open the output file specified in the FILTER_WHAT environment variable: " + os.environ['FILTERWHAT_FILE']) |
|
77 |
||
78 |
# repetitions is for tracking repeated lines in the output log |
|
79 |
# when --check and --what are called |
|
80 |
self.repetitions = {} |
|
81 |
||
82 |
"Regex for old what output" |
|
83 |
if "win" in self.buildparameters.platform: |
|
84 |
self.regex = re.compile("^[a-zA-Z]:\S+$") |
|
85 |
else: |
|
86 |
self.regex = re.compile("^/\S+$") |
|
87 |
||
88 |
"Regex for targets" |
|
89 |
self.target_regex = re.compile("^<(build|stringtable|resource|bitmap)>.*") |
|
90 |
||
91 |
"Regex for exports" |
|
92 |
self.export_regex = re.compile("^<export destination.*") |
|
93 |
||
94 |
"Regex for zip exports" |
|
95 |
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
|
96 |
|
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
|
97 |
"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
|
98 |
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
|
99 |
self.current_bldinf = '' |
3 | 100 |
|
9 | 101 |
self.prints = 0 |
3 | 102 |
self.ok = True |
103 |
return self.ok |
|
104 |
||
105 |
def write(self, text): |
|
106 |
"process some log text" |
|
107 |
||
108 |
for line in text.splitlines(): |
|
109 |
line = line.rstrip() |
|
110 |
||
9 | 111 |
# we are normally the ONLY filter running so we have to pass on |
112 |
# any errors and warnings that emerge |
|
113 |
# |
|
114 |
if line.startswith("<error"): |
|
115 |
sys.stderr.write(self.formatError(line)) |
|
116 |
self.ok = False |
|
117 |
continue |
|
118 |
if line.startswith("<warning"): |
|
119 |
sys.stderr.write(self.formatWarning(line)) |
|
120 |
continue |
|
121 |
||
3 | 122 |
if not line in self.repetitions: |
123 |
self.repetitions[line] = 0 |
|
124 |
||
125 |
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
|
126 |
|
3 | 127 |
if self.regex.match(line) and (self.what or self.check): |
128 |
"Print the whole line" |
|
129 |
self.print_file(line, (-1), len(line)) |
|
130 |
||
131 |
if self.target_regex.match(line): |
|
132 |
"Grab the filename between <build> and </build>" |
|
133 |
start = line.find(">") |
|
134 |
end = line.rfind("<") |
|
135 |
||
136 |
self.print_file(line, start, end) |
|
137 |
||
138 |
elif self.export_regex.match(line): |
|
139 |
"Grab the filename between the first set of '' chars" |
|
140 |
start = line.find("'") |
|
141 |
end = line.find("'", (start + 1)) |
|
142 |
||
143 |
self.print_file(line, start, end) |
|
144 |
||
145 |
elif self.zip_export_regex.match(line): |
|
146 |
"Grab the filename between <member> and </member>" |
|
147 |
start = line.find(">") |
|
148 |
end = line.rfind("<") |
|
149 |
||
150 |
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
|
151 |
|
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
|
152 |
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
|
153 |
"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
|
154 |
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
|
155 |
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
|
156 |
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
|
157 |
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
|
158 |
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
|
159 |
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
|
160 |
self.current_bldinf = bi |
100 | 161 |
if bi != '': |
162 |
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
|
163 |
|
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 |
|
3 | 165 |
|
166 |
self.repetitions[line] += 1 |
|
167 |
||
168 |
return self.ok |
|
169 |
||
9 | 170 |
def summary(self): |
171 |
if self.prints == 0: |
|
172 |
if self.what: |
|
173 |
message = "no WHAT information found" |
|
174 |
else: |
|
175 |
message = "no CHECK information found" |
|
176 |
||
177 |
sys.stderr.write(self.formatError(message)) |
|
178 |
self.ok = False |
|
179 |
return self.ok |
|
180 |
||
3 | 181 |
def close(self): |
182 |
if self.outfile_close: |
|
183 |
self.outfile.close() |
|
184 |
return self.ok |
|
185 |
||
186 |