remove $build_number from name of directory for building source distribution
[pspp] / results2html
index 0e39cb4ed7b1d43b81d10f9d1a2daadc144d644c..4bf398d35c49b9734d92578e3abdc4a6c71f37d2 100755 (executable)
@@ -3,20 +3,12 @@
 use strict;
 use warnings;
 
+use File::Spec;
 use HTML::Entities;
 
 open (LOG, '<', "LOG");
-open (INDEX, '>','index.html');
 open (LOG_HTML, '>', "log.html");
 
-print INDEX <<EOF;
-<html>
-<head>
-  <link rel="stylesheet" href="build.css">
-</head>
-<body>
-EOF
-
 print LOG_HTML <<EOF;
 <html>
 <head>
@@ -39,63 +31,75 @@ sub read_vars {
     }
     return %vars;
 }
-
 my (%vars) = read_vars ('VARS');
-print INDEX "<h2>Build Properties</h2>\n";
-print INDEX "<table>\n";
-print INDEX "<tr><th>Name</th><th>Value</th></tr>\n";
-foreach my $key (sort (keys (%vars))) {
-    print INDEX "<tr>";
-    print INDEX "<td>", encode_entities ($key), "</td>";
-    print INDEX "<td>", encode_entities ($vars{$key}), "</td>";
-    print INDEX "</tr>\n";
-}
-print INDEX "</table>\n";
-
-print INDEX "<h2>Build Summary</h2>\n";
-print INDEX "<ol>\n";
 
-my ($n_products) = 0;
-my ($n_steps) = 0;
+my (@products);
+my (@steps);
 my ($new_page) = 0;
