bc_tools/update_knownissues.pl
changeset 234 74890d706f0c
child 243 4ee1b1d72018
equal deleted inserted replaced
233:cf1d34408de3 234:74890d706f0c
       
     1 #!/usr/bin/perl
       
     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 #	Maciej Seroka, maciejs@symbian.org
       
    12 #
       
    13 # Description:
       
    14 #   This is a tool for adding BC issues to Known Issues list.
       
    15 #
       
    16 
       
    17 use strict;
       
    18 use Getopt::Long;
       
    19 use XML::Simple;
       
    20 use Tie::File;
       
    21 
       
    22 my $hdr_report;
       
    23 my $lib_report;
       
    24 my $ki_file;
       
    25 my $current_report;
       
    26 my $header_num;
       
    27 my $n;
       
    28 my $m;
       
    29 my $file_name;
       
    30 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.
       
    32 my $header_found;
       
    33 my $status;
       
    34 my $line;
       
    35 my @lines;
       
    36 my $help;
       
    37 
       
    38 sub usage($);
       
    39 sub help();
       
    40 sub usage_error();
       
    41 
       
    42 my %optmap = (  'headers-report' => \$hdr_report,
       
    43 			    'libraries-report' => \$lib_report,
       
    44 			    'knownissues-file' => \$ki_file,
       
    45 				'help' => \$help);
       
    46 
       
    47 GetOptions(\%optmap,
       
    48           'headers-report=s',
       
    49           'libraries-report=s',
       
    50           'knownissues-file=s',
       
    51 		  'help!') 
       
    52           or usage_error();
       
    53 
       
    54 if ($help) {
       
    55 	help();
       
    56 }
       
    57 
       
    58 # --headers-report is mandatory.
       
    59 usage_error(), unless (defined($hdr_report) || defined($lib_report));
       
    60 
       
    61 # --knownissues-file is mandatory.
       
    62 usage_error(), unless (defined($ki_file));
       
    63 
       
    64 # Open Known Isses file.
       
    65 tie @lines, 'Tie::File', $ki_file or die ("Cannot tie file \"$ki_file\". $!\n");
       
    66 
       
    67 if ($hdr_report) {
       
    68 	# Parse the input XML into hashrefs.
       
    69 	print "Parsing " . $hdr_report . "... ";
       
    70 	$current_report = XMLin("./$hdr_report", keeproot => 1,
       
    71 		forcearray => [ 'header', 'baselineversion', 'currentversion', 'timestamp', 'day', 'month', 'year', 'hour', 'minute', 'second', #
       
    72 		'haversion', 'formatversion', 'cmdlineparms', 'parm', 'pname', 'pvalue', 'knownissuesversion', 'os', 'version', 'buildweek', 'issuelist',#
       
    73 		'headerfile', 'filename', 'comparefilename', 'status', 'comment', 'issue', 'checksum', 'shortname', 'issueid', 'typeid', 'identityid', #
       
    74 		'identitydescription', 'typestring', 'cause', 'documentation', 'ignoreinformation', 'linenumber', 'severity', 'scseverity'], keyattr => [] );
       
    75 	print "complete \n";
       
    76 	# Get number of header files.
       
    77 	my $header_num = @{$current_report->{'bbcresults'}->{'issuelist'}->[0]->{'headerfile'}};
       
    78 	print "Number of header files in the report: $header_num \n";
       
    79 
       
    80 	$n = 0;
       
    81 	while ($n < $header_num) {
       
    82 		$file_name = $current_report->{'bbcresults'}->{'issuelist'}->[0]->{'headerfile'}->[$n]->{'shortname'}->[0];
       
    83 		$check_sum = $current_report->{'bbcresults'}->{'issuelist'}->[0]->{'headerfile'}->[$n]->{'checksum'}->[0];
       
    84 		$m = 0;
       
    85 		$header_found = 0;
       
    86 		$status = 0;
       
    87 		foreach (@lines) { 
       
    88 			if (@lines[$m] =~ "\"$file_name\"") { # Mark header file as present in the Known Issues file.
       
    89 				$header_found = 1;
       
    90 				$line = $m;
       
    91 				last;
       
    92 			}
       
    93 			$m++;
       
    94 		}
       
    95 		if ($header_found) { # Ensure there is no duplicate in the Known Issues file.
       
    96 			$m = 0;
       
    97 			foreach (@lines) { 
       
    98 				if (@lines[$m] =~ "checksum=\"$check_sum\"") { 
       
    99 					$status = 1; # Means OK issue (already known).
       
   100 					print "Duplicate found ($check_sum) for header file: $file_name\n";
       
   101 					last;
       
   102 				}
       
   103 				$m++;
       
   104 			}
       
   105 		}
       
   106 		if (($header_found) && (!($status))) { # Insert new version of header file.
       
   107 			splice @lines, $line+1, 0, "    <version checksum=\"$check_sum\">";
       
   108 			splice @lines, $line+2, 0, "      <status>OK<\/status>";
       
   109 			splice @lines, $line+3, 0, "      <comment>$comment<\/comment>";
       
   110 			splice @lines, $line+4, 0, "    <\/version>";
       
   111 			print "New version ($check_sum) of header file: $file_name added to Known Issues list\n";
       
   112 		}
       
   113 		if (!($header_found)) { # Insert new header file.
       
   114 			# Find the first occurrence of <headerfile>. - ASSUMPTION: at least one entry exists.
       
   115 			$m = 0;
       
   116 			foreach (@lines) { 
       
   117 				if (@lines[$m] =~ "<headerfile") { 
       
   118 					last; }
       
   119 				else {
       
   120 					$m++;
       
   121 				}
       
   122 			}
       
   123 			splice @lines, $m, 0, "  <headerfile name=\"$file_name\">";
       
   124 			splice @lines, $m+1, 0, "    <version checksum=\"$check_sum\">";
       
   125 			splice @lines, $m+2, 0, "      <status>OK<\/status>";
       
   126 			splice @lines, $m+3, 0, "      <comment>$comment<\/comment>";
       
   127 			splice @lines, $m+4, 0, "    <\/version>";
       
   128 			splice @lines, $m+5, 0, "  <\/headerfile>";
       
   129 			print "Header file: $file_name ($check_sum) added to Known Issues list\n";
       
   130 		}
       
   131 		$n++;
       
   132 	}
       
   133 	print "OK\n";
       
   134 }
       
   135 
       
   136 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"
       
   138 }
       
   139 
       
   140 untie @lines;
       
   141 
       
   142 exit 0;
       
   143 
       
   144 sub usage($)
       
   145 {
       
   146     my $error = shift;
       
   147     my $fh = $error == 0 ? *STDOUT : *STDERR;
       
   148     print $fh "update_knownissues.pl\n" .
       
   149             "Specify the headers report or\/and libraries report and the known issues file\n" .
       
   150             "synopsis:\n" .
       
   151             "  update_knownissues.pl --help\n" .
       
   152             "  update_knownissues.pl [--headers-report=FILENAME1] [--libraries-report=FILENAME2] [--knownissues-file=FILENAME3] \n" .
       
   153             "options:\n" .
       
   154             "  --help                        Display this help and exit\n" .
       
   155             "  --headers-report=FILENAME1    FILENAME1 is the name of the filtered headers (sub-)report.\n" .
       
   156             "  --libraries-report=FILENAME2  FILENAME2 is the name of the filtered libraries report. This option is not implemented yet.\n" .
       
   157             "  --knownissues-file=FILENAME3  FILENAME3 is the name of the known issues file which will be updated.\n";
       
   158     exit $error;            
       
   159 }
       
   160 
       
   161 sub help()
       
   162 {
       
   163     usage(0);
       
   164 }
       
   165 
       
   166 sub usage_error()
       
   167 {
       
   168     usage(1);
       
   169 }