bc_tools/update_knownissues.pl
changeset 222 4ee1b1d72018
parent 215 74890d706f0c
equal deleted inserted replaced
221:b7a101a82e4b 222:4ee1b1d72018
    22 my $hdr_report;
    22 my $hdr_report;
    23 my $lib_report;
    23 my $lib_report;
    24 my $ki_file;
    24 my $ki_file;
    25 my $current_report;
    25 my $current_report;
    26 my $header_num;
    26 my $header_num;
       
    27 my $issues_num;
    27 my $n;
    28 my $n;
    28 my $m;
    29 my $m;
       
    30 my $offset;
       
    31 my $counter;
    29 my $file_name;
    32 my $file_name;
    30 my $check_sum;
    33 my $check_sum;
    31 my $comment = "Issue closed as invalid by the PkO (Not a BC break)."; # This is a default comment that will be added to Known Issues list with each header file.
    34 my $comment = "Issue closed as invalid by the PkO (Not a BC break)."; # This is a default comment that will be added to Known Issues list with each header file.
    32 my $header_found;
    35 my $header_found;
       
    36 my $library_found;
       
    37 my $issue_found;
    33 my $status;
    38 my $status;
    34 my $line;
    39 my $line;
    35 my @lines;
    40 my @lines;
       
    41 my $temp_ref;
       
    42 my $temp_line;
       
    43 my $temp_issues_num;
       
    44 my $my_issue;
    36 my $help;
    45 my $help;
    37 
    46 
    38 sub usage($);
    47 sub usage($);
    39 sub help();
    48 sub help();
    40 sub usage_error();
    49 sub usage_error();
   128 			splice @lines, $m+5, 0, "  <\/headerfile>";
   137 			splice @lines, $m+5, 0, "  <\/headerfile>";
   129 			print "Header file: $file_name ($check_sum) added to Known Issues list\n";
   138 			print "Header file: $file_name ($check_sum) added to Known Issues list\n";
   130 		}
   139 		}
   131 		$n++;
   140 		$n++;
   132 	}
   141 	}
       
   142 	# Free up memory resources.
       
   143 	$current_report = ();
   133 	print "OK\n";
   144 	print "OK\n";
   134 }
   145 }
   135 
   146 
   136 if ($lib_report) {
   147 if ($lib_report) {
   137 	print "Warning: Automatic update of the Known Issues file based on a libraries report is not available in the current version of the script.\n"
   148 	# Parse the input XMLs into hashrefs.
       
   149 	print "Parsing " . $lib_report . "... ";
       
   150 	$current_report = XMLin("./$lib_report", keeproot => 1,
       
   151 		forcearray => [ 'header', 'baselineversion', 'currentversion', 'timestamp', 'day', 'month', 'year', 'hour', 'minute', 'second', #
       
   152 		'laversion', 'formatversion', 'cmdlineparms', 'parm', 'pname', 'pvalue', 'knownissuesversion', 'os', 'version', 'buildweek', 'issuelist',#
       
   153 		'library', 'name', 'comparefilename', 'shortname', 'baseplatform', 'currentplatform', 'issue', 'typeinfo', 'typeid', 'funcname', 'newfuncname', 'newfuncpos', #
       
   154 		'bc_severity', 'sc_severity', 'status', 'comment', 'funcpos' ], keyattr => [] );
       
   155 	print "complete \n";
       
   156 	# Get number of libraries.
       
   157 	my $lib_num = @{$current_report->{'bbcresults'}->{'issuelist'}->[0]->{'library'}};
       
   158 	print "Number of libraries in the report: $lib_num \n";
       
   159 	
       
   160 	$n = 0;
       
   161 	while ($n < $lib_num) {
       
   162 		$file_name = $current_report->{'bbcresults'}->{'issuelist'}->[0]->{'library'}->[$n]->{'shortname'}->[0];
       
   163 		# Check if library present in the Known Issues file.
       
   164 		$m = 0;
       
   165 		$library_found = 0;
       
   166 		foreach (@lines) { 
       
   167 			if (@lines[$m] =~ "\"$file_name\"") { # Mark header file as present in the Known Issues file.
       
   168 				$library_found = 1;
       
   169 				$line = $m;
       
   170 				last;
       
   171 			}
       
   172 			$m++;
       
   173 		}
       
   174 		if ($library_found) { # Some entries already persent in the Known Issues file for the current library.
       
   175 			print "Found library: $file_name in line: $line\n";
       
   176 			$issues_num = @{$current_report->{'bbcresults'}->{'issuelist'}->[0]->{'library'}->[$n]->{'issue'}};
       
   177 			# Get library with all issues to $temp_ref;
       
   178 			$m = $line - 1;
       
   179 			$temp_line = "";
       
   180 			do {
       
   181 				$m++;
       
   182 				$temp_line = $temp_line . @lines[$m];
       
   183 			} while (@lines[$m] !~ "<\/library>");
       
   184 			$temp_ref = XMLin($temp_line, keeproot => 1,
       
   185 			forcearray => [ 'library', 'issue', 'typeid', 'typeinfo', 'funcname', 'newfuncname', 'funcpos', #
       
   186 			'newfuncpos', 'bc_severity', 'sc_severity', 'status', 'comment' ], keyattr => [] );
       
   187 			$temp_issues_num = @{$temp_ref->{'library'}->[0]->{'issue'}};
       
   188 			# For each issue related to the current library check for a matching issue in $temp_ref.
       
   189 			foreach $my_issue (@{$current_report->{'bbcresults'}->{'issuelist'}->[0]->{'library'}->[$n]->{'issue'}}) {
       
   190 				$issue_found = 0;
       
   191 				$m = 0;
       
   192 				while ($m < $temp_issues_num) {
       
   193 					# Compare all possible values.
       
   194 					if (($my_issue->{'typeid'}->[0] eq $temp_ref->{'library'}->[0]->{'issue'}->[$m]->{'typeid'}->[0]) &&
       
   195 						($my_issue->{'typeinfo'}->[0] eq $temp_ref->{'library'}->[0]->{'issue'}->[$m]->{'typeinfo'}->[0]) &&
       
   196 						($my_issue->{'funcname'}->[0] eq $temp_ref->{'library'}->[0]->{'issue'}->[$m]->{'funcname'}->[0]) &&
       
   197 						($my_issue->{'newfuncname'}->[0] eq $temp_ref->{'library'}->[0]->{'issue'}->[$m]->{'newfuncname'}->[0]) &&
       
   198 						($my_issue->{'funcpos'}->[0] eq $temp_ref->{'library'}->[0]->{'issue'}->[$m]->{'funcpos'}->[0]) &&
       
   199 						($my_issue->{'newfuncpos'}->[0] eq $temp_ref->{'library'}->[0]->{'issue'}->[$m]->{'newfuncpos'}->[0]) &&
       
   200 						($my_issue->{'bc_severity'}->[0] eq $temp_ref->{'library'}->[0]->{'issue'}->[$m]->{'bc_severity'}->[0]) &&
       
   201 						($my_issue->{'sc_severity'}->[0] eq $temp_ref->{'library'}->[0]->{'issue'}->[$m]->{'sc_severity'}->[0]) &&
       
   202 						($temp_ref->{'library'}->[0]->{'issue'}->[$m]->{'status'}->[0]) =~ "OK") {
       
   203 						print "Duplicated issue found for library: $file_name\n";
       
   204 						$issue_found = 1; # Do not add this issue to the Known Issues file.
       
   205 						last;
       
   206 					}
       
   207 					$m++;
       
   208 				}
       
   209 				if (!$issue_found) { # Add the issue to the Known Issues file for exising library entry (as the top one).
       
   210 					$offset = 1; # Initial offset value.
       
   211 					splice @lines, $line+$offset, 0, "    <issue>"; $offset++;
       
   212 					if ($my_issue->{'typeid'}->[0]) { splice @lines, $line+$offset, 0, "      <typeid>$my_issue->{'typeid'}->[0]<\/typeid>"; $offset++; }
       
   213 					if ($my_issue->{'typeinfo'}->[0]) { splice @lines, $line+$offset, 0, "      <typeinfo>$my_issue->{'typeinfo'}->[0]<\/typeinfo>"; $offset++; }
       
   214 					if ($my_issue->{'funcname'}->[0]) { 
       
   215 						# Fix ampersand, greater-than and less-than characters before saving.
       
   216 						$my_issue->{'funcname'}->[0] =~ s/&/&amp;/g;
       
   217 						$my_issue->{'funcname'}->[0] =~ s/</&lt;/g;
       
   218 						$my_issue->{'funcname'}->[0] =~ s/>/&gt;/g;
       
   219 						splice @lines, $line+$offset, 0, "      <funcname>$my_issue->{'funcname'}->[0]<\/funcname>"; 
       
   220 						$offset++;
       
   221 					}
       
   222 					if ($my_issue->{'newfuncname'}->[0]) { 
       
   223 						# Fix ampersand, greater-than and less-than characters before saving.
       
   224 						$my_issue->{'newfuncname'}->[0] =~ s/&/&amp;/g;
       
   225 						$my_issue->{'newfuncname'}->[0] =~ s/</&lt;/g;
       
   226 						$my_issue->{'newfuncname'}->[0] =~ s/>/&gt;/g;
       
   227 						splice @lines, $line+$offset, 0, "      <newfuncname>$my_issue->{'newfuncname'}->[0]<\/newfuncname>";
       
   228 						$offset++;
       
   229 					}
       
   230 					if ($my_issue->{'funcpos'}->[0]) { splice @lines, $line+$offset, 0, "      <funcpos>$my_issue->{'funcpos'}->[0]<\/funcpos>"; $offset++; }
       
   231 					if ($my_issue->{'newfuncpos'}->[0]) { splice @lines, $line+$offset, 0, "      <newfuncpos>$my_issue->{'newfuncpos'}->[0]<\/newfuncpos>"; $offset++; }
       
   232 					if ($my_issue->{'bc_severity'}->[0]) { splice @lines, $line+$offset, 0, "      <bc_severity>$my_issue->{'bc_severity'}->[0]<\/bc_severity>"; $offset++; }
       
   233 					if ($my_issue->{'sc_severity'}->[0]) { splice @lines, $line+$offset, 0, "      <sc_severity>$my_issue->{'sc_severity'}->[0]<\/sc_severity>"; $offset++; }
       
   234 					splice @lines, $line+$offset, 0, "      <status>OK<\/status>"; $offset++;
       
   235 					splice @lines, $line+$offset, 0, "      <comment>$comment<\/comment>"; $offset++;
       
   236 					splice @lines, $line+$offset, 0, "    <\/issue>";
       
   237 					print "New issue added to Known Issues list for library: $file_name\n";
       
   238 				}
       
   239 			}
       
   240 			$temp_ref = ();
       
   241 		} else { # Add the whole new entry for the current library.
       
   242 			# Find the first occurrence of <library>. - ASSUMPTION: at least one entry exists.
       
   243 			$m = 0;
       
   244 			foreach (@lines) { 
       
   245 				if (@lines[$m] =~ "<library") { 
       
   246 					last; }
       
   247 				else {
       
   248 					$m++;
       
   249 				}
       
   250 			}
       
   251 			$offset = 0; # Initial offset value.
       
   252 			splice @lines, $m+$offset, 0, "  <library name=\"$file_name\">"; $offset++;
       
   253 			print "Library: $file_name added to Known Issues list\n";
       
   254 			$counter = 1;
       
   255 			foreach $my_issue (@{$current_report->{'bbcresults'}->{'issuelist'}->[0]->{'library'}->[$n]->{'issue'}}) {	
       
   256 				print "Adding issue: $counter... ";
       
   257 				splice @lines, $m+$offset, 0, "    <issue>"; $offset++;
       
   258 				if ($my_issue->{'typeid'}->[0]) { splice @lines, $m+$offset, 0, "      <typeid>$my_issue->{'typeid'}->[0]<\/typeid>"; $offset++; }
       
   259 				if ($my_issue->{'typeinfo'}->[0]) { splice @lines, $m+$offset, 0, "      <typeinfo>$my_issue->{'typeinfo'}->[0]<\/typeinfo>"; $offset++; }
       
   260 				if ($my_issue->{'funcname'}->[0]) { 
       
   261 					# Fix ampersand, greater-than and less-than characters before saving.
       
   262 					$my_issue->{'funcname'}->[0] =~ s/&/&amp;/g;
       
   263 					$my_issue->{'funcname'}->[0] =~ s/</&lt;/g;
       
   264 					$my_issue->{'funcname'}->[0] =~ s/>/&gt;/g;
       
   265 					splice @lines, $m+$offset, 0, "      <funcname>$my_issue->{'funcname'}->[0]<\/funcname>"; 
       
   266 					$offset++;
       
   267 				}
       
   268 				if ($my_issue->{'newfuncname'}->[0]) { 
       
   269 					# Fix ampersand, greater-than and less-than characters before saving.
       
   270 					$my_issue->{'newfuncname'}->[0] =~ s/&/&amp;/g;
       
   271 					$my_issue->{'newfuncname'}->[0] =~ s/</&lt;/g;
       
   272 					$my_issue->{'newfuncname'}->[0] =~ s/>/&gt;/g;
       
   273 					splice @lines, $m+$offset, 0, "      <newfuncname>$my_issue->{'newfuncname'}->[0]<\/newfuncname>";
       
   274 					$offset++;
       
   275 				}
       
   276 				if ($my_issue->{'funcpos'}->[0]) { splice @lines, $m+$offset, 0, "      <funcpos>$my_issue->{'funcpos'}->[0]<\/funcpos>"; $offset++; }
       
   277 				if ($my_issue->{'newfuncpos'}->[0]) { splice @lines, $m+$offset, 0, "      <newfuncpos>$my_issue->{'newfuncpos'}->[0]<\/newfuncpos>"; $offset++; }
       
   278 				if ($my_issue->{'bc_severity'}->[0]) { splice @lines, $m+$offset, 0, "      <bc_severity>$my_issue->{'bc_severity'}->[0]<\/bc_severity>"; $offset++; }
       
   279 				if ($my_issue->{'sc_severity'}->[0]) { splice @lines, $m+$offset, 0, "      <sc_severity>$my_issue->{'sc_severity'}->[0]<\/sc_severity>"; $offset++; }
       
   280 				splice @lines, $m+$offset, 0, "      <status>OK<\/status>"; $offset++;
       
   281 				splice @lines, $m+$offset, 0, "      <comment>$comment<\/comment>"; $offset++;
       
   282 				splice @lines, $m+$offset, 0, "    <\/issue>"; $offset++;
       
   283 				print "done\n";
       
   284 				$counter++;
       
   285 			}
       
   286 			splice @lines, $m+$offset, 0, "  <\/library>";
       
   287 		}
       
   288 		$n++;
       
   289 	}
       
   290 	# Free up memory resources.
       
   291 	$current_report = ();
       
   292 	print "OK\n";
   138 }
   293 }
   139 
   294 
   140 untie @lines;
   295 untie @lines;
   141 
   296 
   142 exit 0;
   297 exit 0;