2 # This CGI script presents the results of the build_farm build
4 # Copyright (C) Andrew Tridgell <tridge@samba.org> 2001-2005
5 # Copyright (C) Andrew Bartlett <abartlet@samba.org> 2001
6 # Copyright (C) Vance Lankhaar <vance@samba.org> 2002-2005
7 # Copyright (C) Martin Pool <mbp@samba.org> 2001
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 # TODO: Allow filtering of the "Recent builds" list to show
24 # e.g. only broken builds or only builds that you care about.
28 use FindBin qw($RealBin);
38 my $WEBDIR = "$RealBin";
39 my $BASEDIR = "$WEBDIR/..";
40 my $CACHEDIR = "$WEBDIR/../cache";
44 my $HEADCOLOR = "#a0a0e0";
46 my $DEADAGE = 60*60*24*4;
48 ##############################################
49 # this defines what it is possible to build
50 # and what boxes. Should be in a config file
51 my @compilers = util::load_list("$WEBDIR/compilers.list");
52 my (%hosts) = util::load_hash("$WEBDIR/hosts.list");
53 my @hosts = sort { $hosts{$a} cmp $hosts{$b} } keys %hosts;
54 my (%trees) = util::load_hash("$WEBDIR/trees.list");
55 # these aren't really trees... they're just things we want in the menu.
56 # (for recent checkins)
57 my @pseudo_trees = util::load_list("$WEBDIR/pseudo.list");
59 # this is automatically filled in
62 ###############################################
63 # work out a URL so I can refer to myself in links
64 my $myself = $req->self_url;
65 if ($myself =~ /(.*)[?].*/) {
68 if ($myself =~ /http:\/\/.*\/(.*)/) {
72 # for now, hard code the self url - need to sanitize self_url
73 $myself = "http://build.samba.org/";
75 my $cgi_headers_done = 0;
77 ################################################
80 if ($cgi_headers_done) {
83 $cgi_headers_done = 1;
85 print "Content-type: text/html\r\n";
86 #print "Content-type: application/xhtml+xml\r\n";
90 print util::FileLoad("$BASEDIR/web/header.html");
91 print '<title>samba.org build farm</title>';
92 print util::FileLoad("$BASEDIR/web/header2.html");
94 print util::FileLoad("$BASEDIR/web/header3.html");
97 ################################################
98 # start CGI headers for diffs
99 sub cgi_headers_diff() {
100 print "Content-type: application/x-diff\r\n";
104 ################################################
105 # start CGI headers for text output
106 sub cgi_headers_text() {
107 print "Content-type: text/plain\r\n";
111 ################################################
114 print util::FileLoad("$BASEDIR/web/footer.html");
117 ################################################
118 # print an error on fatal errors
123 print "<h1>ERROR: $msg</h1>\n";
128 ################################################
129 # get a param from the request, after sanitizing it
134 if (!defined $req->param($param)) {
135 return wantarray ? () : undef;
140 @result = $req->param($param);
143 $result[0] = $req->param($param);
146 for (my $i = 0; $i <= $#result; $i++) {
147 $result[$i] =~ s/ /_/g;
151 if ($_ =~ m/[^a-zA-Z0-9\-\_\.]/) {
152 fatal("Parameter $param is invalid");
153 return wantarray ? () : undef;
157 return wantarray ? @result : $result[0];
160 ################################
161 # get the name of the build file
162 sub build_fname($$$$)
169 return "oldrevs/build.$tree.$host.$compiler-$rev";
171 return "build.$tree.$host.$compiler";
174 ###########################################
175 # get a list of old builds and their status
176 sub get_old_revs($$$)
181 my @list = split('\n', `ls oldrevs/build.$tree.$host.$compiler-*.log`);
184 if ($l =~ /-(\d+).log$/) {
186 $ret{$rev} = build_status($host, $tree, $compiler, $rev);
193 ##############################################
194 # get the age of build from mtime
201 my $file=build_fname($tree, $host, $compiler, $rev);
205 $st = stat("$file.log");
207 $age = time() - $st->mtime;
213 ##############################################
214 # get the svn revision of build
215 sub build_revision($$$$)
221 my $file=build_fname($tree, $host, $compiler, $rev);
229 my $st1 = stat("$file.log");
234 my $st2 = stat("$CACHEDIR/$file.revision");
236 if ($st1 && $st2 && $st1->mtime <= $st2->mtime) {
237 return util::FileLoad("$CACHEDIR/$file.revision");
240 $log = util::FileLoad("$file.log");
242 if ($log =~ /BUILD REVISION:(.*)/) {
246 util::FileSave("$CACHEDIR/$file.revision", "$ret");
251 #############################################
252 # get the overall age of a host
257 for my $compiler (@compilers) {
258 for my $tree (keys %trees) {
259 my $age = build_age($host, $tree, $compiler, "");
260 if ($age != -1 && ($age < $ret || $ret == -1)) {
268 #############################################
269 # show an age as a string
274 if ($age > $OLDAGE) {
275 return sprintf("<span class=\"old\">%s</span>", util::dhm_time($age));
277 return util::dhm_time($age);
281 ##############################################
282 # get status of build
283 sub build_status($$$$)
289 my $file=build_fname($tree, $host, $compiler, $rev);
290 my $cachefile="$CACHEDIR/" . $file . ".status";
291 my ($cstatus, $bstatus, $istatus, $tstatus, $sstatus);
292 $cstatus = $bstatus = $istatus = $tstatus = $sstatus =
293 "<span class=\"status unknown\">?</span>";
298 my $st1 = stat("$file.log");
300 return "Unknown Build";
302 my $st2 = stat("$cachefile");
304 if ($st1 && $st2 && $st1->mtime <= $st2->mtime) {
305 return util::FileLoad($cachefile);
308 $log = util::FileLoad("$file.log");
310 if ($log =~ /TEST STATUS:(.*)/) {
312 $tstatus = "<span class=\"status passed\">ok</span>";
314 $tstatus = "<span class=\"status failed\">$1</span>";
318 if ($log =~ /INSTALL STATUS:(.*)/) {
320 $istatus = "<span class=\"status passed\">ok</span>";
322 $istatus = "<span class=\"status failed\">$1</span>";
326 if ($log =~ /BUILD STATUS:(.*)/) {
328 $bstatus = "<span class=\"status passed\">ok</span>";
330 $bstatus = "<span class=\"status failed\">$1</span>";
334 if ($log =~ /CONFIGURE STATUS:(.*)/) {
336 $cstatus = "<span class=\"status passed\">ok</span>";
338 $cstatus = "<span class=\"status failed\">$1</span>";
342 if ($log =~ /(PANIC|INTERNAL ERROR):.*/ ) {
343 $sstatus = "/<span class=\"status panic\">PANIC</span>";
348 if ($log =~ /CC_CHECKER STATUS: (.*)/ && $1 > 0) {
349 $sstatus .= "/<span class=\"status checker\">$1</span>";
352 $ret = "<a href=\"$myself?function=View+Build;host=$host;tree=$tree;compiler=$compiler";
354 $ret .= ";revision=$rev";
356 $ret .= "\">$cstatus/$bstatus/$istatus/$tstatus$sstatus</a>";
358 util::FileSave("$CACHEDIR/$file.status", $ret);
363 ##############################################
364 # translate a status into a set of int representing status
365 sub build_status_vals($) {
366 my $status = strip_html(shift);
370 $status =~ s/PANIC/1/g;
372 return split m%/%, $status;
374 ##############################################
375 # get status of build
382 my $file=build_fname($tree, $host, $compiler, $rev);
385 my $st1 = stat("$file.err");
389 my $st2 = stat("$CACHEDIR/$file.errcount");
391 if ($st1 && $st2 && $st1->mtime <= $st2->mtime) {
392 return util::FileLoad("$CACHEDIR/$file.errcount");
395 $err = util::FileLoad("$file.err");
397 if (! $err) { return 0; }
399 my $ret = util::count_lines($err);
401 util::FileSave("$CACHEDIR/$file.errcount", "$ret");
408 ##############################################
410 sub view_summary($) {
412 my $list = `ls *.log`;
416 # either "text" or anything else.
417 my $output_type = shift;
424 # zero broken and panic counters
425 for my $tree (keys %trees) {
426 $broken_count{$tree} = 0;
427 $panic_count{$tree} = 0;
428 $host_count{$tree} = 0;
431 #set up a variable to store the broken builds table's code, so we can output when we want
432 my $broken_table = "";
436 # for the text report, include the current time
437 if ($output_type eq 'text') {
439 print "Build status as of $time\n\n";
442 for my $host (@hosts) {
443 for my $compiler (@compilers) {
444 for my $tree (keys %trees) {
445 my $status = build_status($host, $tree, $compiler, "");
446 next if $status =~ /^Unknown Build/;
447 my $age = build_age($host, $tree, $compiler, "");
449 if ($age != -1 && $age < $DEADAGE) {
450 $host_count{$tree}++;
453 if ($age < $DEADAGE && $status =~ /status failed/) {
454 $broken_count{$tree}++;
455 if ($status =~ /PANIC/) {
456 $panic_count{$tree}++;
463 if ($output_type eq 'text') {
464 print "Build counts:\n";
465 printf "%-12s %-6s %-6s %-6s\n", "Tree", "Total", "Broken", "Panic";
469 <div id="build-counts" class="build-section">
470 <h2>Build counts:</h2>
474 <th>Tree</th><th>Total</th><th>Broken</th><th>Panic</th>
482 for my $tree (sort keys %trees) {
483 if ($output_type eq 'text') {
484 printf "%-12s %-6s %-6s %-6s\n", $tree, $host_count{$tree},
485 $broken_count{$tree}, $panic_count{$tree};
488 print " <tr><td><a href=\"$myself?function=Recent+Builds;tree=$tree\" title=\"View recent builds for $tree\">$tree</a></td><td>$host_count{$tree}</td><td>$broken_count{$tree}</td>";
490 if ($panic_count{$tree}) {
491 $panic = " class=\"panic\"";
493 print "<td$panic>$panic_count{$tree}</td></tr>\n";
497 if ($output_type eq 'text') {
501 print " </tbody>\n</table></div>\n";
505 ##############################################
506 # Draw the "recent builds" view
508 sub view_recent_builds() {
519 my $sort = { revision => sub { $$b[6] <=> $$a[6] },
520 age => sub { $$a[0] <=> $$b[0] },
521 host => sub { $$a[2] cmp $$b[2] },
522 platform => sub { $$a[1] cmp $$b[1] },
523 compiler => sub { $$a[3] cmp $$b[3] },
525 my (@bstat) = build_status_vals($$b[5]);
526 my (@astat) = build_status_vals($$a[5]);
529 if (defined $bstat[4] && !defined $astat[4]) {
532 elsif (!defined $bstat[4] && defined $astat[4]) {
535 return ($bstat[0] <=> $astat[0] || # configure
536 $bstat[1] <=> $astat[1] || # compile
537 $bstat[2] <=> $astat[2] || # install
538 $bstat[3] <=> $astat[3] # test
543 my $tree=get_param("tree");
544 my $sort_by=get_param("sortby") || "revision"; # default to revision
546 util::InArray($tree, [keys %trees]) || fatal("not a build tree");
547 util::InArray($sort_by, [keys %$sort]) || fatal("not a valid sort");
549 for my $host (@hosts) {
550 for my $compiler (@compilers) {
551 my $status = build_status($host, $tree, $compiler, "");
552 my $age = build_age($host, $tree, $compiler, "");
553 my $revision = build_revision($host, $tree, $compiler, "");
554 push @all_builds, [$age, $hosts{$host}, "<a href=\"$myself?function=View+Host;host=$host;tree=$tree;compiler=$compiler#$host\">$host</a>", $compiler, $tree, $status, $revision]
555 unless $age == -1 or $age >= $DEADAGE;
559 @all_builds = sort { $sort->{$sort_by}() || $sort->{age}() } @all_builds;
561 my $sorturl = "$myself?tree=$tree;function=Recent+Builds";
565 <div id="recent-builds" class="build-section">
566 <h2>Recent builds of $tree</h2>
570 <th><a href="$sorturl;sortby=age" title="Sort by build age">Age</a></th>
571 <th><a href="$sorturl;sortby=revision" title="Sort by build revision">Revision</a></th>
573 <th><a href="$sorturl;sortby=platform" title="Sort by platform">Platform</a></th>
574 <th><a href="$sorturl;sortby=host" title="Sort by host">Host</a></th>
575 <th><a href="$sorturl;sortby=compiler" title="Sort by compiler">Compiler</a></th>
576 <th><a href="$sorturl;sortby=status" title="Sort by build status">Status</a></th>
583 for my $build (@all_builds) {
584 my $age = $$build[0];
585 my $rev = $$build[6];
587 join("</td><td>" , util::dhm_time($age),
588 $rev, @$build[4, 1, 2, 3, 5]),
591 print " </tbody>\n</table>\n</div>\n";
595 ##############################################
596 # Draw the "dead hosts" table
597 sub draw_dead_hosts {
598 my $output_type = shift;
601 # don't output anything if there are no dead hosts
602 if ($#deadhosts < 0) {
606 # don't include in text report
607 if ($output_type eq 'text') {
612 <div class="build-section" id="dead-hosts">
616 <tr><th>Host</th><th>OS</th><th>Min Age</th></tr>
621 for my $host (@deadhosts) {
622 my $age = host_age($host);
623 print " <tr><td>$host</td><td>$hosts{$host}</td><td>", util::dhm_time($age), "</td></tr>";
627 print " </tbody>\n</table>\n</div>\n";
630 ##############################################
631 # show the available old revisions, if any
632 sub show_oldrevs($$$)
637 my %revs = get_old_revs($tree, $host, $compiler);
638 my @revs = sort { $revs{$b} cmp $revs{$a} } keys %revs;
640 return if ($#revs < 1);
642 print "<h2>Older builds:</h2>\n";
645 <table class=\"real\">
646 <tr><th>Revision</th><th>Status</th></tr>
651 for my $rev (@revs) {
654 next if ($s eq $lastrev);
656 print "<tr><td>$rev</td><td>$revs{$rev}</td></tr>\n";
661 ##############################################
662 # view one build in detail
664 my $tree=get_param("tree");
665 my $host=get_param("host");
666 my $compiler=get_param("compiler");
667 my $rev=get_param('revision');
669 # ensure the params are valid before using them
670 util::InArray($host, [keys %hosts]) || fatal("unknown host");
671 util::InArray($compiler, \@compilers) || fatal("unknown compiler");
672 util::InArray($tree, [keys %trees]) || fatal("not a build tree");
674 my $file=build_fname($tree, $host, $compiler, $rev);
680 my $age = build_age($host, $tree, $compiler, $rev);
681 my $revision = build_revision($host, $tree, $compiler, $rev);
682 my $status = build_status($host, $tree, $compiler, $rev);
686 $log = util::FileLoad("$file.log");
687 $err = util::FileLoad("$file.err");
690 $log = util::cgi_escape($log);
692 if ($log =~ /(.*)/) { $uname=$1; }
693 if ($log =~ /CFLAGS=(.*)/) { $cflags=$1; }
694 if ($log =~ /configure options: (.*)/) { $config=$1; }
698 $err = util::cgi_escape($err);
701 print "<h2>Host information:</h2>\n";
703 print util::FileLoad("../web/$host.html");
706 <table class=\"real\">
707 <tr><td>Host:</td><td><a href=\"$myself?function=View+Host;host=$host;tree=$tree;compiler=$compiler#$host\">$host</a> - $hosts{$host}</td></tr>
708 <tr><td>Uname:</td><td>$uname</td></tr>
709 <tr><td>Tree:</td><td>$tree</td></tr>
710 <tr><td>Build Revision:</td><td>" . $revision . "</td></tr>
711 <tr><td>Build age:</td><td class=\"age\">" . red_age($age) . "</td></tr>
712 <tr><td>Status:</td><td>$status</td></tr>
713 <tr><td>Compiler:</td><td>$compiler</td></tr>
714 <tr><td>CFLAGS:</td><td>$cflags</td></tr>
715 <tr><td>configure options: </td><td>$config</td></tr>
719 show_oldrevs($tree, $host, $compiler);
722 # check the head of the output for our magic string
723 my $plain_logs = (defined get_param("plain") &&
724 get_param("plain") =~ /^(yes|1|on|true|y)$/i);
727 $rev_var = ";revision=$rev";
730 print "<div id=\"log\">\n";
734 print "<p>Switch to the <a href=\"$myself?function=View+Build;host=$host;tree=$tree;compiler=$compiler$rev_var;plain=true\" title=\"Switch to bland, non-javascript, unstyled view\">Plain View</a></p>";
736 print "<div id=\"actionList\">\n";
737 # These can be pretty wide -- perhaps we need to
738 # allow them to wrap in some way?
740 print "<h2>No error log available</h2>\n";
742 print "<h2>Error log:</h2>\n";
743 print make_collapsible_html('action', "Error Output", "\n$err", "stderr-0");
747 print "<h2>No build log available</h2>\n";
749 print "<h2>Build log:</h2>\n";
750 print_log_pretty($log);
753 print "<p><small>Some of the above icons derived from the <a href=\"http://www.gnome.org\">Gnome Project</a>'s stock icons.</p>";
757 print "<p>Switch to the <a href=\"$myself?function=View+Build;host=$host;tree=$tree;compiler=$compiler$rev_var\" title=\"Switch to colourful, javascript-enabled, styled view \">Enhanced View</a></p>";
759 print "<h2>No error log available</h2>\n";
761 print "<h2>Error log:</h2>\n";
762 print "<div id=\"errorLog\"><pre>" . join('', $err) . "</pre></div>\n";
765 print "<h2>No build log available</h2>n";
768 print "<h2>Build log:</h2>\n";
769 print "<div id=\"buildLog\"><pre>" . join('', $log) . "</pre></div>\n";
776 ##################################################
777 # print the host's table of information
780 my $output_type = "html";
782 if ($output_type eq 'text') {
783 print "Host summary:\n";
786 print "<div class=\"build-section\" id=\"build-summary\">\n";
787 print "<h2>Host summary:</h2>\n";
790 my $list = `ls *.log`;
792 my (@requested_hosts) = get_param('host');
794 foreach (@requested_hosts) {
795 util::InArray($_, [keys %hosts]) || fatal("unknown host");
798 for my $host (@requested_hosts) {
799 # make sure we have some data from it
800 if (! ($list =~ /$host/)) {
801 if ($output_type ne 'text') {
802 print "<!-- skipping $host -->\n";
809 for my $compiler (@compilers) {
810 for my $tree (sort keys %trees) {
811 my $age = build_age($host, $tree, $compiler, "");
812 my $warnings = err_count($host, $tree, $compiler, "");
813 if ($age != -1 && $age < $DEADAGE) {
814 my $status = build_status($host, $tree, $compiler, "");
816 if ($output_type eq 'text') {
817 printf "%-12s %-10s %-10s %-10s %-10s\n",
818 "Tree", "Compiler", "Build Age", "Status", "Warnings";
823 <div class="host summary">
824 <a id="$host" name="$host" />
825 <h3>$host - $hosts{$host}</h3>
829 <th>Target</th><th>Build Age</th><th>Status<br />config/build<br />install/test</th><th>Warnings</th>
837 if ($output_type eq 'text') {
838 printf "%-12s %-10s %-10s %-10s %-10s\n",
839 $tree, $compiler, util::dhm_time($age),
840 strip_html($status), $warnings;
843 print " <tr><td><span class=\"tree\">$tree</span>/$compiler</td><td class=\"age\">" . red_age($age) . "</td><td class=\"status\">$status</td><td>$warnings</td></tr>\n";
850 if ($output_type eq 'text') {
854 print " </tbody>\n</table></div>\n";
857 push(@deadhosts, $host);
862 if ($output_type ne 'text') {
866 draw_dead_hosts($output_type, @deadhosts);
870 ##############################################
871 # prints the log in a visually appealing manner
872 sub print_log_pretty() {
875 # do some pretty printing for the actions
878 Running\ action\s+([\w\-]+)
880 ACTION\ (PASSED|FAILED):\ ([\w\-]+)
882 }{make_collapsible_html('action', $2, $1, $id++, $3)}exgs;
884 # $log is already CGI-escaped, so handle '>' in test name by handling >
886 --==--==--==--==--==--==--==--==--==--==--.*?
887 Running\ test\ ([\w\-=,_:\ /.&;]+)\ \(level\ (\d+)\ (\w+)\).*?
888 --==--==--==--==--==--==--==--==--==--==--
890 ==========================================.*?
891 TEST\ (FAILED|PASSED|SKIPPED):(\ \(status\ (\d+)\))?.*?
892 ==========================================\s+
893 }{make_collapsible_html('test', $1, $4, $id++, $5)}exgs;
896 --\ ((ERROR|WARNING|MISTAKE).*?)\n
899 }{make_collapsible_html('cc_checker', $1, $3, $id++, $2)}exgs;
901 print "<tt><pre>" .join('', $log) . "</pre></tt><p>\n";
904 ##############################################
905 # generate html for a collapsible section
906 sub make_collapsible_html($$$$)
908 my $type = shift; # the logical type of it. e.g. "test" or "action"
909 my $title = shift; # the title to be displayed
914 my $icon = (defined $status && ($status =~ /failed/i)) ? 'icon_hide_16.png' : 'icon_unhide_16.png';
916 # note that we may be inside a <pre>, so we don't put any extra whitespace in this html
917 my $return = "<div class=\"$type unit \L$status\E\" id=\"$type-$id\">" .
918 "<a href=\"javascript:handle('$id');\">" .
919 "<img id=\"img-$id\" name=\"img-$id\" src=\"$icon\" /> " .
920 "<div class=\"$type title\">$title</div>" .
922 "<div class=\"$type status \L$status\E\">$status</div>" .
923 "<div class=\"$type output\" id=\"output-$id\">" .
924 "<pre>$output</pre>" .
931 ##############################################
932 # simple html markup stripper
936 # get rid of comments
937 $string =~ s/<!\-\-(.*?)\-\->/$2/g;
940 while ($string =~ s&<(\w+).*?>(.*?)</\1>&$2&) {
948 ##############################################
951 print $req->startform("GET");
952 print "<div id=\"build-menu\">\n";
953 print $req->popup_menu(-name=>'host',
955 -labels=>\%hosts) . "\n";
956 print $req->popup_menu("tree", [sort (keys %trees, @pseudo_trees)]) . "\n";
957 print $req->popup_menu("compiler", \@compilers) . "\n";
959 print $req->submit('function', 'View Build') . "\n";
960 print $req->submit('function', 'View Host') . "\n";
961 print $req->submit('function', 'Recent Checkins') . "\n";
962 print $req->submit('function', 'Summary') . "\n";
963 print $req->submit('function', 'Recent Builds') . "\n";
965 print $req->endform() . "\n";
969 ###############################################
970 # display top of page
973 chdir("$BASEDIR/data") || fatal("can't change to data directory");
977 ###############################################
980 my $fn_name = get_param('function') || '';
982 if ($fn_name eq 'text_diff') {
984 chdir("$BASEDIR/data") || fatal("can't change to data directory");
985 history::diff(get_param('author'),
988 get_param('revision'),
991 elsif ($fn_name eq 'Text_Summary') {
993 chdir("$BASEDIR/data") || fatal("can't change to data directory");
994 view_summary('text');
999 if ($fn_name eq "View_Build") {
1002 elsif ($fn_name eq "View_Host") {
1005 elsif ($fn_name eq "Recent_Builds") {
1006 view_recent_builds();
1008 elsif ($fn_name eq "Recent_Checkins") {
1009 history::history(get_param('tree'));
1011 elsif ($fn_name eq "diff") {
1012 history::diff(get_param('author'),
1015 get_param('revision'),
1019 view_summary('html');