|
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 # Split a system model file into many package model files (one per package) |
|
14 |
|
15 use strict; |
|
16 use Getopt::Long; |
|
17 use XML::DOM; |
|
18 |
|
19 my $DEFAULT_OUTDIR = "models"; |
|
20 |
|
21 my $sysdef = ''; |
|
22 my $outdir = $DEFAULT_OUTDIR; |
|
23 my $help = 0; |
|
24 GetOptions(( |
|
25 'sysdef=s' => \$sysdef, |
|
26 'outdir:s' => \$outdir, |
|
27 'help!' => \$help |
|
28 )); |
|
29 |
|
30 $help = 1 if (!$sysdef); |
|
31 |
|
32 if ($help) |
|
33 { |
|
34 print "Split a system model file into many package model files (one per package)\n"; |
|
35 print "Usage: perl split_sysdef.pl --sysdef=FILE [OPTIONS]\n"; |
|
36 print "where:\n"; |
|
37 print "\tFILE is the input file to split\n"; |
|
38 print "and OPTIONS are:\n"; |
|
39 print "\t--outdir=DIR Generate package model files under DIR (default: $DEFAULT_OUTDIR)\n"; |
|
40 exit(0); |
|
41 } |
|
42 |
|
43 mkdir("$outdir") if (!-d$outdir); |
|
44 |
|
45 my $parser = new XML::DOM::Parser; |
|
46 my $doc = $parser->parsefile ($sysdef); |
|
47 |
|
48 # fix bldFile and mrp paths |
|
49 for my $unit ( $doc->getElementsByTagName("unit") ) |
|
50 { |
|
51 my $bldfile = $unit->getAttribute("bldFile"); |
|
52 if ($bldfile) |
|
53 { |
|
54 $bldfile =~ s,\\,/,g; |
|
55 $bldfile = "/$bldfile" if ( $bldfile !~ m,^/, ); |
|
56 $bldfile = "/sf$bldfile" if ( $bldfile !~ m,^/sf, ); |
|
57 if ($bldfile =~ m,^/sf/(os|mw|app|tools|ostools|adaptation)/,) |
|
58 { |
|
59 $unit->setAttribute("bldFile", $bldfile); |
|
60 } |
|
61 else |
|
62 { |
|
63 print "WARNING: unexpected path in bldFile: $bldfile. Keeping as is\n"; |
|
64 } |
|
65 } |
|
66 |
|
67 my $mrp = $unit->getAttribute("mrp"); |
|
68 if ($mrp) |
|
69 { |
|
70 $mrp =~ s,\\,/,g; |
|
71 $mrp = "/$mrp" if ( $mrp !~ m,^/, ); |
|
72 $mrp = "/sf$mrp" if ( $mrp !~ m,^/sf, ); |
|
73 if ($mrp =~ m,^/sf/(os|mw|app|tools|ostools|adaptation)/,) |
|
74 { |
|
75 $unit->setAttribute("mrp", $mrp); |
|
76 } |
|
77 else |
|
78 { |
|
79 print "WARNING: unexpected path in mrp: $mrp. Keeping as is\n" ; |
|
80 } |
|
81 } |
|
82 } |
|
83 |
|
84 my $packagedef_header = ''; |
|
85 my $packagedef_trailer = ''; |
|
86 |
|
87 my $systemdefinition = $doc->getElementsByTagName("SystemDefinition")->item(0); |
|
88 my $systemdefinition_attributes = $systemdefinition->getAttributes(); |
|
89 my $systemdefinition_attributes_tostring = ''; |
|
90 for ($systemdefinition_attributes->getValues) {$systemdefinition_attributes_tostring .= " ".$_->getName."=\"".$_->getValue."\"";} |
|
91 $packagedef_header .= "<SystemDefinition$systemdefinition_attributes_tostring>\n"; |
|
92 $packagedef_trailer = "\n</SystemDefinition>".$packagedef_trailer; |
|
93 |
|
94 my $systemmodel = $systemdefinition->getElementsByTagName("systemModel")->item(0); |
|
95 my $systemmodel_attributes = $systemmodel->getAttributes(); |
|
96 my $systemmodel_attributes_tostring = ''; |
|
97 for ($systemmodel_attributes->getValues) {$systemmodel_attributes_tostring .= " ".$_->getName."=\"".$_->getValue."\"";} |
|
98 $packagedef_header .= "<systemModel$systemmodel_attributes_tostring>\n"; |
|
99 $packagedef_trailer = "\n</systemModel>".$packagedef_trailer; |
|
100 |
|
101 for my $layer ( $systemmodel->getElementsByTagName("layer") ) |
|
102 { |
|
103 my $layer_name = $layer->getAttribute("name"); |
|
104 |
|
105 my $layer_attributes = $layer->getAttributes(); |
|
106 my $layer_attributes_tostring = ''; |
|
107 for ($layer_attributes->getValues) {$layer_attributes_tostring .= " ".$_->getName."=\"".$_->getValue."\"";} |
|
108 my $layer_header = "<layer$layer_attributes_tostring>\n"; |
|
109 my $layer_trailer = "\n</layer>"; |
|
110 |
|
111 for my $block ( $layer->getElementsByTagName("block") ) |
|
112 { |
|
113 my $block_name = $block->getAttribute("name"); |
|
114 |
|
115 mkdir("$outdir/$layer_name") if (!-d "$outdir/$layer_name"); |
|
116 mkdir("$outdir/$layer_name/$block_name") if (!-d "$outdir/$layer_name/$block_name"); |
|
117 |
|
118 # what source code doesn't belong to this package ? |
|
119 for my $unit ( $block->getElementsByTagName("unit") ) |
|
120 { |
|
121 my $bldinf = $unit->getAttribute("bldFile"); |
|
122 if ($bldinf and $bldinf !~ m,^/sf/$layer_name/$block_name,) |
|
123 { |
|
124 print "WARNING: $bldinf is in package: $layer_name/$block_name\n"; |
|
125 } |
|
126 } |
|
127 |
|
128 open(FILE, ">$outdir/$layer_name/$block_name/package_definition.xml"); |
|
129 print FILE $doc->getXMLDecl->toString."\n" if ($doc->getXMLDecl); |
|
130 print FILE $doc->getDoctype->toString."\n" if ($doc->getDoctype); |
|
131 print FILE $packagedef_header; |
|
132 print FILE $layer_header; |
|
133 print FILE $block->toString; |
|
134 print FILE $layer_trailer; |
|
135 print FILE $packagedef_trailer; |
|
136 close(FILE); |
|
137 } |
|
138 } |
|
139 |
|
140 $doc->dispose; |
|
141 |