Update GPG key for signing flatpaks.
[pspp] / results2html
index 8f8725f82f3067c85358951d6fb711bb138af7a7..b330c871abbdae8a74df08a6fa36cb5d52eb6c3b 100755 (executable)
@@ -3,23 +3,24 @@
 use strict;
 use warnings;
 
-use HTML::Entities;
+use Digest::SHA;
+use File::Spec;
+use HTML::Entities qw();
+use URI::Escape;
+
+sub encode_entities {
+    return HTML::Entities::encode_entities($_[0], "<&>'\"");
+}
+
+my $gitweb_url = 'http://benpfaff.org/cgi-bin/gitweb.cgi?p=pspp;a=blob;f=[FILE];hb=[BRANCH]#l[LINE]';
 
 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>
+  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   <link rel="stylesheet" href="build.css">
 </head>
 <body>
@@ -39,58 +40,99 @@ 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";
 
 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;
+       @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 (.*)$/) {
+       if (my ($name, $product) = /^Saving(?:\s+([^:]*):)?\s+(.*)$/) {
            my $href = "$product/index.html";
            $href = $product if ! -e $href;
 
            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);
+           push (@{$steps[$#steps]{CHILDREN}}, \%p) if @steps;
+
+           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);
+           }
        } else {
            my (%s);
            $s{TITLE} = $_;
            $s{LN} = $ln;
            push (@steps, \%s);
        }
+       $result = 'success' if $_ eq 'Success';
     } else {
-       if (my ($diagnostic) = /(error|warning):/) {
+       if (my ($diagnostic) = /(error|warning):/i) {
            my (%d);
-           $d{DIAGNOSTIC} = $diagnostic;
+           $d{DIAGNOSTIC} = lc ($diagnostic);
            $d{MESSAGE} = $_;
            $d{LN} = $ln;
+
+           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);
 
            $log_class = "$diagnostic";
@@ -104,12 +146,48 @@ while (<LOG>) {
     }
 }
 
+open (INDEX, '>','index.html');
+
+print INDEX <<EOF;
+<html>
+<head>
+  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+  <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><a href=\"", encode_entities ($p->{HREF}), "\">";
+    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 "</a>\n";
+    if ($p->{PRODUCT} =~ /\.tar\.gz$/) {
+       my $sha = Digest::SHA->new(1);
+       $sha->addfile($p->{PRODUCT});
+       print INDEX "<br>sha1: ", $sha->hexdigest, "\n";
+
+       $sha = Digest::SHA->new(256);
+       $sha->addfile($p->{PRODUCT});
+       print INDEX "<br>sha256: ", $sha->hexdigest, "\n";
+    }
+    print INDEX "</li>\n";
 }
 print INDEX "</ul>\n";
 
@@ -126,13 +204,29 @@ 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});
-           print INDEX "</a></p>\n";
+           print INDEX "</a> ";
+           print INDEX log_link ($c->{LN});
+           print INDEX "</p>\n";
        }
     }
     print INDEX "</li>\n";