Sponsor compiler_version
[buildfarm-server.git] / cgi-bin / show_stage_log.pl
index 7fd6438de7fe399fc6413c56d33b0afed9c943fd..e560089beff5fac67e3ef8c7682f7be31effe623 100755 (executable)
@@ -3,6 +3,7 @@
 =comment
 
 Copyright (c) 2003-2010, Andrew Dunstan
+Copyright (c) 2022, The Exim Maintainers
 
 See accompanying License file for license details
 
@@ -16,9 +17,8 @@ use File::Temp qw(tempfile);
 
 use vars qw($dbhost $dbname $dbuser $dbpass $dbport @log_file_names);
 
-
-require "$ENV{BFConfDir}/BuildFarmWeb.pl";
-#require "BuildFarmWeb.pl";
+use FindBin qw($RealBin);
+require "$RealBin/../BuildFarmWeb.pl";
 
 die "no dbname" unless $dbname;
 die "no dbuser" unless $dbuser;
@@ -32,6 +32,7 @@ my $query = new CGI;
 my $system = $query->param('nm'); $system =~ s/[^a-zA-Z0-9_ -]//g;
 my $logdate = $query->param('dt');$logdate =~ s/[^a-zA-Z0-9_ -]//g;
 my $stage = $query->param('stg');$stage =~ s/[^a-zA-Z0-9._ -]//g;
+my $brnch = $query->param('branch') || 'HEAD'; $brnch =~ s/[^a-zA-Z0-9._ -]//g;
 
 use vars qw($tgz);
 
@@ -41,6 +42,20 @@ if ($system && $logdate && $stage)
 
     die $DBI::errstr unless $db;
 
+    if ($logdate =~ /^latest$/i)
+    {
+       my $find_latest = qq{
+            select max(snapshot) 
+            from build_status_log 
+            where sysname = ? 
+                and snapshot > now() - interval '30 days' 
+                and log_stage = ? || '.log'
+                and branch = ?
+        };
+       my $logs = $db->selectcol_arrayref($find_latest,undef,$system,$stage,$brnch);
+       $logdate = shift(@$logs);
+    }
+
     my $statement = q(
 
         select branch, log_text
@@ -48,8 +63,6 @@ if ($system && $logdate && $stage)
         where sysname = ? and snapshot = ? and log_stage = ? || '.log'
 
         );
-
-
     
     my $sth=$db->prepare($statement);
     $sth->execute($system,$logdate,$stage);
@@ -63,11 +76,11 @@ if ($system && $logdate && $stage)
     $sth->finish;
     $db->disconnect;
 
-    print "Content-Type: text/plain\n\n", $logtext,
+    print "Content-Type: text/plain\n\nSnapshot: $logdate\n\n", $logtext,
 
     "-------------------------------------------------\n\n",
-    "Hosting for the PostgreSQL Buildfarm is generously ",
-    "provided by: CommandPrompt, The PostgreSQL Company";
+    "Hosting for the Exim BuildFarm is generously ",
+    "provided by: Mythic Beasts Ltd";
 
 }
 
@@ -76,4 +89,3 @@ else
     print "Status: 460 bad parameters\n",
     "Content-Type: text/plain\n\n";
 }
-