common/tools/split_sysdef.pl
author Simon Howkins <simonh@symbian.org>
Wed, 20 Oct 2010 15:19:52 +0100
changeset 1313 116cb28ed586
parent 1241 776ca456c221
permissions -rw-r--r--
Removed the tools copy of create-canonical-sysdef-file, as it can use the common version. Removed test for Helium 7 as it's now standard.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1067
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     1
# Copyright (c) 2009 Symbian Foundation Ltd
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     2
# This component and the accompanying materials are made available
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     3
# under the terms of the License "Eclipse Public License v1.0"
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     4
# which accompanies this distribution, and is available
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     5
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     6
#
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     7
# Initial Contributors:
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     8
# Symbian Foundation Ltd - initial contribution.
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     9
#
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    10
# Contributors:
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    11
#
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    12
# Description:
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    13
# Split a system model file into many package model files (one per package)
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    14
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    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
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    17
use Getopt::Long;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    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
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    20
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    21
my $DEFAULT_OUTDIR = "models";
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    22
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    23
my $sysdef = '';
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    24
my $outdir = $DEFAULT_OUTDIR;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    25
my $help = 0;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    26
GetOptions((
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    27
	'sysdef=s' => \$sysdef,
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    28
	'outdir:s' => \$outdir,
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    29
	'help!' => \$help
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    30
));
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    31
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    32
$help = 1 if (!$sysdef);
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    33
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    34
if ($help)
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    35
{
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    36
	print "Split a system model file into many package model files (one per package)\n";
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    37
	print "Usage: perl split_sysdef.pl --sysdef=FILE [OPTIONS]\n";
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    38
	print "where:\n";
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    39
	print "\tFILE is the input file to split\n";
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    40
	print "and OPTIONS are:\n";
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    41
	print "\t--outdir=DIR Generate package model files under DIR (default: $DEFAULT_OUTDIR)\n";
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    42
	exit(0);
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    43
}
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    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
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    46
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    47
my $parser = new XML::DOM::Parser;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    48
my $doc = $parser->parsefile ($sysdef);
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    49
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    50
# fix bldFile and mrp paths
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    51
for my $unit ( $doc->getElementsByTagName("unit") )
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    52
{
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    53
	my $bldfile = $unit->getAttribute("bldFile");
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    54
	if ($bldfile)
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    55
	{
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    56
		$bldfile =~ s,\\,/,g;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    57
		$bldfile = "/$bldfile" if ( $bldfile !~ m,^/, );
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    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
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    60
		{
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    61
			$unit->setAttribute("bldFile", $bldfile);
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    62
		}
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    63
		else
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    64
		{
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    65
			print "WARNING: unexpected path in bldFile: $bldfile. Keeping as is\n";
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    66
		}
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    67
	}
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    68
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    69
	my $mrp = $unit->getAttribute("mrp");
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    70
	if ($mrp)
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    71
	{
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    72
		$mrp =~ s,\\,/,g;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    73
		$mrp = "/$mrp" if ( $mrp !~ m,^/, );
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    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
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    76
		{
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    77
			$unit->setAttribute("mrp", $mrp);
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    78
		}
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    79
		else
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    80
		{
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    81
			print "WARNING: unexpected path in mrp: $mrp. Keeping as is\n" ;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    82
		}
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    83
	}
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    84
}
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    85
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    86
my $packagedef_header = '';
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    87
my $packagedef_trailer = '';
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    88
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    89
my $systemdefinition = $doc->getElementsByTagName("SystemDefinition")->item(0);
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    90
my $systemdefinition_attributes = $systemdefinition->getAttributes();
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    91
my $systemdefinition_attributes_tostring = '';
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    92
for ($systemdefinition_attributes->getValues) {$systemdefinition_attributes_tostring .= " ".$_->getName."=\"".$_->getValue."\"";}
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    93
$packagedef_header .= "<SystemDefinition$systemdefinition_attributes_tostring>\n";
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    94
$packagedef_trailer = "\n</SystemDefinition>".$packagedef_trailer;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    95
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    96
my $systemmodel = $systemdefinition->getElementsByTagName("systemModel")->item(0);
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    97
my $systemmodel_attributes = $systemmodel->getAttributes();
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    98
my $systemmodel_attributes_tostring = '';
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    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
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   102
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   103
for my $layer ( $systemmodel->getElementsByTagName("layer") )
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   104
{
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   105
	my $layer_name = $layer->getAttribute("name");
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   106
	
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   107
	my $layer_attributes = $layer->getAttributes();
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   108
	my $layer_attributes_tostring = '';
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   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
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   112
	
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   113
	for my $block ( $layer->getElementsByTagName("block") )
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   114
	{
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   115
		my $block_name = $block->getAttribute("name");
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   116
		
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   117
		mkdir("$outdir/$layer_name") if (!-d "$outdir/$layer_name");
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   118
		mkdir("$outdir/$layer_name/$block_name") if (!-d "$outdir/$layer_name/$block_name");
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   119
		
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   120
		# what source code doesn't belong to this package ?
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   121
		for my $unit ( $block->getElementsByTagName("unit") )
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   122
		{
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   123
			my $bldinf = $unit->getAttribute("bldFile");
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   124
			if ($bldinf and $bldinf !~ m,^/sf/$layer_name/$block_name,)
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   125
			{
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   126
				print "WARNING: $bldinf is in package: $layer_name/$block_name\n";
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   127
			}
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   128
		}
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   129
		
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   130
		open(FILE, ">$outdir/$layer_name/$block_name/package_definition.xml");
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   131
		print FILE $doc->getXMLDecl->toString."\n" if ($doc->getXMLDecl);
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   132
		print FILE $doc->getDoctype->toString."\n" if ($doc->getDoctype);
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   133
		print FILE $packagedef_header;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   134
		print FILE $layer_header;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   135
		print FILE $block->toString;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   136
		print FILE $layer_trailer;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   137
		print FILE $packagedef_trailer;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   138
		close(FILE);
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   139
	}
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   140
}
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   141
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   142
$doc->dispose;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   143