common/tools/csvToSysDef.pl
author Simon Howkins <simonh@symbian.org>
Tue, 04 Aug 2009 12:20:40 +0100
changeset 330 f2e8947e085a
parent 329 06c2c867c6ad
child 331 f7c6fc4239ac
permissions -rw-r--r--
Added invokation to build.xml and adjusted path to backup locations to match my development environment.
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
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
     5
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
     6
use Data::Dumper;
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
     7
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
     8
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
my $sourcesCSV = shift or die "First arg must be source csv file";
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
shift and die "No more than one argument please";
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
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
    12
# 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
    13
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
    14
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
    15
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
    16
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
    17
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
    18
{
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
	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
    20
	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
    21
	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
    22
	{
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
		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
    24
		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
    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
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
	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
    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
		# 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
    30
		@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
    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
	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
    33
	{
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
		# 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
    35
		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
    36
		# 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
    37
		@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
    38
		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
    39
	}
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
}
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
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
    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
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
    44
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
    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
# 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
    47
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
    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
	warn "Warning: Package $package->{dst} does not appear on the local system\n" unless -d $package->{dst};
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
	# Look for the pkg defn in the root of the package 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
    51
	my $pkgDef = "$package->{dst}/$package->{sysdef}";
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
    52
	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
    53
	{
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
    54
		# Not there, so try the "backup" location
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
		$pkgDef =~ s{^/sf/}{};
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
    56
		$pkgDef =~ s{/[^/]*$}{};
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
    57
		# TODO: Where will this be on the build machine?
330
f2e8947e085a Added invokation to build.xml and adjusted path to backup locations to match my development environment.
Simon Howkins <simonh@symbian.org>
parents: 329
diff changeset
    58
		$pkgDef = "../../packages/3k/$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
	}
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
	die unless -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
    61
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
    62
	my $pkgTree = $parser->parsefile($pkgDef) 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
    63
	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
    64
	{
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
    65
		# 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
    66
		$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
    67
	}
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
    68
	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
    69
	{
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
		# 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
    71
		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
    72
	}
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
}
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
#print Data::Dumper->Dump([$outTree->[0]], ["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
    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
# Output total 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
print "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\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
    79
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
    80
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
    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
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
    83
{
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
	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
    85
	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
    86
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
    87
	die unless ref $baseTree eq ref $extrasTree;
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
    88
	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
    89
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
	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
    91
	{
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
		# 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
    93
		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
    94
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
		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
    96
		$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
    97
		
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
		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
    99
		{
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
			# 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
   101
#			warn "Always merge $extraChildTag";
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
			# 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
   103
			$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
   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
		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
   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 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
   108
#			warn "Sometimes merge $extraChildTag";
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
			# 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
   110
			$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
   111
		}
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
		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
   114
		{
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
			# 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
   116
			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
   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
		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
   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
			# 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
   121
			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
   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
	}
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
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
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
   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
	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
   129
	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
   130
	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
   131
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
	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
   133
	{
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
		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
   135
		{
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
			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
   137
		}
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
	
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
	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
   141
}
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
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
   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
	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
   146
	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
   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
	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
   149
	$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
   150
	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
   151
	{
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
		print $tree->{Text};
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
		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
   154
	}
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
	
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
	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
   157
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
   158
	foreach my $attr (grep { ! ref $tree->{$_} } keys %$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
   159
	{
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
   160
		print " $attr=\"$tree->{$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
   161
	}
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
   162
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
   163
	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
   164
	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
   165
	{
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
		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
   167
		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
   168
		{
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
			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
   170
		}
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
   171
		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
   172
	}
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
   173
	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
   174
	{
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
   175
		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
   176
	}
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
   177
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
   178
	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
   179
}
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
   180