split_sysdef.pl
author Dario Sestito <darios@symbian.org>
Wed, 19 May 2010 14:48:47 +0100
changeset 1071 12d6ff1e30cc
parent 1067 bab959d5bc37
permissions -rw-r--r--
Fix all symbian3 package_definition have disappeared from packages
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;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    16
use Getopt::Long;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    17
use XML::DOM;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    18
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    19
my $DEFAULT_OUTDIR = "models";
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 $sysdef = '';
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    22
my $outdir = $DEFAULT_OUTDIR;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    23
my $help = 0;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    24
GetOptions((
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    25
	'sysdef=s' => \$sysdef,
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    26
	'outdir:s' => \$outdir,
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    27
	'help!' => \$help
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    28
));
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    29
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    30
$help = 1 if (!$sysdef);
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
if ($help)
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
	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
    35
	print "Usage: perl split_sysdef.pl --sysdef=FILE [OPTIONS]\n";
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    36
	print "where:\n";
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    37
	print "\tFILE is the input file to split\n";
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    38
	print "and OPTIONS are:\n";
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    39
	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
    40
	exit(0);
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    41
}
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    42
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    43
mkdir("$outdir") if (!-d$outdir);
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    44
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    45
my $parser = new XML::DOM::Parser;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    46
my $doc = $parser->parsefile ($sysdef);
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    47
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    48
# fix bldFile and mrp paths
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    49
for my $unit ( $doc->getElementsByTagName("unit") )
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    50
{
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    51
	my $bldfile = $unit->getAttribute("bldFile");
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    52
	if ($bldfile)
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    53
	{
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    54
		$bldfile =~ s,\\,/,g;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    55
		$bldfile = "/$bldfile" if ( $bldfile !~ m,^/, );
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    56
		$bldfile = "/sf$bldfile" if ( $bldfile !~ m,^/sf, );
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    57
		if ($bldfile =~ m,^/sf/(os|mw|app|tools|ostools|adaptation)/,)
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    58
		{
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    59
			$unit->setAttribute("bldFile", $bldfile);
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
		else
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
			print "WARNING: unexpected path in bldFile: $bldfile. Keeping as is\n";
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
	}
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
	my $mrp = $unit->getAttribute("mrp");
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    68
	if ($mrp)
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    69
	{
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    70
		$mrp =~ s,\\,/,g;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    71
		$mrp = "/$mrp" if ( $mrp !~ m,^/, );
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    72
		$mrp = "/sf$mrp" if ( $mrp !~ m,^/sf, );
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    73
		if ($mrp =~ m,^/sf/(os|mw|app|tools|ostools|adaptation)/,)
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    74
		{
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    75
			$unit->setAttribute("mrp", $mrp);
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
		else
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
			print "WARNING: unexpected path in mrp: $mrp. Keeping as is\n" ;
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
	}
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
my $packagedef_header = '';
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    85
my $packagedef_trailer = '';
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    86
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    87
my $systemdefinition = $doc->getElementsByTagName("SystemDefinition")->item(0);
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    88
my $systemdefinition_attributes = $systemdefinition->getAttributes();
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    89
my $systemdefinition_attributes_tostring = '';
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    90
for ($systemdefinition_attributes->getValues) {$systemdefinition_attributes_tostring .= " ".$_->getName."=\"".$_->getValue."\"";}
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    91
$packagedef_header .= "<SystemDefinition$systemdefinition_attributes_tostring>\n";
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    92
$packagedef_trailer = "\n</SystemDefinition>".$packagedef_trailer;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    93
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    94
my $systemmodel = $systemdefinition->getElementsByTagName("systemModel")->item(0);
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    95
my $systemmodel_attributes = $systemmodel->getAttributes();
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    96
my $systemmodel_attributes_tostring = '';
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    97
for ($systemmodel_attributes->getValues) {$systemmodel_attributes_tostring .= " ".$_->getName."=\"".$_->getValue."\"";}
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    98
$packagedef_header .= "<systemModel$systemmodel_attributes_tostring>\n";
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    99
$packagedef_trailer = "\n</systemModel>".$packagedef_trailer;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   100
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   101
for my $layer ( $systemmodel->getElementsByTagName("layer") )
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
	my $layer_name = $layer->getAttribute("name");
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_attributes = $layer->getAttributes();
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   106
	my $layer_attributes_tostring = '';
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   107
	for ($layer_attributes->getValues) {$layer_attributes_tostring .= " ".$_->getName."=\"".$_->getValue."\"";}
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   108
	my $layer_header = "<layer$layer_attributes_tostring>\n";
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   109
	my $layer_trailer = "\n</layer>";
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   110
	
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   111
	for my $block ( $layer->getElementsByTagName("block") )
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
		my $block_name = $block->getAttribute("name");
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
		mkdir("$outdir/$layer_name") if (!-d "$outdir/$layer_name");
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   116
		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
   117
		
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   118
		# what source code doesn't belong to this package ?
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   119
		for my $unit ( $block->getElementsByTagName("unit") )
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   120
		{
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   121
			my $bldinf = $unit->getAttribute("bldFile");
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   122
			if ($bldinf and $bldinf !~ m,^/sf/$layer_name/$block_name,)
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   123
			{
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   124
				print "WARNING: $bldinf is in package: $layer_name/$block_name\n";
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
		}
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
		open(FILE, ">$outdir/$layer_name/$block_name/package_definition.xml");
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   129
		print FILE $doc->getXMLDecl->toString."\n" if ($doc->getXMLDecl);
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   130
		print FILE $doc->getDoctype->toString."\n" if ($doc->getDoctype);
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   131
		print FILE $packagedef_header;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   132
		print FILE $layer_header;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   133
		print FILE $block->toString;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   134
		print FILE $layer_trailer;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   135
		print FILE $packagedef_trailer;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   136
		close(FILE);
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   137
	}
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   138
}
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
$doc->dispose;
bab959d5bc37 Fix some issues
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   141