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