|
1 # Copyright (c) 2009 Symbian Foundation Ltd |
|
2 # This component and the accompanying materials are made available |
|
3 # under the terms of the License "Eclipse Public License v1.0" |
|
4 # which accompanies this distribution, and is available |
|
5 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
6 # |
|
7 # Initial Contributors: |
|
8 # Symbian Foundation Ltd - initial contribution. |
|
9 # |
|
10 # Contributors: |
|
11 # |
|
12 # Description: |
|
13 # Raptor parser module. |
|
14 # Extract releaseable (whatlog) information |
|
15 |
|
16 package RaptorReleaseable; |
|
17 |
|
18 use strict; |
|
19 use RaptorCommon; |
|
20 |
|
21 our $reset_status = {}; |
|
22 my $buildlog_status = {}; |
|
23 my $whatlog_status = {}; |
|
24 my $bitmap_status = {}; |
|
25 my $resource_status = {}; |
|
26 my $build_status = {}; |
|
27 my $export_status = {}; |
|
28 my $stringtable_status = {}; |
|
29 my $archive_status = {}; |
|
30 my $archive_member_status = {}; |
|
31 my $whatlog_default_status = {}; |
|
32 |
|
33 $reset_status->{name} = 'reset_status'; |
|
34 $reset_status->{next_status} = {buildlog=>$buildlog_status}; |
|
35 |
|
36 $buildlog_status->{name} = 'buildlog_status'; |
|
37 $buildlog_status->{next_status} = {whatlog=>$whatlog_status}; |
|
38 |
|
39 $whatlog_status->{name} = 'whatlog_status'; |
|
40 $whatlog_status->{next_status} = {bitmap=>$bitmap_status, resource=>$resource_status, build=>$build_status, export=>$export_status, stringtable=>$stringtable_status, archive=>$archive_status, '?default?'=>$whatlog_default_status}; |
|
41 $whatlog_status->{on_start} = 'RaptorReleaseable::on_start_whatlog'; |
|
42 $whatlog_status->{on_end} = 'RaptorReleaseable::on_end_whatlog'; |
|
43 |
|
44 $bitmap_status->{name} = 'bitmap_status'; |
|
45 $bitmap_status->{next_status} = {}; |
|
46 $bitmap_status->{on_start} = 'RaptorReleaseable::on_start_bitmap'; |
|
47 $bitmap_status->{on_end} = 'RaptorReleaseable::on_end_whatlog_subtag'; |
|
48 $bitmap_status->{on_chars} = 'RaptorReleaseable::on_chars_whatlog_subtag'; |
|
49 |
|
50 $resource_status->{name} = 'resource_status'; |
|
51 $resource_status->{next_status} = {}; |
|
52 $resource_status->{on_start} = 'RaptorReleaseable::on_start_resource'; |
|
53 $resource_status->{on_end} = 'RaptorReleaseable::on_end_whatlog_subtag'; |
|
54 $resource_status->{on_chars} = 'RaptorReleaseable::on_chars_whatlog_subtag'; |
|
55 |
|
56 $build_status->{name} = 'build_status'; |
|
57 $build_status->{next_status} = {}; |
|
58 $build_status->{on_start} = 'RaptorReleaseable::on_start_build'; |
|
59 $build_status->{on_end} = 'RaptorReleaseable::on_end_whatlog_subtag'; |
|
60 $build_status->{on_chars} = 'RaptorReleaseable::on_chars_whatlog_subtag'; |
|
61 |
|
62 $stringtable_status->{name} = 'stringtable_status'; |
|
63 $stringtable_status->{next_status} = {}; |
|
64 $stringtable_status->{on_start} = 'RaptorReleaseable::on_start_stringtable'; |
|
65 $stringtable_status->{on_end} = 'RaptorReleaseable::on_end_whatlog_subtag'; |
|
66 $stringtable_status->{on_chars} = 'RaptorReleaseable::on_chars_whatlog_subtag'; |
|
67 |
|
68 $archive_status->{name} = 'archive_status'; |
|
69 $archive_status->{next_status} = {member=>$archive_member_status}; |
|
70 |
|
71 $archive_member_status->{name} = 'archive_member_status'; |
|
72 $archive_member_status->{next_status} = {}; |
|
73 $archive_member_status->{on_start} = 'RaptorReleaseable::on_start_archive_member'; |
|
74 $archive_member_status->{on_end} = 'RaptorReleaseable::on_end_whatlog_subtag'; |
|
75 $archive_member_status->{on_chars} = 'RaptorReleaseable::on_chars_whatlog_subtag'; |
|
76 |
|
77 $export_status->{name} = 'export_status'; |
|
78 $export_status->{next_status} = {}; |
|
79 $export_status->{on_start} = 'RaptorReleaseable::on_start_export'; |
|
80 |
|
81 $whatlog_default_status->{name} = 'whatlog_default_status'; |
|
82 $whatlog_default_status->{next_status} = {}; |
|
83 $whatlog_default_status->{on_start} = 'RaptorReleaseable::on_start_whatlog_default'; |
|
84 |
|
85 my $whatlog_info = {}; |
|
86 my $curbldinf = 'unknown'; |
|
87 my $curconfig = 'unknown'; |
|
88 my $curfiletype = 'unknown'; |
|
89 my $characters = ''; |
|
90 |
|
91 sub on_start_whatlog |
|
92 { |
|
93 my ($el) = @_; |
|
94 |
|
95 $whatlog_info = {}; |
|
96 |
|
97 my $bldinf = ''; |
|
98 my $config = ''; |
|
99 my $attributes = $el->{Attributes}; |
|
100 for (keys %{$attributes}) |
|
101 { |
|
102 #print "reading attribute $_\n"; |
|
103 if ($attributes->{$_}->{'LocalName'} eq 'bldinf') |
|
104 { |
|
105 $bldinf = $attributes->{$_}->{'Value'}; |
|
106 #print "bldinf=$bldinf\n"; |
|
107 } |
|
108 elsif ($attributes->{$_}->{'LocalName'} eq 'config') |
|
109 { |
|
110 $config = $attributes->{$_}->{'Value'}; |
|
111 $config =~ s,\.whatlog$,,; |
|
112 } |
|
113 } |
|
114 |
|
115 if ($bldinf eq '') |
|
116 { |
|
117 print "WARNING: whatlog tag with no bldinf attribute. Skipping\n"; |
|
118 return; |
|
119 } |
|
120 |
|
121 $curbldinf = $bldinf; |
|
122 $curconfig = $config; |
|
123 $whatlog_info->{$curbldinf} = {} if (!defined $whatlog_info->{$curbldinf}); |
|
124 $whatlog_info->{$curbldinf}->{$curconfig} = {} if (!defined $whatlog_info->{$curbldinf}->{$curconfig}); |
|
125 } |
|
126 |
|
127 sub on_start_whatlog_subtag |
|
128 { |
|
129 my ($ft) = @_; |
|
130 |
|
131 $curfiletype = $ft; |
|
132 $characters = ''; |
|
133 $whatlog_info->{$curbldinf}->{$curconfig}->{$curfiletype} = [] if (! defined $whatlog_info->{$curbldinf}->{$curconfig}->{$curfiletype}); |
|
134 } |
|
135 |
|
136 sub on_chars_whatlog_subtag |
|
137 { |
|
138 my ($ch) = @_; |
|
139 |
|
140 $characters .= $ch->{Data}; |
|
141 |
|
142 #print "characters is now -->$characters<--\n"; |
|
143 } |
|
144 |
|
145 sub on_end_whatlog_subtag |
|
146 { |
|
147 $characters = normalize_filepath($characters); |
|
148 |
|
149 push(@{$whatlog_info->{$curbldinf}->{$curconfig}->{$curfiletype}}, $characters); |
|
150 |
|
151 $curfiletype = 'unknown'; |
|
152 $characters = ''; |
|
153 } |
|
154 |
|
155 sub on_start_bitmap |
|
156 { |
|
157 on_start_whatlog_subtag('bitmap'); |
|
158 } |
|
159 |
|
160 sub on_start_resource |
|
161 { |
|
162 on_start_whatlog_subtag('resource'); |
|
163 } |
|
164 |
|
165 sub on_start_build |
|
166 { |
|
167 on_start_whatlog_subtag('build'); |
|
168 } |
|
169 |
|
170 sub on_start_stringtable |
|
171 { |
|
172 on_start_whatlog_subtag('stringtable'); |
|
173 } |
|
174 |
|
175 sub on_start_archive_member |
|
176 { |
|
177 on_start_whatlog_subtag('export'); |
|
178 } |
|
179 |
|
180 sub on_start_export |
|
181 { |
|
182 my ($el) = @_; |
|
183 |
|
184 $whatlog_info->{$curbldinf}->{$curconfig}->{export} = [] if (! defined $whatlog_info->{$curbldinf}->{$curconfig}->{export}); |
|
185 |
|
186 my $destination = ''; |
|
187 my $attributes = $el->{Attributes}; |
|
188 for (keys %{$attributes}) |
|
189 { |
|
190 #print "reading attribute $_\n"; |
|
191 if ($attributes->{$_}->{'LocalName'} eq 'destination') |
|
192 { |
|
193 $destination = $attributes->{$_}->{'Value'}; |
|
194 #print "destination=$destination\n"; |
|
195 last; |
|
196 } |
|
197 } |
|
198 |
|
199 if ($destination eq '') |
|
200 { |
|
201 print "WARNING: export tag with no destination attribute. Skipping\n"; |
|
202 return; |
|
203 } |
|
204 |
|
205 $destination = normalize_filepath($destination); |
|
206 |
|
207 push(@{$whatlog_info->{$curbldinf}->{$curconfig}->{export}}, $destination); |
|
208 } |
|
209 |
|
210 sub on_end_whatlog |
|
211 { |
|
212 my $unknown_counter = 0; |
|
213 |
|
214 for my $bldinf (keys %{$whatlog_info}) |
|
215 { |
|
216 for my $config (keys %{$whatlog_info->{$bldinf}}) |
|
217 { |
|
218 my $normalized = lc($bldinf); |
|
219 $normalized =~ s,^[A-Za-z]:,,; |
|
220 $normalized =~ s,[\\],/,g; |
|
221 |
|
222 $normalized =~ m,^/sf/([^/]+)/([^/]+)/,; |
|
223 my $layer = $1; |
|
224 my $package = $2; |
|
225 |
|
226 mkdir("$::basedir/releaseables"); |
|
227 mkdir("$::basedir/releaseables/$layer"); |
|
228 mkdir("$::basedir/releaseables/$layer/$package"); |
|
229 |
|
230 my $filename = "$::basedir/releaseables/$layer/$package/info.tsv"; |
|
231 |
|
232 print "Writing info file $filename\n" if (!-f$filename); |
|
233 open(FILE, ">>$filename"); |
|
234 |
|
235 for my $filetype (keys %{$whatlog_info->{$bldinf}->{$config}}) |
|
236 { |
|
237 for (sort(@{$whatlog_info->{$bldinf}->{$config}->{$filetype}})) |
|
238 { |
|
239 print FILE "$_\t$filetype\t$config\n"; |
|
240 } |
|
241 } |
|
242 |
|
243 close(FILE); |
|
244 } |
|
245 } |
|
246 } |
|
247 |
|
248 sub normalize_filepath |
|
249 { |
|
250 my ($filepath) = @_; |
|
251 |
|
252 if ($filepath =~ m,[^\s^\r^\n]+(.*)[\r\n]+(.*)[^\s^\r^\n]+,) |
|
253 { |
|
254 print "WARNING: file path string extends over multiple line: $filepath. Removing all NL's and CR's\n"; |
|
255 } |
|
256 |
|
257 # strip all CR's and NL's |
|
258 $filepath =~ s,[\r\n],,g; |
|
259 |
|
260 # strip all whitespaces at string start/end |
|
261 $filepath =~ s,^\s+,,g; |
|
262 $filepath =~ s,\s+$,,g; |
|
263 |
|
264 # remove drive letter and colon from the beginning of the string |
|
265 $filepath =~ s,^[A-Za-z]:,,; |
|
266 |
|
267 # normalize slashes |
|
268 $filepath =~ s,\\,/,g; |
|
269 $filepath =~ s,//,/,g; |
|
270 |
|
271 if ($filepath !~ m,^/epoc32/,i) |
|
272 { |
|
273 print "WARNING: file '$filepath' doesn't seem valid. Writing to info file anyway\n"; |
|
274 } |
|
275 |
|
276 return $filepath; |
|
277 } |
|
278 |
|
279 sub on_start_whatlog_default |
|
280 { |
|
281 my ($el) = @_; |
|
282 |
|
283 my $tagname = $el->{LocalName}; |
|
284 |
|
285 print "WARNING: unsupported tag '$tagname' in <whatlog> context\n"; |
|
286 } |
|
287 |
|
288 1; |