metatools/sysdeftools/joinsysdef.pl
author Ross Qin <ross.qin@nokia.com>
Tue, 30 Nov 2010 13:59:58 +0800
changeset 712 df89378e9223
parent 660 66ff3e731c60
child 663 8e27d440923e
permissions -rw-r--r--
Fix these errors: Some cases of PREQ1230 fail because of buildrom issue rombuild crashs when create ext-romimage readimage crashes on reading wk42 vasco_ui core image vc2008 compiling issues
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
		{
660
66ff3e731c60 Sysdeftools additional support for merging misordered system definitions. More extensive validation. Minor bug fixes. Bash wrappers for perl scripts for unix installs.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 658
diff changeset
   279
		foreach my $atr ('bldFile','mrp','base')
624
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");
660
66ff3e731c60 Sysdeftools additional support for merging misordered system definitions. More extensive validation. Minor bug fixes. Bash wrappers for perl scripts for unix installs.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 658
diff changeset
   285
				foreach my $a (sort {length($b) - length($a)} keys(%rootmap)) {
624
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,; 
660
66ff3e731c60 Sysdeftools additional support for merging misordered system definitions. More extensive validation. Minor bug fixes. Bash wrappers for perl scripts for unix installs.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 658
diff changeset
   290
				# remove windows drive letter -- only allow paths on the same drive. Use root attribuite to build across drives / filesystems
66ff3e731c60 Sysdeftools additional support for merging misordered system definitions. More extensive validation. Minor bug fixes. Bash wrappers for perl scripts for unix installs.
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 658
diff changeset
   291
				$link=~s,^[a-z]:/,/,i;	
624
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   292
				$node->setAttribute($atr,$link);
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
			}
658
cab9da9b71bb Test and fail for badly invalid unit elements when joining
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 657
diff changeset
   295
		if(scalar @{$node->getChildNodes()} && $maxschema=~/^3\.0/)
cab9da9b71bb Test and fail for badly invalid unit elements when joining
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 657
diff changeset
   296
			{
cab9da9b71bb Test and fail for badly invalid unit elements when joining
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 657
diff changeset
   297
			die "Error: Fatal syntax error in $file. Unit elements must be empty in schema $maxschema.\n";
cab9da9b71bb Test and fail for badly invalid unit elements when joining
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 657
diff changeset
   298
			}
624
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   299
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   300
	elsif($tag eq 'meta')
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 $rel= $node->getAttribute('rel') || 'Generic';
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   303
		if($excludeMeta{$rel})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   304
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   305
			$node->getParentNode->removeChild($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   306
			return;
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
		my $link= $node->getAttribute('href');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   309
		$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
   310
		if ($link ne '' ) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   311
			{ 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   312
			if($link=~/^[\/]+:/)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   313
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   314
				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
   315
				next; # do not alter children
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
			if(! ($link=~/^\//))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   318
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   319
				$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
   320
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   321
			if(! -e $link) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   322
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   323
				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
   324
				next; # do not alter children
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   325
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   326
			# 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
   327
			# 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
   328
			my $item;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   329
			eval {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   330
				my  $metadoc = $parser->parsefile ($link);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   331
				$item = $metadoc->getDocumentElement;
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
			if(!$item)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   334
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   335
				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
   336
				$errCount++;
624
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   337
				next; # do not alter children
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   338
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   339
			$node->removeAttribute('href');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   340
			&blindCopyInto($node,$item);
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
		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
   343
			{# need to process this now
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   344
			&rootMapMeta($node);
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
		return;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   347
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   348
	else {return}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   349
	my $checkversion=0;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   350
	foreach my $item (@{$node->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   351
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   352
		#print $item->getNodeType,"\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   353
		&walk($file,$item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   354
		$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
   355
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   356
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   357
	if($checkversion && scalar(@config))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   358
		{ # 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
   359
		&doCmpConfig($node);
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
	foreach my $item (@{$node->getChildNodes})
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
		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
   364
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   365
			&processMeta($item);
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
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   368
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   369
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   370
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   371
sub combineLink
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   372
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   373
	# 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
   374
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   375
	my $file = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   376
	my $getfromfile = &localfile($file);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   377
	$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
   378
	my  $doc = $parser->parsefile ($getfromfile);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   379
	my $item =&firstElement($doc->getDocumentElement);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   380
	$item || die "badly formatted $file";	
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   381
	&fixIDs($item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   382
	my %up = &atts($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   383
	my %down = &atts($item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   384
	$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
   385
	$node->removeAttribute('href');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   386
	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
   387
	foreach my $v (keys %down)
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
		$node->setAttribute($v,$down{$v})
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
	foreach my $child (@{$item->getChildNodes})
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
		&copyInto($node,$child);
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
	&walk($file,$node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   396
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   397
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   398
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   399
sub blindCopyInto
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   400
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   401
	# 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
   402
	my $parent=shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   403
	my $item = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   404
	my $doc = $parent->getOwnerDocument;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   405
	my $type = $item->getNodeType;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   406
	my $new;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   407
	if($type==1) 
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
		$new = $doc->createElement($item->getTagName);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   410
		my %down = &atts($item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   411
		while(my($a,$b) = each(%down))
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
			$new->setAttribute($a,$b);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   414
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   415
		foreach my $child (@{$item->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   416
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   417
			&blindCopyInto($new,$child);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   418
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   419
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   420
	elsif($type==3) 
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
		$new = $doc->createTextNode ($item->getData);
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
	elsif($type==8) 
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
		$new = $doc->createComment  ($item->getData);
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
	if($new)
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
		$parent->appendChild($new);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   431
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   432
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   433
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   434
sub copyInto
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   435
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   436
	# 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
   437
	my $parent=shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   438
	my $item = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   439
	my $doc = $parent->getOwnerDocument;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   440
	my $type = $item->getNodeType;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   441
	my $new;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   442
	if($type==1) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   443
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   444
		&fixIDs($item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   445
		$new = $doc->createElement($item->getTagName);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   446
		my %down = &atts($item);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   447
		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
   448
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   449
			if($down{$ordered})
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($ordered,$down{$ordered});
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   452
				delete $down{$ordered}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   453
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   454
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   455
		while(my($a,$b) = each(%down))
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
			$new->setAttribute($a,$b);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   458
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   459
		foreach my $child (@{$item->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   460
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   461
			&copyInto($new,$child);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   462
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   463
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   464
	elsif($type==3) 
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
		$new = $doc->createTextNode ($item->getData);
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
	elsif($type==8) 
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
		$new = $doc->createComment  ($item->getData);
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
	if($new)
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
		$parent->appendChild($new);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   475
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   476
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   477
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   478
sub getNs
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   479
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   480
	# 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
   481
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   482
	my $pre = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   483
	my $uri = $node->getAttribute("xmlns:$pre");
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   484
	if($uri) {return $uri}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   485
	my $parent = $node->getParentNode;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   486
	if($parent && $parent->getNodeType==1)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   487
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   488
		return getNs($parent,$pre);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   489
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   490
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   491
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
sub fixIDs
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
	# 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
   496
	my $node = shift;
657
5720fe8b820c joinsysdef wasn't properly translating the namespace prefix for "replace".
Bob Rosenberg <bob.rosenberg@nokia.com>
parents: 636
diff changeset
   497
	foreach my $id ('id','before','replace')
624
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
		&fixID($node,$id);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   500
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   501
}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   502
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   503
sub fixID
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   504
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   505
	# 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
   506
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   507
	my $attr = shift || 'id';
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   508
	my $id = $node->getAttribute($attr);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   509
	if($id eq '') {return}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   510
	my $ns;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   511
	if($id=~s/^(.*)://)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   512
		{ # 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
   513
		my $pre = $1;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   514
		$ns=&getNs($node,$pre);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   515
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   516
	else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   517
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   518
		$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
   519
			$defaultns;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   520
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   521
	$ns = $urimap{$ns};
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   522
	$id = ($ns eq '') ? $id : "$ns:$id";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   523
	return $node->setAttribute($attr,$id);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   524
}
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
sub firstElement {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   527
	# 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
   528
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   529
	foreach my $item (@{$node->getChildNodes}) {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   530
		if($item->getNodeType==1) {return $item}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   531
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   532
}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   533
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   534
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   535
sub atts {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   536
	# 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
   537
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   538
	my %at = $node->getAttributes;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   539
	my %list;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   540
	foreach my $a (keys %{$node->getAttributes}) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   541
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   542
		if($a ne '')
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
			$list{$a} = $node->getAttribute ($a);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   545
			}
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 %list;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   548
}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   549
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   550
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   551
sub ns 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   552
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   553
	# 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
   554
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   555
	my %list;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   556
	foreach my $a (keys %{$node->getAttributes}) 
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
		my $pre = $a;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   559
		if($pre=~s/^xmlns://)
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
			$list{$pre} = $node->getAttribute ($a);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   562
			}
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 %list;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   565
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   566
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   567
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   568
sub resolvePath
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   569
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   570
	# 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
   571
	my $base = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   572
	my $path = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   573
	if($path=~m,^/,) {return $path } # path is absolute, but has no drive. Let OS deal with it.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   574
	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
   575
	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
   576
	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
   577
	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
   578
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   579
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   580
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   581
sub resolveURI
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   582
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   583
	# 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
   584
	my $base = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   585
	my $path = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   586
	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
   587
	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
   588
	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
   589
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   590
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   591
sub localfile
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   592
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   593
	my $file = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   594
	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
   595
	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
   596
	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
   597
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   598
		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
   599
		$errCount++;
624
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   600
		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
   601
		} 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   602
	return $file
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   603
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   604
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   605
sub namespaces
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   606
	{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   607
	# 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
   608
	# 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
   609
	my $file = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   610
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   611
	my $type = $node->getNodeType;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   612
	if($type!=1) {return}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   613
	my $tag = $node->getTagName;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   614
	my @res;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   615
	my %nslist = &ns($node);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   616
	while(my($pre,$uri)=each(%nslist))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   617
		{ # 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
   618
		push(@res,$uri,$pre);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   619
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   620
	if($tag=~/^(layer|package|collection|component)$/ )
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   621
		{ # 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
   622
		my $link= $node->getAttribute('href');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   623
		if($link)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   624
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   625
			$link=&resolvePath($file,$link);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   626
			if(-e $link)
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
				my  $doc;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   629
				eval {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   630
					$doc = $parser->parsefile ($link);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   631
				};
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   632
				if($doc)
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
					&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
   635
					my @docns = &namespaces($link,$doc->getDocumentElement);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   636
					undef $doc;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   637
					return (@res,@docns);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   638
					#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
   639
					}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   640
				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
   641
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   642
			# 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
   643
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   644
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   645
	elsif($tag eq 'SystemDefinition' )
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
		my $default = $node->getAttribute('id-namespace');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   648
		if($default)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   649
			{# 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
   650
			push(@res,$default,'id namespace');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   651
			}
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
	foreach my $item (@{$node->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   654
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   655
		push(@res,&namespaces($file,$item));
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   656
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   657
	return @res;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   658
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   659
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   660
sub processMeta
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   661
	{ # 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
   662
	my $metanode = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   663
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   664
	my $rel = $metanode->getAttribute('rel') || 'Generic';
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   665
	if($rel eq 'config' && scalar(@config))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   666
		{ # 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
   667
		&doconfig($metanode);
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
	else 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   670
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   671
		# do nothing. Not supported yet
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   672
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   673
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   674
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   675
sub doCmpConfig
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   676
	{ # 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
   677
	my $cmp = shift;	# the component node
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   678
	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
   679
	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
   680
	foreach my $item (@{$cmp->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   681
		{ # 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
   682
		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
   683
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   684
			my $ver = $item->getAttribute('version');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   685
			if($ver eq '') {push(@unversioned,$item)}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   686
			else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   687
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   688
				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
   689
				$versioned{$ver}=$item;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   690
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   691
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   692
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   693
	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
   694
	foreach my $pick (@picks)
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
		my $ver = $pick->getAttribute('version');
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   697
		if(!$versioned{$ver})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   698
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   699
			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
   700
			return;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   701
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   702
		if(&definedMatches($pick))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   703
			{ # remove all other units;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   704
			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
   705
			foreach my $unit (@unversioned, values(%versioned))
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   706
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   707
				$cmp->removeChild($unit);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   708
				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
   709
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   710
			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
   711
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   712
		else
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   713
			{ # remove this unit and continue
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   714
			$cmp->removeChild($versioned{$ver});
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   715
			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
   716
			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
   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
	if (scalar(@unversioned, values(%versioned)) > 1)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   720
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   721
		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
   722
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   723
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   724
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
sub getMetaConfigPick
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   727
	{	# 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
   728
	my $node = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   729
	my @pick;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   730
	while($node->getParentNode->getNodeType==1)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   731
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   732
		foreach my $item (@{$node->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   733
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   734
			my @picks;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   735
			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
   736
				{ # it's conf metadata
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   737
				foreach my $p (@{$item->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   738
					{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   739
					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
   740
					}
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
			@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
   743
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   744
		$node=$node->getParentNode;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   745
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   746
	return @pick;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   747
	}
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
sub definedMatches
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   750
	{ # 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
   751
	my $node  = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   752
	my $match = 1;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   753
	foreach my $def (@{$node->getChildNodes})
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   754
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   755
		if($def->getNodeType == 1) 
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   756
			{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   757
			my $tag = $def->getTagName;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   758
			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
   759
				{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   760
				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
   761
				$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
   762
				$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
   763
				}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   764
			}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   765
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   766
		return $match;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   767
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   768
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   769
sub doconfig
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   770
	{ # 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
   771
	my $meta  = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   772
	my $keep = definedMatches($meta);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   773
	my $parent = $meta->getParentNode;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   774
	if(!$keep)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   775
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   776
		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
   777
		$parent->getParentNode->removeChild($parent);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   778
		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
   779
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   780
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   781
	$parent->removeChild($meta);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   782
	}
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
sub getDefines
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   785
	{ # 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
   786
	my $file = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   787
	my $inc;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   788
	foreach my $i (@includes)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   789
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   790
		$inc.=" -I$i";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   791
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   792
	open(CPP,"cpp -dD$inc \"$file\"|");
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   793
	while(<CPP>)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   794
		{
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   795
		if(!/\S/){next} # skip blank lines
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   796
		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
   797
		s/\s+$//;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   798
		if(s/^#define\s+(\S+)\((.*?)\)\s+//)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   799
			{ #parametered define
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   800
			push(@{$defineParams{$1}},@2,$_);
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
		elsif(s/^#define\s+(\S+)//)
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   803
			{ # normal define
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   804
			my $def = $1;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   805
			s/^\s+//;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   806
			$defines{$1}=$_;
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
		else {die "cannot process $_";}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   809
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   810
	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
   811
	$? && 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
   812
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   813
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   814
sub  checkSyntaxVersion
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   815
	{ # 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
   816
	my $schema = shift;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   817
	my @max=split(/\./,$maxschema);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   818
	my @cur=split(/\./,$schema);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   819
	while(@max) 
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
		($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
   822
		if($cur[0] > $max[0])
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
			$maxschema=$schema;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   825
			return;
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
		shift @max;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   828
		shift @cur;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   829
		}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   830
	# they are equal - do nothing
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   831
	}
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
sub help
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
	my $name= $0; $name=~s,^.*[\\/],,;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   836
my $text;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   837
format STDERR =
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   838
 ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   839
  $text,
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   840
     ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   841
    $text
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   842
.
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   843
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
   844
	foreach (
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   845
		"-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
   846
			"   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
   847
			"   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
   848
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   849
		"-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
   850
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   851
		"-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
   852
			"   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
   853
		"-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
   854
		"-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
   855
		) {
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   856
		$text = $_;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   857
		write STDERR;
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   858
		print STDERR "\n";
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   859
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   860
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   861
	exit(1);
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   862
	}
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   863
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   864
f70b728ea30c Move sysdeftools from buildtools package into build package
Bob Rosenberg <bob.rosenberg@nokia.com>
parents:
diff changeset
   865