common/tools/csvToSysDef.pl
author Simon Howkins <simonh@symbian.org>
Wed, 20 Oct 2010 17:30:21 +0100
changeset 1282 2a30d4157ddd
parent 974 50e351dfaafe
child 1283 8d797b367538
permissions -rw-r--r--
Script now outputs info message if sources.csv specifies a file that's not in the package (irrespective of whether it will try to use it).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
329
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     1
#!perl -w
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     2
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     3
use strict;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     4
331
f7c6fc4239ac Fixed paths and drives for executing script.
Simon Howkins <simonh@symbian.org>
parents: 330
diff changeset
     5
use FindBin;
f7c6fc4239ac Fixed paths and drives for executing script.
Simon Howkins <simonh@symbian.org>
parents: 330
diff changeset
     6
use lib "$FindBin::Bin/lib";
f7c6fc4239ac Fixed paths and drives for executing script.
Simon Howkins <simonh@symbian.org>
parents: 330
diff changeset
     7
329
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     8
use XML::Parser;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     9
use Text::CSV;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    10
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    11
my $sourcesCSV = shift or die "First arg must be source csv file";
331
f7c6fc4239ac Fixed paths and drives for executing script.
Simon Howkins <simonh@symbian.org>
parents: 330
diff changeset
    12
my $backupBaseDir = shift or die "Second arg must be path to tree of package_definitions to use if not found in the source packages";
f7c6fc4239ac Fixed paths and drives for executing script.
Simon Howkins <simonh@symbian.org>
parents: 330
diff changeset
    13
