common/tools/brag/sbsToBrag.pl
changeset 798 db3cbddc6f4a
parent 766 adc25ece36f0
child 815 3ae590eac695
equal deleted inserted replaced
797:cbc760a5fedd 798:db3cbddc6f4a
    48 ToBrag::printTree($doc->[0]);
    48 ToBrag::printTree($doc->[0]);
    49 print "\n";
    49 print "\n";
    50 
    50 
    51 exit (0);
    51 exit (0);
    52 
    52 
    53 my $context;
    53 my $recipeContext;
       
    54 my $errorContext;
       
    55 
    54 sub StartTag
    56 sub StartTag
    55 {
    57 {
    56 	my $expat = shift;
    58 	my $expat = shift;
    57 	my $tagName = shift;
    59 	my $tagName = shift;
    58 	my %attrib = %_;
    60 	my %attrib = %_;
    59 
    61 
    60 	if ($tagName eq "recipe")
    62 	if ($tagName eq "recipe")
    61 	{
    63 	{
    62 		$context = {%attrib};
    64 		$recipeContext = {%attrib};
    63 	}
    65 	}
    64 	elsif ($tagName eq "status")
    66 	elsif ($tagName eq "status")
    65 	{
    67 	{
    66 		$context->{"exit"} = $attrib{"exit"};
    68 		$recipeContext->{"exit"} = $attrib{"exit"};
       
    69 	}
       
    70 	elsif ($tagName eq "error")
       
    71 	{
       
    72 		$errorContext = {%attrib};
    67 	}
    73 	}
    68 }
    74 }
    69 sub EndTag
    75 sub EndTag
    70 {
    76 {
    71 	my $expat = shift;
    77 	my $expat = shift;
    72 	my $tagName = shift;
    78 	my $tagName = shift;
    73 
    79 
    74 	if ($tagName eq "recipe")
    80 	if ($tagName eq "recipe")
    75 	{
    81 	{
    76 		die unless $context;
    82 		die unless $recipeContext;
    77 
    83 
    78 		if ($context->{"exit"} ne "ok")
    84 		if ($recipeContext->{"exit"} ne "ok")
    79 		{
    85 		{
    80 			# Create a more readable error message
    86 			# Create a more readable error message
    81 			my %errorIdToDetail = (
    87 			my %errorIdToDetail = (
    82 				tem => {message => "Failed to execute '$context->{source}' invoked via $context->{bldinf}", severity => "major"},
    88 				tem => {message => "Failed to execute '$recipeContext->{source}' invoked via $recipeContext->{bldinf}", severity => "major"},
    83 				msvctoolscompile => {message => "Failed to compile $context->{source}", severity => "minor"},
    89 				msvctoolscompile => {message => "Failed to compile $recipeContext->{source}", severity => "minor"},
    84 				compile => {message => "Failed to compile $context->{source}", severity => "minor"},
    90 				compile => {message => "Failed to compile $recipeContext->{source}", severity => "minor"},
    85 				compile2object => {message => "Failed to compile $context->{source}", severity => "minor"},
    91 				compile2object => {message => "Failed to compile $recipeContext->{source}", severity => "minor"},
    86 				win32compile2object => {message => "Failed to compile $context->{source}", severity => "minor"},
    92 				win32compile2object => {message => "Failed to compile $recipeContext->{source}", severity => "minor"},
    87 				tools2lib => {message => "Failed to build library $context->{target}", severity => "minor"},
    93 				tools2lib => {message => "Failed to build library $recipeContext->{target}", severity => "minor"},
    88 				ar => {message => "Failed to build library $context->{target}", severity => "minor"},
    94 				ar => {message => "Failed to build library $recipeContext->{target}", severity => "minor"},
    89 				win32archive => {message => "Failed to build library $context->{target}", severity => "minor"},
    95 				win32archive => {message => "Failed to build library $recipeContext->{target}", severity => "minor"},
    90 				win32def2lib => {message => "Failed to build DLL entry point library $context->{target}", severity => "minor"},
    96 				win32def2lib => {message => "Failed to build DLL entry point library $recipeContext->{target}", severity => "minor"},
    91 				"link" => {message => "Failed to create symbols for $context->{target}", severity => "minor"},
    97 				"link" => {message => "Failed to create symbols for $recipeContext->{target}", severity => "minor"},
    92 				postlink => {message => "Failed to link $context->{target}", severity => "minor"},
    98 				postlink => {message => "Failed to link $recipeContext->{target}", severity => "minor"},
    93 				win32stageonelink => {message => "Failed to link $context->{target} (stage 1)", severity => "minor"},
    99 				win32stageonelink => {message => "Failed to link $recipeContext->{target} (stage 1)", severity => "minor"},
    94 				win32stagetwolink => {message => "Failed to link $context->{target}", severity => "minor"},
   100 				win32stagetwolink => {message => "Failed to link $recipeContext->{target}", severity => "minor"},
    95 				win32simplelink => {message => "Failed to link $context->{target}", severity => "minor"},
   101 				win32simplelink => {message => "Failed to link $recipeContext->{target}", severity => "minor"},
    96 				win32processexports => {message => "Failed to export $context->{source} to $context->{target}", severity => "minor"},
   102 				win32processexports => {message => "Failed to export $recipeContext->{source} to $recipeContext->{target}", severity => "minor"},
    97 				tracecompile => {message => "Trace compile failure for $context->{target}", severity => "unknown"},
   103 				tracecompile => {message => "Trace compile failure for $recipeContext->{target}", severity => "unknown"},
    98 				extension_makefile => {message => "Failed within an extension makefile connected to $context->{bldinf}", severity => "major"},
   104 				extension_makefile => {message => "Failed within an extension makefile connected to $recipeContext->{bldinf}", severity => "major"},
    99 			);
   105 			);
   100 #			die $context->{name} unless exists $errorIdToDetail{$context->{name}};
   106 
   101 
   107 			my $message = $errorIdToDetail{$recipeContext->{name}}->{message} || "Unknown failure tag '$recipeContext->{name}' ($recipeContext->{source} -> $recipeContext->{target})";
   102 			my $message = $errorIdToDetail{$context->{name}}->{message} || "Unknown failure tag '$context->{name}' ($context->{source} -> $context->{target})";
   108 			$recipeContext->{severity} = $errorIdToDetail{$recipeContext->{name}}->{severity} || "unknown";
   103 			$context->{severity} = $errorIdToDetail{$context->{name}}->{severity} || "unknown";
       
   104 
   109 
   105 			# Obtain a step object
   110 			# Obtain a step object
   106 			my $step = ToBrag::ensureStep($buildPhase, $context->{config});
   111 			my $step = ToBrag::ensureStep($buildPhase, $recipeContext->{config});
   107 			# Also create empty <failures> tags with severities in a sensible order
   112 			# Also create empty <failures> tags with severities in a sensible order
   108 			ToBrag::ensureFailureSet($step, "critical");
   113 			ToBrag::ensureFailureSet($step, "critical");
   109 			ToBrag::ensureFailureSet($step, "major");
   114 			ToBrag::ensureFailureSet($step, "major");
   110 			ToBrag::ensureFailureSet($step, "minor");
   115 			ToBrag::ensureFailureSet($step, "minor");
   111 			# Obtain a failures object
   116 			# Obtain a failures object
   112 			my $failureSet = ToBrag::ensureFailureSet($step, $context->{severity});
   117 			my $failureSet = ToBrag::ensureFailureSet($step, $recipeContext->{severity});
   113 
   118 
   114 			# Now create the failure itself, and add it to this failure set
   119 			# Now create the failure itself, and add it to this failure set
   115 			my $failureItem = bless {
   120 			my $failureItem = bless {
   116 				Kids => [ bless { Kids => [ bless { Text => $message }, "Characters" ]}, "effect" ],
   121 				Kids => [ bless { Kids => [ bless { Text => $message }, "Characters" ]}, "effect" ],
   117 			}, "failure";
   122 			}, "failure";
   118 			if ($context->{component})
   123 			if ($recipeContext->{component})
   119 			{
   124 			{
   120 				$context->{bldinf} =~ s{^\w:(/sf/.*?/.*?)/.*$}{$1};
   125 				$recipeContext->{bldinf} =~ s{^\w:(/sf/.*?/.*?)/.*$}{$1};
   121 				$failureItem->{package} = $context->{bldinf};
   126 				$failureItem->{package} = $recipeContext->{bldinf};
   122 			}
   127 			}
   123 			my @causes = grep { $_ && ! m/^\+ / } split("\n", $context->{Chars});
   128 			my @causes = grep { $_ && ! m/^\+ / } split("\n", $recipeContext->{Chars});
   124 			@causes = map { "  $_" } @causes;
   129 			@causes = map { "  $_" } @causes;
   125 			if (@causes)
   130 			if (@causes)
   126 			{
   131 			{
   127 				my @reportedCauses = @causes[0 .. min($#causes, 49)];
   132 				my @reportedCauses = @causes[0 .. min($#causes, 49)];
   128 				my $causesItem = bless {
   133 				my $causesItem = bless {
   133 				$failureItem->{unreported_causes} = $unreportedCauses;
   138 				$failureItem->{unreported_causes} = $unreportedCauses;
   134 			}
   139 			}
   135 			push @{$failureSet->{Kids}}, $failureItem, $ToBrag::xmlNewline;
   140 			push @{$failureSet->{Kids}}, $failureItem, $ToBrag::xmlNewline;
   136 		}
   141 		}
   137 		
   142 		
   138 		$context = undef;
   143 		$recipeContext = undef;
       
   144 	}
       
   145 	elsif ($tagName eq "error")
       
   146 	{
       
   147 		die unless $errorContext;
       
   148 
       
   149 		# Add error to output tree
       
   150 
       
   151 		my $severity = "unknown";
       
   152 		my @messageInterpretation = (
       
   153 			{regexp => qr{Cannot process schema version .* of file}, severity => "critical"},
       
   154 			{regexp => qr{No bld\.inf found at}, severity => "major"},
       
   155 			{regexp => qr{^Preprocessor exception}, severity => "major"},
       
   156 			{regexp => qr{No such file or directory$}, severity => "major"},
       
   157 			{regexp => qr{Can't find mmp file}, severity => "minor"},
       
   158 			{regexp => qr{The make-engine exited with errors}, severity => "critical"},
       
   159 			{regexp => qr{tool '.+?' from config '.*' did not return version '.*' as required\.}, severity => "critical"},
       
   160 			{regexp => qr{Unknown build configuration '.*'}, severity => "critical"},
       
   161 			{regexp => qr{No build configurations given}, severity => "critical"},
       
   162 			{regexp => qr{Source of export does not exist:}, severity => "minor"},
       
   163 			{regexp => qr{Could not export}, severity => "minor"},
       
   164 			{regexp => qr{Could not export}, severity => "minor"},
       
   165 			{regexp => qr{Source zip for export does not exist:}, severity => "minor"},
       
   166 		);
       
   167 
       
   168 		foreach (@messageInterpretation)
       
   169 		{
       
   170 			if ($errorContext->{Chars} =~ $_->{regexp})
       
   171 			{
       
   172 				$severity = $_->{severity};
       
   173 				last;
       
   174 			}
       
   175 		}
       
   176 
       
   177 		# Obtain a step object
       
   178 		my $step = ToBrag::ensureStep($buildPhase, "Raptor Initialisation");
       
   179 		# Also create empty <failures> tags with severities in a sensible order
       
   180 		ToBrag::ensureFailureSet($step, "critical");
       
   181 		ToBrag::ensureFailureSet($step, "major");
       
   182 		ToBrag::ensureFailureSet($step, "minor");
       
   183 		# Obtain a failures object
       
   184 		my $failureSet = ToBrag::ensureFailureSet($step, $severity);
       
   185 
       
   186 		# Now create the failure itself, and add it to this failure set
       
   187 		my $failureItem = bless {
       
   188 			Kids => [ bless { Kids => [ bless { Text => $errorContext->{Chars} }, "Characters" ]}, "effect" ],
       
   189 		}, "failure";
       
   190 		push @{$failureSet->{Kids}}, $failureItem, $ToBrag::xmlNewline;
       
   191 
       
   192 		$errorContext = undef;
   139 	}
   193 	}
   140 }
   194 }
   141 sub Text
   195 sub Text
   142 {
   196 {
   143 	s/^\n*//;
   197 	s/^\n*//;
   144 	if ($context)
   198 	if ($recipeContext)
   145 	{
   199 	{
   146 		$context->{Chars} .= $_;
   200 		$recipeContext->{Chars} .= $_;
       
   201 	}
       
   202 	elsif ($errorContext)
       
   203 	{
       
   204 		$errorContext->{Chars} .= $_;
   147 	}
   205 	}
   148 }
   206 }
   149 
   207 
   150 sub min
   208 sub min
   151 {
   209 {