1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | |
---|
6 | my $DEBUG = 0; |
---|
7 | |
---|
8 | my $DISPLAYED_LINES = 40; # how much to display as default |
---|
9 | { |
---|
10 | my $DARWIN = $ENV{DARWIN}; die "expected environment variable DARWIN to be defined" if not defined $DARWIN; |
---|
11 | if ($DARWIN) { |
---|
12 | # check for homebrew build: |
---|
13 | my $HOMEBREW_OS_VERSION = $ENV{HOMEBREW_OS_VERSION}; |
---|
14 | if (defined($HOMEBREW_OS_VERSION) and ($HOMEBREW_OS_VERSION ne '')) { |
---|
15 | # assume this is a homebrew build! |
---|
16 | my $HOMEBREW_FAIL_LOG_LINES=$ENV{HOMEBREW_FAIL_LOG_LINES}; |
---|
17 | if (defined($HOMEBREW_FAIL_LOG_LINES) and (int($HOMEBREW_FAIL_LOG_LINES)>0)) { |
---|
18 | $DISPLAYED_LINES = $HOMEBREW_FAIL_LOG_LINES; |
---|
19 | } |
---|
20 | else { |
---|
21 | $DISPLAYED_LINES = 15; # =default |
---|
22 | } |
---|
23 | } |
---|
24 | } |
---|
25 | } |
---|
26 | $DISPLAYED_LINES -= (1+2); # reserve space for header line + two extra lines shown after excerpt |
---|
27 | |
---|
28 | sub min($$) { my ($a, $b) = @_; return $a<$b ? $a : $b; } |
---|
29 | |
---|
30 | sub disarm($) { |
---|
31 | my ($line) = @_; |
---|
32 | $line =~ s/:/;/go; # avoid output gets interpreted as error message |
---|
33 | return $line; |
---|
34 | } |
---|
35 | |
---|
36 | my $P_STAR = 2; |
---|
37 | my $P_FAILED = 4; |
---|
38 | my $MAXPRIO = 4; |
---|
39 | |
---|
40 | my @count_prio = (); |
---|
41 | for (my $i=0; $i<=$MAXPRIO; ++$i) { $count_prio[$i] = 0; } |
---|
42 | |
---|
43 | my @listed = (); # contains refs to arrays containing [priority, line] |
---|
44 | |
---|
45 | sub list_error($$) { |
---|
46 | my ($priority, $line) = @_; |
---|
47 | |
---|
48 | die if $priority>$MAXPRIO; |
---|
49 | return if not $priority; |
---|
50 | return if $priority==$P_STAR and $line =~ /Waiting for unfinished jobs/o; |
---|
51 | return if $line =~ /warning:/io; |
---|
52 | |
---|
53 | chomp($line); |
---|
54 | |
---|
55 | if ($priority==$P_STAR and scalar(@listed)) { |
---|
56 | my $prev_r = $listed[$#listed]; |
---|
57 | my ($prevPrio, $prevLine) = @$prev_r; |
---|
58 | if ($prevPrio==$P_FAILED and $prevLine =~ /recipe.*failed/io) { |
---|
59 | # seen a line with '***' after 'recipe...failed' -> concat |
---|
60 | pop @listed; |
---|
61 | $line .= ' + '.$prevLine; |
---|
62 | --$count_prio[$prevPrio]; |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | push @listed, [ $priority, $line ]; |
---|
67 | ++$count_prio[$priority]; |
---|
68 | } |
---|
69 | |
---|
70 | sub print_listed() { |
---|
71 | my @allowed_with_prio = (); |
---|
72 | my @printed_with_prio = (); |
---|
73 | |
---|
74 | my $left = $DISPLAYED_LINES; |
---|
75 | |
---|
76 | for (my $i=1; $i<=$MAXPRIO; ++$i) { |
---|
77 | my $use = min($count_prio[$i], $left); |
---|
78 | $left -= $use; |
---|
79 | $allowed_with_prio[$i] = $use; |
---|
80 | $printed_with_prio[$i] = 0; |
---|
81 | |
---|
82 | if ($DEBUG) { |
---|
83 | if ($count_prio[$i]>0) { |
---|
84 | print STDERR "priority $i: ".$count_prio[$i]." (allowed=".$allowed_with_prio[$i].")\n"; |
---|
85 | } |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | foreach my $entry_r (@listed) { |
---|
90 | my ($priority, $line) = @$entry_r; |
---|
91 | if ($printed_with_prio[$priority] < $allowed_with_prio[$priority]) { |
---|
92 | if ($DEBUG) { |
---|
93 | print STDERR $priority.' | '.disarm($line)."\n"; |
---|
94 | } |
---|
95 | else { |
---|
96 | print STDERR disarm($line)."\n"; |
---|
97 | } |
---|
98 | ++$printed_with_prio[$priority]; |
---|
99 | } |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | sub short_error_summary() { |
---|
104 | my $log = shift @ARGV; |
---|
105 | die "Usage: short_error_summary.pl LOGNAME" if not defined $log; |
---|
106 | |
---|
107 | open(LOG, '<'.$log) || die "failed to open '$log' (Reason: $!)"; |
---|
108 | print STDERR "---------------------------------------- [excerpt of obvious errors below; full log in $log]\n"; |
---|
109 | while (defined($_ = <LOG>)) { |
---|
110 | my $priority = 0; |
---|
111 | if (/error:/io) { $priority = 1; } |
---|
112 | elsif (/\*\*\*/o) { $priority = $P_STAR; } |
---|
113 | elsif (/error/io) { $priority = 3; } |
---|
114 | elsif (/failed/io) { $priority = $P_FAILED; } |
---|
115 | list_error($priority, $_); |
---|
116 | } |
---|
117 | close(LOG); |
---|
118 | print_listed(); |
---|
119 | } |
---|
120 | |
---|
121 | short_error_summary(); |
---|