#!perl -w
use strict;
use warnings;
use POSIX "strftime";
use Cwd;
my $branch = "master";
if (defined($ARGV[0]) && ($ARGV[0] ne "")) {$branch = $ARGV[0]}
print "--- Running build status report on branch $branch.\n";
my %status = ();
my $fn;
my $date;
my $time;
my $os;
my $compiler;
my $datamodel;
my $compilerok;
my $libraryok;
my $sourcechange;
my $asmchange;
my $tests;
my $key;
my $ver;
sub clearvars {
$time = ""; $branch = ""; $os = ""; $compiler = "";
$datamodel = ""; $compilerok = ""; $libraryok = ""; $sourcechange = "";
$asmchange = ""; $tests = ""; $key = ""; $ver = "";
}
sub logstatus {
my ($fn) = @_;
if ($compiler ne "") {
$status{"$os-$compiler-$datamodel"} =
[$fn, $date, $time, $os, $compiler, $datamodel, $branch, $compilerok, $libraryok, $sourcechange, $asmchange, $tests];
}
clearvars();
}
sub parselog {
($fn) = @_;
clearvars();
open(my $log, $fn) // die "Couldn't open build log $fn.";
$branch = "Build on $fn started";
while (<$log>) {
s/\r//g; # Remove unwanted MS command prompt CR's.
if (/^([0-9\/]+) ([0-9.]+) .+\.log$/) {$date = $1}
if (/^([0-9.]+) /) {$time = $1}
#14.55.15 === build-oberon.sh: $1=sudo, $2=oberon/voc, $3=gcc, $4=master, $sudo=sudo ===
if (/^[^ ]+ === build-oberon.sh: .* \$3=([^ ]+), \$4=([^ ]+),/) {
($compiler, $branch) = ($1, $2);
}
# 14.55.17 + sudo git checkout -f master
if (/^[^ ]+ .*git checkout -f ([^ ]+) *$/) {
$branch = $1;
}
# 14.55.17 Configuration: 2.1.0 [2016/12/22] for gcc ILP32 on ubuntu
if (/^[^ ]+ Configuration: ([^ ]+) \[[0-9\/]+\] for ([^ ]+) ([^ ]+) on ([^ ]+)/) {
($ver, $compiler, $datamodel, $os) = ($1, $2, $3, $4);
printf "--- Config for $fn: $1 for $2 $3 on $4.\n";
}
#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.]+) --- Generated code unchanged ---$/) {if ($asmchange eq "") {$asmchange = "Unchanged"}}
if (/^([0-9.]+) --- Generated code changed ---$/) {$asmchange = "Changed"}
if (/^([0-9.]+) --- Confidence tests started ---$/) {$tests = "Started";}
if (/^([0-9.]+) --- Confidence tests passed ---$/) {$tests = "Passed";}
if (/^([0-9.]+) --- Make completed ---$/) {
# Go back and convert 'Started' status to 'Failed'.
if ($branch =~ m/^Build on/) {$branch = "Build on $fn failed to start.";}
if ($compilerok eq "Started") {$compilerok = "Failed";}
if ($libraryok eq "Started") {$libraryok = "Failed";}
if ($tests eq "Started") {$tests = "Failed";}
if ($compiler eq "msc") {$sourcechange = "n/a"; $tests = "n/a";}
}
}
close($log);
logstatus($fn);
}
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";
}
sub colourfor {
my ($str) = @_;
if ($str eq "Failed") {return "#e03030";}
if ($str eq "Changed") {return "#ff9d4d";}
if ($str eq "n/a") {return "#707070";}
return "#5adb5a";
}
my $rows = keys %status;
my $width = 710;
my $height = ($rows+2.2) * $lineheight;
open(my $svg, ">build-status.svg") // die "Could not create build-status.svg.";
print $svg '\n";
system 'chmod +r log/*';
system 'scp build-status.svg dave@hub:/var/www';
system 'scp log/* dave@hub:/var/www/log';