common/tools/brag/sbsToBrag.pl
changeset 753 5069de517698
child 766 adc25ece36f0
equal deleted inserted replaced
752:1f07674ec99f 753:5069de517698
       
     1 #!perl -w
       
     2 #
       
     3 # Copyright (c) 2009 Symbian Foundation Ltd
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the License "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Symbian Foundation Ltd - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description:
       
    15 # Generate the BRAG-compatible XML summary of the Raptor log from the CSV output of the raptor parser
       
    16 
       
    17 use strict;
       
    18 
       
    19 use FindBin;
       
    20 use lib "$FindBin::Bin";
       
    21 
       
    22 use XML::Parser;
       
    23 #use Getopt::Long;
       
    24 
       
    25 use ToBrag;
       
    26 
       
    27 my $raptorLogGlob = shift or die "First argument must be raptor XML log to read\n";
       
    28 shift and die "Only one argument please\n";
       
    29 
       
    30 @ARGV = glob $raptorLogGlob;
       
    31 
       
    32 # Start to build structure to be output as XML (same format as XML::Parser would create for us)
       
    33 my ($doc, $buildStatus) = ToBrag::createDocumentAndRoot("buildStatus");
       
    34 # Obtain a phase object
       
    35 my $buildPhase = ToBrag::ensureChild($buildStatus, "phase", "name", "Build");
       
    36 
       
    37 # Parse the Raptor logs
       
    38 # (Use XML::Parser in "Stream" mode so we don't have to hold all the data in memory at the same time)
       
    39 my $xml = XML::Parser->new(Style => "Stream", Pkg => "main");
       
    40 
       
    41 foreach my $log (@ARGV)
       
    42 {
       
    43 	$xml->parsefile($log);
       
    44 }
       
    45 
       
    46 print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
       
    47 print "<?xml-stylesheet type='text/xsl' href='brag.xsl'?>\n";
       
    48 ToBrag::printTree($doc->[0]);
       
    49 print "\n";
       
    50 
       
    51 exit (0);
       
    52 
       
    53 my $context;
       
    54 sub StartTag
       
    55 {
       
    56 	my $expat = shift;
       
    57 	my $tagName = shift;
       
    58 	my %attrib = %_;
       
    59 
       
    60 	if ($tagName eq "recipe")
       
    61 	{
       
    62 		$context = {%attrib};
       
    63 	}
       
    64 	elsif ($tagName eq "status")
       
    65 	{
       
    66 		$context->{"exit"} = $attrib{"exit"};
       
    67 	}
       
    68 }
       
    69 sub EndTag
       
    70 {
       
    71 	my $expat = shift;
       
    72 	my $tagName = shift;
       
    73 
       
    74 	if ($tagName eq "recipe")
       
    75 	{
       
    76 		die unless $context;
       
    77 
       
    78 		if ($context->{"exit"} ne "ok")
       
    79 		{
       
    80 			# Create a more readable error message
       
    81 			my %errorIdToDetail = (
       
    82 				tem => {message => "Failed to execute '$context->{source}' invoked via $context->{bldinf}", severity => "major"},
       
    83 				msvctoolscompile => {message => "Failed to compile $context->{source}", severity => "minor"},
       
    84 				compile => {message => "Failed to compile $context->{source}", severity => "minor"},
       
    85 				compile2object => {message => "Failed to compile $context->{source}", severity => "minor"},
       
    86 				win32compile2object => {message => "Failed to compile $context->{source}", severity => "minor"},
       
    87 				tools2lib => {message => "Failed to build library $context->{target}", severity => "minor"},
       
    88 				ar => {message => "Failed to build library $context->{target}", severity => "minor"},
       
    89 				win32archive => {message => "Failed to build library $context->{target}", severity => "minor"},
       
    90 				"link" => {message => "Failed to create symbols for $context->{target}", severity => "minor"},
       
    91 				postlink => {message => "Failed to link $context->{target}", severity => "minor"},
       
    92 				win32stageonelink => {message => "Failed to link $context->{target} (stage 1)", severity => "minor"},
       
    93 				win32stagetwolink => {message => "Failed to link $context->{target}", severity => "minor"},
       
    94 				win32simplelink => {message => "Failed to link $context->{target}", severity => "minor"},
       
    95 				win32processexports => {message => "Failed to export $context->{source} to $context->{target}", severity => "minor"},
       
    96 				tracecompile => {message => "Trace compile failure for $context->{target}", severity => "unknown"},
       
    97 				extension_makefile => {message => "Failed within an extension makefile connected to $context->{bldinf}", severity => "major"},
       
    98 			);
       
    99 #			die $context->{name} unless exists $errorIdToDetail{$context->{name}};
       
   100 
       
   101 			my $message = $errorIdToDetail{$context->{name}}->{message} || "Unknown failure tag '$context->{name}' ($context->{source} -> $context->{target})";
       
   102 			$context->{severity} = $errorIdToDetail{$context->{name}}->{severity} || "unknown";
       
   103 
       
   104 			# Obtain a step object
       
   105 			my $step = ToBrag::ensureStep($buildPhase, $context->{config});
       
   106 			# Also create empty <failures> tags with severities in a sensible order
       
   107 			ToBrag::ensureFailureSet($step, "critical");
       
   108 			ToBrag::ensureFailureSet($step, "major");
       
   109 			ToBrag::ensureFailureSet($step, "minor");
       
   110 			# Obtain a failures object
       
   111 			my $failureSet = ToBrag::ensureFailureSet($step, $context->{severity});
       
   112 
       
   113 			# Now create the failure itself, and add it to this failure set
       
   114 			my $failureItem = bless {
       
   115 				Kids => [ bless { Kids => [ bless { Text => $message }, "Characters" ]}, "effect" ],
       
   116 			}, "failure";
       
   117 			if ($context->{component})
       
   118 			{
       
   119 				$context->{bldinf} =~ s{^\w:(/sf/.*?/.*?)/.*$}{$1};
       
   120 				$failureItem->{package} = $context->{bldinf};
       
   121 			}
       
   122 			my @causes = grep { $_ && ! m/^\+ / } split("\n", $context->{Chars});
       
   123 			@causes = map { "  $_" } @causes;
       
   124 			if (@causes)
       
   125 			{
       
   126 				my @reportedCauses = @causes[0 .. min($#causes, 49)];
       
   127 				my $causesItem = bless {
       
   128 					Kids => [ bless { Text => join "\n", @reportedCauses }, "Characters" ]
       
   129 				}, "causes";
       
   130 				push @{$failureItem->{Kids}}, $causesItem;
       
   131 				my $unreportedCauses = scalar @causes - scalar @reportedCauses;
       
   132 				$failureItem->{unreported_causes} = $unreportedCauses;
       
   133 			}
       
   134 			push @{$failureSet->{Kids}}, $failureItem, $ToBrag::xmlNewline;
       
   135 		}
       
   136 		
       
   137 		$context = undef;
       
   138 	}
       
   139 }
       
   140 sub Text
       
   141 {
       
   142 	s/^\n*//;
       
   143 	if ($context)
       
   144 	{
       
   145 		$context->{Chars} .= $_;
       
   146 	}
       
   147 }
       
   148 
       
   149 sub min
       
   150 {
       
   151 	return ($_[0] < $_[1]) ? $_[0] : $_[1] ;
       
   152 }
       
   153