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