#! /usr/bin/env perl use strict; use warnings; use File::Spec; use HTML::Entities; open (LOG, '<', "LOG"); open (LOG_HTML, '>', "log.html"); print LOG_HTML < EOF print LOG_HTML "
";

sub read_vars {
    my ($file) = @_;
    my %vars = ();
    if (open (VARS, "<", $file)) {
	while () {
	    chomp;
	    my ($key, $value) = /^([^=]+)=(.*)/ or next;
	    $vars{$key} = $value;
	}
	close (VARS);
    }
    return %vars;
}
my (%vars) = read_vars ('VARS');

my (@products);
my (@steps);
my ($new_page) = 0;
my ($result) = "failure";
my @dirstack;
while () {
    my $ln = $.;
    chomp;

    if (/^$/) {
	$new_page = 1;
	@dirstack = ();
	print LOG_HTML "

\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 ($name, $product) = /^Saving(?:([^:]*):)?\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);
	} else {
	    my (%s);
	    $s{TITLE} = $_;
	    $s{LN} = $ln;
	    push (@steps, \%s);
	}
	$result = 'success' if $_ eq 'Success';
    } else {
	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);
	    }
	    push (@{$steps[$#steps]{CHILDREN}}, \%d);

	    $log_class = "$diagnostic";
	}
    }
    printf LOG_HTML "%4d  ", $ln, $ln;
    if (defined ($log_class)) {
	print LOG_HTML "", encode_entities ($_), "\n";
    } else {
	print LOG_HTML encode_entities ($_), "\n";
    }
}

open (INDEX, '>','index.html');

print INDEX <

  


EOF

print INDEX "

Build ", $vars{"build_number"}, ": $result

\n"; print INDEX "

Build Properties

\n"; print INDEX "\n"; print INDEX "\n"; foreach my $key (sort (keys (%vars))) { print INDEX ""; print INDEX ""; print INDEX ""; print INDEX "\n"; } print INDEX "
NameValue
", encode_entities ($key), "", encode_entities ($vars{$key}), "
\n"; print INDEX "

Build Products

\n"; print INDEX "\n"; sub log_link { my ($ln) = @_; return "(log)"; } print INDEX "

Build Summary

\n"; print INDEX "
    \n"; foreach my $s (@steps) { print INDEX "
  1. ", encode_entities ($s->{TITLE}); print INDEX " ", log_link ($s->{LN}); foreach my $c (@{$s->{CHILDREN}}) { if (defined ($c->{DIAGNOSTIC})) { print INDEX "

    {DIAGNOSTIC}\">"; print INDEX "{LN}\">"; print INDEX encode_entities ($c->{MESSAGE}); print INDEX ""; if (exists $c->{FILE}) { print INDEX " in $c->{FILE}"; } print INDEX "

    \n"; } else { print INDEX "

    {HREF}), "\">"; print INDEX encode_entities ($c->{PRODUCT}); print INDEX " "; print INDEX log_link ($c->{LN}); print INDEX "

    \n"; } } print INDEX "
  2. \n"; } print INDEX "
\n"; print INDEX < EOF print LOG_HTML < EOF open (CSS, '>', "build.css"); print CSS <p { margin: 0pt 0pt 0pt 0em } body>p + p { text-indent: 1.5em; } H1 { font-size: 150%; margin-left: -1.33em } H2 { font-size: 125%; font-weight: bold; margin-left: -.8em } H3 { font-size: 100%; font-weight: bold; margin-left: -.5em } H4 { font-size: 100%; margin-left: 0em } H1, H2, H3, H4, H5, H6 { font-family: sans-serif; color: blue } html { margin: 0 } a:link { color: blue; text-decoration: none; } a:visited { color: gray; text-decoration: none; } a:active { color: black; text-decoration: none; } a:hover { text-decoration: underline } ol>li>p { margin-top: 0; margin-bottom: 0 } .step { font-weight: bold } .warning { background: yellow } .error { background: orange } EOF