#!perl -w
use strict;
use warnings;
use POSIX "strftime";
use Cwd;
my $branch = "master";
my %machines = (
"pi" => ['pi@pie', "sudo", "make full", "projects/oberon/vishap/voc"],
"darwin" => ['dave@dcb', "sudo", "make full", "projects/oberon/vishap/voc"],
"wind" => ['-p5932 dave@wax', "", "make full", "vishaps/voc"],
"lub32" => ['dave@lub32', "sudo", "make full", "vishap/voc"],
"ob32" => ['root@nas-ob32', "", "make full", "vishap/voc"],
"ce64" => ['-p5922 obe@www', "sudo", "make full", "vishap/voc"],
"ub64" => ['dave@nas-ub64', "sudo", "make full", "vishap/voc"],
"fb64" => ['root@oberon', "", "make full", "vishap/voc"]
);
sub logged {
my ($cmd, $id) = @_;
my $child = fork;
if (not defined $child) {die "Fork failed.";}
if ($child) {
# parent process
print "Started $id, pid = $child\n";
} else {
# child process
open(my $log, ">log/$id.log") // die "Could not create log file log/$id.log";
print $log strftime("%Y/%m/%d %H.%M.%S ", localtime), "$id.log\n";
print $log strftime("%H.%M.%S", localtime), "> $cmd\n";
print $id, " ", strftime("%H.%M.%S", localtime), "> $cmd\n";
open(my $pipe, "$cmd 2>&1 |") // die "Could not open pipe from command $cmd.";
while (<$pipe>) {
my $line = $_;
print $id, " ", strftime("%H.%M.%S", localtime), " ", $line;
print $log strftime("%H.%M.%S", localtime), " ", $line;
}
close($pipe);
close($log);
exit;
}
}
unlink glob "log/*";
for my $machine (sort keys %machines) {
my ($login, $sudo, $mkcmd, $dir) = @{$machines{$machine}};
my $cmd = "ssh $login \"cd $dir && $sudo git checkout $branch && $sudo git pull && $sudo $mkcmd\" ";
logged($cmd, $machine);
}
while ((my $pid = wait) > 0) {print "Child pid $pid completed.\n";}
# # All builds have completed. Now scan the logs for pass/fail and build the passing report.
my %status = ();
sub parselog {
my ($fn) = @_;
#print "Parsing log $fn\n";
my $date = "";
my $time = "";
my $branch = "";
my $os = "";
my $compiler = "";
my $datamodel = "";
my $compilerok = "";
my $libraryok = "";
my $sourcechange = "";
my $tests = "";
open(my $log, $fn) // die "Couldn't open build log $fn.";
while (<$log>) {
if (/^([0-9\/]+) ([0-9.]+) .+\.log$/) {$date = $1; $time = $2}
if (/^[^ ]+ --- Cleaning branch ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+) ---$/) {
($branch, $os, $compiler, $datamodel) = ($1, $2, $3, $4, $5);
}
if (/^([0-9.]+) --- Compiler build started ---$/) {$compilerok = "Started";}
if (/^([0-9.]+) --- Compiler build successfull ---$/) {$compilerok = "Built";}
if (/^([0-9.]+) --- Library build started ---$/) {$libraryok = "Started";}
if (/^([0-9.]+) --- Library build successfull ---$/) {$libraryok = "Built";}
if (/^([0-9.]+) --- Generated c source files match bootstrap ---$/) {$sourcechange = "Unchanged";}
if (/^([0-9.]+) --- Generated c source files differ from bootstrap ---$/) {$sourcechange = "Changed";}
if (/^([0-9.]+) --- Confidence tests started ---$/) {$tests = "Started";}
if (/^([0-9.]+) --- Confidence tests passed ---$/) {$tests = "Passed";}
}
close($log);
my $key = "$os-$compiler-$datamodel";
if ($key ne "") {
$status{$key} = [$fn, $date, $time, $os, $compiler, $datamodel, $branch, $compilerok, $libraryok, $sourcechange, $tests];
}
}
opendir DIR, "log" // die "Could not open log directory.";
my @logs = readdir DIR;
closedir DIR;
for my $logname (sort @logs) {
$logname = "log/" . $logname;
#print "Consider $logname\n";
if (-f $logname) {parselog($logname);}
}
my $fontheight = 12;
my $lineheight = 15;
sub svgtext {
my ($f, $x, $y, $colour, $msg) = @_;
print $f '';
print $f $msg;
print $f "\n";
}
my $rows = keys %status;
my $width = 620;
my $height = ($rows+2.2) * $lineheight;
open(my $svg, ">build-status.svg") // die "Could not create build-status.svg.";
print $svg '\n";
system 'scp build-status.svg dave@hub:/var/www';
system 'scp log/* dave@hub:/var/www/log';