#!/usr/bonsaitools/bin/perl -- # -*- Mode: perl; indent-tabs-mode: nil -*- # # The contents of this file are subject to the Netscape Public # License Version 1.1 (the "License"); you may not use this file # except in compliance with the License. You may obtain a copy of # the License at http://www.mozilla.org/NPL/ # # Software distributed under the License is distributed on an "AS # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or # implied. See the License for the specific language governing # rights and limitations under the License. # # The Original Code is the Tinderbox build tool. # # The Initial Developer of the Original Code is Netscape Communications # Corporation. Portions created by Netscape are # Copyright (C) 1998 Netscape Communications Corporation. All # Rights Reserved. # # Contributor(s): use lib '../bonsai'; require 'tbglobals.pl'; require 'lloydcgi.pl'; require 'header.pl'; ############################################################# # Global variables $LINES_AFTER_ERROR = 5; $LINES_BEFORE_ERROR = 30; # These variables are set by the error parser functions: # has_error(), has_warning(), and has_errorline(). $error_file = ''; $error_file_ref = ''; $error_line = 0; $error_guess = 0; ############################################################# # CGI inputs if (defined($args = $form{log}) or defined($args = $form{exerpt})) { ($full_logfile, $linenum) = split /:/, $args; ($tree, $logfile) = split /\//, $full_logfile; my $br = tb_find_build_record($tree, $logfile); $errorparser = $br->{errorparser}; $buildname = $br->{buildname}; $buildtime = $br->{buildtime}; $numlines = 50; $numlines = $form{numlines} if exists $form{numlines}; } else { $tree = $form{tree}; $errorparser = $form{errorparser}; $logfile = $form{logfile}; $buildname = $form{buildname}; $buildtime = $form{buildtime}; } $fulltext = $form{fulltext}; $enc_buildname = url_encode($buildname); die "the \"tree\" parameter must be provided\n" unless $tree; require "$tree/treedata.pl"; $time_str = print_time($buildtime); $|=1; if ($linenum) { print_fragment(); exit; } print_header(); print_notes(); # Dynamically load the error parser # die "the \"errorparser\" parameter must be provided\n" unless $errorparser; require "ep_${errorparser}.pl"; if ($fulltext) { my $errors = print_summary(); print_log($errors); } else { $brief_filename = $logfile; $brief_filename =~ s/.gz$/.brief.html/; if (-T "$tree/$brief_filename" and -M _ > -M $tree/$logfile) { open(BRIEFFILE, "<$tree/$brief_filename"); print while () } else { open(BRIEFFILE, ">$tree/$brief_filename"); my $errors = print_summary(); print_log($errors); } } # end of main ############################################################ sub print_fragment { print "Content-type: text/html\n\n"; print "\n"; my $heading = "Build Log (Fragment)"; my $subheading = "$buildname on $time_str"; my $title = "$heading - $subheading"; EmitHtmlTitleAndHeader($title, $heading, $subheading); print "Show Full Build Log"; open(BUILD_IN, "$gzip -d -c $tree/$logfile|"); my $first_line = $linenum - ($numlines/2); my $last_line = $linenum + ($numlines/2); print "
.
.
.
"; while () { next if $. < $first_line; last if $. > $last_line; print "" if $. == $linenum; print; print "" if $. == $linenum; } print ".
.
.
"; } sub print_header { print "Content-type: text/html\n\n"; if ($fulltext) { $s = 'Show Brief Log'; $s1 = ''; $s2 = 'Full'; } else { $s = 'Show Full Log'; $s1 = 1; $s2 = 'Brief'; } print "\n"; my $heading = "Build Log ($s2)"; my $subheading = "$buildname on $time_str"; my $title = "$heading - $subheading"; EmitHtmlTitleAndHeader($title, $heading, $subheading); print "
$s
Return to the Build Page
Add a Comment to the Log "; } sub print_notes { # # Print notes # $found_note = 0; open(NOTES,"<$tree/notes.txt") or print "

warning: Couldn't open $tree/notes.txt

\n"; print "$buildtime, $buildname
\n"; while () { chop; ($nbuildtime,$nbuildname,$nwho,$nnow,$nenc_note) = split(/\|/); #print "$_
\n"; if ($nbuildtime == $buildtime and $nbuildname eq $buildname) { if (not $found_note) { print "

