common/tools/raptor/RaptorRecipe.pm
changeset 383 52675b624b66
parent 242 51e429810aba
child 715 ee8b99c7aa0d
equal deleted inserted replaced
373:cc469b3fe547 383:52675b624b66
    19 use RaptorCommon;
    19 use RaptorCommon;
    20 
    20 
    21 our $reset_status = {};
    21 our $reset_status = {};
    22 my $buildlog_status = {};
    22 my $buildlog_status = {};
    23 my $buildlog_recipe_status = {};
    23 my $buildlog_recipe_status = {};
       
    24 my $buildlog_recipe_status_status = {};
    24 
    25 
    25 $reset_status->{name} = 'reset_status';
    26 $reset_status->{name} = 'reset_status';
    26 $reset_status->{next_status} = {buildlog=>$buildlog_status};
    27 $reset_status->{next_status} = {buildlog=>$buildlog_status};
    27 
    28 
    28 $buildlog_status->{name} = 'buildlog_status';
    29 $buildlog_status->{name} = 'buildlog_status';
    29 $buildlog_status->{next_status} = {recipe=>$buildlog_recipe_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';
    30 
    33 
    31 $buildlog_recipe_status->{name} = 'buildlog_recipe_status';
    34 $buildlog_recipe_status->{name} = 'buildlog_recipe_status';
    32 $buildlog_recipe_status->{next_status} = {};
    35 $buildlog_recipe_status->{next_status} = {status=>$buildlog_recipe_status_status};
    33 $buildlog_recipe_status->{on_start} = 'RaptorRecipe::on_start_buildlog_recipe';
    36 $buildlog_recipe_status->{on_start} = 'RaptorRecipe::on_start_buildlog_recipe';
    34 $buildlog_recipe_status->{on_end} = 'RaptorRecipe::on_end_buildlog_recipe';
    37 $buildlog_recipe_status->{on_end} = 'RaptorRecipe::on_end_buildlog_recipe';
    35 $buildlog_recipe_status->{on_chars} = 'RaptorRecipe::on_chars_buildlog_recipe';
    38 $buildlog_recipe_status->{on_chars} = 'RaptorRecipe::on_chars_buildlog_recipe';
    36 
    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 
    37 my $characters = '';
    50 my $characters = '';
    38 my $recipe_info = {};
    51 
    39 
    52 my $CATEGORY_RECIPEFAILURE = 'recipe_failure';
    40 my $category = $RaptorCommon::CATEGORY_RAPTORRECIPE;
    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';
    41 
    56 
    42 sub process
    57 sub process
    43 {
    58 {
    44 	my ($text) = @_;
    59 	my ($text, $component, $phase, $recipe, $file, $line) = @_;
    45 	
    60 	
    46 	my $severity = $RaptorCommon::SEVERITY_UNKNOWN;
    61 	my $category = $CATEGORY_RECIPEFAILURE;
    47 	
    62 	my $severity = '';
    48 	if ($text =~ m,Cannot process schema version .* of file,)
    63 	my $subcategory = '';
    49 	{
    64 	
    50 		$severity = $RaptorCommon::SEVERITY_CRITICAL;
    65 	if ($text =~ m,Error:  #5: cannot open source input file .*: No such file or directory,)
    51 		
    66 	{
    52 		#dump_recipe($category, $severity, $text);
    67 		$severity = $RaptorCommon::SEVERITY_MAJOR;
    53 		print "$category, $severity, $text\n";
    68 		my $subcategory = $CATEGORY_RECIPEFAILURE_ARMCC_CANNOTOPENSOURCEINPUTFILE;
    54 	}
    69 		RaptorCommon::dump_fault($category, $subcategory, $severity, $component, $phase, $recipe, $file, $line);
       
    70 	}
       
    71 	elsif ($text =~ m,Fatal error: L6002U: Could not open file .*: No such file or directory,)
       
    72 	{
       
    73 		$severity = $RaptorCommon::SEVERITY_MAJOR;
       
    74 		my $subcategory = $CATEGORY_RECIPEFAILURE_ARMLINK_COULDNOTOPENFILE;
       
    75 		RaptorCommon::dump_fault($category, $subcategory, $severity, $component, $phase, $recipe, $file, $line);
       
    76 	}
       
    77 	elsif ($text =~ m,elf2e32 : Error: E1001: Could not open file : .*.,)
       
    78 	{
       
    79 		$severity = $RaptorCommon::SEVERITY_MAJOR;
       
    80 		my $subcategory = $CATEGORY_RECIPEFAILURE_ELF2E32_COULDNOTOPENFILE;
       
    81 		RaptorCommon::dump_fault($category, $subcategory, $severity, $component, $phase, $recipe, $file, $line);
       
    82 	}
       
    83 	else # log everything by default
       
    84 	{
       
    85 		RaptorCommon::dump_fault($category, $subcategory, $severity, $component, $phase, $recipe, $file, $line);
       
    86 	}
       
    87 }
       
    88 
       
    89 sub on_start_buildlog
       
    90 {
       
    91 	#print FILE "line,layer,component,name,armlicence,platform,phase,code,bldinf,mmp,target,source,\n";
       
    92 	
       
    93 	RaptorCommon::init();
    55 }
    94 }
    56 
    95 
    57 sub on_start_buildlog_recipe
    96 sub on_start_buildlog_recipe
    58 {
    97 {
    59 	my ($el) = @_;
    98 	my ($el) = @_;
    60 	
    99 	
       
   100 	#print "on_start_buildlog_recipe\n";
       
   101 	
    61 	$recipe_info = {};
   102 	$recipe_info = {};
    62 	$characters = '';
       
    63 	
       
    64 	my $attrstring = '';
       
    65 	my $bldinf = '';
       
    66 	
   103 	
    67 	my $attributes = $el->{Attributes};
   104 	my $attributes = $el->{Attributes};
    68 	for (keys %{$attributes})
   105 	for (keys %{$attributes})
    69 	{
   106 	{
    70 		if ($attributes->{$_}->{'LocalName'} eq 'bldinf')
   107 		$recipe_info->{$attributes->{$_}->{'LocalName'}} = $attributes->{$_}->{'Value'};
    71 		{
   108 		#print "$_ -> $attributes->{$_}->{'Value'}\n";
    72 			$bldinf = $attributes->{$_}->{'Value'};
   109 	}
    73 		}
       
    74 		
       
    75 		$attrstring .= "$attributes->{$_}->{'LocalName'}}='$attributes->{$_}->{'Value'}' ";
       
    76 		
       
    77 	}
       
    78 	
       
    79 	if ($bldinf eq '')
       
    80 	{
       
    81 		print "WARNING: recipe tag with no bldinf attribute. Associating to package unknown/unknown\n";
       
    82 		$bldinf = "/sf/unknown/unknown/group/bld.inf";
       
    83 	}
       
    84 	
       
    85 	$recipe_info->{bldinf} = $bldinf;
       
    86 	
       
    87 	$characters = "<recipe $attrstring>\n";
       
    88 }
   110 }
    89 
   111 
    90 sub on_chars_buildlog_recipe
   112 sub on_chars_buildlog_recipe
    91 {
   113 {
    92 	my ($ch) = @_;
   114 	my ($ch) = @_;
    96 	$characters .= $ch->{Data};
   118 	$characters .= $ch->{Data};
    97 	
   119 	
    98 	#print "characters is now -->$characters<--\n";
   120 	#print "characters is now -->$characters<--\n";
    99 }
   121 }
   100 
   122 
       
   123 sub on_start_buildlog_recipe_status
       
   124 {
       
   125 	my ($el) = @_;
       
   126 	
       
   127 	my $attributes = $el->{Attributes};
       
   128 	for (keys %{$attributes})
       
   129 	{
       
   130 		if ($attributes->{$_}->{'LocalName'} eq 'code')
       
   131 		{
       
   132 			$recipe_info->{$attributes->{$_}->{'LocalName'}} = $attributes->{$_}->{'Value'};
       
   133 		}
       
   134 		elsif ($attributes->{$_}->{'LocalName'} eq 'exit')
       
   135 		{
       
   136 			$recipe_info->{$attributes->{$_}->{'LocalName'}} = $attributes->{$_}->{'Value'};
       
   137 		}
       
   138 		elsif ($attributes->{$_}->{'LocalName'} eq 'attempt')
       
   139 		{
       
   140 			$recipe_info->{$attributes->{$_}->{'LocalName'}} = $attributes->{$_}->{'Value'};
       
   141 		}
       
   142 	}
       
   143 }
       
   144 
   101 sub on_end_buildlog_recipe
   145 sub on_end_buildlog_recipe
   102 {
   146 {
   103 	#print "on_end_buildlog_recipe\n";
   147 	if ($recipe_info->{exit} =~ /failed/)
   104 	
   148 	{
   105 	$characters .= "\n</recipe>\n";
   149 		# normalize bldinf path
   106 	
   150 		$recipe_info->{bldinf} = lc($recipe_info->{bldinf});
   107 	my $normalized = lc($recipe_info->{bldinf});
   151 		$recipe_info->{bldinf} =~ s,^[A-Za-z]:,,;
   108 	$normalized =~ s,^[A-Za-z]:,,;
   152 		$recipe_info->{bldinf} =~ s,[\\],/,g;
   109 	$normalized =~ s,[\\],/,g;
   153 		
   110 	
   154 		my $package = '';
   111 	$normalized =~ m,^/sf/([^/]+)/([^/]+)/,;
   155 		if ($recipe_info->{bldinf} =~ m,/((os|mw|app|tools|ostools|adaptation)/[^/]*),)
   112 	my $layer = $1;
   156 		{
   113 	my $package = $2;
   157 			$package = $1;
   114 	
   158 			$package =~ s,/,_,;
   115 	mkdir("$::basedir/recipes");
   159 		}
   116 	mkdir("$::basedir/recipes/$layer");
   160 		else
   117 	mkdir("$::basedir/recipes/$layer/$package");
   161 		{
   118 	
   162 			print "WARNING: can't understand bldinf attribute of recipe: $recipe_info->{bldinf}. Won't dump to failed recipes file.\n";
   119 	my $filename = "$::basedir/recipes/$layer/$package/recipes.txt";
   163 		}
   120 	
   164 		
   121 	print "Writing recipes file $filename\n" if (!-f$filename);
   165 		$characters =~ s,^[\r\n]*,,;
   122 	open(FILE, ">>$filename");
   166 		$characters =~ s,[\r\n]*$,,;
   123 	print FILE $characters;
   167 		
   124 	close(FILE);
   168 		if ($package)
       
   169 		{
       
   170 			$filename = "$::basedir/$package.txt";
       
   171 			if (!-f$filename)
       
   172 			{
       
   173 				print "Writing recipe file $filename\n";
       
   174 				open(FILE, ">$filename");
       
   175 				close(FILE);
       
   176 			}
       
   177 			
       
   178 			if ($failure_item == 0 and -f "$filename")
       
   179 			{
       
   180 				open(FILE, "$filename");
       
   181 				{
       
   182 					local $/ = undef;
       
   183 					my $filecontent = <FILE>;
       
   184 					$failure_item = $1 if ($filecontent =~ m/.*---failure_item_(\d+)/s);
       
   185 				}
       
   186 				close(FILE);
       
   187 			}
       
   188 			
       
   189 			$failure_item++;
       
   190 			
       
   191 			open(FILE, ">>$filename");
       
   192 			print FILE "---failure_item_$failure_item\---\n";
       
   193 			print FILE "$characters\n\n";
       
   194 			close(FILE);
       
   195 		}
       
   196 		
       
   197 		process($characters, $recipe_info->{bldinf}, $recipe_info->{phase}, $recipe_info->{name}, "$package.txt", $failure_item);
       
   198 	}
       
   199 
       
   200 	$characters = '';
       
   201 }
       
   202 
       
   203 sub on_end_buildlog
       
   204 {
   125 }
   205 }
   126 
   206 
   127 
   207 
   128 1;
   208 1;