|
1 # |
|
2 # Copyright (c) 1997-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 # |
|
16 |
|
17 # This package contains routines to read the information from the Component Description Files. |
|
18 package cdfparser; |
|
19 |
|
20 # Include Module package to use APIs to parse an XML file. |
|
21 use genericparser; |
|
22 |
|
23 require Exporter; |
|
24 @ISA=qw(Exporter); |
|
25 @EXPORT=qw( |
|
26 CreateCDFFileBinaryMapFromDir |
|
27 GetBinaries |
|
28 GetCDFFileName |
|
29 LoadCDF |
|
30 GetDynamicDependencies |
|
31 GetBinaryInfo |
|
32 GetIncludedFeatureList |
|
33 GetExcludedFeatureList |
|
34 ); |
|
35 |
|
36 use strict; |
|
37 |
|
38 # Map between the CDF File Name and the corresponding list of binaries |
|
39 # This is required so that one can fetch the list of binaries for a particular CDF file. |
|
40 my %binaryCDFFileMap=(); |
|
41 |
|
42 # Include Feature List |
|
43 # The list of features to be included for a given binary. |
|
44 my @includeFeatureList; |
|
45 |
|
46 # Exclude Feature List |
|
47 # The list of features to be excluded for a given binary. |
|
48 my @excludeFeatureList; |
|
49 |
|
50 # List that contains the complete information of each binary |
|
51 my %binaryInfo=(); |
|
52 |
|
53 my $warning_level = 0; |
|
54 |
|
55 # Absolute path that contains the CDF Files |
|
56 my @cdfDirectories; |
|
57 |
|
58 # To extract the cdf files from the directory specified as input. The default directory is chosen if no |
|
59 # input is specified. |
|
60 sub CreateCDFFileBinaryMapFromDir |
|
61 { |
|
62 |
|
63 my @acdfDirList = @_; |
|
64 # To store the list of cdf file names specified under the directory |
|
65 my @cdfFileList; |
|
66 |
|
67 if ((scalar @acdfDirList) != 0) |
|
68 { |
|
69 foreach my $acdfDir (@acdfDirList) |
|
70 { |
|
71 opendir DIR, "$acdfDir"; |
|
72 if(not grep /$acdfDir/i, @cdfDirectories) |
|
73 { |
|
74 push @cdfDirectories, $acdfDir; |
|
75 } |
|
76 |
|
77 push (@cdfFileList, (grep /\.cdf/i, readdir DIR)); |
|
78 foreach my $filename (@cdfFileList) |
|
79 { |
|
80 &CreateCDFFileBinaryMap(lc($filename), $acdfDir); |
|
81 $binaryCDFFileMap{$filename}{path} = $acdfDir; |
|
82 } |
|
83 } |
|
84 } |
|
85 } |
|
86 |
|
87 # To create a mapping between the CDF file name and the corresponding list of binaries |
|
88 sub CreateCDFFileBinaryMap |
|
89 { |
|
90 my ($cdffilename, $aCdfDir) = @_; |
|
91 |
|
92 if( defined $binaryCDFFileMap{$cdffilename} ) |
|
93 { |
|
94 return; |
|
95 } |
|
96 |
|
97 my $path; |
|
98 if( defined $aCdfDir) |
|
99 { |
|
100 $path = "$aCdfDir\\$cdffilename"; |
|
101 } |
|
102 else |
|
103 { |
|
104 $path = $cdffilename; |
|
105 } |
|
106 |
|
107 my $rootNode = &genericparser::getRootElement($path); |
|
108 $binaryCDFFileMap{$cdffilename}{root} = $rootNode; |
|
109 |
|
110 my @binaryList = &genericparser::getChildElements($rootNode); |
|
111 |
|
112 my $binaryInfoRef; |
|
113 foreach my $binary (@binaryList) |
|
114 { |
|
115 my $filename = &genericparser::getAttrValue($binary, "id"); |
|
116 push @{$binaryCDFFileMap{$cdffilename}{binaries}}, $filename; |
|
117 # This is required so that one can fetch the CDF file name in which the binary is present |
|
118 $binaryInfoRef = \%{$binaryInfo{$filename}}; |
|
119 $binaryInfoRef->{"filename"} = $cdffilename; |
|
120 } |
|
121 } |
|
122 |
|
123 # To get the complete list of binaries present in a given CDF file |
|
124 # Input Parameter : CDF filename |
|
125 # Returns the complete list of binaries |
|
126 sub GetBinaries |
|
127 { |
|
128 my $cdffilename = shift; |
|
129 if (exists $binaryCDFFileMap{$cdffilename}) |
|
130 { |
|
131 return @{$binaryCDFFileMap{$cdffilename}{binaries}}; |
|
132 } |
|
133 else |
|
134 { |
|
135 return undef; |
|
136 } |
|
137 } |
|
138 |
|
139 |
|
140 # To get the name of the CDF file that contains the input binary |
|
141 # Input Parameter : Binary Name |
|
142 # Returns the CDF file name |
|
143 sub GetCDFFileName |
|
144 { |
|
145 my $aBinary = lc(shift); |
|
146 |
|
147 if (exists $binaryInfo{$aBinary}) |
|
148 { |
|
149 my $binInfo = \%{$binaryInfo{$aBinary}}; |
|
150 return $binInfo->{filename}; |
|
151 } |
|
152 else |
|
153 { |
|
154 return undef; |
|
155 } |
|
156 |
|
157 } |
|
158 |
|
159 #Loads all the specified CDF files. |
|
160 sub LoadCDF |
|
161 { |
|
162 my @cdfFileList = @_; |
|
163 |
|
164 foreach my $afile (@cdfFileList) |
|
165 { |
|
166 CreateCDFFileBinaryMap($afile); |
|
167 my $rootNode = $binaryCDFFileMap{$afile}{root}; |
|
168 |
|
169 # Get the total list of files present in the cdf file. |
|
170 my @binaryList = &genericparser::getChildElements($rootNode); |
|
171 |
|
172 # Hash Reference to the hash map binaryInfo |
|
173 my $binaryInfoHashRef; |
|
174 |
|
175 foreach my $binaryNode (@binaryList) |
|
176 { |
|
177 my $fileId = &genericparser::getAttrValue($binaryNode, "id"); |
|
178 $binaryInfoHashRef = \%{$binaryInfo{$fileId}}; |
|
179 &setBinaryInfo($binaryInfoHashRef, $binaryNode); |
|
180 } |
|
181 } |
|
182 |
|
183 } |
|
184 |
|
185 #Sets the information of the CDF file to a hash map |
|
186 sub setBinaryInfo |
|
187 { |
|
188 my ($aBinaryInfoRef, $aBinaryNode) = @_; |
|
189 |
|
190 # Set the File attributes |
|
191 $aBinaryInfoRef->{"id"} = &genericparser::getAttrValue($aBinaryNode, "id"); |
|
192 $aBinaryInfoRef->{"customisable"} = &genericparser::getAttrValue($aBinaryNode, "customisable"); |
|
193 $aBinaryInfoRef->{"addressable"} = &genericparser::getAttrValue($aBinaryNode, "addressable"); |
|
194 $aBinaryInfoRef->{"compress"} = &genericparser::getAttrValue($aBinaryNode, "compress"); |
|
195 $aBinaryInfoRef->{"type"} = &genericparser::getAttrValue($aBinaryNode, "type"); |
|
196 $aBinaryInfoRef->{"plugin_name"} = &genericparser::getAttrValue($aBinaryNode, "plugin_name"); |
|
197 |
|
198 # Check for the plugin, setting the plugin type as ECOM_PLUGIN |
|
199 |
|
200 if (defined $aBinaryInfoRef->{"plugin_name"}) |
|
201 { |
|
202 $aBinaryInfoRef->{"IsFoundInCDF"} = 1; |
|
203 $aBinaryInfoRef->{"source"} = "ABI_DIR\\BUILD_DIR\\$aBinaryInfoRef->{id}"; |
|
204 $aBinaryInfoRef->{"plugin_name"} =~ s/$aBinaryInfoRef->{plugin_name}/ECOM/; |
|
205 } |
|
206 |
|
207 else { |
|
208 |
|
209 # Get all the nodes of element 'file' |
|
210 my @children = &genericparser::getChildElements($aBinaryNode); |
|
211 |
|
212 foreach my $childNode (@children) |
|
213 { |
|
214 $aBinaryInfoRef->{"IsFoundInCDF"} = 1; |
|
215 |
|
216 if (&genericparser::getElementName($childNode) eq "source") |
|
217 { |
|
218 $aBinaryInfoRef->{"source"} = &genericparser::getElementValue($childNode); |
|
219 } |
|
220 |
|
221 if (&genericparser::getElementName($childNode) eq "destination") |
|
222 { |
|
223 $aBinaryInfoRef->{"destination"} = &genericparser::getElementValue($childNode); |
|
224 } |
|
225 |
|
226 if (&genericparser::getElementName($childNode) eq "features") |
|
227 { |
|
228 # The children nodes will specify the list of features |
|
229 my @aFeatureNodes = &genericparser::getChildElements($childNode); |
|
230 foreach my $aFeatureChildNode (@aFeatureNodes) |
|
231 { |
|
232 # A list of features can be listed out either for supported case or for the prevented case. |
|
233 if (&genericparser::getElementName($aFeatureChildNode) eq "supports") |
|
234 { |
|
235 my @aSupportedFeatureNodes = &genericparser::getChildElements($aFeatureChildNode); |
|
236 foreach my $aSuppChildNode (@aSupportedFeatureNodes) |
|
237 { |
|
238 my %feat = (); |
|
239 my $featureName = &genericparser::getAttrValue($aSuppChildNode, "name"); |
|
240 my $featureUID = &genericparser::getAttrValue($aSuppChildNode, "uid"); |
|
241 if (defined ($featureName) and ($featureName ne "")) |
|
242 { |
|
243 $feat{name} = $featureName ; |
|
244 $feat{uid} = undef; |
|
245 } |
|
246 elsif(defined ($featureUID) and ($featureUID ne "")) |
|
247 { |
|
248 if(&featureparser::ValidateUIDValue($featureUID)) |
|
249 { |
|
250 $featureUID = &featureparser::ConvertHexToDecimal($featureUID); |
|
251 $feat{uid} = $featureUID; |
|
252 $feat{name} = undef; |
|
253 } |
|
254 else |
|
255 { |
|
256 print "The uid value $featureUID specified for the Include feature list for the Binary, $aBinaryInfoRef->{id}, is not a valid number\n"; |
|
257 } |
|
258 } |
|
259 else |
|
260 { |
|
261 print ("Warning: Feature $featureName has both name and Uid mentioned\n") if ($warning_level < 2); |
|
262 next; |
|
263 } |
|
264 |
|
265 $feat{include} = 1; |
|
266 push @includeFeatureList, \%feat; |
|
267 |
|
268 } |
|
269 } |
|
270 if (&genericparser::getElementName($aFeatureChildNode) eq "prevents") |
|
271 { |
|
272 my @aPreventedFeatureNodes = &genericparser::getChildElements($aFeatureChildNode); |
|
273 foreach my $aPreventedChildNode (@aPreventedFeatureNodes) |
|
274 { |
|
275 my %feat = (); |
|
276 my $featureName = &genericparser::getAttrValue($aPreventedChildNode, "name"); |
|
277 my $featureUID = &genericparser::getAttrValue($aPreventedChildNode, "uid"); |
|
278 if (defined ($featureName) and ($featureName ne "")) |
|
279 { |
|
280 $feat{name} = $featureName ; |
|
281 $feat{uid} = undef; |
|
282 } |
|
283 elsif(defined ($featureUID) and ($featureUID ne "")) |
|
284 { |
|
285 if(&featureparser::ValidateUIDValue($featureUID)) |
|
286 { |
|
287 $featureUID = &featureparser::ConvertHexToDecimal($featureUID); |
|
288 $feat{uid} = $featureUID; |
|
289 $feat{name} = undef; |
|
290 } |
|
291 else |
|
292 { |
|
293 print "The uid value $featureUID specified for the Exclude feature list for the Binary, $aBinaryInfoRef->{id}, is not a valid number\n"; |
|
294 } |
|
295 } |
|
296 else |
|
297 { |
|
298 print "Warning: Feature $featureName has both name and Uid mentioned\n" if ($warning_level < 2); |
|
299 next; |
|
300 } |
|
301 |
|
302 $feat{exclude} = 1; |
|
303 push @excludeFeatureList, \%feat; |
|
304 |
|
305 } |
|
306 push @{$aBinaryInfoRef->{"prevents"}}, (&genericparser::getElementValue($aFeatureChildNode)); |
|
307 } |
|
308 } |
|
309 } |
|
310 |
|
311 if (&genericparser::getElementName($childNode) eq "dynamicdependencies") |
|
312 { |
|
313 # The children nodes will contain the file name. |
|
314 my @aDynDependNodes = &genericparser::getChildElements($childNode); |
|
315 |
|
316 foreach my $aDynDependChildNode (@aDynDependNodes) |
|
317 { |
|
318 # There can be a list of binaries for dynamic dependencies |
|
319 if (&genericparser::getElementName($aDynDependChildNode) eq "depend") |
|
320 { |
|
321 push @{$aBinaryInfoRef->{"depend"}}, (&genericparser::getElementValue($aDynDependChildNode)); |
|
322 } |
|
323 } |
|
324 } |
|
325 |
|
326 if (&genericparser::getElementName($childNode) eq "localisation") |
|
327 { |
|
328 # The children nodes will contain the language code |
|
329 my @aLocalisationNodes = &genericparser::getChildElements($childNode); |
|
330 |
|
331 foreach my $aLocalisationChildNode (@aLocalisationNodes) |
|
332 { |
|
333 # There can be a list of binaries for dynamic dependencies |
|
334 if (&genericparser::getElementName($aLocalisationChildNode) eq "default") |
|
335 { |
|
336 $aBinaryInfoRef->{"default"} = &genericparser::getElementValue($aLocalisationChildNode); |
|
337 } |
|
338 if (&genericparser::getElementName($aLocalisationChildNode) eq "language") |
|
339 { |
|
340 push @{$aBinaryInfoRef->{"language"}}, (&genericparser::getElementValue($aLocalisationChildNode)); |
|
341 } |
|
342 } |
|
343 } |
|
344 |
|
345 if (&genericparser::getElementName($childNode) eq "options") |
|
346 { |
|
347 # The children nodes will contain the option details |
|
348 my @aOptionNodes = &genericparser::getChildElements($childNode); |
|
349 foreach my $aOptionChildNode (@aOptionNodes) |
|
350 { |
|
351 if (&genericparser::getElementName($aOptionChildNode) eq "multilinguify") |
|
352 { |
|
353 $aBinaryInfoRef->{"multilinguify"} = &genericparser::getElementValue($aOptionChildNode); |
|
354 } |
|
355 if (&genericparser::getElementName($aOptionChildNode) eq "stack") |
|
356 { |
|
357 $aBinaryInfoRef->{"stack"} = &genericparser::getElementValue($aOptionChildNode); |
|
358 } |
|
359 if (&genericparser::getElementName($aOptionChildNode) eq "heapmin") |
|
360 { |
|
361 $aBinaryInfoRef->{"heapmin"} = &genericparser::getElementValue($aOptionChildNode); |
|
362 } |
|
363 if (&genericparser::getElementName($aOptionChildNode) eq "heapmax") |
|
364 { |
|
365 $aBinaryInfoRef->{"heapmax"} = &genericparser::getElementValue($aOptionChildNode); |
|
366 } |
|
367 if (&genericparser::getElementName($aOptionChildNode) eq "fixed") |
|
368 { |
|
369 $aBinaryInfoRef->{"fixed"} = &genericparser::getElementValue($aOptionChildNode); |
|
370 } |
|
371 if (&genericparser::getElementName($aOptionChildNode) eq "priority") |
|
372 { |
|
373 $aBinaryInfoRef->{"priority"} = &genericparser::getElementValue($aOptionChildNode); |
|
374 } |
|
375 if (&genericparser::getElementName($aOptionChildNode) eq "uid1") |
|
376 { |
|
377 $aBinaryInfoRef->{"uid1"} = &genericparser::getElementValue($aOptionChildNode); |
|
378 } |
|
379 if (&genericparser::getElementName($aOptionChildNode) eq "uid2") |
|
380 { |
|
381 $aBinaryInfoRef->{"uid2"} = &genericparser::getElementValue($aOptionChildNode); |
|
382 } |
|
383 if (&genericparser::getElementName($aOptionChildNode) eq "uid3") |
|
384 { |
|
385 $aBinaryInfoRef->{"uid3"} = &genericparser::getElementValue($aOptionChildNode); |
|
386 } |
|
387 if (&genericparser::getElementName($aOptionChildNode) eq "dll") |
|
388 { |
|
389 $aBinaryInfoRef->{"dll"} = &genericparser::getElementValue($aOptionChildNode); |
|
390 } |
|
391 if (&genericparser::getElementName($aOptionChildNode) eq "dlldatatop") |
|
392 { |
|
393 $aBinaryInfoRef->{"dlldatatop"} = &genericparser::getElementValue($aOptionChildNode); |
|
394 } |
|
395 } |
|
396 } |
|
397 } |
|
398 } |
|
399 } |
|
400 |
|
401 # To get the complete list of information for a given binary |
|
402 # Input Parameter : Binary |
|
403 # Returns the detailed information for each binary |
|
404 sub GetBinaryInfo |
|
405 { |
|
406 my $aBinary = shift; |
|
407 my $aBinaryInfoHash = \%{$binaryInfo{$aBinary}}; |
|
408 if ($aBinaryInfoHash->{IsFoundInCDF}) |
|
409 { |
|
410 return $aBinaryInfoHash; |
|
411 } |
|
412 return undef; |
|
413 } |
|
414 |
|
415 # To get the complete list of dynamic dependencies for a given binary |
|
416 # Input Parameter : Binary |
|
417 # Returns the complete list of dynamic dependencies |
|
418 sub GetDynamicDependencies |
|
419 { |
|
420 my $aBinary = shift; |
|
421 |
|
422 my $bin = \%{$binaryInfo{$aBinary}}; |
|
423 |
|
424 return \@{$bin->{"depend"}}; |
|
425 } |
|
426 |
|
427 #Returns the included feature list |
|
428 sub GetIncludedFeatureList |
|
429 { |
|
430 return \@includeFeatureList; |
|
431 } |
|
432 |
|
433 #Returns the excluded feature list |
|
434 sub GetExcludedFeatureList |
|
435 { |
|
436 return \@excludeFeatureList; |
|
437 } |
|
438 |
|
439 1; |