common/tools/brag/toBrag.pm
author Simon Howkins <simonh@symbian.org>
Tue, 10 Nov 2009 16:52:27 +0000
changeset 752 1f07674ec99f
child 753 5069de517698
permissions -rw-r--r--
Moved common code to shared module.
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
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    24
sub createBuildStatus
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    25
{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    26
	return [
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    27
		bless
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    28
		{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    29
			Kids =>
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    30
			[ $ToBrag::xmlNewline ]
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    31
		}, "buildStatus"
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    32
	];
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    33
}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    34
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    35
sub ensurePhase
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    36
{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    37
	my $buildStatus = shift;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    38
	my $phaseName = shift;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    39
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    40
	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
    41
	unless ($phase)
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    42
	{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    43
		$phase = bless
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    44
		{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    45
			name => $phaseName,
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    46
			Kids => [ $ToBrag::xmlNewline ]
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    47
		}, "phase";
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    48
		push @{$buildStatus->[-1]->{Kids}}, $phase, $ToBrag::xmlNewline;
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
	return $phase;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    51
}
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
sub ensureStep
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    54
{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    55
	my $phase = shift;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    56
	my $stepName = shift;
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
	my ($step) = grep { ref $_ eq "step" && $_->{name} eq $stepName } @{$phase->{Kids}};
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    59
	unless ($step)
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    60
	{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    61
		$step = bless
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
			name => $stepName,
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    64
			Kids => [ $ToBrag::xmlNewline ]
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    65
		}, "step";
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    66
		push @{$phase->{Kids}}, $step, $ToBrag::xmlNewline;
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
	return $step;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    69
}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    70
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    71
sub ensureFailureSet
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
	my $step = shift;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    74
	my $level = shift;
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 ($failureSet) = grep { ref $_ eq "failures" && $_->{level} eq $level } @{$step->{Kids}};
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    77
	unless ($failureSet)
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    78
	{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    79
		$failureSet = bless
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    80
		{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    81
			level => $level,
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    82
			Kids => [ $ToBrag::xmlNewline ]
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    83
		}, "failures";
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    84
		push @{$step->{Kids}}, $failureSet, $ToBrag::xmlNewline;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    85
	}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    86
	return $failureSet;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    87
}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    88
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    89
# Prints out the XML tree to STDOUT
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    90
sub printTree
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    91
{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    92
	my $tree = shift or die;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    93
	die unless ref $tree;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    94
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    95
	my $tagName = ref $tree;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    96
	$tagName =~ s{^main::}{};
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    97
	if ($tagName eq "Characters")
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    98
	{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    99
		print $tree->{Text};
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   100
		return;
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
	
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   103
	print "<$tagName";
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
	foreach my $attr (
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   106
		sort {
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   107
			my $order = "name level start stop href";
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   108
			my $ixA = index $order, $a;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   109
			my $ixB = index $order, $b;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   110
			die "$a $b" if $ixA + $ixB == -2;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   111
			$ixA - $ixB;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   112
		}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   113
		grep {
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   114
			! ref $tree->{$_}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   115
		}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   116
		keys %$tree)
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   117
	{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   118
		print " $attr=\"$tree->{$attr}\"";
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   119
	}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   120
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   121
	my $children = $tree->{Kids} || [];
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   122
	if (scalar @$children)
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   123
	{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   124
		print ">";
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   125
		foreach my $child (@$children)
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   126
		{
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   127
			printTree($child);
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   128
		}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   129
		print "</$tagName";
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   130
	}
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   131
	else
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
		print "/"
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   134
	}
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
	print ">";
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
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   139
1;
1f07674ec99f Moved common code to shared module.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   140