Build Comments

\n"; $found_note = 1; } $now_str = print_time($nnow); $note = url_decode($nenc_note); print "
\n[$nwho - $now_str]\n$note\n
"; } } close(NOTES); } sub print_summary { # # Print the summary first # logprint('

Build Error Summary

');

  @log_errors = ();

  my $line_num = 0;
  my $error_num = 0;
  open(BUILD_IN, "$gzip -d -c $tree/$logfile|");
  while ($line = ) {
    $line_has_error = output_summary_line($line, $error_num);
    
    if ($line_has_error) {
      push @log_errors, $line_num;        
      $error_num++;
    }
    $line_num++;
  }
  close(BUILD_IN);

  logprint('
'); return \@log_errors; } sub print_log_section { my ($tree, $logfile, $line_of_interest, $num_lines) = shift; local $_; my $first_line = $line_of_interest - $num_lines / 2; my $last_line = $first_line + $num_lines; print "" ."Previous $num_lines"; print ".
.
.
"; print "
";
  my $ii = 0;
  open BUILD_IN, "$gzip -d -c $tree/$logfile|";
  while () {
    $ii++;
    next if $ii < $first_line;
    last if $ii > $last_line;
    if ($ii == $line_of_intested) {
      print "$_";
    } else {
      print;
    }
  }
  close BUILD_IN;
  print "
"; print ".
.
.
"; print "" ."Next $num_lines"; } sub print_log { my ($errors) = $_[0]; logprint('

Build Error Log

');

  $line_num = 0;
  open(BUILD_IN, "$gzip -d -c $tree/$logfile|");
  while ($line = ) {
    output_log_line($line, $line_num, $errors);
    $line_num++;
  }
  close(BUILD_IN);

  logprint('

' ."No More Errors" .'


'); } BEGIN { my $last_was_error = 0; sub output_summary_line { my ($line, $error_id) = @_; if (has_error($line)) { $line =~ s/&/&/g; $line =~ s/$line"); } else { logprint("$line"); } $last_was_error = 1; } else { $last_was_error = 0; } return $last_was_error; } } BEGIN { my $next_error = 0; sub output_log_line { my ($line, $line_num, $errors) = @_; my $has_error = $line_num == $errors->[$next_error]; my $has_warning = has_warning($line); $line =~ s/&/&/g; $line =~ s/]*>(?:<\/a>)?$/i or $line =~ /^<\/a>$/i; my $logline = ''; my %out = (); if (($has_error or $has_warning) and has_errorline($line, \%out)) { $q = quotemeta($out{error_file}); $goto_line = $out{error_line} > 10 ? $out{error_line} - 10 : 1; $cvsblame = $out{error_guess} ? "cvsguess.cgi" : "cvsblame.cgi"; $line =~ s@$q@$out{error_file}@ } if ($has_error) { $next_error++; unless ($last_was_error) { $logline .= ""; # Only print "NEXT ERROR" link if there is another error to jump to $have_more_errors = 0; my $ii = $next_error; while ($ii < $#{$errors} - 1) { if ($errors->[$ii] != $errors->[$ii + 1] - 1) { $have_more_errors = 1; last; } $ii++; } if ($have_more_errors) { $logline .= "NEXT ERROR "; } } $logline .= "$line"; $last_was_error = 1; } elsif ($has_warning) { $logline = "$line"; } else { $logline = $line; $last_was_error = 0; } push_log_line($logline, $errors); } } sub push_log_line { my ($line, $log_errors) = @_; if ($fulltext) { logprint($line); return; } if ($log_line > $log_errors->[$cur_error] + $LINES_AFTER_ERROR) { $cur_error++; } if ($log_line >= $log_errors->[$cur_error] - $LINES_BEFORE_ERROR) { if ($log_skip != 0) { logprint("\n Skipping $log_skip Lines...\n\n"); $log_skip = 0; } logprint($line); } else { $log_skip++; } $log_line++; } sub logprint { my $line = $_[0]; print $line; print BRIEFFILE $line if not $fulltext; }