1998-06-17 01:43:24 +04:00
|
|
|
#!/usr/bonsaitools/bin/perl --
|
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
#
|
1999-11-02 02:33:56 +03:00
|
|
|
# The contents of this file are subject to the Netscape Public
|
|
|
|
# License Version 1.1 (the "License"); you may not use this file
|
|
|
|
# except in compliance with the License. You may obtain a copy of
|
|
|
|
# the License at http://www.mozilla.org/NPL/
|
1998-06-17 01:43:24 +04:00
|
|
|
#
|
1999-11-02 02:33:56 +03:00
|
|
|
# Software distributed under the License is distributed on an "AS
|
|
|
|
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
# implied. See the License for the specific language governing
|
|
|
|
# rights and limitations under the License.
|
1998-06-17 01:43:24 +04:00
|
|
|
#
|
|
|
|
# The Original Code is the Tinderbox build tool.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Netscape Communications
|
1999-11-02 02:33:56 +03:00
|
|
|
# Corporation. Portions created by Netscape are
|
|
|
|
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
1998-06-17 01:43:24 +04:00
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
use Time::Local;
|
1999-10-25 21:31:39 +04:00
|
|
|
require 'tbglobals.pl'; # for $gzip
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
umask 0;
|
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
if ($ARGV[0] eq '--check-mail') {
|
|
|
|
$only_check_mail = 1;
|
|
|
|
shift @ARGV;
|
|
|
|
}
|
|
|
|
$mail_file = $ARGV[0];
|
1999-07-22 02:15:21 +04:00
|
|
|
|
1998-11-13 04:27:02 +03:00
|
|
|
%MAIL_HEADER = ();
|
1999-10-23 05:43:28 +04:00
|
|
|
%tinderbox = ();
|
1999-07-22 02:15:21 +04:00
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
# Scan the logfile once to get mail header and build variables
|
|
|
|
#
|
|
|
|
open LOG, "<$mail_file" or die "Can't open $!";
|
1999-07-22 21:48:29 +04:00
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
parse_mail_header(*LOG, \%MAIL_HEADER);
|
|
|
|
parse_log_variables(*LOG, \%tinderbox);
|
1999-08-26 21:13:21 +04:00
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
close LOG;
|
1999-08-26 21:13:21 +04:00
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
# Make sure variables are defined correctly
|
|
|
|
#
|
|
|
|
check_required_variables(\%tinderbox, \%MAIL_HEADER);
|
1999-08-26 21:13:21 +04:00
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
die "Mail variables passed the test\n" if $only_check_mail;
|
1999-07-22 21:48:29 +04:00
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
# Write data to "build.dat"
|
|
|
|
#
|
|
|
|
$tinderbox{logfile} = "$tinderbox{builddate}.$$.gz";
|
|
|
|
write_build_data(\%tinderbox);
|
1999-05-26 22:51:47 +04:00
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
# Compress the build log and put it in the tree
|
|
|
|
#
|
|
|
|
compress_log_file(\%tinderbox, $mail_file)
|
|
|
|
unless $tinderbox{status} =~ /building/;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
unlink $mail_file;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
# Who data
|
|
|
|
#
|
2001-11-11 12:08:56 +03:00
|
|
|
system("./buildwho.pl", "$tinderbox{tree}");
|
1999-10-23 05:43:28 +04:00
|
|
|
|
1999-10-25 21:31:39 +04:00
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
# Warnings
|
|
|
|
# Compare the name with $warning_buildnames_pat which is defined in
|
|
|
|
# $tinderbox{tree}/treedata.pl if at all.
|
1999-10-25 21:31:39 +04:00
|
|
|
require "$tinderbox{tree}/treedata.pl" if -r "$tinderbox{tree}/treedata.pl";
|
1999-10-23 05:43:28 +04:00
|
|
|
if (defined $warning_buildnames_pat
|
|
|
|
and $tinderbox{build} =~ /^$warning_buildnames_pat$/
|
2000-03-11 05:55:19 +03:00
|
|
|
and $tinderbox{status} ne 'failed') {
|
2001-11-11 12:08:56 +03:00
|
|
|
system("./warnings.pl", "$tinderbox{tree}/$tinderbox{logfile}");
|
1999-08-26 21:13:21 +04:00
|
|
|
}
|
1999-07-22 21:48:29 +04:00
|
|
|
|
2001-11-02 12:43:12 +03:00
|
|
|
# Scrape data
|
2001-11-10 00:37:02 +03:00
|
|
|
# Look for build name in scrapedata.pl.
|
2001-11-10 09:01:35 +03:00
|
|
|
require "$tinderbox{tree}/scrapebuilds.pl" if -r "$tinderbox{tree}/scrapebuilds.pl";
|
2001-11-11 11:30:21 +03:00
|
|
|
if ($scrape_builds->{$tinderbox{build}}
|
2003-09-23 02:23:04 +04:00
|
|
|
and $tinderbox{status} ne 'building') {
|
2001-11-11 12:08:56 +03:00
|
|
|
system("./scrape.pl", "$tinderbox{tree}", "$tinderbox{logfile}");
|
2001-11-02 12:43:12 +03:00
|
|
|
}
|
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
# Static pages
|
|
|
|
# For Sidebar flash and tinderbox panels.
|
|
|
|
$ENV{QUERY_STRING}="tree=$tinderbox{tree}&static=1";
|
2001-11-11 12:08:56 +03:00
|
|
|
system("./showbuilds.cgi");
|
1999-10-23 05:43:28 +04:00
|
|
|
|
1999-07-22 01:56:10 +04:00
|
|
|
# end of main
|
|
|
|
######################################################################
|
1998-06-17 01:43:24 +04:00
|
|
|
|
1999-07-22 02:15:21 +04:00
|
|
|
|
|
|
|
# This routine will scan through log looking for 'tinderbox:' variables
|
|
|
|
#
|
1998-06-17 01:43:24 +04:00
|
|
|
sub parse_log_variables {
|
1999-10-23 05:43:28 +04:00
|
|
|
my ($fh, $tbx) = @_;
|
|
|
|
local $_;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
while (<$fh>) {
|
|
|
|
chomp;
|
|
|
|
if (/^tinderbox:.*:/) {
|
|
|
|
last if /^tinderbox: END/;
|
|
|
|
my ($key, $value) = (split /:\s*/, $_, 3)[1..2];
|
2000-02-11 03:11:01 +03:00
|
|
|
$value =~ s/\s*$//;
|
1999-10-23 05:43:28 +04:00
|
|
|
$tbx->{$key} = $value;
|
1999-07-22 02:15:21 +04:00
|
|
|
}
|
1999-10-23 05:43:28 +04:00
|
|
|
}
|
1998-06-17 01:43:24 +04:00
|
|
|
}
|
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
sub parse_mail_header {
|
|
|
|
my ($fh, $mail_ref) = @_;
|
|
|
|
local $_;
|
|
|
|
my $name = '';
|
|
|
|
|
|
|
|
while(<$fh>) {
|
|
|
|
chomp;
|
|
|
|
last if $line eq '';
|
|
|
|
|
|
|
|
if (/([^ :]*)\:[ \t]+([^\n]*)/) {
|
|
|
|
$name = $1;
|
|
|
|
$name =~ tr/A-Z/a-z/;
|
|
|
|
$mail_ref{$name} = $2;
|
1999-07-22 02:15:21 +04:00
|
|
|
}
|
1999-10-23 05:43:28 +04:00
|
|
|
elsif ($name ne '') {
|
|
|
|
$mail_ref{$name} .= $2;
|
1999-07-22 02:15:21 +04:00
|
|
|
}
|
1999-10-23 05:43:28 +04:00
|
|
|
}
|
|
|
|
}
|
1999-07-22 02:15:21 +04:00
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
sub check_required_variables {
|
|
|
|
my ($tbx, $mail_header) = @_;
|
|
|
|
my $err_string = '';
|
1999-07-22 02:15:21 +04:00
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
if ($tbx->{tree} eq '') {
|
|
|
|
$err_string .= "Variable 'tinderbox:tree' not set.\n";
|
|
|
|
}
|
|
|
|
elsif (not -r $tbx->{tree}) {
|
|
|
|
$err_string .= "Variable 'tinderbox:tree' not set to a valid tree.\n";
|
|
|
|
}
|
|
|
|
elsif (($mail_header->{'to'} =~ /external/i or
|
|
|
|
$mail_header->{'cc'} =~ /external/i) and
|
|
|
|
$tbx->{tree} !~ /external/i) {
|
|
|
|
$err_string .= "Data from an external source didn't specify an 'external' tree.";
|
|
|
|
}
|
|
|
|
if ($tbx->{build} eq '') {
|
|
|
|
$err_string .= "Variable 'tinderbox:build' not set.\n";
|
|
|
|
}
|
|
|
|
if ($tbx->{errorparser} eq '') {
|
|
|
|
$err_string .= "Variable 'tinderbox:errorparser' not set.\n";
|
|
|
|
}
|
1999-07-22 02:15:21 +04:00
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
# Grab the date in the form of mm/dd/yy hh:mm:ss
|
|
|
|
#
|
|
|
|
# Or a GMT unix date
|
|
|
|
#
|
|
|
|
if ($tbx->{builddate} eq '') {
|
|
|
|
$err_string .= "Variable 'tinderbox:builddate' not set.\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ($tbx->{builddate} =~
|
|
|
|
/([0-9]*)\/([0-9]*)\/([0-9]*)[ \t]*([0-9]*)\:([0-9]*)\:([0-9]*)/) {
|
|
|
|
$tbx->{builddate} = timelocal($6,$5,$4,$2,$1-1,$3);
|
1999-07-22 02:15:21 +04:00
|
|
|
}
|
1999-10-23 05:43:28 +04:00
|
|
|
elsif ($tbx->{builddate} < 7000000) {
|
|
|
|
$err_string .= "Variable 'tinderbox:builddate' not of the form MM/DD/YY HH:MM:SS or unix date\n";
|
1999-07-22 02:15:21 +04:00
|
|
|
}
|
1999-10-23 05:43:28 +04:00
|
|
|
}
|
1999-07-22 02:15:21 +04:00
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
# Build Status
|
|
|
|
#
|
|
|
|
if ($tbx->{status} eq '') {
|
|
|
|
$err_string .= "Variable 'tinderbox:status' not set.\n";
|
|
|
|
}
|
|
|
|
elsif (not $tbx->{status} =~ /success|busted|building|testfailed/) {
|
|
|
|
$err_string .= "Variable 'tinderbox:status' must be 'success', 'busted', 'testfailed', or 'building'\n";
|
|
|
|
}
|
|
|
|
|
2004-03-24 06:37:38 +03:00
|
|
|
# Log compression
|
|
|
|
#
|
|
|
|
if ($tbx->{logcompression} !~ /^(bzip2|gzip)?$/) {
|
|
|
|
$err_string .= "Variable 'tinderbox:logcompression' must be '', 'bzip2' or 'gzip'\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
# Log encoding
|
|
|
|
if ($tbx->{logencoding} !~ /^(base64|uuencode)?$/) {
|
|
|
|
$err_string .= "Variable 'tinderbox:logencoding' must be '', 'base64' or 'uuencode'\n";
|
|
|
|
}
|
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
# Report errors
|
|
|
|
#
|
|
|
|
die $err_string unless $err_string eq '';
|
1998-06-17 01:43:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub write_build_data {
|
1999-10-23 05:43:28 +04:00
|
|
|
my $tbx = $_[0];
|
|
|
|
$process_time = time;
|
|
|
|
open BUILDDATA, ">>$tbx->{tree}/build.dat"
|
|
|
|
or die "can't open $! for writing";
|
2000-02-25 21:19:56 +03:00
|
|
|
print BUILDDATA "$process_time|$tbx->{builddate}|$tbx->{build}|$tbx->{errorparser}|$tbx->{status}|$tbx->{logfile}|$tbx->{binaryurl}\n";
|
1999-10-23 05:43:28 +04:00
|
|
|
close BUILDDATA;
|
1998-06-17 01:43:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub compress_log_file {
|
1999-10-23 05:43:28 +04:00
|
|
|
my ($tbx, $maillog) = @_;
|
|
|
|
local *LOG2;
|
1999-07-23 03:12:00 +04:00
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
open(LOG2, "<$maillog") or die "cant open $!";
|
1999-07-23 03:12:00 +04:00
|
|
|
|
|
|
|
# Skip past the the RFC822.HEADER
|
|
|
|
#
|
|
|
|
while (<LOG2>) {
|
|
|
|
chomp;
|
|
|
|
last if /^$/;
|
|
|
|
}
|
|
|
|
|
1999-10-23 05:43:28 +04:00
|
|
|
open ZIPLOG, "| $gzip -c > $tbx->{tree}/$tbx->{logfile}"
|
|
|
|
or die "can't open $! for writing";
|
2004-03-24 06:37:38 +03:00
|
|
|
|
|
|
|
# If this log is compressed, we need to decode it and decompress
|
|
|
|
# it before storing its contents into ZIPLOG.
|
|
|
|
if($tbx->{logcompression} ne '') {
|
|
|
|
|
|
|
|
# tinderbox variables are not compressed
|
|
|
|
# write them directly to the gzip'd log
|
|
|
|
while(<LOG2>) {
|
1999-07-23 03:12:00 +04:00
|
|
|
print ZIPLOG $_;
|
2004-03-24 06:37:38 +03:00
|
|
|
last if(m/^tinderbox: END/);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Decode the log using the logencoding variable to determine
|
|
|
|
# the type of encoding.
|
|
|
|
my $decoded = "$tbx->{tree}/$tbx->{logfile}.uncomp";
|
|
|
|
if ($tbx->{logencoding} eq 'base64') {
|
|
|
|
eval "use MIME::Base64 ();";
|
|
|
|
open DECODED, ">$decoded"
|
|
|
|
or die "Can't open $decoded for writing: $!";
|
|
|
|
while (<LOG2>) {
|
|
|
|
print DECODED MIME::Base64::decode($_);
|
1999-07-23 03:12:00 +04:00
|
|
|
}
|
2004-03-24 06:37:38 +03:00
|
|
|
close DECODED;
|
1999-07-22 02:15:21 +04:00
|
|
|
}
|
2004-03-24 06:37:38 +03:00
|
|
|
elsif ($tbx->{logencoding} eq 'uuencode') {
|
|
|
|
open DECODED, ">$decoded"
|
|
|
|
or die "Can't open $decoded for writing: $!";
|
|
|
|
while (<LOG2>) {
|
|
|
|
print DECODED unpack("u*", $_);
|
|
|
|
}
|
|
|
|
close DECODED;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Decompress the log using the logcompression variable to determine
|
|
|
|
# the type of compression used.
|
|
|
|
my $cmd = undef;
|
|
|
|
if ($tbx->{logcompression} eq 'gzip') {
|
|
|
|
$cmd = $gzip;
|
|
|
|
}
|
|
|
|
elsif ($tbx->{logcompression} eq 'bzip2') {
|
|
|
|
$cmd = $bzip2;
|
|
|
|
}
|
|
|
|
if (defined $cmd) {
|
|
|
|
open UNCOMP, "$cmd -dc $decoded |"
|
|
|
|
or die "Can't open $! for reading";
|
|
|
|
while (<UNCOMP>) {
|
|
|
|
print ZIPLOG $_;
|
|
|
|
}
|
|
|
|
close UNCOMP;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Remove our temporary decoded file
|
|
|
|
unlink($decoded) if -f $decoded;
|
|
|
|
}
|
|
|
|
# This log is not compressed/encoded so we can simply write out
|
|
|
|
# it's contents to the gzip'd log file.
|
|
|
|
else {
|
|
|
|
while (<LOG2>) {
|
|
|
|
print ZIPLOG $_;
|
1999-07-22 02:15:21 +04:00
|
|
|
}
|
1999-07-23 03:12:00 +04:00
|
|
|
}
|
|
|
|
close ZIPLOG;
|
|
|
|
close LOG2;
|
1999-07-22 02:15:21 +04:00
|
|
|
}
|