common/tools/brag/toBrag.pm
author Johan Groth <johan.groth@cell-telecom.com>
Tue, 06 Jul 2010 16:30:27 +0100
changeset 1151 b15dfb01fee6
parent 753 5069de517698
permissions -rw-r--r--
Updated rev to 3.0.0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
752
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     1
#!perl -w
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     2
#
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     3
# Copyright (c) 2009 Symbian Foundation Ltd
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     4
# This component and the accompanying materials are made available
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     6
# which accompanies this distribution, and is available
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     8
#
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     9
# Initial Contributors:
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    10
# Symbian Foundation Ltd - initial contribution.
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    11
#
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    12
# Contributors:
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    13
#
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    14
# Description:
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    15
# Functionality common to BRAG file generation
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    16
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    17
use strict;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    18
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    19
package ToBrag;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    20
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    21
# A useful constant
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    22
our $xmlNewline = bless { Text => "\n" }, "Characters";
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    23
753
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    24
sub createDocumentAndRoot
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    25
{
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    26
	my $rootTag = shift;
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    27
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    28
	my $root = bless
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    29
	{
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    30
		Kids =>
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    31
		[ $ToBrag::xmlNewline ]
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    32
	}, $rootTag;
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    33
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    34
	return [$root], $root;
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    35
}
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    36
752
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    37
sub createBuildStatus
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    38
{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    39
	return [
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    40
		bless
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    41
		{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    42
			Kids =>
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    43
			[ $ToBrag::xmlNewline ]
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    44
		}, "buildStatus"
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    45
	];
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    46
}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    47
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    48
sub ensurePhase
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    49
{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    50
	my $buildStatus = shift;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    51
	my $phaseName = shift;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    52
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    53
	my ($phase) = grep { ref $_ eq "phase" && $_->{name} eq $phaseName } @{$buildStatus->[-1]->{Kids}};
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    54
	unless ($phase)
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    55
	{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    56
		$phase = bless
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    57
		{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    58
			name => $phaseName,
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    59
			Kids => [ $ToBrag::xmlNewline ]
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    60
		}, "phase";
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    61
		push @{$buildStatus->[-1]->{Kids}}, $phase, $ToBrag::xmlNewline;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    62
	}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    63
	return $phase;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    64
}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    65
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    66
sub ensureStep
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    67
{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    68
	my $phase = shift;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    69
	my $stepName = shift;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    70
753
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    71
	return ensureChild($phase, "step", "name", $stepName);
752
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    72
}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    73
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    74
sub ensureFailureSet
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    75
{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    76
	my $step = shift;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    77
	my $level = shift;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    78
753
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    79
	return ensureChild($step, "failures", "level", $level);
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    80
}
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    81
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    82
sub ensureChild
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    83
{
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    84
	my $parent = shift;
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    85
	my $childName = shift;
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    86
	my $childAttr = shift;
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    87
	my $childAttrValue = shift;
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    88
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    89
	my ($child) = grep { ref $_ eq $childName && $_->{$childAttr} eq $childAttrValue } @{$parent->{Kids}};
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    90
	unless ($child)
752
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    91
	{
753
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    92
		$child = bless
752
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    93
		{
753
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    94
			$childAttr => $childAttrValue,
752
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    95
			Kids => [ $ToBrag::xmlNewline ]
753
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    96
		}, $childName;
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    97
		push @{$parent->{Kids}}, $child, $ToBrag::xmlNewline;
752
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    98
	}
753
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
    99
	return $child;
752
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   100
}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   101
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   102
# Prints out the XML tree to STDOUT
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   103
sub printTree
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   104
{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   105
	my $tree = shift or die;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   106
	die unless ref $tree;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   107
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   108
	my $tagName = ref $tree;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   109
	$tagName =~ s{^main::}{};
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   110
	if ($tagName eq "Characters")
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   111
	{
753
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
   112
		if ($tree->{Text} =~ m{[<>&]})
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
   113
		{
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
   114
			print "<![CDATA[$tree->{Text}]]>";
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
   115
		}
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
   116
		else
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
   117
		{
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
   118
			print $tree->{Text};
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
   119
		}
752
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   120
		return;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   121
	}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   122
	
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   123
	print "<$tagName";
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   124
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   125
	foreach my $attr (
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   126
		sort {
753
5069de517698 New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents: 752
diff changeset
   127
			my $order = "name level start stop href package effect";
752
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   128
			my $ixA = index $order, $a;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   129
			my $ixB = index $order, $b;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   130
			die "$a $b" if $ixA + $ixB == -2;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   131
			$ixA - $ixB;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   132
		}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   133
		grep {
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   134
			! ref $tree->{$_}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   135
		}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   136
		keys %$tree)
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   137
	{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   138
		print " $attr=\"$tree->{$attr}\"";
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   139
	}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   140
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   141
	my $children = $tree->{Kids} || [];
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   142
	if (scalar @$children)
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   143
	{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   144
		print ">";
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   145
		foreach my $child (@$children)
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   146
		{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   147
			printTree($child);
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   148
		}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   149
		print "</$tagName";
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   150
	}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   151
	else
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   152
	{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   153
		print "/"
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   154
	}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   155
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   156
	print ">";
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   157
}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   158
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   159
1;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   160