metatools/sysdeftools/joinsysdef.pl
author Jon Chatten
Thu, 26 Aug 2010 13:41:01 +0100
changeset 630 31ef8a13d4f4
parent 624 f70b728ea30c
child 636 29e6a24e9521
permissions -rw-r--r--
sbs version 2.15.1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
624
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
     1
# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
     2
# All rights reserved.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
     3
# This component and the accompanying materials are made available
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
     4
# under the terms of "Eclipse Public License v1.0"
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
     5
# which accompanies this distribution, and is available
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
     7
#
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
     8
# Initial Contributors:
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
     9
# Nokia Corporation - initial contribution.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    10
#
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    11
# Contributors:
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    12
#
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    13
# Description:
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    14
#
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    15
#!/usr/bin/perl
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    16
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    17
use strict;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    18
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    19
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    20
use FindBin;		# for FindBin::Bin
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    21
use lib $FindBin::Bin;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    22
use lib "$FindBin::Bin/lib";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    23
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    24
use Cwd;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    25
use Cwd 'abs_path';
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    26
use Getopt::Long;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    27
use File::Basename;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    28
use File::Spec;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    29
use XML::DOM;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    30
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    31
my $output;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    32
my $path;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    33
my @config;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    34
my @includes;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    35
my %defineParams;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    36
my %defines;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    37
my $defaultns = 'http://www.symbian.org/system-definition';	# needed if no DTD
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    38
my @excludeMetaList;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    39
my @cannotExclude= ('link-mapping', 'config');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    40
my %ID;	# list of all IDs
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    41
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    42
my @newarg;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    43
foreach my $a (@ARGV)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    44
	{ #extract all -I parameters from the parameter list 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    45
	if($a=~s/^-I//)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    46
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    47
		push(@includes,$a);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    48
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    49
	else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    50
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    51
		push(@newarg,$a);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    52
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    53
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    54
@ARGV=@newarg;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    55
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    56
# need to add options for controlling which metas are filtered out and which are included inline
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    57
GetOptions
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    58
	(
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    59
	 'path=s' => \$path,
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    60
	'output=s' => \$output,
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    61
	'config=s' => \@config,
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    62
	'exclude-meta=s' => \@excludeMetaList
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    63
	);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    64
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    65
# -path specifies the full system-model path to the file which is being processed. 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    66
#	This must be an absolute path if you're processing a root sysdef.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    67
#	If processing a pkgdef file, you can use "./package_definition.xml" to leave all links relative. Though I can't really see the use case for this.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    68
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    69
# -output specifies the file to save the output to. If not specified this will write to stdout
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    70
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    71
# -config specifies the name of an .hrh file in which the configuration data is acquired from. If not set, no confguration will be done.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    72
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    73
# -I[path] specifies the include paths to use when resolving #includes in the .hrh file. Same syntax as cpp command uses. Any number of these can be provided.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    74
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    75
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    76
# if config is not set, no confguration will be done.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    77
# If it is set, all configuration metadata will be processed and stripped from the output, even if the confguration data is empty
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    78
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    79
 if($path eq '') {$path = '/os/deviceplatformrelease/foundation_system/system_model/system_definition.xml'}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    80
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    81
($#ARGV == -1 ) && &help();
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    82
my $sysdef = &abspath(shift);	# resolve the location of the root sysdef
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    83
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    84
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    85
my %excludeMeta;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    86
foreach (@excludeMetaList) {$excludeMeta{$_}=1}	# make list a hash table
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    87
foreach (@cannotExclude)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    88
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    89
	$excludeMeta{$_} && print STDERR "Error: Cannot exclude meta rel=\"$_\"\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    90
	$excludeMeta{$_}=0
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    91
	}	# cannot exclude any of these rel types
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    92
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    93
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    94
# rootmap is a mapping from the filesystem to the paths in the doc
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    95
my %rootmap = &rootMap($path,$sysdef);	
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    96
my %nsmap;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    97
my %urimap;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    98
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    99
foreach my $conf (@config) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   100
	{ # run cpp to get all #defines
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   101
	&getDefines($conf);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   102
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   103
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   104
my $parser = new XML::DOM::Parser;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   105
my   $sysdefdoc = $parser->parsefile ($sysdef);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   106
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   107
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   108
my $maxschema = $sysdefdoc->getDocumentElement()->getAttribute('schema');	# don't check value, just store it.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   109
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   110
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   111
# find all the namespaces used in all trhe fragments and use that 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   112
# to set the namespaces ni the root element of the created doc
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   113
#   should be able to optimise by only parsing each doc once and 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   114
#	maybe skipping the contends of <meta>
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   115
my @nslist = &namespaces($sysdef,$sysdefdoc->getDocumentElement());
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   116
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   117
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   118
while(@nslist)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   119
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   120
	my $uri = shift(@nslist);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   121
	my $prefix =shift(@nslist);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   122
	if($prefix eq 'id namespace'){$prefix=''}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   123
	if(defined $urimap{$uri}) {next} # already done this uri
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   124
	$urimap{$uri} = $prefix;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   125
	if($nsmap{$prefix})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   126
		{ # need a new prefix for this, guess from the URI (for readability)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   127
		if($uri=~/http:\/\/(www\.)?([^.\/]+)\./) {$prefix = $2}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   128
		my $i=0;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   129
		while($nsmap{$prefix})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   130
			{ # still no prefix, just make up 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   131
			$prefix="ns$i";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   132
			$i++;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   133
			# next line not really necessary, but it's a good safety to stop infinite loops
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   134
			$i eq 1000 && die "cannot create namespace prefix for $uri";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   135
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   136
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   137
	$nsmap{$prefix}=$uri;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   138
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   139
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   140
my $docroot =  $sysdefdoc->getDocumentElement;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   141
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   142
my $ns = $docroot->getAttribute('id-namespace');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   143
if(!$ns && $nsmap{''})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   144
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   145
	$docroot->setAttribute('id-namespace',$nsmap{''});
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   146
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   147
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   148
$docroot->setAttribute('schema',$maxschema);	# output has the largest syntax version of all includes
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   149
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   150
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   151
while(my($pre,$uri) = each(%nsmap))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   152
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   153
	$pre ne '' || next ;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   154
	$docroot->setAttribute("xmlns:$pre",$uri);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   155
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   156
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   157
&walk($sysdef,$docroot);	# process the XML
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   158
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   159
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   160
# print to file or stdout
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   161
if($output eq '') 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   162
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   163
	print $sysdefdoc->toString;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   164
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   165
else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   166
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   167
	$sysdefdoc->printToFile($output);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   168
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   169
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   170
 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   171
sub abspath
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   172
	{ 	# normalize the path into an absolute one
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   173
	my  ($name,$path) = fileparse($_[0]);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   174
	$path=~tr,\\,/,;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   175
	if( -e $path)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   176
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   177
		return abs_path($path)."/$name";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   178
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   179
	my @dir = split('/',$_[0]);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   180
	my @new;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   181
	foreach my $d (@dir)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   182
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   183
		if($d eq '.') {next}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   184
		if($d eq '..')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   185
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   186
			pop(@new);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   187
			next;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   188
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   189
		push(@new,$d)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   190
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   191
	return join('/',@new);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   192
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   193
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   194
sub rootMap {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   195
	my @pathdirs = split(/\//,$_[0]);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   196
	my @rootdirs = split(/\//,$_[1]);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   197
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   198
	while(lc($rootdirs[$#rootdirs])  eq lc($pathdirs[$#pathdirs])  )
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   199
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   200
		pop(@rootdirs);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   201
		pop(@pathdirs);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   202
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   203
	return (join('/',@rootdirs)  => join('/',@pathdirs) );
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   204
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   205
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   206
sub rootMapMeta {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   207
	# find all the explict path mapping from the link-mapping metadata
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   208
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   209
	foreach my $child (@{$node->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   210
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   211
			if ($child->getNodeType==1 && $child->getTagName eq 'map-prefix')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   212
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   213
				my $from = $child->getAttribute('link');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   214
				my $to = $child->getAttribute('to');		# optional, but blank if not set
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   215
				$rootmap{$from} = $to;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   216
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   217
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   218
	# once this is processed we have no more need for it. Remove from output
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   219
	$node->getParentNode->removeChild($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   220
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   221
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   222
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   223
sub walk
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   224
	{ 	# walk through the doc, resolving all links
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   225
	my $file = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   226
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   227
	my $type = $node->getNodeType;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   228
	if($type!=1) {return}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   229
	my $tag = $node->getTagName;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   230
	if($tag=~/^(layer|package|collection|component)$/ )
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   231
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   232
		if($file eq $sysdef)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   233
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   234
			&fixIDs($node);	# normalise all IDs in the root doc. Child docs are handled elsewhere.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   235
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   236
		my $link= $node->getAttribute('href');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   237
		if($link)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   238
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   239
			my $file = &resolvePath($file,$link); 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   240
			if(-e $file)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   241
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   242
				&combineLink($node,$file);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   243
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   244
			else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   245
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   246
				print STDERR "Note: $file not found\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   247
				$node->removeAttribute('href');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   248
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   249
			return;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   250
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   251
		else 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   252
			{ # only check for duplicate IDs on the implementation
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   253
			my $id= $node->getAttribute('id');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   254
			my $p = $node->getParentNode();
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   255
			my $ptext = $p->getTagName()." \"".$p->getAttribute('id')."\"";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   256
			if(defined $ID{$id})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   257
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   258
				print STDERR "Error: duplicate ID: $tag \"$id\" in $ptext matches $ID{$id}\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   259
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   260
			else 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   261
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   262
				my $p = $node->getParentNode();
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   263
				$ID{$id}="$tag in $ptext";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   264
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   265
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   266
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   267
	elsif($tag=~/^(SystemDefinition|systemModel)$/ )
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   268
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   269
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   270
	elsif($tag eq 'unit')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   271
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   272
		foreach my $atr ('bldFile','mrp','base','proFile')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   273
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   274
			my $link= $node->getAttribute($atr);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   275
			if($link && !($link=~/^\//))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   276
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   277
				$link= &abspath(File::Basename::dirname($file)."/$link");
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   278
				foreach my $a (keys %rootmap) {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   279
					$link=~s,^$a,$rootmap{$a},ie;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   280
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   281
				# remove leading ./  which is used to indicate that paths should remain relative
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   282
				$link=~s,^\./([^/]),$1,; 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   283
				$node->setAttribute($atr,$link);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   284
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   285
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   286
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   287
	elsif($tag eq 'meta')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   288
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   289
		my $rel= $node->getAttribute('rel') || 'Generic';
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   290
		if($excludeMeta{$rel})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   291
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   292
			$node->getParentNode->removeChild($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   293
			return;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   294
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   295
		my $link= $node->getAttribute('href');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   296
		$link=~s,^file://(/([a-z]:/))?,$2,; # convert file URI to absolute path
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   297
		if ($link ne '' ) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   298
			{ 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   299
			if($link=~/^[\/]+:/)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   300
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   301
				print STDERR "Note: Remote URL $link not embedded\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   302
				next; # do not alter children
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   303
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   304
			if(! ($link=~/^\//))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   305
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   306
				$link= &abspath(File::Basename::dirname($file)."/$link");
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   307
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   308
			if(! -e $link) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   309
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   310
				print STDERR "Warning: Local metadata file not found: $link\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   311
				next; # do not alter children
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   312
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   313
			# if we're here we can just embed the file
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   314
			# no processing logic is done! It's just embedded blindly
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   315
			my $item;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   316
			eval {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   317
				my  $metadoc = $parser->parsefile ($link);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   318
				$item = $metadoc->getDocumentElement;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   319
			};
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   320
			if(!$item)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   321
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   322
				print STDERR "Error: Could not process metadata file: $link\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   323
				next; # do not alter children
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   324
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   325
			$node->removeAttribute('href');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   326
			&blindCopyInto($node,$item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   327
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   328
		if($node->getAttribute('rel') eq 'link-mapping')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   329
			{# need to process this now
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   330
			&rootMapMeta($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   331
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   332
		return;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   333
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   334
	else {return}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   335
	my $checkversion=0;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   336
	foreach my $item (@{$node->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   337
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   338
		#print $item->getNodeType,"\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   339
		&walk($file,$item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   340
		$checkversion = $checkversion  || ($tag eq 'component' &&  $item->getNodeType==1 && $item->getAttribute('version') ne '');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   341
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   342
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   343
	if($checkversion && scalar(@config))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   344
		{ # need to check the conf metadata on the units in this component
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   345
		&doCmpConfig($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   346
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   347
	foreach my $item (@{$node->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   348
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   349
		if ($item->getNodeType==1 && $item->getTagName eq 'meta')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   350
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   351
			&processMeta($item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   352
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   353
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   354
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   355
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   356
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   357
sub combineLink
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   358
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   359
	# combine data from linked sysdef fragment w/ equivalent element in parent document
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   360
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   361
	my $file = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   362
	my $getfromfile = &localfile($file);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   363
	$getfromfile eq '' && return;  # already raised warning, no need to repeat
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   364
	my  $doc = $parser->parsefile ($getfromfile);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   365
	my $item =&firstElement($doc->getDocumentElement);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   366
	$item || die "badly formatted $file";	
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   367
	&fixIDs($item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   368
	my %up = &atts($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   369
	my %down = &atts($item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   370
	$up{'id'} eq $down{'id'}  || die "$up{id} differs from $down{id}";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   371
	$node->removeAttribute('href');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   372
	foreach my $v (keys %up) {delete $down{$v}}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   373
	foreach my $v (keys %down)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   374
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   375
		$node->setAttribute($v,$down{$v})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   376
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   377
	foreach my $child (@{$item->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   378
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   379
		&copyInto($node,$child);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   380
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   381
	&walk($file,$node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   382
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   383
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   384
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   385
sub blindCopyInto
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   386
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   387
	# make a deep copy the node (2nd arg) into the element (1st arg)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   388
	my $parent=shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   389
	my $item = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   390
	my $doc = $parent->getOwnerDocument;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   391
	my $type = $item->getNodeType;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   392
	my $new;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   393
	if($type==1) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   394
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   395
		$new = $doc->createElement($item->getTagName);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   396
		my %down = &atts($item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   397
		while(my($a,$b) = each(%down))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   398
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   399
			$new->setAttribute($a,$b);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   400
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   401
		foreach my $child (@{$item->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   402
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   403
			&blindCopyInto($new,$child);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   404
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   405
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   406
	elsif($type==3) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   407
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   408
		$new = $doc->createTextNode ($item->getData);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   409
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   410
	elsif($type==8) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   411
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   412
		$new = $doc->createComment  ($item->getData);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   413
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   414
	if($new)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   415
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   416
		$parent->appendChild($new);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   417
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   418
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   419
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   420
sub copyInto
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   421
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   422
	# make a deep copy the node (2nd arg) into the element (1st arg)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   423
	my $parent=shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   424
	my $item = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   425
	my $doc = $parent->getOwnerDocument;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   426
	my $type = $item->getNodeType;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   427
	my $new;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   428
	if($type==1) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   429
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   430
		&fixIDs($item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   431
		$new = $doc->createElement($item->getTagName);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   432
		my %down = &atts($item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   433
		foreach my $ordered ('id','name','bldFile','mrp','level','levels','introduced','deprecated','filter')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   434
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   435
			if($down{$ordered})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   436
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   437
				$new->setAttribute($ordered,$down{$ordered});
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   438
				delete $down{$ordered}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   439
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   440
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   441
		while(my($a,$b) = each(%down))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   442
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   443
			$new->setAttribute($a,$b);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   444
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   445
		foreach my $child (@{$item->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   446
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   447
			&copyInto($new,$child);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   448
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   449
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   450
	elsif($type==3) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   451
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   452
		$new = $doc->createTextNode ($item->getData);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   453
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   454
	elsif($type==8) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   455
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   456
		$new = $doc->createComment  ($item->getData);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   457
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   458
	if($new)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   459
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   460
		$parent->appendChild($new);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   461
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   462
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   463
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   464
sub getNs
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   465
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   466
	# find the namespace URI that applies to the specified prefix.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   467
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   468
	my $pre = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   469
	my $uri = $node->getAttribute("xmlns:$pre");
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   470
	if($uri) {return $uri}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   471
	my $parent = $node->getParentNode;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   472
	if($parent && $parent->getNodeType==1)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   473
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   474
		return getNs($parent,$pre);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   475
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   476
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   477
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   478
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   479
sub fixIDs
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   480
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   481
	# translate the ID to use the root doc's namespaces 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   482
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   483
	foreach my $id ('id','before')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   484
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   485
		&fixID($node,$id);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   486
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   487
}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   488
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   489
sub fixID
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   490
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   491
	# translate the ID to use the root doc's namespaces 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   492
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   493
	my $attr = shift || 'id';
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   494
	my $id = $node->getAttribute($attr);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   495
	if($id eq '') {return}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   496
	my $ns;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   497
	if($id=~s/^(.*)://)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   498
		{ # it's got a ns, find out what it is
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   499
		my $pre = $1;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   500
		$ns=&getNs($node,$pre);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   501
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   502
	else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   503
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   504
		$ns = $node->getOwnerDocument->getDocumentElement->getAttribute("id-namespace") ||
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   505
			$defaultns;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   506
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   507
	$ns = $urimap{$ns};
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   508
	$id = ($ns eq '') ? $id : "$ns:$id";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   509
	return $node->setAttribute($attr,$id);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   510
}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   511
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   512
sub firstElement {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   513
	# return the first element in this node
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   514
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   515
	foreach my $item (@{$node->getChildNodes}) {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   516
		if($item->getNodeType==1) {return $item}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   517
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   518
}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   519
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   520
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   521
sub atts {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   522
	# return a hash of all attribtues defined for this element
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   523
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   524
	my %at = $node->getAttributes;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   525
	my %list;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   526
	foreach my $a (keys %{$node->getAttributes}) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   527
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   528
		if($a ne '')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   529
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   530
			$list{$a} = $node->getAttribute ($a);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   531
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   532
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   533
	return %list;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   534
}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   535
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   536
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   537
sub ns 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   538
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   539
	# return a hash of ns prefix and uri -- the xmlns: part is stripped off
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   540
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   541
	my %list;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   542
	foreach my $a (keys %{$node->getAttributes}) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   543
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   544
		my $pre = $a;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   545
		if($pre=~s/^xmlns://)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   546
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   547
			$list{$pre} = $node->getAttribute ($a);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   548
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   549
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   550
	return %list;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   551
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   552
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   553
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   554
sub resolvePath
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   555
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   556
	# return full path to 2nd arg relative to first (path or absolute URI)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   557
	my $base = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   558
	my $path = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   559
	if($path=~m,^/,) {return $path } # path is absolute, but has no drive. Let OS deal with it.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   560
	if($path=~s,^file:///([a-zA-Z]:/),$1,) {return $path } # file URI with drive letter
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   561
	if($path=~m,^file://,) {return $path } # file URI with no drive letter (unit-style). Just pass on as is with leading / and let OS deal with it
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   562
	if($path=~m,^[a-z0-9][a-z0-9]+:,i) {return $path } # absolute URI -- no idea how to handle, so just return
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   563
	return &abspath(File::Basename::dirname($base)."/$path");
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   564
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   565
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   566
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   567
sub resolveURI
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   568
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   569
	# return full path to 2nd arg relative to first (path or absolute URI)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   570
	my $base = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   571
	my $path = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   572
	if($path=~m,[a-z0-9][a-z0-9]+:,i) {return $path } # absolute URI -- just return
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   573
	if($path=~m,^/,) {return $path } # path is absolute, but has no drive. Let OS deal with it.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   574
	return &abspath(File::Basename::dirname($base)."/$path");
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   575
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   576
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   577
sub localfile
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   578
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   579
	my $file = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   580
	if($file=~s,file:///([a-zA-Z]:/),$1,) {return $file } # file URI with drive letter
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   581
	if($file=~m,file://,) {return $file } # file URI with no drive letter (unit-style). Just pass on as is with leading / and let OS deal with it
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   582
	if($file=~m,^([a-z0-9][a-z0-9]+):,i)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   583
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   584
		print STDERR "ERROR: $1 scheme not supported\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   585
		return;  # return empty string if not supported.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   586
		} 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   587
	return $file
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   588
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   589
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   590
sub namespaces
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   591
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   592
	# return a list of namespace URI / prefix pairs, in the order they're defined
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   593
	# these need to be used to define namespaces in the root element
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   594
	my $file = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   595
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   596
	my $type = $node->getNodeType;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   597
	if($type!=1) {return}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   598
	my $tag = $node->getTagName;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   599
	my @res;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   600
	my %nslist = &ns($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   601
	while(my($pre,$uri)=each(%nslist))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   602
		{ # push all namespaces defined here onto the list
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   603
		push(@res,$uri,$pre);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   604
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   605
	if($tag=~/^(layer|package|collection|component)$/ )
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   606
		{ # these have the potential of linking, so check for that
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   607
		my $link= $node->getAttribute('href');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   608
		if($link)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   609
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   610
			$link=&resolvePath($file,$link);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   611
			if(-e $link)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   612
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   613
				my  $doc;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   614
				eval {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   615
					$doc = $parser->parsefile ($link);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   616
				};
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   617
				if($doc)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   618
					{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   619
					&checkSyntaxVersion($doc->getDocumentElement->getAttribute('schema'));	# ensure we track we highest syntax number
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   620
					my @docns = &namespaces($link,$doc->getDocumentElement);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   621
					undef $doc;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   622
					return (@res,@docns);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   623
					#ignore any children nodes if this is a link
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   624
					}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   625
				print STDERR "Error: Malformed XML. Could not process $link\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   626
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   627
			# print STDERR "Note: $link not found\n";  -- no need to warm now. Do so later when trying to join
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   628
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   629
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   630
	elsif($tag eq 'SystemDefinition' )
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   631
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   632
		my $default = $node->getAttribute('id-namespace');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   633
		if($default)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   634
			{# mangle with a space so it's clear it's not a qname
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   635
			push(@res,$default,'id namespace');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   636
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   637
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   638
	foreach my $item (@{$node->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   639
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   640
		push(@res,&namespaces($file,$item));
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   641
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   642
	return @res;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   643
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   644
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   645
sub processMeta
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   646
	{ # acts upon any known <meta> and strips it from the output if it's used
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   647
	my $metanode = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   648
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   649
	my $rel = $metanode->getAttribute('rel') || 'Generic';
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   650
	if($rel eq 'config' && scalar(@config))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   651
		{ # only process if there is something to configure
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   652
		&doconfig($metanode);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   653
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   654
	else 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   655
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   656
		# do nothing. Not supported yet
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   657
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   658
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   659
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   660
sub doCmpConfig
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   661
	{ # configure in or out the units in a component
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   662
	my $cmp = shift;	# the component node
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   663
	my @unversioned;	# list of all units with no version attribute (if more than one, they should all have filters defined)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   664
	my %versioned;		# hash table of all units with a specified version, it's a fatal error to hav the same verison twice in one component
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   665
	foreach my $item (@{$cmp->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   666
		{ # populate %versioned and @unversioned to save processsing later
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   667
		if($item->getNodeType==1 && $item->getTagName eq 'unit')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   668
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   669
			my $ver = $item->getAttribute('version');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   670
			if($ver eq '') {push(@unversioned,$item)}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   671
			else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   672
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   673
				defined $versioned{$ver}  && die "Cannot have more than one unit with version $ver in the same component ".$cmp->getAttribute('id');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   674
				$versioned{$ver}=$item;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   675
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   676
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   677
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   678
	my @picks = &getMetaConfigPick($cmp); # the list, in order, of all <pick> elements that affect this component
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   679
	foreach my $pick (@picks)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   680
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   681
		my $ver = $pick->getAttribute('version');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   682
		if(!$versioned{$ver})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   683
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   684
			print STDERR "ERROR: Reference to invalid unit version $ver in component ",$cmp->getAttribute('id'),". Ignoring.\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   685
			return;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   686
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   687
		if(&definedMatches($pick))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   688
			{ # remove all other units;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   689
			delete $versioned{$ver}; # to avoid removing in loop
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   690
			foreach my $unit (@unversioned, values(%versioned))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   691
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   692
				$cmp->removeChild($unit);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   693
				print STDERR "Note: unit ",$unit->getAttribute('version')," in component " ,$cmp->getAttribute('id')," configured out\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   694
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   695
			last; # done. No more processing after first match
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   696
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   697
		else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   698
			{ # remove this unit and continue
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   699
			$cmp->removeChild($versioned{$ver});
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   700
			print STDERR "Note: unit $ver in component " ,$cmp->getAttribute('id')," configured out\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   701
			delete $versioned{$ver}; # gone, don't process anymore;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   702
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   703
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   704
	if (scalar(@unversioned, values(%versioned)) > 1)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   705
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   706
		print STDERR "Warning: component ",$cmp->getAttribute('id')," has more than one unit after configuration\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   707
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   708
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   709
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   710
	
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   711
sub getMetaConfigPick
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   712
	{	# return an array of all <pick> elements that affect the specified element
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   713
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   714
	my @pick;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   715
	while($node->getParentNode->getNodeType==1)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   716
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   717
		foreach my $item (@{$node->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   718
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   719
			my @picks;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   720
			if($item->getNodeType==1 &&  $item->getAttribute('rel') eq 'config') 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   721
				{ # it's conf metadata
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   722
				foreach my $p (@{$item->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   723
					{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   724
					if($p->getNodeType==1 &&  $p->getTagName eq 'pick') {push(@picks,$p)}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   725
					}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   726
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   727
			@pick=(@picks,@pick); # prepend this to the start;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   728
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   729
		$node=$node->getParentNode;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   730
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   731
	return @pick;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   732
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   733
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   734
sub definedMatches
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   735
	{ # process all <defined> and <not-defined> the specified element and return true or false if the combination matches
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   736
	my $node  = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   737
	my $match = 1;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   738
	foreach my $def (@{$node->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   739
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   740
		if($def->getNodeType == 1) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   741
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   742
			my $tag = $def->getTagName;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   743
			if($tag eq 'defined' or $tag eq 'not-defined')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   744
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   745
				my $var = $def->getAttribute('condition') || die "Must have condition set on all $tag elements";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   746
				$defineParams{$var} && die "Cannot use a macro with parameters as a feature flag: $var(".$defineParams{$var}->[0].")"; 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   747
				$match = $match &&  (($tag eq 'defined') ? defined($defines{$var}) : ! defined($defines{$var}));
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   748
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   749
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   750
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   751
		return $match;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   752
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   753
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   754
sub doconfig
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   755
	{ # confgure in or out a system model item that owns the specified <meta>, remove the <meta> when done.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   756
	my $meta  = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   757
	my $keep = definedMatches($meta);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   758
	my $parent = $meta->getParentNode;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   759
	if(!$keep)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   760
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   761
		print STDERR "Note: ",$parent->getTagName," " ,$parent->getAttribute('id')," configured out\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   762
		$parent->getParentNode->removeChild($parent);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   763
		return; # it's removed, so there's nothing else we can possibly do
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   764
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   765
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   766
	$parent->removeChild($meta);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   767
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   768
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   769
sub getDefines
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   770
	{ # populate the list of #defines from a specified .hrh file.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   771
	my $file = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   772
	my $inc;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   773
	foreach my $i (@includes)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   774
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   775
		$inc.=" -I$i";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   776
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   777
	open(CPP,"cpp -dD$inc \"$file\"|");
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   778
	while(<CPP>)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   779
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   780
		if(!/\S/){next} # skip blank lines
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   781
		if(/^# [0-9]+ /) {next} # don't care about these
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   782
		s/\s+$//;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   783
		if(s/^#define\s+(\S+)\((.*?)\)\s+//)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   784
			{ #parametered define
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   785
			push(@{$defineParams{$1}},@2,$_);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   786
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   787
		elsif(s/^#define\s+(\S+)//)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   788
			{ # normal define
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   789
			my $def = $1;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   790
			s/^\s+//;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   791
			$defines{$1}=$_;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   792
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   793
		else {die "cannot process $_";}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   794
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   795
	close CPP;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   796
	$? && die "Call to cpp produced an error";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   797
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   798
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   799
sub  checkSyntaxVersion
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   800
	{ # check if supplied version number is greater than $maxschema
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   801
	my $schema = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   802
	my @max=split(/\./,$maxschema);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   803
	my @cur=split(/\./,$schema);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   804
	while(@max) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   805
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   806
		($max[0] > $cur[0])  && return;		# max is bigger, do nothing
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   807
		if($cur[0] > $max[0])
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   808
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   809
			$maxschema=$schema;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   810
			return;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   811
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   812
		shift @max;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   813
		shift @cur;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   814
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   815
	# they are equal - do nothing
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   816
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   817
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   818
sub help
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   819
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   820
	my $name= $0; $name=~s,^.*[\\/],,;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   821
my $text;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   822
format STDERR =
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   823
 ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   824
  $text,
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   825
     ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   826
    $text
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   827
.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   828
print STDERR "usage: $name  [options...] sysdef\n  valid options are:\n\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   829
	foreach (
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   830
		"-path\tspecifies the full system-model path to the file which is being processed. By default this is  \"/os/deviceplatformrelease/foundation_system/system_model/system_definition.xml\"",
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   831
			"   This must be an absolute path if you're processing a root sysdef.",
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   832
			"   If processing a pkgdef file, you can use \"./package_definition.xml\" to leave all links relative.",
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   833
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   834
		"-output\tspecifies the file to save the output to. If not specified this will write to stdout",
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   835
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   836
		"-config\tspecifies the name of an .hrh file in which the configuration data is acquired from. If not set, no confguration will be done.",
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   837
			"   If it is set, all configuration metadata will be processed and stripped from the output, even if the confguration data is empty",
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   838
		"-I[path]\tspecifies the include paths to use when resolving #includes in the .hrh file. This uses the same syntax as cpp command uses: a captial \"I\" followed by the path with no space in between. Any number of these can be provided.",
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   839
		"-exclude-meta [rel]\tspecifies the 'rel' value of <meta> elements to exclude from the output. Any number of these can be provided. The following meta rel values affect the processing of the system definition and cannot be excluded: ".join(', ',@cannotExclude)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   840
		) {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   841
		$text = $_;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   842
		write STDERR;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   843
		print STDERR "\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   844
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   845
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   846
	exit(1);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   847
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   848
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   849
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   850