as released as part of build91
[pspp] / results2html
index abc520d3db5033cad7701e7725f29a09c7113adf..9c73d12e31ef3d380297c551c4da14b48129958a 100755 (executable)
@@ -3,7 +3,11 @@
 use strict;
 use warnings;
 
+use File::Spec;
 use HTML::Entities;
+use URI::Escape;
+
+my $gitweb_url = 'http://benpfaff.org/cgi-bin/gitweb.cgi?p=pspp;a=blob;f=[FILE];hb=[BRANCH]#l[LINE]';
 
 open (LOG, '<', "LOG");
 open (LOG_HTML, '>', "log.html");
@@ -34,24 +38,25 @@ my (%vars) = read_vars ('VARS');
 
 my (@products);
 my (@steps);
-my ($new_page) = 0;
 my ($result) = "failure";
+my (%dist_files);
+my ($dist_dir);
+my @dirstack;
 while (<LOG>) {
     my $ln = $.;
     chomp;
 
-    if (/^\f$/) {
-       $new_page = 1;
-       print LOG_HTML "</pre><hr><pre>\n";
-       next;
+    if (/Entering directory `(.*)'$/) {
+        push (@dirstack, $1);
+    } elsif (/Leaving directory `(.*)'$/) {
+        pop (@dirstack);
     }
 
     my $log_class;
-    if ($new_page) {
-       $new_page = 0;
+    if (my ($title) = /^## (.*) ##$/) {
        $log_class = "step";
-       if (my ($name, $product) = /^Saving(?:([^:]*):)?\s+(.*)$/) {
-           my $href = "$product/index.html";
+       if (my ($name, $product) = $title =~ /^Saving(?:\s+([^:]*):)?\s+(.*)$/) {
+           my $href = "$product/summary.html";
            $href = $product if ! -e $href;
 
            my (%p);
@@ -61,22 +66,63 @@ while (<LOG>) {
            $p{LN} = $ln;
            push (@products, \%p);
            push (@{$steps[$#steps]{CHILDREN}}, \%p);
-       } else {
+
+           if (defined ($name) && $name eq 'source distribution') {
+               open (DIST, '-|', "zcat $product | tar tf -");
+               while (my $line = <DIST>) {
+                   chomp $line;
+                   $line =~ s%^([./])*%%; # Trim leading ./
+                   $dist_files{$line} = 1;
+                   if (!defined ($dist_dir)) {
+                       $dist_dir = (split ('/', $line))[0];
+                   }
+               }
+               close (DIST);
+           }
+       } elsif ($title eq 'Success') {
+           $result = 'success';
+       } elsif ($title !~ /^-+$/) {
            my (%s);
-           $s{TITLE} = $_;
+           $s{TITLE} = $title;
            $s{LN} = $ln;
            push (@steps, \%s);
        }
-       $result = 'success' if $_ eq 'Success';
     } else {
-       if (my ($diagnostic) = /(error|warning):/i) {
+       my $diagnostic;
+       $diagnostic = "error" if /error:/i || /FAILED/;
+       $diagnostic = "warning" if /warning:/i;
+       if ($diagnostic) {
            my (%d);
-           $d{DIAGNOSTIC} = lc ($diagnostic);
+           $d{DIAGNOSTIC} = $diagnostic;
            $d{MESSAGE} = $_;
            $d{LN} = $ln;
-           push (@{$steps[$#steps]{CHILDREN}}, \%d);
 
-           $log_class = "$diagnostic";
+           if (@dirstack && defined ($dist_dir)
+               && (my ($match, $file, $line) = /^(([^\s:]+):(\d+):)/)) {
+               $file = File::Spec->rel2abs ($file, $dirstack[$#dirstack]);
+               my (@path) = grep ($_ ne '' && $_ ne '.', split ('/', $file));
+               for (my $i = 1; $i <= $#path; ) {
+                   if ($path[$i] eq '..') {
+                       splice (@path, $i - 1, 2);
+                       $i-- if $i > 1;
+                   } else {
+                       $i++;
+                   }
+               }
+
+               for (my $i = $#path; $i >= 0; $i--) {
+                   if ($path[$i] eq $dist_dir) {
+                       my $dist_file = join ('/', @path[$i..$#path]);
+                       if (exists ($dist_files{$dist_file})) {
+                           $d{MATCH} = length ($match);
+                           $d{LINE} = $line;
+                           $d{FILE} = $dist_file;
+                       }
+                       last;
+                   }
+               }
+           }
+           push (@{$steps[$#steps]{CHILDREN}}, \%d);
        }
     }
     printf LOG_HTML "<a name=\"%d\"><tt>%4d</tt></a>  ", $ln, $ln;
@@ -87,7 +133,7 @@ while (<LOG>) {
     }
 }
 
-open (INDEX, '>','index.html');
+open (INDEX, '>','summary.html');
 
 print INDEX <<EOF;
 <html>
@@ -97,7 +143,7 @@ print INDEX <<EOF;
 <body>
 EOF
 
-print INDEX "<h1>Build ", $vars{"build_number"}, ": $result</h1>\n";
+print INDEX "<h1>Build ", $vars{"BUILD_NUMBER"}, ": $result</h1>\n";
 
 print INDEX "<h2>Build Properties</h2>\n";
 print INDEX "<table>\n";
@@ -134,9 +180,23 @@ foreach my $s (@steps) {
     foreach my $c (@{$s->{CHILDREN}}) {
        if (defined ($c->{DIAGNOSTIC})) {
            print INDEX "<p class=\"$c->{DIAGNOSTIC}\">";
-           print INDEX "<a href=\"log.html#$c->{LN}\">";
-           print INDEX encode_entities ($c->{MESSAGE});
-           print INDEX "</a></p>\n";
+           if (defined ($c->{MATCH})) {
+               my $href = $gitweb_url;
+               $href =~ s/\[FILE\]/uri_escape ($c->{FILE})/ge;
+               $href =~ s/\[LINE\]/$c->{LINE}/g;
+               $href =~ s/\[BRANCH\]/uri_escape ($vars{'dist_commit'})/e;
+
+               print INDEX '<a href="', encode_entities ($href), '">';
+               print INDEX encode_entities (substr ($c->{MESSAGE},
+                                                    0, $c->{MATCH}));
+               print INDEX '</a>';
+               print INDEX encode_entities (substr ($c->{MESSAGE},
+                                                    $c->{MATCH}));
+           } else {
+               print INDEX encode_entities ($c->{MESSAGE});
+           }
+           print INDEX " ", log_link ($c->{LN});
+           print INDEX "</p>\n";
        } else {
            print INDEX "<p>&rarr; <a href=\"", encode_entities ($c->{HREF}), "\">";
            print INDEX encode_entities ($c->{PRODUCT});
@@ -160,6 +220,11 @@ print LOG_HTML <<EOF;
 </html>
 EOF
 
+open (HTACCESS, '>', '.htaccess');
+print HTACCESS <<EOF;
+DirectorySlash off
+EOF
+
 open (CSS, '>', "build.css");
 print CSS <<EOF;
 body {