uh_parser/RaptorRecipe.pm
changeset 177 6d3c3db11e72
child 184 38468523076d
equal deleted inserted replaced
176:266a7e9b9237 177:6d3c3db11e72
       
     1 # Copyright (c) 2009 Symbian Foundation Ltd
       
     2 # This component and the accompanying materials are made available
       
     3 # under the terms of the License "Eclipse Public License v1.0"
       
     4 # which accompanies this distribution, and is available
       
     5 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     6 #
       
     7 # Initial Contributors:
       
     8 # Symbian Foundation Ltd - initial contribution.
       
     9 #
       
    10 # Contributors:
       
    11 #
       
    12 # Description:
       
    13 # Raptor parser module.
       
    14 # Extract, analyzes and dumps raptor recipes i.e. content of <recipe> tags from a raptor log file
       
    15 
       
    16 package RaptorRecipe;
       
    17 
       
    18 use strict;
       
    19 use RaptorCommon;
       
    20 
       
    21 our $reset_status = {};
       
    22 my $buildlog_status = {};
       
    23 my $buildlog_recipe_status = {};
       
    24 my $buildlog_recipe_status_status = {};
       
    25 
       
    26 $reset_status->{name} = 'reset_status';
       
    27 $reset_status->{next_status} = {buildlog=>$buildlog_status};
       
    28 
       
    29 $buildlog_status->{name} = 'buildlog_status';
       
    30 $buildlog_status->{next_status} = {recipe=>$buildlog_recipe_status};
       
    31 $buildlog_status->{on_start} = 'RaptorRecipe::on_start_buildlog';
       
    32 $buildlog_status->{on_end} = 'RaptorRecipe::on_end_buildlog';
       
    33 
       
    34 $buildlog_recipe_status->{name} = 'buildlog_recipe_status';
       
    35 $buildlog_recipe_status->{next_status} = {status=>$buildlog_recipe_status_status};
       
    36 $buildlog_recipe_status->{on_start} = 'RaptorRecipe::on_start_buildlog_recipe';
       
    37 $buildlog_recipe_status->{on_end} = 'RaptorRecipe::on_end_buildlog_recipe';
       
    38 $buildlog_recipe_status->{on_chars} = 'RaptorRecipe::on_chars_buildlog_recipe';
       
    39 
       
    40 $buildlog_recipe_status_status->{name} = 'buildlog_recipe_status_status';
       
    41 $buildlog_recipe_status_status->{next_status} = {};
       
    42 $buildlog_recipe_status_status->{on_start} = 'RaptorRecipe::on_start_buildlog_recipe_status';
       
    43 
       
    44 
       
    45 my $filename = '';
       
    46 my $failure_item = 0;
       
    47 
       
    48 my $recipe_info = {};
       
    49 
       
    50 my $characters = '';
       
    51 
       
    52 my $CATEGORY_RECIPEFAILURE = 'recipe_failure';
       
    53 my $CATEGORY_RECIPEFAILURE_ARMCC_CANNOTOPENSOURCEINPUTFILE = 'armcc_cannot_open_source_input_file';
       
    54 my $CATEGORY_RECIPEFAILURE_ARMLINK_COULDNOTOPENFILE = 'armlink_could_not_open_file';
       
    55 my $CATEGORY_RECIPEFAILURE_ELF2E32_COULDNOTOPENFILE = 'elf2e32_could_not_open_file';
       
    56 my $CATEGORY_RECIPEFAILURE_ARMAR_FILEDOESNOTEXIST = 'armar_file_does_not_exist';
       
    57 my $CATEGORY_RECIPEFAILURE_ARMCC_CONTROLLINGEXPRESSIONISCONSTANT = 'armcc_controlling_expression_is_constant';
       
    58 my $CATEGORY_RECIPEFAILURE_ARMCC_INTERNALFAULT = 'armcc_internal_fault';
       
    59 my $CATEGORY_RECIPEFAILURE_ARMCC_MODIFIERNOTALLOWED = 'armcc_modifier_not_allowed';
       
    60 my $CATEGORY_RECIPEFAILURE_ARMCC_GENERICWARNINGSERRORS = 'armcc_generic_warnings_errors';
       
    61 my $CATEGORY_RECIPEFAILURE_ELF2E32_SYMBOLMISSINGFROMELFFILE = 'elf2e32_symbol_missing_from_elf_file';
       
    62 my $CATEGORY_RECIPEFAILURE_MWCCSYM2_FILECANNOTBEOPENED = 'mwccsym2_file_cannot_be_opened';
       
    63 
       
    64 my $mmp_with_issues = {};
       
    65 
       
    66 
       
    67 sub process
       
    68 {
       
    69 	my ($text, $config, $component, $mmp, $phase, $recipe, $file, $line) = @_;
       
    70 	
       
    71 	my $category = $CATEGORY_RECIPEFAILURE;
       
    72 	my $severity = '';
       
    73 	my $subcategory = '';
       
    74 	
       
    75 	# if mmp is defined assign severity=MAJOR for the first failure
       
    76 	# then severity=MINOR to all other (for each logfile)
       
    77 	if ($mmp and defined $mmp_with_issues->{$::current_log_file}->{$mmp})
       
    78 	{
       
    79 		$severity = $RaptorCommon::SEVERITY_MINOR;
       
    80 	}
       
    81 	elsif ($mmp)
       
    82 	{
       
    83 		$mmp_with_issues->{$::current_log_file} = {} if (!defined $mmp_with_issues->{$::current_log_file});
       
    84 		$mmp_with_issues->{$::current_log_file}->{$mmp} = 1;
       
    85 		$severity = $RaptorCommon::SEVERITY_MAJOR;
       
    86 	}
       
    87 	else
       
    88 	{
       
    89 		$severity = $RaptorCommon::SEVERITY_MAJOR;
       
    90 	}
       
    91 	
       
    92 	
       
    93 	if ($text =~ m,Error:  #5: cannot open source input file .*: No such file or directory,)
       
    94 	{
       
    95 		my $subcategory = $CATEGORY_RECIPEFAILURE_ARMCC_CANNOTOPENSOURCEINPUTFILE;
       
    96 		RaptorCommon::dump_fault($category, $subcategory, $severity, $config, $component, $mmp, $phase, $recipe, $file, $line);
       
    97 	}
       
    98 	elsif ($text =~ m,Fatal error: L6002U: Could not open file .*: No such file or directory,)
       
    99 	{
       
   100 		my $subcategory = $CATEGORY_RECIPEFAILURE_ARMLINK_COULDNOTOPENFILE;
       
   101 		RaptorCommon::dump_fault($category, $subcategory, $severity, $config, $component, $mmp, $phase, $recipe, $file, $line);
       
   102 	}
       
   103 	elsif ($text =~ m,elf2e32 : Error: E1001: Could not open file : .*.,)
       
   104 	{
       
   105 		my $subcategory = $CATEGORY_RECIPEFAILURE_ELF2E32_COULDNOTOPENFILE;
       
   106 		RaptorCommon::dump_fault($category, $subcategory, $severity, $config, $component, $mmp, $phase, $recipe, $file, $line);
       
   107 	}
       
   108 	elsif ($text =~ m,elf2e32 : Error: E1036: Symbol .* Missing from ELF File,)
       
   109 	{
       
   110 		my $subcategory = $CATEGORY_RECIPEFAILURE_ELF2E32_SYMBOLMISSINGFROMELFFILE;
       
   111 		RaptorCommon::dump_fault($category, $subcategory, $severity, $config, $component, $mmp, $phase, $recipe, $file, $line);
       
   112 	}
       
   113 	elsif ($text =~ m,Error: L6833E: File '.*' does not exist,)
       
   114 	{
       
   115 		my $subcategory = $CATEGORY_RECIPEFAILURE_ARMAR_FILEDOESNOTEXIST;
       
   116 		RaptorCommon::dump_fault($category, $subcategory, $severity, $config, $component, $mmp, $phase, $recipe, $file, $line);
       
   117 	}
       
   118 	elsif ($text =~ m,: Warning:  #236-D: controlling expression is constant,)
       
   119 	{
       
   120 		my $subcategory = $CATEGORY_RECIPEFAILURE_ARMCC_CONTROLLINGEXPRESSIONISCONSTANT;
       
   121 		RaptorCommon::dump_fault($category, $subcategory, $severity, $config, $component, $mmp, $phase, $recipe, $file, $line);
       
   122 	}
       
   123 	elsif ($text =~ m,/armcc.exe , and $text =~ m,Internal fault: ,)
       
   124 	{
       
   125 		my $subcategory = $CATEGORY_RECIPEFAILURE_ARMCC_INTERNALFAULT;
       
   126 		RaptorCommon::dump_fault($category, $subcategory, $severity, $config, $component, $mmp, $phase, $recipe, $file, $line);
       
   127 	}
       
   128 	elsif ($text =~ m,/armcc.exe , and $text =~ m,Error:  #655-D: the modifier ".*" is not allowed on this declaration,)
       
   129 	{
       
   130 		my $subcategory = $CATEGORY_RECIPEFAILURE_ARMCC_MODIFIERNOTALLOWED;
       
   131 		RaptorCommon::dump_fault($category, $subcategory, $severity, $config, $component, $mmp, $phase, $recipe, $file, $line);
       
   132 	}
       
   133 	# the following captures generic armcc error/warnings, not captured by regexps above
       
   134 	elsif ($text =~ m,/armcc.exe , and $text =~ m,: \d+ warnings\, \d+ errors$,)
       
   135 	{
       
   136 		my $subcategory = $CATEGORY_RECIPEFAILURE_ARMCC_GENERICWARNINGSERRORS;
       
   137 		RaptorCommon::dump_fault($category, $subcategory, $severity, $config, $component, $mmp, $phase, $recipe, $file, $line);
       
   138 	}
       
   139 	elsif ($text =~ m,mwccsym2.exe , and $text =~ m,: the file '.*' cannot be opened,)
       
   140 	{
       
   141 		my $subcategory = $CATEGORY_RECIPEFAILURE_MWCCSYM2_FILECANNOTBEOPENED;
       
   142 		RaptorCommon::dump_fault($category, $subcategory, $severity, $config, $component, $mmp, $phase, $recipe, $file, $line);
       
   143 	}
       
   144 	else # log everything by default
       
   145 	{
       
   146 		RaptorCommon::dump_fault($category, $subcategory, $severity, $config, $component, $mmp, $phase, $recipe, $file, $line);
       
   147 	}
       
   148 }
       
   149 
       
   150 sub on_start_buildlog
       
   151 {
       
   152 	#print FILE "line,layer,component,name,armlicence,platform,phase,code,bldinf,mmp,target,source,\n";
       
   153 	
       
   154 	RaptorCommon::init();
       
   155 }
       
   156 
       
   157 sub on_start_buildlog_recipe
       
   158 {
       
   159 	my ($el) = @_;
       
   160 	
       
   161 	#print "on_start_buildlog_recipe\n";
       
   162 	
       
   163 	$recipe_info = {};
       
   164 	
       
   165 	my $attributes = $el->{Attributes};
       
   166 	for (keys %{$attributes})
       
   167 	{
       
   168 		$recipe_info->{$attributes->{$_}->{'LocalName'}} = $attributes->{$_}->{'Value'};
       
   169 		#print "$_ -> $attributes->{$_}->{'Value'}\n";
       
   170 	}
       
   171 }
       
   172 
       
   173 sub on_chars_buildlog_recipe
       
   174 {
       
   175 	my ($ch) = @_;
       
   176 	
       
   177 	#print "on_chars_buildlog_recipe\n";
       
   178 	
       
   179 	$characters .= $ch->{Data};
       
   180 	
       
   181 	#print "characters is now -->$characters<--\n";
       
   182 }
       
   183 
       
   184 sub on_start_buildlog_recipe_status
       
   185 {
       
   186 	my ($el) = @_;
       
   187 	
       
   188 	my $attributes = $el->{Attributes};
       
   189 	for (keys %{$attributes})
       
   190 	{
       
   191 		if ($attributes->{$_}->{'LocalName'} eq 'code')
       
   192 		{
       
   193 			$recipe_info->{$attributes->{$_}->{'LocalName'}} = $attributes->{$_}->{'Value'};
       
   194 		}
       
   195 		elsif ($attributes->{$_}->{'LocalName'} eq 'exit')
       
   196 		{
       
   197 			$recipe_info->{$attributes->{$_}->{'LocalName'}} = $attributes->{$_}->{'Value'};
       
   198 		}
       
   199 		elsif ($attributes->{$_}->{'LocalName'} eq 'attempt')
       
   200 		{
       
   201 			$recipe_info->{$attributes->{$_}->{'LocalName'}} = $attributes->{$_}->{'Value'};
       
   202 		}
       
   203 	}
       
   204 }
       
   205 
       
   206 sub on_end_buildlog_recipe
       
   207 {
       
   208 	$::allbldinfs->{$recipe_info->{bldinf}} = 1;
       
   209 	
       
   210 	if ($recipe_info->{exit} =~ /failed/)
       
   211 	{
       
   212 		# normalize bldinf path
       
   213 		$recipe_info->{bldinf} = lc($recipe_info->{bldinf});
       
   214 		$recipe_info->{bldinf} =~ s,^[A-Za-z]:,,;
       
   215 		$recipe_info->{bldinf} =~ s,[\\],/,g;
       
   216 		
       
   217 		my $package = '';
       
   218 		if ($recipe_info->{bldinf} =~ m,/((os|mw|app|tools|ostools|adaptation)/[^/]*),)
       
   219 		{
       
   220 			$package = $1;
       
   221 			$package =~ s,/,_,;
       
   222 		}
       
   223 		else
       
   224 		{
       
   225 			print "WARNING: can't understand bldinf attribute of recipe: $recipe_info->{bldinf}. Won't dump to failed recipes file.\n";
       
   226 		}
       
   227 		
       
   228 		# also normalize mmp path if this exists
       
   229 		if ($recipe_info->{mmp})
       
   230 		{
       
   231 			$recipe_info->{mmp} = lc($recipe_info->{mmp});
       
   232 			$recipe_info->{mmp} =~ s,^[A-Za-z]:,,;
       
   233 			$recipe_info->{mmp} =~ s,[\\],/,g;
       
   234 		}
       
   235 		
       
   236 		$characters =~ s,^[\r\n]*,,;
       
   237 		$characters =~ s,[\r\n]*$,,;
       
   238 		
       
   239 		if ($package)
       
   240 		{
       
   241 			$filename = "$::raptorbitsdir/$package.txt";
       
   242 			if (!-f$filename)
       
   243 			{
       
   244 				print "Writing recipe file $filename\n";
       
   245 				open(FILE, ">$filename");
       
   246 				close(FILE);
       
   247 			}
       
   248 			
       
   249 			if ($failure_item == 0 and -f "$filename")
       
   250 			{
       
   251 				open(FILE, "$filename");
       
   252 				{
       
   253 					local $/ = undef;
       
   254 					my $filecontent = <FILE>;
       
   255 					$failure_item = $1 if ($filecontent =~ m/.*---failure_item_(\d+)/s);
       
   256 				}
       
   257 				close(FILE);
       
   258 			}
       
   259 			
       
   260 			$failure_item++;
       
   261 			
       
   262 			open(FILE, ">>$filename");
       
   263 			print FILE "---failure_item_$failure_item\---\n";
       
   264 			print FILE "$characters\n\n";
       
   265 			close(FILE);
       
   266 		}
       
   267 		
       
   268 		process($characters, $recipe_info->{config}, $recipe_info->{bldinf}, $recipe_info->{mmp}, $recipe_info->{phase}, $recipe_info->{name}, "$package.txt", $failure_item);
       
   269 	}
       
   270 
       
   271 	$characters = '';
       
   272 }
       
   273 
       
   274 sub on_end_buildlog
       
   275 {
       
   276 }
       
   277 
       
   278 
       
   279 1;