remove $build_number from name of directory for building source distribution
[pspp] / results2html
1 #! /usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use File::Spec;
7 use HTML::Entities;
8
9 open (LOG, '<', "LOG");
10 open (LOG_HTML, '>', "log.html");
11
12 print LOG_HTML <<EOF;
13 <html>
14 <head>
15   <link rel="stylesheet" href="build.css">
16 </head>
17 <body>
18 EOF
19 print LOG_HTML "<pre>";
20
21 sub read_vars {
22     my ($file) = @_;
23     my %vars = ();
24     if (open (VARS, "<", $file)) {
25         while (<VARS>) {
26             chomp;
27             my ($key, $value) = /^([^=]+)=(.*)/ or next;
28             $vars{$key} = $value;
29         }
30         close (VARS);
31     }
32     return %vars;
33 }
34 my (%vars) = read_vars ('VARS');
35
36 my (@products);
37 my (@steps);
38 my ($new_page) = 0;
39 my ($result) = "failure";
40 my @dirstack;
41 while (<LOG>) {
42     my $ln = $.;
43     chomp;
44
45     if (/^\f$/) {
46         $new_page = 1;
47         @dirstack = ();
48         print LOG_HTML "</pre><hr><pre>\n";
49         next;
50     }
51
52     if (/Entering directory `(.*)'$/) {
53         push (@dirstack, $1);
54     } elsif (/Leaving directory `(.*)'$/) {
55         pop (@dirstack);
56     }
57
58     my $log_class;
59     if ($new_page) {
60         $new_page = 0;
61         $log_class = "step";
62         if (my ($name, $product) = /^Saving(?:([^:]*):)?\s+(.*)$/) {
63             my $href = "$product/index.html";
64             $href = $product if ! -e $href;
65
66             my (%p);
67             $p{NAME} = $name if defined ($name);
68             $p{PRODUCT} = $product;
69             $p{HREF} = $href;
70             $p{LN} = $ln;
71             push (@products, \%p);
72             push (@{$steps[$#steps]{CHILDREN}}, \%p);
73         } else {
74             my (%s);
75             $s{TITLE} = $_;
76             $s{LN} = $ln;
77             push (@steps, \%s);
78         }
79         $result = 'success' if $_ eq 'Success';
80     } else {
81         if (my ($diagnostic) = /(error|warning):/i) {
82             my (%d);
83             $d{DIAGNOSTIC} = lc ($diagnostic);
84             $d{MESSAGE} = $_;
85             $d{LN} = $ln;
86
87             if (@dirstack && (my ($file, $line) = /^([^\s:]+):(\d+):\s/)) {
88                 $file = File::Spec->rel2abs ($file, $dirstack[$#dirstack]);
89                 my (@path) = grep ($_ ne '' && $_ ne '.', split ('/', $file));
90                 for (my $i = 0; $i < $#path; ) {
91                     if ($path[$i + 1] eq '..') {
92                         splice (@path, $i, 2);
93                     } else {
94                         $i++;
95                     }
96                 }
97
98                 $d{LINE} = $line;
99                 $d{FILE} = join ('/', @path);
100             }
101             push (@{$steps[$#steps]{CHILDREN}}, \%d);
102
103             $log_class = "$diagnostic";
104         }
105     }
106     printf LOG_HTML "<a name=\"%d\"><tt>%4d</tt></a>  ", $ln, $ln;
107     if (defined ($log_class)) {
108         print LOG_HTML "<span class=\"$log_class\">", encode_entities ($_), "</span>\n";
109     } else {
110         print LOG_HTML encode_entities ($_), "\n";
111     }
112 }
113
114 open (INDEX, '>','index.html');
115
116 print INDEX <<EOF;
117 <html>
118 <head>
119   <link rel="stylesheet" href="build.css">
120 </head>
121 <body>
122 EOF
123
124 print INDEX "<h1>Build ", $vars{"build_number"}, ": $result</h1>\n";
125
126 print INDEX "<h2>Build Properties</h2>\n";
127 print INDEX "<table>\n";
128 print INDEX "<tr><th>Name</th><th>Value</th></tr>\n";
129 foreach my $key (sort (keys (%vars))) {
130     print INDEX "<tr>";
131     print INDEX "<td>", encode_entities ($key), "</td>";
132     print INDEX "<td>", encode_entities ($vars{$key}), "</td>";
133     print INDEX "</tr>\n";
134 }
135 print INDEX "</table>\n";
136
137 print INDEX "<h2>Build Products</h2>\n";
138 print INDEX "<ul>\n";
139 foreach my $p (@products) {
140     print INDEX "<li>";
141     print INDEX encode_entities ($p->{NAME}), ": " if defined ($p->{NAME});
142     print INDEX "<a href=\"", encode_entities ($p->{HREF}), "\">";
143     print INDEX encode_entities ($p->{PRODUCT});
144     print INDEX "</a></li>\n";
145 }
146 print INDEX "</ul>\n";
147
148 sub log_link {
149     my ($ln) = @_;
150     return "<small><a href=\"log.html#$ln\">(log)</a></small>";
151 }
152
153 print INDEX "<h2>Build Summary</h2>\n";
154 print INDEX "<ol>\n";
155 foreach my $s (@steps) {
156     print INDEX "<li>", encode_entities ($s->{TITLE});
157     print INDEX " ", log_link ($s->{LN});
158     foreach my $c (@{$s->{CHILDREN}}) {
159         if (defined ($c->{DIAGNOSTIC})) {
160             print INDEX "<p class=\"$c->{DIAGNOSTIC}\">";
161             print INDEX "<a href=\"log.html#$c->{LN}\">";
162             print INDEX encode_entities ($c->{MESSAGE});
163             print INDEX "</a>";
164             if (exists $c->{FILE}) {
165                 print INDEX " in $c->{FILE}";
166             }
167             print INDEX "</p>\n";
168         } else {
169             print INDEX "<p>&rarr; <a href=\"", encode_entities ($c->{HREF}), "\">";
170             print INDEX encode_entities ($c->{PRODUCT});
171             print INDEX "</a> ";
172             print INDEX log_link ($c->{LN});
173             print INDEX "</p>\n";
174         }
175     }
176     print INDEX "</li>\n";
177 }
178 print INDEX "</ol>\n";
179
180 print INDEX <<EOF;
181 </body>
182 </html>
183 EOF
184
185 print LOG_HTML <<EOF;
186 </pre>
187 </body>
188 </html>
189 EOF
190
191 open (CSS, '>', "build.css");
192 print CSS <<EOF;
193 body {
194         background: white;
195         color: black;
196         padding: 0em 3em 0em 3em;
197         margin: 0
198 }
199 body>p {
200         margin: 0pt 0pt 0pt 0em
201 }
202 body>p + p {
203         text-indent: 1.5em;
204 }
205 H1 {
206         font-size: 150%;
207         margin-left: -1.33em
208 }
209 H2 {
210         font-size: 125%;
211         font-weight: bold;
212         margin-left: -.8em
213 }
214 H3 {
215         font-size: 100%;
216         font-weight: bold;
217         margin-left: -.5em }
218 H4 {
219         font-size: 100%;
220         margin-left: 0em
221 }
222 H1, H2, H3, H4, H5, H6 {
223         font-family: sans-serif;
224         color: blue
225 }
226 html {
227         margin: 0
228 }
229
230 a:link {
231         color: blue;
232         text-decoration: none;
233 }
234 a:visited {
235         color: gray;
236         text-decoration: none;
237 }
238 a:active {
239         color: black;
240         text-decoration: none;
241 }
242 a:hover {
243         text-decoration: underline
244 }
245
246 ol>li>p {
247         margin-top: 0;
248         margin-bottom: 0
249 }
250 .step {
251         font-weight: bold
252 }
253 .warning {
254         background: yellow
255 }
256 .error {
257         background: orange
258 }
259 EOF