shift and die "No more than two arguments please";
329
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    14
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    15
# Load CSV
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    16
open my $csvText, "<", $sourcesCSV or die;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    17
my $csv = Text::CSV->new();
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    18
my @keys;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    19
my @packages;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    20
while (my $line = <$csvText>)
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    21
{
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    22
	chomp $line;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    23
	next unless $line;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    24
	unless ($csv->parse($line))
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    25
	{
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    26
		my $err = $csv->error_input();
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    27
		die "Failed to parse line '$line': $err";
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    28
	}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    29
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    30
	if (! @keys)
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    31
	{
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    32
		# First line - note the column names
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    33
		@keys =  $csv->fields();
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    34
	}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    35
	else
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    36
	{
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    37
		# Already got the keys, so get the data
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    38
		my %package;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    39
		# Read into a hash slice
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    40
		@package{@keys} = $csv->fields();
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    41
		push @packages, \%package;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    42
	}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    43
}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    44
close $csvText;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    45
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    46
my $parser = new XML::Parser(Style => "Objects") or die;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    47
my $outTree;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    48
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    49
# For each package in CSV...
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    50
foreach my $package (@packages)
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    51
{
335
15307a7772ea If a package does not have a definition in the sources.csv then it won't get built, so don't try to incorporate it into the system definition.
Simon Howkins <simonh@symbian.org>
parents: 333
diff changeset
    52
	# If the sources.csv does not include a sys def for this package, it doesn't get built
15307a7772ea If a package does not have a definition in the sources.csv then it won't get built, so don't try to incorporate it into the system definition.
Simon Howkins <simonh@symbian.org>
parents: 333
diff changeset
    53
	next unless $package->{sysdef};
340
aee074ee2646 Changed preference for selecting package definition files, so that it takes the one from our tree in preference to the one in the package itself. This means that we can just delete items from our tree when we're happy to switch to using the one in the package (as this will vary from package to package).
Simon Howkins <simonh@symbian.org>
parents: 335
diff changeset
    54
	# If it's in the "backup" location, use that one (ie our copy overrides the package's own copy)
329
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    55
	my $pkgDef = "$package->{dst}/$package->{sysdef}";
340
aee074ee2646 Changed preference for selecting package definition files, so that it takes the one from our tree in preference to the one in the package itself. This means that we can just delete items from our tree when we're happy to switch to using the one in the package (as this will vary from package to package).
Simon Howkins <simonh@symbian.org>
parents: 335
diff changeset
    56
	$pkgDef =~ s{^/sf/}{};
aee074ee2646 Changed preference for selecting package definition files, so that it takes the one from our tree in preference to the one in the package itself. This means that we can just delete items from our tree when we're happy to switch to using the one in the package (as this will vary from package to package).
Simon Howkins <simonh@symbian.org>
parents: 335
diff changeset
    57
	$pkgDef =~ s{/[^/]*$}{};
aee074ee2646 Changed preference for selecting package definition files, so that it takes the one from our tree in preference to the one in the package itself. This means that we can just delete items from our tree when we're happy to switch to using the one in the package (as this will vary from package to package).
Simon Howkins <simonh@symbian.org>
parents: 335
diff changeset
    58
	$pkgDef = "$backupBaseDir/$pkgDef/package_definition.xml";
329
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    59
	if (!-f $pkgDef)
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    60
	{
340
aee074ee2646 Changed preference for selecting package definition files, so that it takes the one from our tree in preference to the one in the package itself. This means that we can just delete items from our tree when we're happy to switch to using the one in the package (as this will vary from package to package).
Simon Howkins <simonh@symbian.org>
parents: 335
diff changeset
    61
		# Not there, so look for the pkg defn in the root of the package tree
1282
2a30d4157ddd Script now outputs info message if sources.csv specifies a file that's not in the package (irrespective of whether it will try to use it).
Simon Howkins <simonh@symbian.org>
parents: 974
diff changeset
    62
		warn "WARNING: Package $package->{dst} does not appear on the local system\n" unless -d $package->{dst};
340
aee074ee2646 Changed preference for selecting package definition files, so that it takes the one from our tree in preference to the one in the package itself. This means that we can just delete items from our tree when we're happy to switch to using the one in the package (as this will vary from package to package).
Simon Howkins <simonh@symbian.org>
parents: 335
diff changeset
    63
		$pkgDef = "$package->{dst}/$package->{sysdef}";
329
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    64
	}
1282
2a30d4157ddd Script now outputs info message if sources.csv specifies a file that's not in the package (irrespective of whether it will try to use it).
Simon Howkins <simonh@symbian.org>
parents: 974
diff changeset
    65
	warn "INFO: sources.csv lists '$package->{sysdef}', which is not supplied in $package->{dst}\n" if -d "$package->{dst}" && !-f "$package->{dst}/$package->{sysdef}";
2a30d4157ddd Script now outputs info message if sources.csv specifies a file that's not in the package (irrespective of whether it will try to use it).
Simon Howkins <simonh@symbian.org>
parents: 974
diff changeset
    66
	die "ERROR: Unable to locate any package_definition at all for $package->{dst}" unless -f $pkgDef;
329
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    67
344
348670fc497a Added output of the package definition incorporated for each package.
Simon Howkins <simonh@symbian.org>
parents: 341
diff changeset
    68
	warn "Including $pkgDef for $package->{dst}\n";
333
7b0a774a0c87 Made error messages more useful.
Simon Howkins <simonh@symbian.org>
parents: 331
diff changeset
    69
	my $pkgTree = eval { $parser->parsefile($pkgDef) } or die "Failed to parse $pkgDef : $@";
329
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    70
	if (!$outTree)
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    71
	{
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    72
		# The first file is taken verbatim
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    73
		$outTree = $pkgTree;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    74
	}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    75
	else
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    76
	{
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    77
		# Merge into output Tree
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    78
		mergeTrees($outTree->[0], $pkgTree->[0]);
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    79
	}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    80
}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    81
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    82
# Output total tree
340
aee074ee2646 Changed preference for selecting package definition files, so that it takes the one from our tree in preference to the one in the package itself. This means that we can just delete items from our tree when we're happy to switch to using the one in the package (as this will vary from package to package).
Simon Howkins <simonh@symbian.org>
parents: 335
diff changeset
    83
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
329
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    84
printTree($outTree->[0]);
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    85
print "\n";
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    86
340
aee074ee2646 Changed preference for selecting package definition files, so that it takes the one from our tree in preference to the one in the package itself. This means that we can just delete items from our tree when we're happy to switch to using the one in the package (as this will vary from package to package).
Simon Howkins <simonh@symbian.org>
parents: 335
diff changeset
    87
exit;
aee074ee2646 Changed preference for selecting package definition files, so that it takes the one from our tree in preference to the one in the package itself. This means that we can just delete items from our tree when we're happy to switch to using the one in the package (as this will vary from package to package).
Simon Howkins <simonh@symbian.org>
parents: 335
diff changeset
    88
