common/tools/brag/raptorToBRAG.pl
author Brendan Donegan brendand@symbian.org
Wed, 07 Oct 2009 11:09:46 +0100
changeset 612 78ccc60a13b1
parent 547 19f9d5fc6406
child 556 fa2414b24dc4
permissions -rw-r--r--
fixed up multimedia to match fts
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
547
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     1
#!perl -w
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     2
#
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     3
# Copyright (c) 2009 Symbian Foundation Ltd
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     4
# This component and the accompanying materials are made available
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     6
# which accompanies this distribution, and is available
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     8
#
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     9
# Initial Contributors:
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    10
# Symbian Foundation Ltd - initial contribution.
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    11
#
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    12
# Contributors:
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    13
#
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    14
# Description:
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    15
# Generate the BRAG-compatible XML summary of the Raptor log from the CSV output of the raptor parser
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    16
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    17
use strict;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    18
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    19
use Getopt::Long;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    20
use Text::CSV;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    21
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    22
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    23
my $raptorSummary;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    24
my $help = 0;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    25
GetOptions((
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    26
	'raptorsummary=s' => \$raptorSummary,
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    27
	'help!' => \$help
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    28
));
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    29
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    30
$help = 1 if (!$raptorSummary);
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    31
if ($help)
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    32
{
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    33
	print "Generate an XML summary of the Raptor build from a summary.csv file\n";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    34
	print "Usage: perl summarize.pl --raptorsummary=CSV\n";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    35
	exit(0);
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    36
}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    37
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    38
# Start to build structure to be output as XML (same format as XML::Parser would create for us)
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    39
my $xmlNewline = bless { Text => "\n" }, "Characters";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    40
my $data = [bless {name => "build", Kids => [ $xmlNewline ] }, "stage"];
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    41
# Get a shortcut reference to the bit we will use a lot
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    42
my $buildStage = $data->[0];
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    43
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    44
# READ SUMMARY.CSV FILE
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    45
open(CSV, $raptorSummary);
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    46
my $csv = Text::CSV->new();
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    47
while (my $line = <CSV>)
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    48
{
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    49
	chomp $line;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    50
	
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    51
	unless ($csv->parse($line))
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    52
	{
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    53
		my $err = $csv->error_input();
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    54
		warn "Failed to parse $raptorSummary line line $. as CSV '$line': $err  Skipping\n";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    55
		next;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    56
	}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    57
	
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    58
	my @keys = qw{category subcategory severity config component phase recipe file linenum};
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    59
	my @values = $csv->fields();
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    60
	unless (scalar @keys == scalar @keys)
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    61
	{
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    62
		warn "WARNING: line does not match expected format at $raptorSummary line $.. Skipping\n";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    63
		next;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    64
	}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    65
	
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    66
	my $failure = {};
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    67
	@{$failure}{@keys} = @values;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    68
	
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    69
	if (!$failure->{category})
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    70
	{
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    71
		warn "WARNING: summary line without a category at $raptorSummary line $.. Skipping\n";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    72
		next;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    73
	}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    74
	
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    75
	if ($failure->{category} =~ m{^recipe_failure$}i and !$failure->{component})
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    76
	{
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    77
		warn "WARNING: recipe_failure with component field empty at $raptorSummary line $.. Skipping\n";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    78
		next;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    79
	}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    80
	$failure->{subcategory} ||= 'uncategorized';
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    81
	$failure->{severity} ||= 'unknown';
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    82
	
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    83
	# Look through the steps to see if we already have one to match this config
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    84
	my $step;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    85
	foreach (@{$buildStage->{Kids}})
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    86
	{
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    87
		next unless ref $_ eq "step";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    88
		if ($_->{name} eq $failure->{config})
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    89
		{
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    90
			$step = $_;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    91
			last;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    92
		}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    93
	}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    94
	unless ($step)
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    95
	{
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    96
		# First item found in this step - create step entry
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    97
		$step = bless { name => $failure->{config}, Kids => [ $xmlNewline ] }, "step";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    98
		push @{$buildStage->{Kids}}, $step, $xmlNewline;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    99
	}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   100
	
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   101
	# Look through the sets of failures in this step to see if we hve one which matches this severity
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   102
	my $failureSet;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   103
	foreach (@{$step->{Kids}})
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   104
	{
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   105
		next unless ref $_ eq "failures";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   106
		if ($_->{level} eq $failure->{severity})
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   107
		{
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   108
			$failureSet = $_;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   109
			last;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   110
		}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   111
	}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   112
	unless ($failureSet)
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   113
	{
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   114
		# First item found at this severity - create failures entry
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   115
		$failureSet = bless { level => $failure->{severity}, Kids => [ $xmlNewline ] }, "failures";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   116
		push @{$step->{Kids}}, $failureSet, $xmlNewline;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   117
	}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   118
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   119
	# Now create the failure itself, and add it to this failure set
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   120
	my $failureItem = bless { href => "", Kids => [ bless { Text => $failure->{subcategory} }, "Characters" ] }, "failure";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   121
	push @{$failureSet->{Kids}}, $failureItem, $xmlNewline;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   122
}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   123
close(CSV);
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   124
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   125
# Print XML
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   126
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   127
print "<?xml-stylesheet type='text/xsl' href='brag.xsl'?>\n";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   128
printTree($data->[0]);
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   129
print "\n";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   130
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   131
exit(0);
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   132
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   133
sub printTree
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   134
{
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   135
	my $tree = shift or die;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   136
	die unless ref $tree;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   137
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   138
	my $tagName = ref $tree;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   139
	$tagName =~ s{^main::}{};
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   140
	if ($tagName eq "Characters")
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   141
	{
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   142
		print $tree->{Text};
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   143
		return;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   144
	}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   145
	
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   146
	print "<$tagName";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   147
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   148
	foreach my $attr (
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   149
		sort {
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   150
			my $order = "name level start stop href";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   151
			my $ixA = index $order, $a;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   152
			my $ixB = index $order, $b;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   153
			die "$a $b" if $ixA + $ixB == -2;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   154
			$ixA - $ixB;
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   155
		}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   156
		grep {
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   157
			! ref $tree->{$_}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   158
		}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   159
		keys %$tree)
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   160
	{
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   161
		print " $attr=\"$tree->{$attr}\"";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   162
	}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   163
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   164
	my $children = $tree->{Kids} || [];
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   165
	if (scalar @$children)
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   166
	{
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   167
		print ">";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   168
		foreach my $child (@$children)
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   169
		{
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   170
			printTree($child);
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   171
		}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   172
		print "</$tagName";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   173
	}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   174
	else
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   175
	{
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   176
		print "/"
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   177
	}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   178
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   179
	print ">";
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   180
}
19f9d5fc6406 Added really basic failure extraction and BRAG calculation to build.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   181