build_report.pl 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/perl
  2. use Scalar::Util qw(looks_like_number);
  3. $" = "\n"; # change list separator
  4. $keil_size = "Program Size:.+";
  5. %report_patterns =
  6. ( #toolchain, pattern-list
  7. 'keil' => ['Build target \'(.+)\'', '(\d+ Error.+\d+ Warning)', $keil_size . 'Code=(\d+)', $keil_size . 'RO-data=(\d+)', $keil_size . 'RW-data=(\d+)', $keil_size . 'ZI-data=(\d+)'],
  8. 'iar' => ['Building configuration.+ (.+)', 'Total number of (.+)', '((\s+\d+){4})\s+[0-9a-f]+'],
  9. 'xpresso' => ['Build of configuration (\S+) ', '(Finished) building target', '((\s+\d+){4})\s+[0-9a-f]+']
  10. );
  11. @report_file_list = <build_all_*.txt>;
  12. #print "@report_file_list"; die;
  13. open $freport, ">build_report.txt" or die "cannot open build_reprot.txt";
  14. foreach (@report_file_list)
  15. {
  16. /build_all_([^_]+)_/;
  17. build_report($_, $1);
  18. }
  19. sub build_report
  20. {
  21. my $report_file = $_[0];
  22. my $toolchain = $_[1];
  23. my @pattern = @{$report_patterns{$toolchain}};
  24. open $report_handle, $report_file or die "cannot open $report_file";
  25. $report_file =~ /build_all_(.+).txt/;
  26. print $freport "--------------------------------------------------------------------\n";
  27. printf $freport "%-25s", $1;
  28. printf $freport "%13s", "" if $toolchain eq 'iar';
  29. print $freport " text data bss dec" if $toolchain eq 'xpresso' or $toolchain eq 'iar';
  30. print $freport " Code RO RW ZI" if $toolchain eq 'keil';
  31. print $freport "\n--------------------------------------------------------------------";
  32. while( my $line = <$report_handle> )
  33. {
  34. local $/ = "\r\n";
  35. chomp $line;
  36. foreach (@pattern)
  37. {
  38. if ($line =~ /$_/)
  39. {
  40. my $fmat = ($_ eq $pattern[0]) ? "\n%-25s" : "%s ";
  41. $fmat = "%6s " if $toolchain eq 'keil' and looks_like_number($1);
  42. printf $freport $fmat, $1;
  43. }
  44. }
  45. }
  46. close $report_handle;
  47. print $freport "\n\n";
  48. }