+my ($result) = "failure";
+my @dirstack;
 while (<LOG>) {
     my $ln = $.;
     chomp;
 
     if (/^\f$/) {
        $new_page = 1;
+       @dirstack = ();
        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;
        $log_class = "step";
-       if (my ($product) = /^Saving (.*)$/) {
-           print INDEX "\n  <ul>\n" if !$n_products++;
+       if (my ($name, $product) = /^Saving(?:([^:]*):)?\s+(.*)$/) {
            my $href = "$product/index.html";
            $href = $product if ! -e $href;
-           print INDEX "  <li><a href=\"", encode_entities ($href), "\">";
-           print INDEX encode_entities ($product), "</a>";
-           print INDEX " <small><a href=\"log.html#$ln\">(log)</a></small>";
-           print INDEX "</li>\n";
+
+           my (%p);
+           $p{NAME} = $name if defined ($name);
+           $p{PRODUCT} = $product;
+           $p{HREF} = $href;
+           $p{LN} = $ln;
+           push (@products, \%p);
+           push (@{$steps[$#steps]{CHILDREN}}, \%p);
        } else {
-           print INDEX "</ul>" if !$n_steps;
-           print INDEX "<li>", encode_entities ($_);
-           print INDEX " <small><a href=\"log.html#$ln\">(log)</a></small>";
-            $n_products = 0;
+           my (%s);
+           $s{TITLE} = $_;
+           $s{LN} = $ln;
+           push (@steps, \%s);
        }
+       $result = 'success' if $_ eq 'Success';
     } else {
-       if (my ($diagnostic) = /(error|warning):/) {
-           if ($n_products) {
-               print INDEX "  </ul>\n";
-               $n_products = 0;
+       if (my ($diagnostic) = /(error|warning):/i) {
+           my (%d);
+           $d{DIAGNOSTIC} = lc ($diagnostic);
+           $d{MESSAGE} = $_;
+           $d{LN} = $ln;
+
+           if (@dirstack && (my ($file, $line) = /^([^\s:]+):(\d+):\s/)) {
+               $file = File::Spec->rel2abs ($file, $dirstack[$#dirstack]);
+               my (@path) = grep ($_ ne '' && $_ ne '.', split ('/', $file));
+               for (my $i = 0; $i < $#path; ) {
+                   if ($path[$i + 1] eq '..') {
+                       splice (@path, $i, 2);
+                   } else {
+                       $i++;
+                   }
+               }
+
+               $d{LINE} = $line;
+               $d{FILE} = join ('/', @path);
            }
-           print INDEX "<p class=\"$diagnostic\">";
-           print INDEX "<a href=\"log.html#$ln\">";
-           print INDEX encode_entities ($_);
-           print INDEX "</a></p>\n";
+           push (@{$steps[$#steps]{CHILDREN}}, \%d);
+
            $log_class = "$diagnostic";
        }
     }
@@ -106,10 +110,74 @@ while (<LOG>) {
        print LOG_HTML encode_entities ($_), "\n";
     }
 }
-print INDEX "  </ul>\n" if $n_products;
-print INDEX "</li>\n" if $n_steps;
+
+open (INDEX, '>','index.html');
+
+print INDEX <<EOF;
+<html>
+<head>
+  <link rel="stylesheet" href="build.css">
+</head>
+<body>
+EOF
+
+print INDEX "<h1>Build ", $vars{"build_number"}, ": $result</h1>\n";
+
+print INDEX "<h2>Build Properties</h2>\n";
+print INDEX "<table>\n";
+print INDEX "<tr><th>Name</th><th>Value</th></tr>\n";
+foreach my $key (sort (keys (%vars))) {
+    print INDEX "<tr>";
+    print INDEX "<td>", encode_entities ($key), "</td>";
+    print INDEX "<td>", encode_entities ($vars{$key}), "</td>";
+    print INDEX "</tr>\n";
+}
+print INDEX "</table>\n";
+
+print INDEX "<h2>Build Products</h2>\n";
+print INDEX "<ul>\n";
+foreach my $p (@products) {
+    print INDEX "<li>";
+    print INDEX encode_entities ($p->{NAME}), ": " if defined ($p->{NAME});
+    print INDEX "<a href=\"", encode_entities ($p->{HREF}), "\">";
+    print INDEX encode_entities ($p->{PRODUCT});
+    print INDEX "</a></li>\n";
+}
+print INDEX "</ul>\n";
+
+sub log_link {
+    my ($ln) = @_;
+    return "<small><a href=\"log.html#$ln\">(log)</a></small>";
+}
+
+print INDEX "<h2>Build Summary</h2>\n";
+print INDEX "<ol>\n";
+foreach my $s (@steps) {
+    print INDEX "<li>", encode_entities ($s->{TITLE});
+    print INDEX " ", log_link ($s->{LN});
+    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>";
+           if (exists $c->{FILE}) {
+               print INDEX " in $c->{FILE}";
+           }
+           print INDEX "</p>\n";
+       } else {
+           print INDEX "<p>&rarr; <a href=\"", encode_entities ($c->{HREF}), "\">";
+           print INDEX encode_entities ($c->{PRODUCT});
+           print INDEX "</a> ";
+           print INDEX log_link ($c->{LN});
+           print INDEX "</p>\n";
+       }
+    }
+    print INDEX "</li>\n";
+}
+print INDEX "</ol>\n";
+
 print INDEX <<EOF;
-</ol>
 </body>
 </html>
 EOF
@@ -125,7 +193,7 @@ print CSS <<EOF;
 body {
        background: white;
        color: black;
-       padding: 0em 12em 0em 3em;
+       padding: 0em 3em 0em 3em;
        margin: 0
 }
 body>p {
@@ -175,17 +243,17 @@ a:hover {
         text-decoration: underline
 }
 
+ol>li>p {
+       margin-top: 0;
+       margin-bottom: 0
+}
 .step {
        font-weight: bold
 }
 .warning {
-       background: yellow;
-       margin-top: 0;
-       margin-bottom: 0
+       background: yellow
 }
 .error {
-       background: orange;
-       margin-top: 0;
-       margin-bottom: 0
+       background: orange
 }
 EOF