655
|
1 |
#
|
|
2 |
# Copyright (c) 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 "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 |
#! perl
|
|
17 |
|
|
18 |
# Read a Schedule12 file and check the system_model items
|
|
19 |
# against a supplied System_Definition.xml
|
|
20 |
|
|
21 |
use strict;
|
|
22 |
|
|
23 |
use FindBin;
|
|
24 |
use lib ".";
|
|
25 |
use lib "./lib";
|
|
26 |
use lib "$FindBin::Bin";
|
|
27 |
use lib "$FindBin::Bin/lib";
|
|
28 |
use XML::DOM;
|
|
29 |
use XML::DOM::ValParser;
|
|
30 |
|
|
31 |
# produces the "Use of uninitialized value in concatenation (.) or string" warning
|
|
32 |
use XML::XQL;
|
|
33 |
use XML::XQL::DOM;
|
|
34 |
|
|
35 |
# Read the command line to get the filenames
|
|
36 |
|
|
37 |
sub Usage($)
|
|
38 |
{
|
|
39 |
my ($reason) = @_;
|
|
40 |
|
|
41 |
print "Usage: $reason\n" if ($reason);
|
|
42 |
print <<USAGE_EOF;
|
|
43 |
|
|
44 |
Usage: validate_sch12_model.pl <params> [options]
|
|
45 |
|
|
46 |
params:
|
|
47 |
-s <schedule12> XML version of Schedule 12
|
|
48 |
-m <system_model> XML version of System Model
|
|
49 |
|
|
50 |
options:
|
|
51 |
-o <whats_left> XML file showing unreferenced
|
|
52 |
parts of the System Model
|
|
53 |
-r Remove matched objects from -o output
|
|
54 |
-c <cbr_mapping> Tab separated file showing the Schedule 12
|
|
55 |
component for each MRP file
|
|
56 |
|
|
57 |
USAGE_EOF
|
|
58 |
exit(1);
|
|
59 |
}
|
|
60 |
|
|
61 |
use Getopt::Long;
|
|
62 |
|
|
63 |
my $schedule12file = "Symbian_OS_v9.1_Schedule12.xml";
|
|
64 |
my $systemmodelfile = "System_Definition.xml";
|
|
65 |
my $whatsleftfile = "";
|
|
66 |
my $remove = 0;
|
|
67 |
my $cbrmappingfile = "";
|
|
68 |
|
|
69 |
Usage("Bad arguments") unless GetOptions(
|
|
70 |
's=s' => \$schedule12file,
|
|
71 |
'm=s' => \$systemmodelfile,
|
|
72 |
'o=s' => \$whatsleftfile,
|
|
73 |
'r' => \$remove,
|
|
74 |
'c=s' => \$cbrmappingfile);
|
|
75 |
|
|
76 |
Usage("Too many arguments") if (scalar @ARGV > 0);
|
|
77 |
Usage("Cannot find $schedule12file") if (!-f $schedule12file);
|
|
78 |
Usage("Cannot find $systemmodelfile") if (!-f $systemmodelfile);
|
|
79 |
|
|
80 |
|
|
81 |
# Don't print info messages
|
|
82 |
sub my_fail
|
|
83 |
{
|
|
84 |
my $code = shift;
|
|
85 |
if ($code < 300)
|
|
86 |
{
|
|
87 |
XML::Checker::print_error ($code, @_);
|
|
88 |
}
|
|
89 |
}
|
|
90 |
$XML::Checker::FAIL = \&my_fail;
|
|
91 |
|
|
92 |
# Load the XML documents
|
|
93 |
my %expat_options =
|
|
94 |
(
|
|
95 |
KeepCDATA => 1,
|
|
96 |
Handlers => [],
|
|
97 |
);
|
|
98 |
|
|
99 |
my $xmlParser = new XML::DOM::ValParser(%expat_options);
|
|
100 |
XML::DOM::ignoreReadOnly(1);
|
|
101 |
|
|
102 |
my $sch12path = ".";
|
|
103 |
my $modelpath = ".";
|
|
104 |
$sch12path = $1 if ($schedule12file =~ /^(.+)\\[^\\]+$/);
|
|
105 |
$modelpath = $1 if ($systemmodelfile =~ /^(.+)\\[^\\]+$/);
|
|
106 |
$xmlParser->set_sgml_search_path($sch12path, $modelpath);
|
|
107 |
|
|
108 |
my $modelXML = $xmlParser->parsefile ($systemmodelfile);
|
|
109 |
my $sch12XML = $xmlParser->parsefile ($schedule12file);
|
|
110 |
|
|
111 |
# Collect the Schedule12 entries, checking for duplicates
|
|
112 |
|
|
113 |
my %sch12refs;
|
|
114 |
my %componenttype;
|
|
115 |
my ($sch12) = $sch12XML->getElementsByTagName("Schedule12");
|
|
116 |
Usage("No <Schedule12> in $schedule12file ?") if (!defined $sch12);
|
|
117 |
|
|
118 |
my @children = $sch12->getChildNodes;
|
|
119 |
foreach my $child (@children)
|
|
120 |
{
|
|
121 |
next if ($child->getNodeTypeName ne "ELEMENT_NODE");
|
|
122 |
my $tagname = $child->getTagName;
|
|
123 |
next if ($tagname eq "footnote");
|
|
124 |
my $component = $child->getAttribute("name");
|
|
125 |
$componenttype{$component} = $tagname;
|
|
126 |
|
|
127 |
my @entries = $child->getElementsByTagName("system_model");
|
|
128 |
if (scalar @entries == 0)
|
|
129 |
{
|
|
130 |
print STDERR "No system_model entries in $component\n";
|
|
131 |
next;
|
|
132 |
}
|
|
133 |
|
|
134 |
foreach my $entry (@entries)
|
|
135 |
{
|
|
136 |
my $name = $entry->getAttribute("entry");
|
|
137 |
if (defined $sch12refs{$name})
|
|
138 |
{
|
|
139 |
print STDERR "$name occurs in $sch12refs{$name} and $component\n";
|
|
140 |
}
|
|
141 |
else
|
|
142 |
{
|
|
143 |
$sch12refs{$name} = $component;
|
|
144 |
}
|
|
145 |
}
|
|
146 |
}
|
|
147 |
|
|
148 |
# Find the Schedule12 entries in the XML file
|
|
149 |
|
|
150 |
my %modelnames;
|
|
151 |
sub match_names($); # declare the prototype for recursive call
|
|
152 |
sub match_names($)
|
|
153 |
{
|
|
154 |
my ($node) = @_;
|
|
155 |
|
|
156 |
my @children = $node->getChildNodes;
|
|
157 |
foreach my $child (@children)
|
|
158 |
{
|
|
159 |
if ($child->getNodeTypeName ne "ELEMENT_NODE")
|
|
160 |
{
|
|
161 |
# text and comments don't count
|
|
162 |
next;
|
|
163 |
}
|
|
164 |
my $tagname = $child->getTagName;
|
|
165 |
if ($tagname eq "unit")
|
|
166 |
{
|
|
167 |
# units are detail inside the model, so they don't count
|
|
168 |
next;
|
|
169 |
}
|
|
170 |
my $name = $child->getAttribute("name");
|
|
171 |
if ($name)
|
|
172 |
{
|
|
173 |
if (defined $modelnames{$name})
|
|
174 |
{
|
|
175 |
print STDERR "Name $name occurs more than once in the System Model\n";
|
|
176 |
}
|
|
177 |
$modelnames{$name} = $tagname;
|
|
178 |
|
|
179 |
if (defined $sch12refs{$name})
|
|
180 |
{
|
|
181 |
$child->setAttribute("MATCHED", $sch12refs{$name});
|
|
182 |
$modelnames{$name} = "1";
|
|
183 |
}
|
|
184 |
}
|
|
185 |
match_names($child);
|
|
186 |
}
|
|
187 |
}
|
|
188 |
|
|
189 |
my ($model) = $modelXML->getElementsByTagName("systemModel");
|
|
190 |
|
|
191 |
match_names($model);
|
|
192 |
|
|
193 |
# Report on the accuracy of Schedule 12
|
|
194 |
print STDERR "\n";
|
|
195 |
my @allnames = ();
|
|
196 |
my $unmatched = 0;
|
|
197 |
foreach my $name (sort keys %sch12refs)
|
|
198 |
{
|
|
199 |
next if (defined $modelnames{$name});
|
|
200 |
push @allnames, "$name\t(Sch12 $sch12refs{$name})\n";
|
|
201 |
print STDERR "No match for $name (associated with $sch12refs{$name})\n";
|
|
202 |
$unmatched += 1;
|
|
203 |
}
|
|
204 |
if ($unmatched == 0)
|
|
205 |
{
|
|
206 |
print STDERR "All Schedule 12 entries matched in System Model\n";
|
|
207 |
}
|
|
208 |
else
|
|
209 |
{
|
|
210 |
printf STDERR "%d Schedule 12 entry references not matched (from a total of %d)\n", $unmatched, scalar keys %sch12refs;
|
|
211 |
}
|
|
212 |
|
|
213 |
# Remove the matched elements to leave the unmatched parts,
|
|
214 |
# and accumulate the MRP files for each Sch12 component
|
|
215 |
|
|
216 |
my %sch12bymrp;
|
|
217 |
my %locationbymrp;
|
|
218 |
|
|
219 |
sub list_mrps($$$); # declare the prototype for recursive call
|
|
220 |
sub list_mrps($$$)
|
|
221 |
{
|
|
222 |
my ($node,$location,$sch12name) = @_;
|
|
223 |
my @children = $node->getChildNodes;
|
|
224 |
my $nodename = $node->getAttribute("name");
|
|
225 |
|
|
226 |
my $sublocation = $nodename;
|
|
227 |
$sublocation = "$location/$nodename" if ($location ne "");
|
|
228 |
|
|
229 |
foreach my $child (@children)
|
|
230 |
{
|
|
231 |
if ($child->getNodeTypeName ne "ELEMENT_NODE")
|
|
232 |
{
|
|
233 |
# text and comments don't count
|
|
234 |
next;
|
|
235 |
}
|
|
236 |
my $tagname = $child->getTagName;
|
|
237 |
if ($tagname eq "unit" || $tagname eq "package" || $tagname eq "prebuilt")
|
|
238 |
{
|
|
239 |
# these elements have the mrp information, but no substructure
|
|
240 |
my $mrp = $child->getAttribute("mrp");
|
|
241 |
$mrp = $1 if ($mrp =~ /\\([^\\]+)\.mrp$/i);
|
|
242 |
$sch12bymrp{$mrp} = $sch12name;
|
|
243 |
$locationbymrp{$mrp} = "$location\t$nodename";
|
|
244 |
next;
|
|
245 |
}
|
|
246 |
my $submatch = $child->getAttribute("MATCHED");
|
|
247 |
if ($submatch)
|
|
248 |
{
|
|
249 |
list_mrps($child,$sublocation,$submatch);
|
|
250 |
}
|
|
251 |
else
|
|
252 |
{
|
|
253 |
list_mrps($child,$sublocation,$sch12name);
|
|
254 |
}
|
|
255 |
}
|
|
256 |
}
|
|
257 |
|
|
258 |
sub delete_matched($$); # declare the prototype for recursive call
|
|
259 |
sub delete_matched($$)
|
|
260 |
{
|
|
261 |
my ($node, $location) = @_;
|
|
262 |
my $nodename = $node->getAttribute("name");
|
|
263 |
|
|
264 |
my $sublocation = $nodename;
|
|
265 |
$sublocation = "$location/$nodename" if ($location ne "");
|
|
266 |
|
|
267 |
my @children = $node->getChildNodes;
|
|
268 |
return 0 if (scalar @children == 0);
|
|
269 |
my $now_empty = 1;
|
|
270 |
foreach my $child (@children)
|
|
271 |
{
|
|
272 |
if ($child->getNodeTypeName ne "ELEMENT_NODE")
|
|
273 |
{
|
|
274 |
# text and comments don't count
|
|
275 |
next;
|
|
276 |
}
|
|
277 |
my $sch12name = $child->getAttribute("MATCHED");
|
|
278 |
if ($sch12name)
|
|
279 |
{
|
|
280 |
list_mrps($child, $sublocation, $sch12name);
|
|
281 |
$node->removeChild($child) if ($remove);
|
|
282 |
}
|
|
283 |
else
|
|
284 |
{
|
|
285 |
if (delete_matched($child,$sublocation) == 1)
|
|
286 |
{
|
|
287 |
# Child was empty and can be removed
|
|
288 |
$node->removeChild($child) if ($remove);
|
|
289 |
}
|
|
290 |
else
|
|
291 |
{
|
|
292 |
list_mrps($child, $sublocation, "*UNREFERENCED*");
|
|
293 |
$now_empty = 0; # something left in due to this child
|
|
294 |
}
|
|
295 |
}
|
|
296 |
}
|
|
297 |
return $now_empty;
|
|
298 |
}
|
|
299 |
|
|
300 |
# scan the tagged model, recording various details as a side-effect
|
|
301 |
|
|
302 |
my $allgone = delete_matched($model,"");
|
|
303 |
|
|
304 |
if ($whatsleftfile ne "")
|
|
305 |
{
|
|
306 |
if ($allgone)
|
|
307 |
{
|
|
308 |
print STDERR "System Model is completely covered by Schedule 12\n";
|
|
309 |
}
|
|
310 |
else
|
|
311 |
{
|
|
312 |
$modelXML->normalize;
|
|
313 |
$modelXML->printToFile($whatsleftfile);
|
|
314 |
print STDERR "Remains of System Model written to $whatsleftfile\n";
|
|
315 |
}
|
|
316 |
}
|
|
317 |
|
|
318 |
if ($cbrmappingfile ne "")
|
|
319 |
{
|
|
320 |
$componenttype{"*UNREFERENCED*"} = "??";
|
|
321 |
open CBRMAP, ">$cbrmappingfile" or die("Unable to write to $cbrmappingfile: $!\n");
|
|
322 |
foreach my $mrp (sort keys %sch12bymrp)
|
|
323 |
{
|
|
324 |
my $component = $sch12bymrp{$mrp};
|
|
325 |
my $comptype = $componenttype{$component};
|
|
326 |
my $location = $locationbymrp{$mrp};
|
|
327 |
print CBRMAP "$mrp\t$location\t$component\t$comptype\n";
|
|
328 |
}
|
|
329 |
close CBRMAP;
|
|
330 |
print STDERR "MRP -> Schedule 12 mapping written to $cbrmappingfile\n";
|
|
331 |
}
|
|
332 |
|
|
333 |
exit 0;
|