metatools/sysdeftools/joinsysdef.pl
author Bob Rosenberg <bob.rosenberg@nokia.com>
Thu, 12 Aug 2010 15:59:45 +0100
changeset 636 29e6a24e9521
parent 624 f70b728ea30c
child 657 5720fe8b820c
permissions -rw-r--r--
More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
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
636
29e6a24e9521 More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 624
diff changeset
    41
my $errCount=0;
624
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    42
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    43
my @newarg;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    44
foreach my $a (@ARGV)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    45
	{ #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
    46
	if($a=~s/^-I//)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    47
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    48
		push(@includes,$a);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    49
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    50
	else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    51
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    52
		push(@newarg,$a);
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
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    55
@ARGV=@newarg;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    56
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    57
# 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
    58
GetOptions
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    59
	(
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    60
	 'path=s' => \$path,
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    61
	'output=s' => \$output,
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    62
	'config=s' => \@config,
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    63
	'exclude-meta=s' => \@excludeMetaList
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
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    66
# -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
    67
#	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
    68
#	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
    69
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    70
# -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
    71
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    72
# -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
    73
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    74
# -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
    75
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    76
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    77
# 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
    78
# 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
    79
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    80
 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
    81
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    82
($#ARGV == -1 ) && &help();
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    83
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
    84
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    85
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    86
my %excludeMeta;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    87
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
    88
foreach (@cannotExclude)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    89
	{
636
29e6a24e9521 More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 624
diff changeset
    90
	if($excludeMeta{$_})
29e6a24e9521 More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 624
diff changeset
    91
		{
29e6a24e9521 More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 624
diff changeset
    92
		print STDERR "Error: Cannot exclude meta rel=\"$_\"\n";
29e6a24e9521 More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 624
diff changeset
    93
		$errCount++;
29e6a24e9521 More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 624
diff changeset
    94
		}
624
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    95
	$excludeMeta{$_}=0
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
    96
	}	# 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
    97
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
# 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
   100
my %rootmap = &rootMap($path,$sysdef);	
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   101
my %nsmap;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   102
my %urimap;
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
foreach my $conf (@config) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   105
	{ # run cpp to get all #defines
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   106
	&getDefines($conf);
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
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   109
my $parser = new XML::DOM::Parser;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   110
my   $sysdefdoc = $parser->parsefile ($sysdef);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   111
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   112
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   113
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
   114
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   115
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   116
# 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
   117
# 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
   118
#   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
   119
#	maybe skipping the contends of <meta>
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   120
my @nslist = &namespaces($sysdef,$sysdefdoc->getDocumentElement());
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   121
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   122
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   123
while(@nslist)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   124
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   125
	my $uri = shift(@nslist);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   126
	my $prefix =shift(@nslist);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   127
	if($prefix eq 'id namespace'){$prefix=''}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   128
	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
   129
	$urimap{$uri} = $prefix;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   130
	if($nsmap{$prefix})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   131
		{ # 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
   132
		if($uri=~/http:\/\/(www\.)?([^.\/]+)\./) {$prefix = $2}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   133
		my $i=0;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   134
		while($nsmap{$prefix})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   135
			{ # still no prefix, just make up 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   136
			$prefix="ns$i";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   137
			$i++;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   138
			# 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
   139
			$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
   140
			}
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
	$nsmap{$prefix}=$uri;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   143
	}
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
my $docroot =  $sysdefdoc->getDocumentElement;
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
my $ns = $docroot->getAttribute('id-namespace');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   148
if(!$ns && $nsmap{''})
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
	$docroot->setAttribute('id-namespace',$nsmap{''});
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   151
	}
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
$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
   154
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
while(my($pre,$uri) = each(%nsmap))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   157
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   158
	$pre ne '' || next ;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   159
	$docroot->setAttribute("xmlns:$pre",$uri);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   160
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   161
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   162
&walk($sysdef,$docroot);	# process the XML
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   163
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
# print to file or stdout
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   166
if($output eq '') 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   167
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   168
	print $sysdefdoc->toString;
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
else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   171
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   172
	$sysdefdoc->printToFile($output);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   173
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   174
636
29e6a24e9521 More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 624
diff changeset
   175
$errCount && die "Fatal syntax errors";
624
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
sub abspath
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   178
	{ 	# 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
   179
	my  ($name,$path) = fileparse($_[0]);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   180
	$path=~tr,\\,/,;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   181
	if( -e $path)
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
		return abs_path($path)."/$name";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   184
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   185
	my @dir = split('/',$_[0]);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   186
	my @new;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   187
	foreach my $d (@dir)
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
		if($d eq '.') {next}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   190
		if($d eq '..')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   191
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   192
			pop(@new);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   193
			next;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   194
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   195
		push(@new,$d)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   196
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   197
	return join('/',@new);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   198
	}
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
sub rootMap {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   201
	my @pathdirs = split(/\//,$_[0]);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   202
	my @rootdirs = split(/\//,$_[1]);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   203
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   204
	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
   205
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   206
		pop(@rootdirs);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   207
		pop(@pathdirs);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   208
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   209
	return (join('/',@rootdirs)  => join('/',@pathdirs) );
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
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   212
sub rootMapMeta {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   213
	# 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
   214
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   215
	foreach my $child (@{$node->getChildNodes})
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
			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
   218
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   219
				my $from = $child->getAttribute('link');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   220
				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
   221
				$rootmap{$from} = $to;
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
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   224
	# 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
   225
	$node->getParentNode->removeChild($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   226
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   227
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   228
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   229
sub walk
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   230
	{ 	# 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
   231
	my $file = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   232
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   233
	my $type = $node->getNodeType;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   234
	if($type!=1) {return}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   235
	my $tag = $node->getTagName;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   236
	if($tag=~/^(layer|package|collection|component)$/ )
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   237
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   238
		if($file eq $sysdef)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   239
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   240
			&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
   241
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   242
		my $link= $node->getAttribute('href');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   243
		if($link)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   244
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   245
			my $file = &resolvePath($file,$link); 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   246
			if(-e $file)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   247
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   248
				&combineLink($node,$file);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   249
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   250
			else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   251
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   252
				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
   253
				$node->removeAttribute('href');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   254
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   255
			return;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   256
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   257
		else 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   258
			{ # 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
   259
			my $id= $node->getAttribute('id');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   260
			my $p = $node->getParentNode();
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   261
			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
   262
			if(defined $ID{$id})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   263
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   264
				print STDERR "Error: duplicate ID: $tag \"$id\" in $ptext matches $ID{$id}\n";
636
29e6a24e9521 More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 624
diff changeset
   265
				$errCount++;
624
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
			else 
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
				my $p = $node->getParentNode();
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   270
				$ID{$id}="$tag in $ptext";
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
			}
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
	elsif($tag=~/^(SystemDefinition|systemModel)$/ )
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   275
		{
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
	elsif($tag eq 'unit')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   278
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   279
		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
   280
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   281
			my $link= $node->getAttribute($atr);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   282
			if($link && !($link=~/^\//))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   283
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   284
				$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
   285
				foreach my $a (keys %rootmap) {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   286
					$link=~s,^$a,$rootmap{$a},ie;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   287
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   288
				# 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
   289
				$link=~s,^\./([^/]),$1,; 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   290
				$node->setAttribute($atr,$link);
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
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   293
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   294
	elsif($tag eq 'meta')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   295
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   296
		my $rel= $node->getAttribute('rel') || 'Generic';
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   297
		if($excludeMeta{$rel})
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
			$node->getParentNode->removeChild($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   300
			return;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   301
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   302
		my $link= $node->getAttribute('href');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   303
		$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
   304
		if ($link ne '' ) 
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
			if($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
				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
   309
				next; # do not alter children
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   310
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   311
			if(! ($link=~/^\//))
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
				$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
   314
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   315
			if(! -e $link) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   316
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   317
				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
   318
				next; # do not alter children
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 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
   321
			# 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
   322
			my $item;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   323
			eval {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   324
				my  $metadoc = $parser->parsefile ($link);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   325
				$item = $metadoc->getDocumentElement;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   326
			};
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   327
			if(!$item)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   328
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   329
				print STDERR "Error: Could not process metadata file: $link\n";
636
29e6a24e9521 More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 624
diff changeset
   330
				$errCount++;
624
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   331
				next; # do not alter children
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   332
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   333
			$node->removeAttribute('href');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   334
			&blindCopyInto($node,$item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   335
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   336
		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
   337
			{# need to process this now
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   338
			&rootMapMeta($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   339
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   340
		return;
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
	else {return}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   343
	my $checkversion=0;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   344
	foreach my $item (@{$node->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   345
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   346
		#print $item->getNodeType,"\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   347
		&walk($file,$item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   348
		$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
   349
		}
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
	if($checkversion && scalar(@config))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   352
		{ # 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
   353
		&doCmpConfig($node);
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
	foreach my $item (@{$node->getChildNodes})
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
		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
   358
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   359
			&processMeta($item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   360
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   361
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   362
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   363
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   364
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   365
sub combineLink
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   366
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   367
	# 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
   368
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   369
	my $file = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   370
	my $getfromfile = &localfile($file);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   371
	$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
   372
	my  $doc = $parser->parsefile ($getfromfile);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   373
	my $item =&firstElement($doc->getDocumentElement);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   374
	$item || die "badly formatted $file";	
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   375
	&fixIDs($item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   376
	my %up = &atts($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   377
	my %down = &atts($item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   378
	$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
   379
	$node->removeAttribute('href');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   380
	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
   381
	foreach my $v (keys %down)
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
		$node->setAttribute($v,$down{$v})
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
	foreach my $child (@{$item->getChildNodes})
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
		&copyInto($node,$child);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   388
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   389
	&walk($file,$node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   390
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   391
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   392
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   393
sub blindCopyInto
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
	# 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
   396
	my $parent=shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   397
	my $item = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   398
	my $doc = $parent->getOwnerDocument;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   399
	my $type = $item->getNodeType;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   400
	my $new;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   401
	if($type==1) 
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
		$new = $doc->createElement($item->getTagName);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   404
		my %down = &atts($item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   405
		while(my($a,$b) = each(%down))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   406
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   407
			$new->setAttribute($a,$b);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   408
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   409
		foreach my $child (@{$item->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   410
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   411
			&blindCopyInto($new,$child);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   412
			}
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
	elsif($type==3) 
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
		$new = $doc->createTextNode ($item->getData);
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
	elsif($type==8) 
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
		$new = $doc->createComment  ($item->getData);
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
	if($new)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   423
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   424
		$parent->appendChild($new);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   425
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   426
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   427
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   428
sub copyInto
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
	# 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
   431
	my $parent=shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   432
	my $item = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   433
	my $doc = $parent->getOwnerDocument;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   434
	my $type = $item->getNodeType;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   435
	my $new;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   436
	if($type==1) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   437
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   438
		&fixIDs($item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   439
		$new = $doc->createElement($item->getTagName);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   440
		my %down = &atts($item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   441
		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
   442
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   443
			if($down{$ordered})
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
				$new->setAttribute($ordered,$down{$ordered});
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   446
				delete $down{$ordered}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   447
				}
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
		while(my($a,$b) = each(%down))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   450
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   451
			$new->setAttribute($a,$b);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   452
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   453
		foreach my $child (@{$item->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   454
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   455
			&copyInto($new,$child);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   456
			}
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
	elsif($type==3) 
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
		$new = $doc->createTextNode ($item->getData);
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
	elsif($type==8) 
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
		$new = $doc->createComment  ($item->getData);
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
	if($new)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   467
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   468
		$parent->appendChild($new);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   469
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   470
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   471
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   472
sub getNs
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
	# 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
   475
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   476
	my $pre = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   477
	my $uri = $node->getAttribute("xmlns:$pre");
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   478
	if($uri) {return $uri}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   479
	my $parent = $node->getParentNode;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   480
	if($parent && $parent->getNodeType==1)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   481
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   482
		return getNs($parent,$pre);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   483
		}
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
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
sub fixIDs
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
	# 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
   490
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   491
	foreach my $id ('id','before')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   492
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   493
		&fixID($node,$id);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   494
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   495
}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   496
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   497
sub fixID
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   498
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   499
	# 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
   500
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   501
	my $attr = shift || 'id';
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   502
	my $id = $node->getAttribute($attr);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   503
	if($id eq '') {return}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   504
	my $ns;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   505
	if($id=~s/^(.*)://)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   506
		{ # 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
   507
		my $pre = $1;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   508
		$ns=&getNs($node,$pre);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   509
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   510
	else
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
		$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
   513
			$defaultns;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   514
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   515
	$ns = $urimap{$ns};
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   516
	$id = ($ns eq '') ? $id : "$ns:$id";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   517
	return $node->setAttribute($attr,$id);
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
sub firstElement {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   521
	# 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
   522
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   523
	foreach my $item (@{$node->getChildNodes}) {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   524
		if($item->getNodeType==1) {return $item}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   525
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   526
}
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
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   529
sub atts {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   530
	# 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
   531
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   532
	my %at = $node->getAttributes;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   533
	my %list;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   534
	foreach my $a (keys %{$node->getAttributes}) 
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
		if($a ne '')
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   537
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   538
			$list{$a} = $node->getAttribute ($a);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   539
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   540
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   541
	return %list;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   542
}
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
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   545
sub ns 
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
	# 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
   548
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   549
	my %list;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   550
	foreach my $a (keys %{$node->getAttributes}) 
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
		my $pre = $a;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   553
		if($pre=~s/^xmlns://)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   554
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   555
			$list{$pre} = $node->getAttribute ($a);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   556
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   557
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   558
	return %list;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   559
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   560
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   561
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   562
sub resolvePath
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   563
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   564
	# 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
   565
	my $base = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   566
	my $path = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   567
	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
   568
	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
   569
	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
   570
	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
   571
	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
   572
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   573
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   574
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   575
sub resolveURI
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
	# 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
   578
	my $base = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   579
	my $path = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   580
	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
   581
	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
   582
	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
   583
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   584
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   585
sub localfile
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
	my $file = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   588
	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
   589
	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
   590
	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
   591
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   592
		print STDERR "ERROR: $1 scheme not supported\n";
636
29e6a24e9521 More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 624
diff changeset
   593
		$errCount++;
624
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   594
		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
   595
		} 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   596
	return $file
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   597
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   598
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   599
sub namespaces
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   600
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   601
	# 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
   602
	# 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
   603
	my $file = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   604
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   605
	my $type = $node->getNodeType;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   606
	if($type!=1) {return}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   607
	my $tag = $node->getTagName;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   608
	my @res;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   609
	my %nslist = &ns($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   610
	while(my($pre,$uri)=each(%nslist))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   611
		{ # 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
   612
		push(@res,$uri,$pre);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   613
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   614
	if($tag=~/^(layer|package|collection|component)$/ )
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   615
		{ # 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
   616
		my $link= $node->getAttribute('href');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   617
		if($link)
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
			$link=&resolvePath($file,$link);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   620
			if(-e $link)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   621
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   622
				my  $doc;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   623
				eval {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   624
					$doc = $parser->parsefile ($link);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   625
				};
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   626
				if($doc)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   627
					{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   628
					&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
   629
					my @docns = &namespaces($link,$doc->getDocumentElement);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   630
					undef $doc;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   631
					return (@res,@docns);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   632
					#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
   633
					}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   634
				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
   635
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   636
			# 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
   637
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   638
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   639
	elsif($tag eq 'SystemDefinition' )
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   640
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   641
		my $default = $node->getAttribute('id-namespace');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   642
		if($default)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   643
			{# 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
   644
			push(@res,$default,'id namespace');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   645
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   646
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   647
	foreach my $item (@{$node->getChildNodes})
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
		push(@res,&namespaces($file,$item));
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   650
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   651
	return @res;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   652
	}
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
sub processMeta
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   655
	{ # 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
   656
	my $metanode = shift;
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
	my $rel = $metanode->getAttribute('rel') || 'Generic';
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   659
	if($rel eq 'config' && scalar(@config))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   660
		{ # 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
   661
		&doconfig($metanode);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   662
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   663
	else 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   664
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   665
		# do nothing. Not supported yet
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   666
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   667
	}
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
sub doCmpConfig
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   670
	{ # 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
   671
	my $cmp = shift;	# the component node
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   672
	my @unversioned;	# list of all units with no version attribute (if more than one, they should all have filters defined)
636
29e6a24e9521 More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 624
diff changeset
   673
	my %versioned;		# hash table of all units with a specified version, it's a fatal error to have the same verison twice in one component
624
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   674
	foreach my $item (@{$cmp->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   675
		{ # 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
   676
		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
   677
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   678
			my $ver = $item->getAttribute('version');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   679
			if($ver eq '') {push(@unversioned,$item)}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   680
			else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   681
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   682
				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
   683
				$versioned{$ver}=$item;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   684
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   685
			}
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
	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
   688
	foreach my $pick (@picks)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   689
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   690
		my $ver = $pick->getAttribute('version');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   691
		if(!$versioned{$ver})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   692
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   693
			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
   694
			return;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   695
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   696
		if(&definedMatches($pick))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   697
			{ # remove all other units;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   698
			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
   699
			foreach my $unit (@unversioned, values(%versioned))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   700
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   701
				$cmp->removeChild($unit);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   702
				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
   703
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   704
			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
   705
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   706
		else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   707
			{ # remove this unit and continue
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   708
			$cmp->removeChild($versioned{$ver});
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   709
			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
   710
			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
   711
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   712
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   713
	if (scalar(@unversioned, values(%versioned)) > 1)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   714
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   715
		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
   716
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   717
	}
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
	
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   720
sub getMetaConfigPick
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   721
	{	# 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
   722
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   723
	my @pick;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   724
	while($node->getParentNode->getNodeType==1)
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
		foreach my $item (@{$node->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   727
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   728
			my @picks;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   729
			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
   730
				{ # it's conf metadata
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   731
				foreach my $p (@{$item->getChildNodes})
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
					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
   734
					}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   735
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   736
			@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
   737
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   738
		$node=$node->getParentNode;
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
	return @pick;
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
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   743
sub definedMatches
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   744
	{ # 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
   745
	my $node  = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   746
	my $match = 1;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   747
	foreach my $def (@{$node->getChildNodes})
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
		if($def->getNodeType == 1) 
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
			my $tag = $def->getTagName;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   752
			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
   753
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   754
				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
   755
				$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
   756
				$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
   757
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   758
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   759
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   760
		return $match;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   761
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   762
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   763
sub doconfig
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   764
	{ # 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
   765
	my $meta  = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   766
	my $keep = definedMatches($meta);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   767
	my $parent = $meta->getParentNode;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   768
	if(!$keep)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   769
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   770
		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
   771
		$parent->getParentNode->removeChild($parent);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   772
		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
   773
		}
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
	$parent->removeChild($meta);
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
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   778
sub getDefines
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   779
	{ # 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
   780
	my $file = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   781
	my $inc;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   782
	foreach my $i (@includes)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   783
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   784
		$inc.=" -I$i";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   785
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   786
	open(CPP,"cpp -dD$inc \"$file\"|");
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   787
	while(<CPP>)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   788
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   789
		if(!/\S/){next} # skip blank lines
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   790
		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
   791
		s/\s+$//;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   792
		if(s/^#define\s+(\S+)\((.*?)\)\s+//)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   793
			{ #parametered define
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   794
			push(@{$defineParams{$1}},@2,$_);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   795
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   796
		elsif(s/^#define\s+(\S+)//)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   797
			{ # normal define
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   798
			my $def = $1;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   799
			s/^\s+//;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   800
			$defines{$1}=$_;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   801
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   802
		else {die "cannot process $_";}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   803
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   804
	close CPP;
636
29e6a24e9521 More extensive error reporting in sysdef perl tools. Allow sysdef merging with an empty upstream model.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 624
diff changeset
   805
	$? && die "Error: Call to cpp produced an error";
624
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   806
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   807
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   808
sub  checkSyntaxVersion
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   809
	{ # 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
   810
	my $schema = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   811
	my @max=split(/\./,$maxschema);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   812
	my @cur=split(/\./,$schema);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   813
	while(@max) 
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
		($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
   816
		if($cur[0] > $max[0])
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
			$maxschema=$schema;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   819
			return;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   820
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   821
		shift @max;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   822
		shift @cur;
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
	# they are equal - do nothing
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
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   827
sub help
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   828
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   829
	my $name= $0; $name=~s,^.*[\\/],,;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   830
my $text;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   831
format STDERR =
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   832
 ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   833
  $text,
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   834
     ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   835
    $text
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   836
.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   837
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
   838
	foreach (
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   839
		"-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
   840
			"   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
   841
			"   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
   842
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   843
		"-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
   844
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   845
		"-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
   846
			"   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
   847
		"-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
   848
		"-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
   849
		) {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   850
		$text = $_;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   851
		write STDERR;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   852
		print STDERR "\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   853
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   854
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   855
	exit(1);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   856
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   857
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   858
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   859