329
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    89
sub mergeTrees
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    90
{
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    91
	my $baseTree = shift or die;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    92
	my $extrasTree = shift or die;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    93
333
7b0a774a0c87 Made error messages more useful.
Simon Howkins <simonh@symbian.org>
parents: 331
diff changeset
    94
	die ("Package Definitions do not match: ".(ref $baseTree)." vs ".(ref $extrasTree)) unless ref $baseTree eq ref $extrasTree;
329
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    95
	return if ref $baseTree eq "main::Characters";
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    96
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    97
	foreach my $extraChild (@{$extrasTree->{Kids}})
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    98
	{
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    99
		# Work out whether this child should be merged with a namesake, or appended
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   100
		my $mergeIt = undef;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   101
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   102
		my $extraChildTag = ref $extraChild;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   103
		$extraChildTag =~ s{^main::}{};
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   104
		
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   105
		if ($extraChildTag =~ m{^(SystemDefinition|systemModel)$})
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   106
		{
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   107
			# Should be merged if there's already one there
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   108
			# Look for a namesake in the base
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   109
			$mergeIt = matchTag($baseTree->{Kids}, $extraChild, undef);
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   110
		}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   111
		elsif ($extraChildTag =~ m{layer|block|package|collection|component})
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   112
		{
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   113
			# Should be merged if there is another tag with the same "name" attribute
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   114
			# Look for a namesake in the base
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   115
			$mergeIt = matchTag($baseTree->{Kids}, $extraChild, "name");
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   116
		}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   117
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   118
		if ($mergeIt)
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   119
		{
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   120
			# Merge children
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   121
			mergeTrees($mergeIt, $extraChild);
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   122
		}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   123
		else
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   124
		{
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   125
			# Add this child
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   126
			push @{$baseTree->{Kids}}, $extraChild;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   127
		}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   128
	}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   129
}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   130
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   131
sub matchTag
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   132
{
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   133
	my $peers = shift;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   134
	my $outsider = shift;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   135
	my $attr = shift;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   136
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   137
	foreach my $peer (@$peers)
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   138
	{
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   139
		if (ref $peer eq ref $outsider && (!defined $attr || $peer->{$attr} eq $outsider->{$attr}))
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   140
		{
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   141
			return $peer;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   142
		}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   143
	}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   144
	
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   145
	return undef;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   146
}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   147
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   148
sub printTree
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   149
{
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   150
	my $tree = shift or die;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   151
	die unless ref $tree;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   152
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   153
	my $tagName = ref $tree;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   154
	$tagName =~ s{^main::}{};
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   155
	if ($tagName eq "Characters")
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   156
	{
959
94716c328941 Fix canonical_system_definition.xml doesn't have XML special characters escaped
Dario Sestito <darios@symbian.org>
parents: 344
diff changeset
   157
		if ($tree->{Text} =~ m{[<>&]})
94716c328941 Fix canonical_system_definition.xml doesn't have XML special characters escaped
Dario Sestito <darios@symbian.org>
parents: 344
diff changeset
   158
		{
94716c328941 Fix canonical_system_definition.xml doesn't have XML special characters escaped
Dario Sestito <darios@symbian.org>
parents: 344
diff changeset
   159
			print "<![CDATA[$tree->{Text}]]>";
94716c328941 Fix canonical_system_definition.xml doesn't have XML special characters escaped
Dario Sestito <darios@symbian.org>
parents: 344
diff changeset
   160
		}
94716c328941 Fix canonical_system_definition.xml doesn't have XML special characters escaped
Dario Sestito <darios@symbian.org>
parents: 344
diff changeset
   161
		else
94716c328941 Fix canonical_system_definition.xml doesn't have XML special characters escaped
Dario Sestito <darios@symbian.org>
parents: 344
diff changeset
   162
		{
94716c328941 Fix canonical_system_definition.xml doesn't have XML special characters escaped
Dario Sestito <darios@symbian.org>
parents: 344
diff changeset
   163
			print $tree->{Text};
94716c328941 Fix canonical_system_definition.xml doesn't have XML special characters escaped
Dario Sestito <darios@symbian.org>
parents: 344
diff changeset
   164
		}
329
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   165
		return;
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   166
	}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   167
	
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   168
	print "<$tagName";
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   169
340
aee074ee2646 Changed preference for selecting package definition files, so that it takes the one from our tree in preference to the one in the package itself. This means that we can just delete items from our tree when we're happy to switch to using the one in the package (as this will vary from package to package).
Simon Howkins <simonh@symbian.org>
parents: 335
diff changeset
   170
	foreach my $attr (
aee074ee2646 Changed preference for selecting package definition files, so that it takes the one from our tree in preference to the one in the package itself. This means that we can just delete items from our tree when we're happy to switch to using the one in the package (as this will vary from package to package).
Simon Howkins <simonh@symbian.org>
parents: 335
diff changeset
   171
		sort {
974
50e351dfaafe Update csvToSysDef.pl to understand proFile and qmakeArgs attributes
Shabe Razvi <shaber@symbian.org>
parents: 959
diff changeset
   172
			my $order = "name long-name tech_domain level span schema levels filter introduced deprecated purpose class plugin origin-model bldFile proFile qmakeArgs mrp version priority";
340
aee074ee2646 Changed preference for selecting package definition files, so that it takes the one from our tree in preference to the one in the package itself. This means that we can just delete items from our tree when we're happy to switch to using the one in the package (as this will vary from package to package).
Simon Howkins <simonh@symbian.org>
parents: 335
diff changeset
   173
			my $ixA = index $order, $a;
aee074ee2646 Changed preference for selecting package definition files, so that it takes the one from our tree in preference to the one in the package itself. This means that we can just delete items from our tree when we're happy to switch to using the one in the package (as this will vary from package to package).
Simon Howkins <simonh@symbian.org>
parents: 335
diff changeset
   174
			my $ixB = index $order, $b;
aee074ee2646 Changed preference for selecting package definition files, so that it takes the one from our tree in preference to the one in the package itself. This means that we can just delete items from our tree when we're happy to switch to using the one in the package (as this will vary from package to package).
Simon Howkins <simonh@symbian.org>
parents: 335
diff changeset
   175
			die "$a $b" if $ixA + $ixB == -2;
aee074ee2646 Changed preference for selecting package definition files, so that it takes the one from our tree in preference to the one in the package itself. This means that we can just delete items from our tree when we're happy to switch to using the one in the package (as this will vary from package to package).
Simon Howkins <simonh@symbian.org>
parents: 335
diff changeset
   176
			$ixA - $ixB;
aee074ee2646 Changed preference for selecting package definition files, so that it takes the one from our tree in preference to the one in the package itself. This means that we can just delete items from our tree when we're happy to switch to using the one in the package (as this will vary from package to package).
Simon Howkins <simonh@symbian.org>
parents: 335
diff changeset
   177
		}
aee074ee2646 Changed preference for selecting package definition files, so that it takes the one from our tree in preference to the one in the package itself. This means that we can just delete items from our tree when we're happy to switch to using the one in the package (as this will vary from package to package).
Simon Howkins <simonh@symbian.org>
parents: 335
diff changeset
   178
		grep {
aee074ee2646 Changed preference for selecting package definition files, so that it takes the one from our tree in preference to the one in the package itself. This means that we can just delete items from our tree when we're happy to switch to using the one in the package (as this will vary from package to package).
Simon Howkins <simonh@symbian.org>
parents: 335
diff changeset
   179
			! ref $tree->{$_}
aee074ee2646 Changed preference for selecting package definition files, so that it takes the one from our tree in preference to the one in the package itself. This means that we can just delete items from our tree when we're happy to switch to using the one in the package (as this will vary from package to package).
Simon Howkins <simonh@symbian.org>
parents: 335
diff changeset
   180
		}
aee074ee2646 Changed preference for selecting package definition files, so that it takes the one from our tree in preference to the one in the package itself. This means that we can just delete items from our tree when we're happy to switch to using the one in the package (as this will vary from package to package).
Simon Howkins <simonh@symbian.org>
parents: 335
diff changeset
   181
		keys %$tree)
329
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   182
	{
959
94716c328941 Fix canonical_system_definition.xml doesn't have XML special characters escaped
Dario Sestito <darios@symbian.org>
parents: 344
diff changeset
   183
		my $value_escaped = $tree->{$attr};
94716c328941 Fix canonical_system_definition.xml doesn't have XML special characters escaped
Dario Sestito <darios@symbian.org>
parents: 344
diff changeset
   184
		$value_escaped =~ s/&/&amp;/g;
94716c328941 Fix canonical_system_definition.xml doesn't have XML special characters escaped
Dario Sestito <darios@symbian.org>
parents: 344
diff changeset
   185
		$value_escaped =~ s/</&lt;/g;
94716c328941 Fix canonical_system_definition.xml doesn't have XML special characters escaped
Dario Sestito <darios@symbian.org>
parents: 344
diff changeset
   186
		$value_escaped =~ s/>/&gt;/g;
94716c328941 Fix canonical_system_definition.xml doesn't have XML special characters escaped
Dario Sestito <darios@symbian.org>
parents: 344
diff changeset
   187
		print " $attr=\"$value_escaped\"";
329
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   188
	}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   189
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   190
	my $children = $tree->{Kids};
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   191
	if (scalar @$children)
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   192
	{
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   193
		print ">";
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   194
		foreach my $child (@$children)
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   195
		{
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   196
			printTree($child);
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   197
		}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   198
		print "</$tagName";
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   199
	}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   200
	else
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   201
	{
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   202
		print "/"
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   203
	}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   204
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   205
	print ">";
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   206
}
06c2c867c6ad Added tool for collating a build definition from the set of package defintions indicated by the sources.csv
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   207