13 # Description: |
13 # Description: |
14 # This is a tool for filtering static BC header reports. |
14 # This is a tool for filtering static BC header reports. |
15 # |
15 # |
16 |
16 |
17 use strict; |
17 use strict; |
|
18 use Getopt::Long; |
18 use XML::Simple; |
19 use XML::Simple; |
19 use File::Copy; |
|
20 use Tie::File; |
20 use Tie::File; |
21 use Data::Dumper; |
|
22 |
21 |
23 my $report; |
22 my $report; |
24 my $header_list; |
23 my $header_list; |
25 my $destfile; |
24 my $destfile; |
26 my $pkg_destfile; |
25 my $pkg_destfile; |
27 my $del_ok_issues = 1; # This variable determines whether to delete OK issues first. |
26 my $del_ok_issues = 1; # This variable determines whether to delete OK issues first. |
28 my $del_comp_issues = 0; # This variable determines whether to delete Compilation errors. |
27 my $del_comp_issues = 0; # This variable determines whether to delete Compilation errors. |
29 my $del_boost_issues = 1; # This variable determines whether to delete issues for Boost API headers. |
28 my $del_boost_issues = 1; # This variable determines whether to delete issues for Boost API headers. |
30 my $tsv_file; |
29 my $tsv_file; # If defined then sub-reports per package will be generated. |
31 my $sub_reports = 0; # This variable determines whether to generate sub-reports per package. |
|
32 my $n; |
30 my $n; |
33 my $m; |
31 my $m; |
34 my $p; |
32 my $p; |
35 my $file_name; |
33 my $file_name; |
36 my $delete_node; |
34 my $delete_node; |
37 my @lines; |
35 my @lines; |
38 my $line; |
36 my $line; |
39 my @pkgs; |
37 my @pkgs; |
40 my $nopkg; |
38 my $nopkg; |
41 my $pkgs_num; |
39 my $pkgs_num; |
42 my $hdr_to_pkg; |
40 my ($hdr_to_pkg, $package); |
43 my $package; |
|
44 my $pkg_found; |
41 my $pkg_found; |
45 my $add_pkg; |
42 my $add_pkg; |
46 my $temp_report; |
43 my $temp_report; |
47 my $current_pkg; |
44 my $current_pkg; |
48 |
45 my $help; |
49 if ($ARGV[1]) { |
46 |
50 $report = $ARGV[0]; |
47 sub usage($); |
51 $header_list = $ARGV[1]; |
48 sub help(); |
52 $destfile = "filtered_" . $report; |
49 sub usage_error(); |
53 } else { |
50 |
54 die "Missing parameter(s). For example: ha_filter.pl headers_report.xml public_headers.txt"; |
51 my %optmap = ( 'headers-report' => \$report, |
55 } |
52 'public-api-list' => \$header_list, |
56 |
53 'xref-file' => \$tsv_file, |
57 if ($ARGV[2]) { |
54 'help' => \$help); |
58 $tsv_file = $ARGV[2]; |
55 |
59 $sub_reports = 1; |
56 GetOptions(\%optmap, |
60 } |
57 'headers-report=s', |
|
58 'public-api-list=s', |
|
59 'xref-file=s', |
|
60 'help!') |
|
61 or usage_error(); |
|
62 |
|
63 if ($help) { |
|
64 help(); |
|
65 } |
|
66 |
|
67 # --headers-report is mandatory. |
|
68 usage_error(), unless (defined($report)); |
|
69 |
|
70 # --public-headers is mandatory. |
|
71 usage_error(), unless (defined($header_list)); |
|
72 |
|
73 # Define output file based on the headers report name. |
|
74 $destfile = "filtered_" . $report; |
61 |
75 |
62 # Parse the input XML into hashrefs. |
76 # Parse the input XML into hashrefs. |
63 print "Parsing " . $report . "... "; |
77 print "Parsing " . $report . "... "; |
64 my $current_report = XMLin("./$report", keeproot => 1, |
78 my $current_report = XMLin("./$report", keeproot => 1, |
65 forcearray => [ 'header', 'baselineversion', 'currentversion', 'timestamp', 'day', 'month', 'year', 'hour', 'minute', 'second', # |
79 forcearray => [ 'header', 'baselineversion', 'currentversion', 'timestamp', 'day', 'month', 'year', 'hour', 'minute', 'second', # |
135 $n = 0; |
149 $n = 0; |
136 while ($n < $header_num) { |
150 while ($n < $header_num) { |
137 $file_name = $current_report->{'bbcresults'}->{'issuelist'}->[0]->{'headerfile'}->[$n]->{'shortname'}->[0]; |
151 $file_name = $current_report->{'bbcresults'}->{'issuelist'}->[0]->{'headerfile'}->[$n]->{'shortname'}->[0]; |
138 $delete_node = 1; |
152 $delete_node = 1; |
139 # Load Public API definitions. |
153 # Load Public API definitions. |
140 open FILE, "<$header_list" or print "Failed to read $header_list: $!\n" and return; |
154 open FILE, "<$header_list" or die("Failed to read $header_list: $!\n"); |
141 while ($line = <FILE>) { # Check against header list. |
155 while ($line = <FILE>) { # Check against header list. |
142 chomp $line; |
156 chomp $line; |
143 if (lc($file_name) eq lc($line)) { # Mark the node to NOT be deleted. |
157 if (lc($file_name) eq lc($line)) { # Mark the node to NOT be deleted. |
144 $delete_node = 0; |
158 $delete_node = 0; |
145 last; |
159 last; |
171 tie @lines, 'Tie::File', $destfile or die ("Cannot tie file \"$destfile\". $!\n"); |
185 tie @lines, 'Tie::File', $destfile or die ("Cannot tie file \"$destfile\". $!\n"); |
172 unshift @lines, "<?xml-stylesheet type=\"text/xsl\" href=\"BBCResults.xsl\"?>"; |
186 unshift @lines, "<?xml-stylesheet type=\"text/xsl\" href=\"BBCResults.xsl\"?>"; |
173 unshift @lines, "<?xml version=\"1.0\" encoding=\"ASCII\" standalone=\"no\" ?>"; |
187 unshift @lines, "<?xml version=\"1.0\" encoding=\"ASCII\" standalone=\"no\" ?>"; |
174 untie @lines; |
188 untie @lines; |
175 |
189 |
176 if ($sub_reports) { # Generate sub-reports per package. |
190 if (defined($tsv_file)) { # Generate sub-reports per package. |
177 # Create the list of packages that link to remaining header files and generate sub-report for Removed header files. |
191 # Create the list of packages that link to remaining header files and generate sub-report for Removed header files. |
178 $nopkg = 0; |
192 $nopkg = 0; |
179 $n = 0; |
193 $n = 0; |
180 while ($n < $header_num) { |
194 while ($n < $header_num) { |
181 $file_name = $current_report->{'bbcresults'}->{'issuelist'}->[0]->{'headerfile'}->[$n]->{'shortname'}->[0]; |
195 $file_name = $current_report->{'bbcresults'}->{'issuelist'}->[0]->{'headerfile'}->[$n]->{'shortname'}->[0]; |
182 $pkg_found = 0; |
196 $pkg_found = 0; |
183 open FILE, "<$tsv_file" or print "Failed to read $tsv_file: $!\n" and return; |
197 open FILE, "<$tsv_file" or die("Failed to read $tsv_file: $!\n"); |
184 while ($line = <FILE>) |
198 while ($line = <FILE>) |
185 { |
199 { |
186 chomp $line; |
200 chomp $line; |
187 ($hdr_to_pkg,$package) = split /\t/,$line; |
201 ($hdr_to_pkg,$package) = split /\t/,$line; |
188 $hdr_to_pkg =~ s/\//\\/g; |
202 $hdr_to_pkg =~ s/\//\\/g; |
248 $header_num = @{$temp_report->{'bbcresults'}->{'issuelist'}->[0]->{'headerfile'}}; |
262 $header_num = @{$temp_report->{'bbcresults'}->{'issuelist'}->[0]->{'headerfile'}}; |
249 print "Processing header files for $current_pkg... \n"; |
263 print "Processing header files for $current_pkg... \n"; |
250 while ($n < $header_num) { |
264 while ($n < $header_num) { |
251 $file_name = $temp_report->{'bbcresults'}->{'issuelist'}->[0]->{'headerfile'}->[$n]->{'shortname'}->[0]; |
265 $file_name = $temp_report->{'bbcresults'}->{'issuelist'}->[0]->{'headerfile'}->[$n]->{'shortname'}->[0]; |
252 $pkg_found = 0; |
266 $pkg_found = 0; |
253 open FILE, "<$tsv_file" or print "Failed to read $tsv_file: $!\n" and return; |
267 open FILE, "<$tsv_file" or die("Failed to read $tsv_file: $!\n");; |
254 while ($line = <FILE>) |
268 while ($line = <FILE>) |
255 { |
269 { |
256 chomp $line; |
270 chomp $line; |
257 ($hdr_to_pkg,$package) = split /\t/,$line; |
271 ($hdr_to_pkg,$package) = split /\t/,$line; |
258 $hdr_to_pkg =~ s/\//\\/g; |
272 $hdr_to_pkg =~ s/\//\\/g; |
283 unshift @lines, "<?xml-stylesheet type=\"text/xsl\" href=\"BBCResults.xsl\"?>"; |
297 unshift @lines, "<?xml-stylesheet type=\"text/xsl\" href=\"BBCResults.xsl\"?>"; |
284 unshift @lines, "<?xml version=\"1.0\" encoding=\"ASCII\" standalone=\"no\" ?>"; |
298 unshift @lines, "<?xml version=\"1.0\" encoding=\"ASCII\" standalone=\"no\" ?>"; |
285 untie @lines; |
299 untie @lines; |
286 } |
300 } |
287 } |
301 } |
|
302 |
|
303 exit 0; |
|
304 |
|
305 sub usage($) |
|
306 { |
|
307 my $error = shift; |
|
308 my $fh = $error == 0 ? *STDOUT : *STDERR; |
|
309 print $fh "ha_filter.pl\n" . |
|
310 "Specify the headers report and public API list\n" . |
|
311 "synopsis:\n" . |
|
312 " ha_filter.pl --help\n" . |
|
313 " ha_filter.pl [--headers-report=XML_FILE] [--public-api-list=TXT_FILE] [--xref-file=TSV_FILE] \n" . |
|
314 "options:\n" . |
|
315 " --help Display this help and exit.\n" . |
|
316 " --headers-report=XML_FILE XML_FILE is the name of the headers report xml file.\n" . |
|
317 " --public-api-list=TXT_FILE TXT_FILE is the file containing the list of public header files.\n" . |
|
318 " --xref-file=TSV_FILE TSV_FILE is the file containing the index of header files linked to packages generated by summarise_tsv.pl.\n"; |
|
319 exit $error; |
|
320 } |
|
321 |
|
322 sub help() |
|
323 { |
|
324 usage(0); |
|
325 } |
|
326 |
|
327 sub usage_error() |
|
328 { |
|
329 usage(1); |
|
330 } |