diff --git a/tools/tinderbox/build-seamonkey-util.pl b/tools/tinderbox/build-seamonkey-util.pl index 1bcead8b5f9f..6ec66102ef04 100644 --- a/tools/tinderbox/build-seamonkey-util.pl +++ b/tools/tinderbox/build-seamonkey-util.pl @@ -3,254 +3,238 @@ require 5.000; use Sys::Hostname; -use POSIX "sys_wait_h"; -use Cwd; - -sub InitVars { - for (@ARGV) { - # Save DATA section for printing the example. - return if /^--example-config$/; - } - eval while ; # See __END__ section below -} +use strict; +package TinderboxClientUtils; sub GetSystemInfo { - $OS = `uname -s`; - $OSVer = `uname -r`; - $CPU = `uname -m`; - $BuildName = ''; - - my $host = hostname; - $host =~ s/\..*$//; - - chomp($OS, $OSVer, $CPU, $host); - - if ($OS eq 'AIX') { - my $osAltVer = `uname -v`; - chomp($osAltVer); - $OSVer = "$osAltVer.$OSVer"; - } - - $OS = 'BSD_OS' if $OS eq 'BSD/OS'; - $OS = 'IRIX' if $OS eq 'IRIX64'; - - if ($OS eq 'QNX') { - $OSVer = `uname -v`; - chomp($OSVer); - $OSVer =~ s/^([0-9])([0-9]*)$/$1.$2/; - } - if ($OS eq 'SCO_SV') { - $OS = 'SCOOS'; - $OSVer = '5.0'; - } - - unless ("$host" eq '') { - $BuildName = "$host $OS ". ($BuildDepend ? 'Depend' : 'Clobber'); - } - $DirName = "${OS}_${OSVer}_". ($BuildDepend ? 'depend' : 'clobber'); - $logfile = "${DirName}.log"; - - # - # Make the build names reflect architecture/OS - # - - if ($OS eq 'AIX') { - # Assumes 4.2.1 for now. - } - if ($OS eq 'BSD_OS') { - $BuildName = "$host BSD/OS $OSVer ". ($BuildDepend ? 'Depend' : 'Clobber'); - } - if ($OS eq 'FreeBSD') { - $BuildName = "$host $OS/$CPU $OSVer ". ($BuildDepend ? 'Depend':'Clobber'); - } - if ($OS eq 'HP-UX') { - } - if ($OS eq 'IRIX') { - } - if ($OS eq 'Linux') { - if ($CPU eq 'alpha' or $CPU eq 'sparc') { - $BuildName = "$host $OS/$CPU $OSVer " - . ($BuildDepend ? 'Depend' : 'Clobber'); - } elsif ($CPU eq 'armv4l' or $CPU eq 'sa110') { - $BuildName = "$host $OS/arm $OSVer ". ($BuildDepend?'Depend':'Clobber'); - } elsif ($CPU eq 'ppc') { - $BuildName = "$host $OS/$CPU $OSVer ". ($BuildDepend?'Depend':'Clobber'); - } else { - $BuildName = "$host $OS ". ($BuildDepend?'Depend':'Clobber'); - - # What's the right way to test for this? - $ObjDir .= 'libc1' if $host eq 'truth'; + $Settings::OS = `uname -s`; + my $os_ver = `uname -r`; + $Settings::CPU = `uname -m`; + $Settings::BuildName = ''; + $Settings::ObjDir = ''; + my $build_type = $Settings::BuildDepend ? 'Depend' : 'Clobber'; + my $host = ::hostname(); + $host =~ s/\..*$//; + + chomp($Settings::OS, $os_ver, $Settings::CPU, $host); + + if ($Settings::OS eq 'AIX') { + my $osAltVer = `uname -v`; + chomp($osAltVer); + $os_ver = "$osAltVer.$os_ver"; } - } - if ($OS eq 'NetBSD') { - $BuildName = "$host $OS/$CPU $OSVer ". ($BuildDepend?'Depend':'Clobber'); - } - if ($OS eq 'OSF1') { - # Assumes 4.0D for now. - } - if ($OS eq 'QNX') { - } - if ($OS eq 'SunOS') { - if ($CPU eq 'i86pc') { - $BuildName = "$host $OS/i386 $OSVer ". ($BuildDepend?'Depend':'Clobber'); - } else { - $OSVerMajor = substr($OSVer, 0, 1); - if ($OSVerMajor ne '4') { - $BuildName = "$host $OS/sparc $OSVer " - . ($BuildDepend?'Depend':'Clobber'); - } + + $Settings::OS = 'BSD_OS' if $Settings::OS eq 'BSD/OS'; + $Settings::OS = 'IRIX' if $Settings::OS eq 'IRIX64'; + + if ($Settings::OS eq 'QNX') { + $os_ver = `uname -v`; + chomp($os_ver); + $os_ver =~ s/^([0-9])([0-9]*)$/$1.$2/; + } + if ($Settings::OS eq 'SCO_SV') { + $Settings::OS = 'SCOOS'; + $os_ver = '5.0'; + } + + unless ("$host" eq '') { + $Settings::BuildName = "$host $Settings::OS $build_type"; + } + $Settings::DirName = "${Settings::OS}_${os_ver}_$build_type"; + + # Make the build names reflect architecture/OS + + if ($Settings::OS eq 'AIX') { + # Assumes 4.2.1 for now. + } + if ($Settings::OS eq 'BSD_OS') { + $Settings::BuildName = "$host BSD/OS $os_ver $build_type"; + } + if ($Settings::OS eq 'FreeBSD') { + $Settings::BuildName = "$host $Settings::OS/$Settings::CPU $os_ver $build_type"; + } + if ($Settings::OS eq 'HP-UX') { + } + if ($Settings::OS eq 'IRIX') { + } + if ($Settings::OS eq 'Linux') { + if ($Settings::CPU eq 'alpha' or $Settings::CPU eq 'sparc') { + $Settings::BuildName = "$host $Settings::OS/$Settings::CPU $os_ver $build_type"; + } elsif ($Settings::CPU eq 'armv4l' or $Settings::CPU eq 'sa110') { + $Settings::BuildName = "$host $Settings::OS/arm $os_ver $build_type"; + } elsif ($Settings::CPU eq 'ppc') { + $Settings::BuildName = "$host $Settings::OS/$Settings::CPU $os_ver $build_type"; + } else { + $Settings::BuildName = "$host $Settings::OS $build_type"; + + # What's the right way to test for this? + $Settings::ObjDir .= 'libc1' if $host eq 'truth'; + } + } + if ($Settings::OS eq 'NetBSD') { + $Settings::BuildName = "$host $Settings::OS/$Settings::CPU $os_ver $build_type"; + } + if ($Settings::OS eq 'OSF1') { + # Assumes 4.0D for now. + } + if ($Settings::OS eq 'QNX') { + } + if ($Settings::OS eq 'SunOS') { + if ($Settings::CPU eq 'i86pc') { + $Settings::BuildName = "$host $Settings::OS/i386 $os_ver $build_type"; + } else { + $Settings::OSVerMajor = substr($os_ver, 0, 1); + if ($Settings::OSVerMajor ne '4') { + $Settings::BuildName = "$host $Settings::OS/sparc $os_ver $build_type"; + } + } } - } } sub LoadConfig { - if (-r 'tinder-config.pl') { - require 'tinder-config.pl'; - } else { - warn "Error: Need tinderbox config file, tinder-config.pl\n"; - warn " To get started, run the following,\n"; - warn " $0 --example-config > tinder-config.pl\n"; - exit; - } - + if (-r 'tinder-config.pl') { + { package Settings; do 'tinder-config.pl'; } + } else { + warn "Error: Need tinderbox config file, tinder-config.pl\n"; + warn " To get started, run the following,\n"; + warn " $0 --example-config > tinder-config.pl\n"; + exit; + } } sub SetupEnv { - umask 0; - $ENV{LD_LIBRARY_PATH} = "$BaseDir/$DirName/mozilla/${ObjDir}dist/bin:/usr/lib/png:" - ."/usr/local/lib:$BaseDir/$DirName/mozilla/dist/bin"; - $ENV{DISPLAY} = $DisplayServer; - $ENV{MOZCONFIG} = "$BaseDir/$MozConfigFileName" if $MozConfigFileName ne ''; + umask 0; + $ENV{LD_LIBRARY_PATH} = "$Settings::BaseDir/$Settings::DirName/mozilla/${Settings::ObjDir}dist/bin:/usr/lib/png:" + ."/usr/local/lib:$Settings::BaseDir/$Settings::DirName/mozilla/dist/bin"; + $ENV{DISPLAY} = $Settings::DisplayServer; + $ENV{MOZCONFIG} = "$Settings::BaseDir/$Settings::MozConfigFileName" if $Settings::MozConfigFileName ne '' and -e $Settings::MozConfigFileName; } sub SetupPath { - my $comptmp; - $comptmp = ''; - #print "Path before: $ENV{PATH}\n"; - - if ($OS eq 'AIX') { - $ENV{PATH} = "/builds/local/bin:$ENV{PATH}:/usr/lpp/xlC/bin"; - $ConfigureArgs .= '--x-includes=/usr/include/X11 ' - . '--x-libraries=/usr/lib --disable-shared'; - $ConfigureEnvArgs = 'CC=xlC_r CXX=xlC_r'; - $Compiler = 'xlC_r'; - $NSPRArgs .= 'NS_USE_NATIVE=1 USE_PTHREADS=1'; - } - - if ($OS eq 'BSD_OS') { - $ENV{PATH} = "/usr/contrib/bin:/bin:/usr/bin:$ENV{PATH}"; - $ConfigureArgs .= '--disable-shared'; - $ConfigureEnvArgs = 'CC=shlicc2 CXX=shlicc2'; - $Compiler = 'shlicc2'; - $mail = '/usr/ucb/mail'; - # Because ld dies if it encounters -include - $MakeOverrides = 'CPP_PROG_LINK=0 CCF=shlicc2'; - $NSPRArgs .= 'NS_USE_GCC=1 NS_USE_NATIVE='; - } + #print "Path before: $ENV{PATH}\n"; - if ($OS eq 'FreeBSD') { - $ENV{PATH} = "/bin:/usr/bin:$ENV{PATH}"; - if ($ENV{HOST} eq 'angelus.mcom.com') { - $ConfigureEnvArgs = 'CC=egcc CXX=eg++'; - $Compiler = 'egcc'; + if ($Settings::OS eq 'AIX') { + $ENV{PATH} = "/builds/local/bin:$ENV{PATH}:/usr/lpp/xlC/bin"; + $Settings::ConfigureArgs .= '--x-includes=/usr/include/X11 ' + . '--x-libraries=/usr/lib --disable-shared'; + $Settings::ConfigureEnvArgs = 'CC=xlC_r CXX=xlC_r'; + $Settings::Compiler = 'xlC_r'; + $Settings::NSPRArgs .= 'NS_USE_NATIVE=1 USE_PTHREADS=1'; } - $mail = '/usr/bin/mail'; - } - - if ($OS eq 'HP-UX') { - $ENV{PATH} = "/opt/ansic/bin:/opt/aCC/bin:/builds/local/bin:" - . "$ENV{PATH}"; - $ENV{LPATH} = "/usr/lib:$ENV{LD_LIBRARY_PATH}:/builds/local/lib"; - $ENV{SHLIB_PATH} = $ENV{LPATH}; - $ConfigureArgs .= '--x-includes=/usr/include/X11 ' - . '--x-libraries=/usr/lib --disable-gtktest '; - $ConfigureEnvArgs = 'CC="cc -Ae" CXX="aCC -ext"'; - $Compiler = 'cc/aCC'; - # Use USE_PTHREADS=1 instead of CLASSIC_NSPR if you've got DCE installed. - $NSPRArgs .= 'NS_USE_NATIVE=1 CLASSIC_NSPR=1'; - } - - if ($OS eq 'IRIX') { - $ENV{PATH} = "/opt/bin:$ENV{PATH}"; - $ENV{LD_LIBRARY_PATH} .= ':/opt/lib'; - $ENV{LD_LIBRARYN32_PATH} = $ENV{LD_LIBRARY_PATH}; - $ConfigureEnvArgs = 'CC=cc CXX=CC CFLAGS="-n32 -O" CXXFLAGS="-n32 -O"'; - $Compiler = 'cc/CC'; - $NSPRArgs .= 'NS_USE_NATIVE=1 USE_PTHREADS=1'; - } - - if ($OS eq 'NetBSD') { - $ENV{PATH} = "/bin:/usr/bin:$ENV{PATH}"; - $ENV{LD_LIBRARY_PATH} .= ':/usr/X11R6/lib'; - $ConfigureEnvArgs = 'CC=egcc CXX=eg++'; - $Compiler = 'egcc'; - $mail = '/usr/bin/mail'; - } - - if ($OS eq 'OSF1') { - $ENV{PATH} = "/usr/gnu/bin:$ENV{PATH}"; - $ENV{LD_LIBRARY_PATH} .= ':/usr/gnu/lib'; - $ConfigureEnvArgs = 'CC="cc -readonly_strings" CXX="cxx"'; - $Compiler = 'cc/cxx'; - $MakeOverrides = 'SHELL=/usr/bin/ksh'; - $NSPRArgs .= 'NS_USE_NATIVE=1 USE_PTHREADS=1'; - $ShellOverride = '/usr/bin/ksh'; - } - - if ($OS eq 'QNX') { - $ENV{PATH} = "/usr/local/bin:$ENV{PATH}"; - $ENV{LD_LIBRARY_PATH} .= ':/usr/X11/lib'; - $ConfigureArgs .= '--x-includes=/usr/X11/include ' - . '--x-libraries=/usr/X11/lib --disable-shared '; - $ConfigureEnvArgs = 'CC="cc -DQNX" CXX="cc -DQNX"'; - $Compiler = 'cc'; - $mail = '/usr/bin/sendmail'; - } - - if ($OS eq 'SunOS') { - if ($OSVerMajor eq '4') { - $ENV{PATH} = "/usr/gnu/bin:/usr/local/sun4/bin:/usr/bin:$ENV{PATH}"; - $ENV{LD_LIBRARY_PATH} = "/home/motif/usr/lib:$ENV{LD_LIBRARY_PATH}"; - $ConfigureArgs .= '--x-includes=/home/motif/usr/include/X11 ' - . '--x-libraries=/home/motif/usr/lib'; - $ConfigureEnvArgs = 'CC="egcc -DSUNOS4" CXX="eg++ -DSUNOS4"'; - $Compiler = 'egcc'; - } else { - $ENV{PATH} = '/usr/ccs/bin:' . $ENV{PATH}; + + if ($Settings::OS eq 'BSD_OS') { + $ENV{PATH} = "/usr/contrib/bin:/bin:/usr/bin:$ENV{PATH}"; + $Settings::ConfigureArgs .= '--disable-shared'; + $Settings::ConfigureEnvArgs = 'CC=shlicc2 CXX=shlicc2'; + $Settings::Compiler = 'shlicc2'; + $Settings::mail = '/usr/ucb/mail'; + # Because ld dies if it encounters -include + $Settings::MakeOverrides = 'CPP_PROG_LINK=0 CCF=shlicc2'; + $Settings::NSPRArgs .= 'NS_USE_GCC=1 NS_USE_NATIVE='; } - if ($CPU eq 'i86pc') { - $ENV{PATH} = '/opt/gnu/bin:' . $ENV{PATH}; - $ENV{LD_LIBRARY_PATH} .= ':/opt/gnu/lib'; - $ConfigureEnvArgs = 'CC=egcc CXX=eg++'; - $Compiler = 'egcc'; - - # Possible NSPR bug... If USE_PTHREADS is defined, then - # _PR_HAVE_ATOMIC_CAS gets defined (erroneously?) and - # libnspr21 does not work. - $NSPRArgs .= 'CLASSIC_NSPR=1 NS_USE_GCC=1 NS_USE_NATIVE='; - } else { - # This is utterly lame.... - if ($ENV{HOST} eq 'fugu') { - $ENV{PATH} = "/tools/ns/workshop/bin:/usrlocal/bin:$ENV{PATH}"; - $ENV{LD_LIBRARY_PATH} = '/tools/ns/workshop/lib:/usrlocal/lib:' + + if ($Settings::OS eq 'FreeBSD') { + $ENV{PATH} = "/bin:/usr/bin:$ENV{PATH}"; + if ($ENV{HOST} eq 'angelus.mcom.com') { + $Settings::ConfigureEnvArgs = 'CC=egcc CXX=eg++'; + $Settings::Compiler = 'egcc'; + } + $Settings::mail = '/usr/bin/mail'; + } + + if ($Settings::OS eq 'HP-UX') { + $ENV{PATH} = "/opt/ansic/bin:/opt/aCC/bin:/builds/local/bin:" + . "$ENV{PATH}"; + $ENV{LPATH} = "/usr/lib:$ENV{LD_LIBRARY_PATH}:/builds/local/lib"; + $ENV{SHLIB_PATH} = $ENV{LPATH}; + $Settings::ConfigureArgs .= '--x-includes=/usr/include/X11 ' + . '--x-libraries=/usr/lib --disable-gtktest '; + $Settings::ConfigureEnvArgs = 'CC="cc -Ae" CXX="aCC -ext"'; + $Settings::Compiler = 'cc/aCC'; + # Use USE_PTHREADS=1 instead of CLASSIC_NSPR if DCE is installed. + $Settings::NSPRArgs .= 'NS_USE_NATIVE=1 CLASSIC_NSPR=1'; + } + + if ($Settings::OS eq 'IRIX') { + $ENV{PATH} = "/opt/bin:$ENV{PATH}"; + $ENV{LD_LIBRARY_PATH} .= ':/opt/lib'; + $ENV{LD_LIBRARYN32_PATH} = $ENV{LD_LIBRARY_PATH}; + $Settings::ConfigureEnvArgs = 'CC=cc CXX=CC CFLAGS="-n32 -O" CXXFLAGS="-n32 -O"'; + $Settings::Compiler = 'cc/CC'; + $Settings::NSPRArgs .= 'NS_USE_NATIVE=1 USE_PTHREADS=1'; + } + + if ($Settings::OS eq 'NetBSD') { + $ENV{PATH} = "/bin:/usr/bin:$ENV{PATH}"; + $ENV{LD_LIBRARY_PATH} .= ':/usr/X11R6/lib'; + $Settings::ConfigureEnvArgs = 'CC=egcc CXX=eg++'; + $Settings::Compiler = 'egcc'; + $Settings::mail = '/usr/bin/mail'; + } + + if ($Settings::OS eq 'OSF1') { + $ENV{PATH} = "/usr/gnu/bin:$ENV{PATH}"; + $ENV{LD_LIBRARY_PATH} .= ':/usr/gnu/lib'; + $Settings::ConfigureEnvArgs = 'CC="cc -readonly_strings" CXX="cxx"'; + $Settings::Compiler = 'cc/cxx'; + $Settings::MakeOverrides = 'SHELL=/usr/bin/ksh'; + $Settings::NSPRArgs .= 'NS_USE_NATIVE=1 USE_PTHREADS=1'; + $Settings::ShellOverride = '/usr/bin/ksh'; + } + + if ($Settings::OS eq 'QNX') { + $ENV{PATH} = "/usr/local/bin:$ENV{PATH}"; + $ENV{LD_LIBRARY_PATH} .= ':/usr/X11/lib'; + $Settings::ConfigureArgs .= '--x-includes=/usr/X11/include ' + . '--x-libraries=/usr/X11/lib --disable-shared '; + $Settings::ConfigureEnvArgs = 'CC="cc -DQNX" CXX="cc -DQNX"'; + $Settings::Compiler = 'cc'; + $Settings::mail = '/usr/bin/sendmail'; + } + + if ($Settings::OS eq 'SunOS') { + if ($Settings::OSVerMajor eq '4') { + $ENV{PATH} = "/usr/gnu/bin:/usr/local/sun4/bin:/usr/bin:$ENV{PATH}"; + $ENV{LD_LIBRARY_PATH} = "/home/motif/usr/lib:$ENV{LD_LIBRARY_PATH}"; + $Settings::ConfigureArgs .= '--x-includes=/home/motif/usr/include/X11 ' + . '--x-libraries=/home/motif/usr/lib'; + $Settings::ConfigureEnvArgs = 'CC="egcc -DSUNOS4" CXX="eg++ -DSUNOS4"'; + $Settings::Compiler = 'egcc'; + } else { + $ENV{PATH} = '/usr/ccs/bin:' . $ENV{PATH}; + } + if ($Settings::CPU eq 'i86pc') { + $ENV{PATH} = '/opt/gnu/bin:' . $ENV{PATH}; + $ENV{LD_LIBRARY_PATH} .= ':/opt/gnu/lib'; + $Settings::ConfigureEnvArgs = 'CC=egcc CXX=eg++'; + $Settings::Compiler = 'egcc'; + + # Possible NSPR bug... If USE_PTHREADS is defined, then + # _PR_HAVE_ATOMIC_CAS gets defined (erroneously?) and + # libnspr21 does not work. + $Settings::NSPRArgs .= 'CLASSIC_NSPR=1 NS_USE_GCC=1 NS_USE_NATIVE='; + } else { + # This is utterly lame.... + if ($ENV{HOST} eq 'fugu') { + $ENV{PATH} = "/tools/ns/workshop/bin:/usrlocal/bin:$ENV{PATH}"; + $ENV{LD_LIBRARY_PATH} = '/tools/ns/workshop/lib:/usrlocal/lib:' . $ENV{LD_LIBRARY_PATH}; - $ConfigureEnvArgs = 'CC=cc CXX=CC'; - $comptmp = `cc -V 2>&1 | head -1`; - chomp($comptmp); - $Compiler = "cc/CC \($comptmp\)"; - $NSPRArgs .= 'NS_USE_NATIVE=1'; - } else { - $NSPRArgs .= 'NS_USE_GCC=1 NS_USE_NATIVE='; - } - if ($OSVerMajor eq '5') { - $NSPRArgs .= ' USE_PTHREADS=1'; - } + $Settings::ConfigureEnvArgs = 'CC=cc CXX=CC'; + my $comptmp = `cc -V 2>&1 | head -1`; + chomp($comptmp); + $Settings::Compiler = "cc/CC \($comptmp\)"; + $Settings::NSPRArgs .= 'NS_USE_NATIVE=1'; + } else { + $Settings::NSPRArgs .= 'NS_USE_GCC=1 NS_USE_NATIVE='; + } + if ($Settings::OSVerMajor eq '5') { + $Settings::NSPRArgs .= ' USE_PTHREADS=1'; + } + } } - } - #print "Path after: $ENV{PATH}\n"; + #print "Path after: $ENV{PATH}\n"; } - # Need to end with a true value, (since we're using "require"). 1; diff --git a/tools/tinderbox/build-seamonkey.pl b/tools/tinderbox/build-seamonkey.pl index 8908d0e8093d..8a7c2d30bda3 100755 --- a/tools/tinderbox/build-seamonkey.pl +++ b/tools/tinderbox/build-seamonkey.pl @@ -6,835 +6,724 @@ require 5.000; # script so they can be re-used by other scripts. require "build-seamonkey-util.pl"; -use Sys::Hostname; +use strict; use POSIX qw(sys_wait_h strftime); use Cwd; +use File::Basename; # for basename(); -$Version = '$Revision: 1.62 $ '; - +$::Version = '$Revision: 1.63 $ '; sub PrintUsage { - die <) { + s/^\s*\$(\S*)/\$Settings::$1/; + eval; } - elsif ($arg eq '--mozconfig' or $arg eq '--configfile') { - # File generated by the build configurator, - # http://cvs-mirror.mozilla.org/webtools/build/config.cgi - $MozConfigFileName = shift @ARGV; - &PrintUsage if $MozConfigFileName eq ''; - } - elsif ($arg eq '--version' or $arg eq '-v') { - die "$0: version" . substr($Version,9,6) . "\n"; - } else { - &PrintUsage; - } - } - &PrintUsage if $BuildTree =~ /^\s+$/i; } sub PrintExampleConfig { - print "#- tinder-config.pl - Tinderbox configuration file.\n"; - print "#- Uncomment the variables you need to set.\n"; - print "#- The default values are the same as the commented variables\n\n"; - - while () { - s/^\$/\#\$/; - print; - } + local $_; + print "#- tinder-config.pl - Tinderbox configuration file.\n"; + print "#- Uncomment the variables you need to set.\n"; + print "#- The default values are the same as the commented variables.\n"; + print "\n"; + + while () { + s/^\$/\#\$/; + print; + } +} + +sub ParseArgs { + PrintUsage() if $#ARGV == -1; + + package Settings; + while (my $arg = shift @ARGV) { + $Settings::BuildDepend = 0, next if $arg eq '--clobber'; + $Settings::BuildDepend = 1, next if $arg eq '--depend'; + PrintExampleConfig(), exit if $arg eq '--example-config'; + PrintUsage(), exit if $arg eq '--help' or $arg eq '-h'; + $Settings::ReportStatus = 0, next if $arg eq '--noreport'; + $Settings::ReportFinalStatus = 0, next if $arg eq '--nofinalreport'; + $Settings::RunTest = 0, next if $arg eq '--notest'; + $Settings::TestOnly = 1, next if $arg eq '--testonly'; + $Settings::BuildOnce = 1, next if $arg eq '--once'; + $Settings::UseTimeStamp = 0, next if $arg eq '--notimestamp'; + + if ($arg eq '-tag') { + $Settings::BuildTag = shift @ARGV; + PrintUsage() if $Settings::BuildTag eq '' + or $Settings::BuildTag =~ /^-/; + } + elsif ($arg eq '-t') { + $Settings::BuildTree = shift @ARGV; + PrintUsage() if $Settings::BuildTree eq '' + or $Settings::BuildTree =~ /^-/; + } + elsif ($arg eq '--mozconfig' or $arg eq '--configfile') { + # File generated by the build configurator, + # http://cvs-mirror.mozilla.org/webtools/build/config.cgi + $Settings::MozConfigFileName = shift @ARGV; + PrintUsage() if $Settings::MozConfigFileName eq '' + or $Settings::MozConfigFileName =~ /^-/; + } + elsif ($arg eq '--version' or $arg eq '-v') { + die "$0: version" . substr($::Version,9,6) . "\n"; + } else { + PrintUsage(); + } + } + PrintUsage() if $Settings::BuildTree =~ /^\s+$/i; } sub ConditionalArgs { - my $cvsuser = $ENV{USER}; - - $mozillaBinary = 'mozilla-bin'; - $RelBinaryName = "dist/bin/$mozillaBinary"; - #$FullBinaryName = "$BaseDir/$DirName/$TopLevel/$Topsrcdir/$RelBinaryName"; - $ENV{CVSROOT} = ":pserver:$cvsuser%netscape.com\@cvs.mozilla.org:/cvsroot"; - $CVSCO .= " -r $BuildTag" unless $BuildTag eq ''; + $ENV{CVSROOT} = ":pserver:$ENV{USER}%netscape.com\@cvs.mozilla.org:/cvsroot"; + $Settings::CVSCO .= " -r $Settings::BuildTag" + unless $Settings::BuildTag eq ''; } +sub print_log { + my ($text) = $_[0]; + print LOG $text; + print $text; +} + +sub run_shell_command { + my ($shell_command) = $_[0]; + local $_; + + chomp($shell_command); + print_log "$shell_command\n"; + open CMD, "$shell_command 2>&1|" or die "open: $!\n"; + print_log $_ while ; + close CMD; +} + +sub adjust_start_time { + # Allows the start time to match up with the update times of a mirror. + my ($start_time) = $_[0]; + + # Since we are not pulling for cvs-mirror anymore, just round times + # to 1 minute intervals to make them nice and even. + my $cycle = 1 * 60; # Updates every 1 minutes. + my $begin = 0 * 60; # Starts 0 minutes after the hour. + my $lag = 0 * 60; # Takes 0 minute to update. + return int(($start_time - $begin - $lag) / $cycle) * $cycle + $begin; +} sub BuildIt { - - die "\$BuildName is the empty string ('')\n" if $BuildName eq ''; - - mkdir $DirName, 0777; - chdir $DirName or die "Couldn't enter $DirName"; - - my ($StartDir) = getcwd(); - my ($LastStartTime) = 0; - my ($EarlyExit) = 0; - my ($SaveCVSCO) = $CVSCO; - - # Bypass profile at startup. - $ENV{MOZ_BYPASS_PROFILE_AT_STARTUP} = 1; - - print "Starting dir is : $StartDir\n"; - - while (not $EarlyExit) { - chdir $StartDir; - - if (not $TestOnly and (time - $LastStartTime < (60 * $BuildSleep))) { - my ($SleepTime) = (60 * $BuildSleep) - (time - $LastStartTime); - print "\n\nSleeping $SleepTime seconds ...\n"; - sleep $SleepTime; - } + # $Settings::DirName is set in buildl-seamonkey-utils.pl + mkdir $Settings::DirName, 0777; + chdir $Settings::DirName or die "Couldn't enter $Settings::DirName"; - $StartTime = time(); - $LastStartTime = $StartTime; + my $build_dir = getcwd(); + my $binary_basename = '$Settings::BinaryName'; + my $binary_dir = "$build_dir/$Settings::Topsrcdir/dist/bin"; + my $full_binary_name = "$binary_dir/$binary_basename"; + my $exit_early = 0; + my $start_time = 0; - if ($UseTimeStamp) { - # Round tinderbox pull times to 1 minute intervals. - $cycle = 1 * 60; # Updates every 1 minutes. - $begin = 0 * 60; # Starts 0 minutes after the hour. - $lag = 0 * 60; # Takes 0 minute to update. - $StartTime = int(($StartTime - $begin - $lag) / $cycle) * $cycle + $begin; - $BuildStart = strftime("%m/%d/%Y %H:%M", localtime($StartTime)); - $CVSCO = "$SaveCVSCO -D '$BuildStart'"; - } else { - $CVSCO = "$SaveCVSCO -A"; - } - - &MailStartBuildMessage if $ReportStatus; - - $CurrentDir = getcwd(); - if ($CurrentDir ne $StartDir) { - print "startdir: $StartDir, curdir $CurrentDir\n"; - die "curdir != startdir"; - } + # Bypass profile at startup. + $ENV{MOZ_BYPASS_PROFILE_AT_STARTUP} = 1; - $BuildDir = $CurrentDir; + print_log "Starting dir is : $build_dir\n"; - unlink $logfile; - - print "Opening $logfile\n"; - - open LOG, ">$logfile" or print "can't open $?\n"; - print LOG "current dir is -- " . $ENV{HOST} . ":$CurrentDir\n"; - print LOG "Build Administrator is $BuildAdministrator\n"; - &PrintEnv; - if ($Compiler ne '') { - print LOG "===============================\n"; - if ($Compiler eq 'gcc' or $Compiler eq 'egcc') { - my $comptmp = `$Compiler --version`; - chomp($comptmp); - print LOG "Compiler is -- $Compiler ($comptmp)\n"; - } else { - print LOG "Compiler is -- $Compiler\n"; - } - print LOG "===============================\n"; - } - - $BuildStatus = 0; - - mkdir $TopLevel, 0777; - chdir $TopLevel or die "chdir($TopLevel): $!\n"; - - unless (-e "$Topsrcdir/client.mk") { - print "$CVS $CVSCO $Topsrcdir/client.mk\n"; - print LOG "$CVS $CVSCO $Topsrcdir/client.mk\n"; - open PULL, "$CVS $CVSCO $Topsrcdir/client.mk 2>&1 |" or die "open: $!\n"; - while () { - print $_; - print LOG $_; - } - close PULL; - } - - chdir $Topsrcdir or die "chdir $Topsrcdir: $!\n"; - - - # Delete the binary before rebuilding - if (&BinaryExists($mozillaBinary)) { - # Don't delete binary if we're only running tests. - unless ($TestOnly) { - print LOG "deleting existing binary: $mozillaBinary\n"; - &DeleteBinary($mozillaBinary); - } - } else { - print LOG "no binary detected, can't delete.\n"; - } - - - $ENV{MOZ_CO_DATE} = "$BuildStart" if $UseTimeStamp; - - # Don't build if testing smoke tests. - unless ($TestOnly) { - - # If we are building depend, don't clobber. - if ($BuildDepend) { - print LOG "$Make -f client.mk\n"; - open MAKEDEPEND, "$Make -f client.mk 2>&1 |"; - while () { - print $_; - print LOG $_; - } - close MAKEDEPEND; - } else { - # Building clobber - print LOG "$Make -f client.mk checkout realclean build 2>&1 |\n"; - open MAKECLOBBER, "$Make -f client.mk checkout realclean build 2>&1 |"; - while () { - print $_; - print LOG $_; + while (not $exit_early) { + # $BuildSleep is the minimum amount of time a build is allowed to take. + # It prevents sending too many messages to the tinderbox server when + # something is broken. + my $sleep_time = ($Settings::BuildSleep * 60) - (time - $start_time); + if (not $Settings::TestOnly and $sleep_time > 0) { + print_log "\n\nSleeping $sleep_time seconds ...\n"; + sleep $sleep_time; } - close MAKECLOBBER; - } - - } # unless ($TestOnly) - - if (&BinaryExists($mozillaBinary)) { - if ($RunTest) { - print LOG "$mozillaBinary binary exists, build successful.\n"; - - # Mozilla AliveTest. - print LOG "Running AliveTest ...\n"; - print "Running AliveTest ...\n"; - $BuildStatus = &RunAliveTest($mozillaBinary, 60); - - # ViewerTest. - if ($BuildStatus == 0 and $ViewerTest) { - print LOG "Running ViewerTest ...\n"; - print "Running ViewerTest ...\n"; - $BuildStatus = &RunAliveTest("viewer", 60); - } - - # BloatTest. - if ($BuildStatus == 0 and ($BloatStats or $BloatTest)) { - $BuildStatusStr = 'success'; - print LOG "Running BloatTest ...\n"; - print "Running BloatTest ...\n"; - $BuildStatus = &RunBloatTest; - } - - # Run MailNews test. - # - # This test needs the following security pref set - # user_pref("signed.applets.codebase_principal_support", true); - # first time around, you get two dialogs, which sets this pref: - # user_pref("security.principal.X0", "[Codebase http://www.mozilla.org/quality/mailnews/APITest.html] UniversalBrowserRead=1 UniversalXPConnect=1"); - # - - # XXX MailNewsTest will not work for clobber builds because they - # trash the dist directory every time (where the pref is set) - if ($BuildStatus == 0 and $MailNewsTest and $BuildDepend) { - $BuildStatusStr = 'success'; - print LOG "Running MailNewsTest ...\n"; - print "Running MailNewsTest ...\n"; - $BuildStatus = - &RunFileBasedTest("MailNewsTest", - "mozilla-bin http://www.mozilla.org/quality/mailnews/APITest.html", - 90, "MAILNEWS TEST: Passed", 1); # Hack: testing some partial success string for now. - } - - # Run Editor test. - if ($BuildStatus == 0 and ($EditorTest or $DomToTextConversionTest)) { - $BuildStatusStr = 'success'; - print LOG "Running DomToTextConversionTest ...\n"; - print "Running DomToTextConversionTest ...\n"; - $BuildStatus = &RunFileBasedTest("DomToTextConversionTest", "TestOutSinks", 15, "FAILED", 0); - } + $start_time = time(); + my $cvsco = ''; + if ($Settings::UseTimeStamp) { + $start_time = adjust_start_time($start_time); + my $time_str = strftime("%m/%d/%Y %H:%M", localtime($start_time)); + $ENV{MOZ_CO_DATE} = "$time_str"; + $cvsco = "$Settings::CVSCO -D '$time_str'"; + } else { + $cvsco = "$Settings::CVSCO -A"; + } + + mail_build_started_message($start_time) if $Settings::ReportStatus; + + chdir $build_dir; + my $logfile = "$Settins::DirName.log"; + print "Opening $logfile\n"; + open LOG, ">$logfile" + or die "Cannot open logfile, $logfile: $?\n"; + print_log "current dir is -- " . $ENV{HOST} . ":$build_dir\n"; + print_log "Build Administrator is $Settings::BuildAdministrator\n"; + + PrintEnv(); + + unless (-e "mozilla/client.mk") { + run_shell_command "$Settings::CVS $cvsco mozilla/client.mk"; + } + + chdir $Settings::Topsrcdir or die "chdir $Settings::Topsrcdir: $!\n"; + + DeleteBinary($full_binary_name); # Delete the binary before rebuilding - } else { - print LOG "$mozillaBinary binary exists, build successful. Skipping test.\n"; - $BuildStatus = 0; - } - } else { - print LOG "Error: $mozillaBinary binary missing, build FAILED\n"; + # Build it + unless ($Settings::TestOnly) { # Do not build if testing smoke tests. + my $targets = ''; + $targets = 'checkout realclean build' unless $Settings::BuildDepend; + run_shell_command "$Settings::Make -f client.mk $targets"; + } + + my $build_status; + if (BinaryExists($full_binary_name)) { + if ($Settings::RunTest) { + $build_status = run_tests($full_binary_name, $build_dir); + } else { + print_log "$binary_basename binary exists, build successful.\n"; + print_log "Skipping test.\n"; + $build_status = 'success'; + } + } else { + print_log "Error: $binary_basename binary missing, build FAILED\n"; + $exit_early++ if $Settings::TestOnly; + $build_status = 'busted'; + } + + close LOG; + chdir $build_dir; + + mail_build_finished_message($start_time, $build_status) + if $Settings::ReportStatus; - # If we're only running tests and have no binary, bail. - if ($TestOnly) { - $EarlyExit++; - } + $exit_early++ if $Settings::BuildOnce; + } +} - $BuildStatus = 666; - } # if (&BinaryExists($mozillaBinary)) - - - if ($BuildStatus == 0) { - $BuildStatusStr = 'success'; - } - elsif ($BuildStatus == 333) { - $BuildStatusStr = 'testfailed'; - } else { - $BuildStatusStr = 'busted'; - } +sub mail_build_started_message { + my ($start_time) = @_; + + open LOG, "|$Settings::mail $Settings::Tinderbox_server"; + + print_log "\n"; + print_log "tinderbox: tree: $Settings::BuildTree\n"; + print_log "tinderbox: builddate: $start_time\n"; + print_log "tinderbox: status: building\n"; + print_log "tinderbox: build: $Settings::BuildName\n"; + print_log "tinderbox: errorparser: unix\n"; + print_log "tinderbox: buildfamily: unix\n"; + print_log "tinderbox: version: $::Version\n"; + print_log "tinderbox: END\n"; + print_log "\n"; close LOG; - chdir $StartDir; +} + +sub mail_build_finished_message { + my ($start_time, $build_status, $logfile) = @_; + + # Rewrite LOG to OUTLOG, shortening lines. + open OUTLOG, ">$logfile.last" or die "Couldn't open logfile: $!\n"; + + # Put the status at the top of the log, so the server will not + # have to search through the entire log to find it. + print OUTLOG "tinderbox: tree: $Settings::BuildTree\n"; + print OUTLOG "tinderbox: builddate: $start_time\n"; + print OUTLOG "tinderbox: status: $build_status\n"; + print OUTLOG "tinderbox: build: $Settings::BuildName\n"; + print OUTLOG "tinderbox: errorparser: unix\n"; + print OUTLOG "tinderbox: buildfamily: unix\n"; + print OUTLOG "tinderbox: version: $::Version\n"; + print OUTLOG "tinderbox: END\n"; - # This fun line added on 2/5/98. do not remove. Translated to english, - # that's "take any line longer than 1000 characters, and split it into less - # than 1000 char lines. If any of the resulting lines is - # a dot on a line by itself, replace that with a blank line." - # This is to prevent cases where a . occurs in the log file. + # Make sendmail happy. + # Split lines longer than 1000 charaters into 1000 character lines. + # If any line is a dot on a line by itself, replace it with a blank + # line. This prevents cases where a . occurs in the log file. # Sendmail interprets that as the end of the mail, and truncates the # log before it gets to Tinderbox. (terry weismann, chris yeh) - # - # This was replaced by a perl 'port' of the above, writen by - # preed@netscape.com; good things: no need for system() call, and now it's - # all in perl, so we don't have to do OS checking like before. - # - - # Rewrite LOG to OUTLOG, shortening lines. + open LOG, "$logfile" or die "Couldn't open logfile: $!\n"; - open OUTLOG, ">${logfile}.last" or die "Couldn't open logfile: $!\n"; - - # Stuff the status at the top of the new file, so - # we don't need to parse the whole file to get to the - # status part on the server-side. - print OUTLOG "tinderbox: tree: $BuildTree\n"; - print OUTLOG "tinderbox: builddate: $StartTime\n"; - print OUTLOG "tinderbox: status: $BuildStatusStr\n"; - print OUTLOG "tinderbox: build: $BuildName\n"; - print OUTLOG "tinderbox: errorparser: unix\n"; - print OUTLOG "tinderbox: buildfamily: unix\n"; - print OUTLOG "tinderbox: version: $Version\n"; - print OUTLOG "tinderbox: END\n"; - while () { - for ($q = 0; ; $q++) { - $val = $q * 1000; - $Output = substr $_, $val, 1000; - - last if $Output eq undef; - - $Output =~ s/^\.$//g; - $Output =~ s/\n//g; - print OUTLOG "$Output\n"; - } + for (my $offset = 0; ; $offset += 1000) { + my $output = substr $_, $offset, 1000; + last if $output eq undef; + $output =~ s/^\.$//g; + $output =~ s/\n//g; + print OUTLOG "$output\n"; + } } - close OUTLOG; close LOG; - - if ($ReportStatus and $ReportFinalStatus) { - system("$mail $Tinderbox_server < ${logfile}.last"); - } - - unlink("$logfile"); + unlink($logfile); - # If this is a test run, set early_exit to 0. - # This mean one loop of execution - $EarlyExit++ if $BuildOnce; - } + if ($Settings::ReportStatus and $Settings::ReportFinalStatus) { + system "$Settings::mail $Settings::Tinderbox_server " + ." < $logfile.last"; + } +} + +sub run_tests { + my ($binary, $build_dir) = @_; + my $binary_basename = basename($binary); + my $binary_dir = dirname($binary); + + # Mozilla alive test + print_log "Running AliveTest ...\n"; + my $build_status = RunAliveTest($binary, 60); + return $build_status if $build_status ne 'success'; + + # Viewer alive test + if ($Settings::ViewerTest) { + print_log "Running ViewerTest ...\n"; + $build_status = RunAliveTest("$binary_dir/viewer", 60); + return $build_status if $build_status ne 'success'; + } + + # Bloat test + if ($Settings::BloatStats or $Settings::BloatTest) { + $build_status = RunBloatTest($binary, $build_dir); + return $build_status if $build_status ne 'success'; + } + + # MailNews test + # Needs the following security pref set: + # user_pref("signed.applets.codebase_principal_support",true); + # First time around, you get two dialogs, they set this pref: + # user_pref("security.principal.X0","[Codebase http://www.mozilla.org/quality/mailnews/APITest.html] UniversalBrowserRead=1 UniversalXPConnect=1"); + if ($Settings::MailNewsTest) { + print_log "Running MailNewsTest ...\n"; + # Hack: testing some partial success string for now. + $build_status = &RunFileBasedTest("MailNewsTest", $binary_dir, + "$binary_basename" + ." http://www.mozilla.org/quality/mailnews/APITest.html", + 90, "MAILNEWS TEST: Passed", 1); + return $build_status if $build_status ne 'success'; + } + + # Run Editor test. + if ($Settings::EditorTest or $Settings::DomToTextConversionTest) { + print_log "Running DomToTextConversionTest ...\n"; + $build_status = &RunFileBasedTest("DomToTextConversionTest", + $build_dir, $binary_dir, + "TestOutSinks", 15, + "FAILED", 0); + return $build_status if $build_status ne 'success'; + } + return $build_status; } -sub MailStartBuildMessage { - - open LOG, "|$mail $Tinderbox_server"; - - print LOG "\n"; - print LOG "tinderbox: tree: $BuildTree\n"; - print LOG "tinderbox: builddate: $StartTime\n"; - print LOG "tinderbox: status: building\n"; - print LOG "tinderbox: build: $BuildName\n"; - print LOG "tinderbox: errorparser: unix\n"; - print LOG "tinderbox: buildfamily: unix\n"; - print LOG "tinderbox: version: $Version\n"; - print LOG "tinderbox: END\n"; - print LOG "\n"; - - close LOG; -} - -# check for the existence of the binary sub BinaryExists { - my ($bin) = @_; - my $BinName; - - $BinName = "$BuildDir/$TopLevel/$Topsrcdir/$RelBinaryName"; - - if (-e $BinName and -x _ and -s _) { - print LOG "$BinName exists, is nonzero, and executable.\n"; - 1; - } - else { - print LOG "$BinName doesn't exist, is zero-size, or not executable.\n"; - 0; - } + my ($binary) = $_[0]; + my ($binary_basename) = basename($binary); + + if (not -e $binary) { + print_log "$binary does not exist.\n"; + 0; + } elsif (not -s _) { + print_log "$binary is zero-size.\n"; + 0; + } elsif (not -x _) { + print_log "$binary is not executable.\n"; + 0; + } else { + print_log "$binary_basename exists, is nonzero, and executable.\n"; + 1; + } } sub DeleteBinary { - my ($bin) = @_; - my $BinName; + my ($binary) = $_[0]; + my ($binary_basename) = basename($binary); - print LOG "DeleteBinary: fe = $bin\n"; - - $BinName = "$BuildDir/$TopLevel/${Topsrcdir}/$RelBinaryName"; - - print LOG "unlinking $BinName\n"; - unlink $BinName or print LOG "ERROR: Unlinking $BinName failed\n"; + if (BinaryExists($binary)) { + # Don't delete binary if we're only running tests. + unless ($Settings::TestOnly) { + print_log "Deleting binary: $binary_basename\n"; + print_log "unlinking $binary\n"; + unlink $binary or print_log "Error: Unlinking $binary failed\n"; + } + } else { + print_log "No binary detected; none deleted.\n"; + } } sub PrintEnv { - my($key); - foreach $key (sort keys %ENV) { - print LOG "$key=$ENV{$key}\n"; - print "$key=$ENV{$key}\n"; - } - if (-e $ENV{MOZCONFIG}) { - print LOG "-->mozconfig<----------------------------------------\n"; - print "-->mozconfig<----------------------------------------\n"; - open CONFIG, "$ENV{MOZCONFIG}"; - while () { - print LOG "$_"; - print "$_"; + local $_; + + foreach my $key (sort keys %ENV) { + print_log "$key=$ENV{$key}\n"; + } + if (-e $ENV{MOZCONFIG}) { + print_log "-->mozconfig<----------------------------------------\n"; + open CONFIG, "$ENV{MOZCONFIG}"; + print_log $_ while ; + close CONFIG; + print_log "-->end mozconfig<----------------------------------------\n"; + } + if ($Settings::Compiler ne '') { + print_log "===============================\n"; + if ($Settings::Compiler eq 'gcc' or $Settings::Compiler eq 'egcc') { + my $comptmp = `$Settings::Compiler --version`; + chomp($comptmp); + print_log "Compiler is -- $Settings::Compiler ($comptmp)\n"; + } else { + print_log "Compiler is -- $Settings::Compiler\n"; + } + print_log "===============================\n"; } - close CONFIG; - print LOG "-->end mozconfig<----------------------------------------\n"; - print "-->end mozconfig<----------------------------------------\n"; - } } # Parse a file for $token, given a file handle. -# Return 1 if found, 0 otherwise. -sub parse_file_for_token { - my ($filehandle, $token) = @_; - my $foundStatus = 0; - local $_; - - while (<$filehandle>) { - chomp; - if (/$token/) { - print "Found a \"$token\"!\n"; - $foundStatus = 1; +sub file_has_token { + my ($filehandle, $token) = @_; + local $_; + + while (<$filehandle>) { + if (/$token/) { + print "Found a '$token'!\n"; + return 1; + } } - } - - return $foundStatus; + return 0; } - - sub killer { - &killproc($pid); + &killproc($::pid); } sub killproc { - my ($local_pid) = @_; - my $status; - - # try to kill 3 times, then try a kill -9 - for ($i=0; $i < 3; $i++) { - kill('TERM',$local_pid); - # give it 3 seconds to actually die - sleep 3; - $status = waitpid($local_pid, WNOHANG()); - last if $status != 0; - } - return $status; + my ($local_pid) = @_; + my $status; + + # try to kill 3 times, then try a kill -9 + for (my $ii=0; $ii < 3; $ii++) { + kill('TERM',$local_pid); + # give it 3 seconds to actually die + sleep 3; + $status = waitpid($local_pid, WNOHANG()); + last if $status != 0; + } + return $status; } -# # Start up Mozilla, test passes if Mozilla is still alive # after $waittime (seconds). # sub RunAliveTest { - my ($binaryName, $testTimeoutSec) = @_; - my $Binary; - my $status = 0; - $binaryName = 'x' unless defined $binaryName; - - $ENV{LD_LIBRARY_PATH} = "$BuildDir/$TopLevel/$Topsrcdir/dist/bin"; - $ENV{MOZILLA_FIVE_HOME} = $ENV{LD_LIBRARY_PATH}; - $Binary = "$BuildDir/$TopLevel/$Topsrcdir/$RelBinaryName"; - - print LOG "$Binary\n"; - $BinaryDir = "$BuildDir/$TopLevel/$Topsrcdir/dist/bin"; - $Binary = "$BuildDir/$TopLevel/$Topsrcdir/dist/bin/$binaryName"; - $BinaryLog = $BuildDir . '/runlog'; - - # Fork off a child process. - $pid = fork; + my ($build_dir, $binary, $testTimeoutSec) = @_; + my $status = 0; + my $binary_basename = basename($binary); + my $binary_dir = dirname($binary); + my $binary_log = "$build_dir/runlog"; - unless ($pid) { # child + die "Error: RunAliveTest: No binary given" unless defined $binary; - chdir $BinaryDir; - unlink $BinaryLog; - $SaveHome = $ENV{HOME}; - $ENV{HOME} = $BinaryDir; - open STDOUT, ">$BinaryLog"; - select STDOUT; $| = 1; # make STDOUT unbuffered - open STDERR,">&STDOUT"; - select STDERR; $| = 1; # make STDERR unbuffered - exec $Binary; - close STDOUT; - close STDERR; - $ENV{HOME} = $SaveHome; - die "Couldn't exec()"; - } - - # parent - wait $testTimeoutSec seconds then check on child - sleep $testTimeoutSec; - $status = waitpid($pid, WNOHANG()); + $ENV{LD_LIBRARY_PATH} = $binary_dir; + $ENV{MOZILLA_FIVE_HOME} = $binary_dir; - print LOG "$binaryName quit AliveTest with status $status\n"; - if ($status != 0) { - print LOG "Error: $binaryName has crashed or quit on the AliveTest. Turn the tree orange now.\n"; - print LOG "----------- failure output from $binaryName for alive test --------------- \n"; - open READRUNLOG, "$BinaryLog"; - while () { - print $_; - print LOG $_; + $::pid = fork; # Fork off a child process. + + unless ($::pid) { # child + chdir $binary_dir; + $ENV{HOME} = $build_dir; + open STDOUT, ">$binary_log"; + open STDERR, ">&STDOUT"; + select STDOUT; $| = 1; # make STDOUT unbuffered + select STDERR; $| = 1; # make STDERR unbuffered + exec $binary_basename + or die "Couldn't exec()"; + } + + # Parent - Wait $testTimeoutSec seconds then check on child + sleep $testTimeoutSec; + $status = waitpid($::pid, WNOHANG()); + + if ($status == 0) { + print_log "$binary_basename quit AliveTest with status $status\n"; + } else { + print_log "Error: $binary_basename has crashed or quit on the AliveTest. Turn the tree orange now.\n"; + print_log "----------- failure output from $binary_basename for alive test --------------- \n"; + open READRUNLOG, "$binary_log"; + while (my $line = ) { + print_log $line; + } + close READRUNLOG; + print_log "--------------- End of AliveTest($binary_basename) Output -------------------- \n"; + return 'testfailed'; + } + + &killproc($::pid); + + print_log "----------- success output from $binary_basename for alive test --------------- \n"; + open READRUNLOG, "$binary_log"; + while (my $line = ) { + print_log $line; } close READRUNLOG; - print LOG "--------------- End of AliveTest($binaryName) Output -------------------- \n"; - return 333; - } - - print LOG "Success! $binaryName is still running.\n"; - - &killproc($pid); - - print LOG "----------- success output from $binaryName for alive test --------------- \n"; - open READRUNLOG, "$BinaryLog"; - while () { - print $_; - print LOG $_; - } - close READRUNLOG; - print LOG "--------------- End of AliveTest ($binaryName) Output -------------------- \n"; - return 0; - + print_log "--------------- End of AliveTest ($binary_basename) Output -------------------- \n"; + return 'success'; + } # RunAliveTest -# Run a generic test that writes output -# to stdout, save that output to a file, -# parse the file looking for failure token and -# report status based on that. A hack, but should -# be useful for many tests. +# Run a generic test that writes output to stdout, save that output to a +# file, parse the file looking for failure token and report status based +# on that. A hack, but should be useful for many tests. # -# testName = Name of test we're gonna run, in dist/bin. +# test_name = Name of test we're gonna run, in dist/bin. # testExecString = How to run the test # testTimeoutSec = Timeout for hung tests, minimum test time. -# statusToken = What string to look for in test output to -# determine test status. -# -# statusTokenMeansPass = Default use of status token is to look for failure string. -# If this is set to 1, then invert logic to look for success -# string. +# statusToken = What string to look for in test output to +# determine test status. +# statusTokenMeansPass = Default use of status token is to look for +# failure string. If this is set to 1, then invert logic to look for +# success string. # # Note: I tried to merge this function with RunAliveTest(), # the process flow control got too confusing :( -mcafee # sub RunFileBasedTest { - my ($testName, $testExecString, $testTimeoutSec, $statusToken, $statusTokenMeansPass) = @_; - my $Binary; + my ($test_name, $build_dir, $binary_dir, $testExecString, $testTimeoutSec, + $statusToken, $statusTokenMeansPass) = @_; + local $_; - print LOG "testExecString = ", $testExecString, "\n"; - - $ENV{LD_LIBRARY_PATH} = "$BuildDir/$TopLevel/$Topsrcdir/dist/bin"; - $ENV{MOZILLA_FIVE_HOME} = $ENV{LD_LIBRARY_PATH}; - - $BinaryDir = "$BuildDir/$TopLevel/$Topsrcdir/dist/bin"; - - # Assume the app is the first argument in the execString. - @parseExecString = split ' ', $testExecString; - $Binary = $BinaryDir . '/' . $parseExecString[0]; - - $BinaryLog = $BuildDir . '/' .$testName . '.log'; - - # If we care about log files, clear the old log, if there is one. - unlink($BinaryLog); - - print LOG "Binary = ", $Binary, "\n"; - print "Binary = ", $Binary, "\n"; - - print LOG "BinaryLog = ", $BinaryLog, "\n"; - print "BinaryLog = ", $BinaryLog, "\n"; - - # Fork off a child process. - $pid = fork; - - unless ($pid) { # child - print "child\n"; - print LOG "child\n"; - - print LOG "2:Binary = ", $Binary, "\n"; - print "2:Binary = ", $Binary, "\n"; - - - # The following set of lines makes stdout/stderr show up - # in the tinderbox logs. - $SaveHome = $ENV{HOME}; - $ENV{HOME} = $BinaryDir; - open STDOUT, ">$BinaryLog"; - select STDOUT; $| = 1; # make STDOUT unbuffered - open STDERR,">&STDOUT"; - select STDERR; $| = 1; # make STDERR unbuffered - - - # Timestamp when we're running the test. - print LOG `date`, "\n"; - print `date`, "\n"; - - if (-e $Binary) { - $cmd = "$testExecString"; - print LOG $cmd, "\n"; - print $cmd, "\n"; - print LOG $cmd; - chdir($BinaryDir); - exec ($cmd); - } else { - print LOG "ERROR: cannot run ", $testName, ".\n"; - print "ERROR: cannot run ", $testName, ".\n"; - } - - close STDOUT; - close STDERR; - $ENV{HOME} = $SaveHome; - die "Couldn't exec()"; - } else { - print "parent\n"; - print LOG "parent\n"; - } - - # Set up a timer with a signal handler. - $SIG{ALRM} = \&killer; - - # Wait $testTimeoutSec seconds, then kill the process if it's still alive. - alarm $testTimeoutSec; - print "testTimeoutSec = $testTimeoutSec\n"; - print LOG "testTimeoutSec = $testTimeoutSec\n"; - - $status = waitpid($pid, 0); - - # Back to parent. - - # Clear the alarm so we don't kill the next test! - alarm 0; - - # - # Determine proper status, look in log file for failure token. - # XXX: What if test is supposed to exit, but crashes? -mcafee - - print LOG "$testName exited with status $status\n"; - - if ($status < 0) { - print LOG "$testName timed out and needed to be killed.\n"; - } else { - print LOG "$testName completed on its own, before the timeout.\n"; - } - - open TESTLOG, "<$BinaryLog" or die "Can't open $!"; - # Return 1 if we find statusToken in output. - $status = parse_file_for_token(*TESTLOG, $statusToken); - - if($status) { - print LOG "found statusToken $statusToken!\n"; - } else { - print LOG "statusToken $statusToken not found\n"; - } - - close TESTLOG; - - # If we're using success string, invert status logic. - if($statusTokenMeansPass == 1) { - # Invert $status. This is probably sloppy perl, help me! - if($status == 0) { - $status = 1; - } else { - $status = 0; - } - } - - - # - # Write test output to log. - # - if ($status != 0) { - print LOG "Error: $testName has failed. Turn the tree orange now.\n"; - print LOG "----------- failure output from ", $testName, " test --------------- \n"; - } else { - print LOG "----------- success output from ", $testName, " test --------------- \n"; - } - - # Parse the test log, dumping lines into tinderbox log. - open READRUNLOG, "$BinaryLog"; - while () { - print $_; - print LOG $_; - } - close READRUNLOG; - print LOG "--------------- End of ", $testName, " Output -------------------- \n"; - - # 0 = success, 333 = orange. - if ($status != 0) { - return 333; - } else { - return 0; - } + print_log "Running $testExecString\n"; + + $ENV{LD_LIBRARY_PATH} = $binary_dir; + $ENV{MOZILLA_FIVE_HOME} = $binary_dir; + + # Assume the app is the first argument in the execString. + my ($binary_basename) = (split /\s+/, $testExecString)[0]; + my $binary = "$binary_dir/$binary_basename"; + my $binary_log = "$build_dir/$test_name.log"; + print_log "Binary = $binary\n"; + print_log "Binary Log = $binary_log\n"; + + # Fork off a child process. + $::pid = fork; + + unless ($::pid) { # child + print_log "child\n"; + print_log "2:Binary = $binary\n"; + + # The following set of lines makes stdout/stderr show up + # in the tinderbox logs. + $ENV{HOME} = $build_dir; + open STDOUT, ">$binary_log"; + open STDERR, ">&STDOUT"; + select STDOUT; $| = 1; # make STDOUT unbuffered + select STDERR; $| = 1; # make STDERR unbuffered + + # Timestamp when we're running the test. + print_log `date`, "\n"; + + if (-e $binary) { + my $cmd = "$testExecString"; + print_log "$cmd\n"; + chdir($binary_dir); + exec $cmd; + } else { + print_log "Error: cannot run $test_name\n"; + } + die "Couldn't exec()"; + } else { + print "parent\n"; + print_log "parent\n"; + } + + # Set up a timer with a signal handler. + $SIG{ALRM} = \&killer; + + # Wait $testTimeoutSec seconds, then kill the process if it's still alive. + alarm $testTimeoutSec; + print "testTimeoutSec = $testTimeoutSec\n"; + print_log "testTimeoutSec = $testTimeoutSec\n"; + + my $status = waitpid($::pid, 0); + + # Back to parent. + + # Clear the alarm so we don't kill the next test! + alarm 0; + + # Determine proper status, look in log file for failure token. + # XXX: What if test is supposed to exit, but crashes? -mcafee + + print_log "$test_name exited with status $status\n"; + + if ($status < 0) { + print_log "$test_name timed out and needed to be killed.\n"; + } else { + print_log "$test_name completed on its own, before the timeout.\n"; + } + + open TESTLOG, "<$binary_log" or die "Can't open $!"; + # Return 1 if we find statusToken in output. + $status = file_has_token(*TESTLOG, $statusToken); + + if($status) { + print_log "found statusToken $statusToken!\n"; + } else { + print_log "statusToken $statusToken not found\n"; + } + close TESTLOG; + + # If we're using success string, invert status logic. + if($statusTokenMeansPass == 1) { + # Invert $status. This is probably sloppy perl, help me! + if($status == 0) { + $status = 1; + } else { + $status = 0; + } + } + + # Write test output to log. + if ($status == 0) { + print_log "----------- success output from $test_name test --------------- \n"; + } else { + print_log "Error: $test_name has failed. Turn the tree orange now.\n"; + print_log "----------- failure output from $test_name test --------------- \n"; + } + + # Parse the test log, dumping lines into tinderbox log. + open READRUNLOG, "$binary_log"; + print_log $_ while ; + close READRUNLOG; + print_log "--------------- End of $test_name Output -------------------- \n"; + + if ($status == 0) { + return 'success'; + } else { + return 'testfailed'; + } } # RunFileBasedTest sub RunBloatTest { - my $Binary; - my $status = 0; - $bin = 'x' unless defined $bin; + my ($binary, $build_dir) = $_[0]; + my $binary_basename = basename($binary); + my $binary_dir = dirname($binary); + my $binary_log = "$build_dir/bloat-cur.log"; + my $old_binary_log = "$build_dir/bloat-prev.log"; + my $status = 0; + local $_; - print LOG "in runBloatTest\n"; - - $ENV{LD_LIBRARY_PATH} = "$BuildDir/$TopLevel/$Topsrcdir/dist/bin"; - $ENV{MOZILLA_FIVE_HOME} = $ENV{LD_LIBRARY_PATH}; - - # Turn on ref counting to track leaks (bloaty tool). - $ENV{XPCOM_MEM_BLOAT_LOG} = "1"; - - $Binary = "$BuildDir/$TopLevel/$Topsrcdir/$RelBinaryName"; - $BinaryDir = "$BuildDir/$TopLevel/$Topsrcdir/dist/bin"; - $BinaryLog = $BuildDir . '/bloat-cur.log'; - - rename ($BinaryLog, "$BuildDir/bloat-prev.log"); - - # Fork off a child process. - $pid = fork; - - unless ($pid) { # child - chdir $BinaryDir; - - $SaveHome = $ENV{HOME}; - $ENV{HOME} = $BinaryDir; - open STDOUT, ">$BinaryLog"; - select STDOUT; $| = 1; # make STDOUT unbuffered - open STDERR,">&STDOUT"; - select STDERR; $| = 1; # make STDERR unbuffered - - if (-e "bloaturls.txt") { - $cmd = "$Binary -f bloaturls.txt"; - print LOG $cmd; - exec ($cmd); - } else { - print LOG "ERROR: bloaturls.txt does not exist.\n"; - } - - close STDOUT; - close STDERR; - $ENV{HOME} = $SaveHome; - die "Couldn't exec()"; - } - - # Set up a timer with a signal handler. - $SIG{ALRM} = \&killer; - - # Wait 120 seconds, then kill the process if it's still alive. - alarm 120; - - $status = waitpid($pid, 0); - - # Clear the alarm so we don't kill the next test! - alarm 0; - - print LOG "$mozillaBinary quit Bloat Test with status $status\n"; - if ($status <= 0) { - print LOG "Error: $mozillaBinary has crashed or quit on the BloatTest. Turn the tree orange now.\n"; - print LOG "----------- failure Output from $mozillaBinary for BloatTest --------------- \n"; - open READRUNLOG, "$BinaryLog"; - while () { - print $_; - print LOG $_; + print_log "Running BloatTest ...\n"; + + $ENV{LD_LIBRARY_PATH} = $binary_dir; + $ENV{MOZILLA_FIVE_HOME} = $binary_dir; + + # Turn on ref counting to track leaks (bloaty tool). + $ENV{XPCOM_MEM_BLOAT_LOG} = "1"; + + rename($binary_log, $old_binary_log); + + # Fork off a child process. + $::pid = fork; + + unless ($::pid) { # child + chdir $binary_dir; + + $ENV{HOME} = $build_dir; + open STDOUT, ">$binary_log"; + open STDERR, ">&STDOUT"; + select STDOUT; $| = 1; # make STDOUT unbuffered + select STDERR; $| = 1; # make STDERR unbuffered + + if (-e "bloaturls.txt") { + my $cmd = "$binary_basename -f bloaturls.txt"; + print_log $cmd; + exec $cmd; + } else { + print_log "Error: bloaturls.txt does not exist.\n"; + } + die "Could not exec()"; } + + $SIG{ALRM} = \&killer; # Set up a timer with a signal handler. + + alarm 120; # Wait 120 seconds, then kill the process if it's still alive. + $status = waitpid($::pid, 0); + alarm 0; # Clear the alarm to avoid killing next test. + + print_log "$binary_basename quit bloat test with status $status\n"; + if ($status <= 0) { + print_log "Error: bloat test: $binary_basename has crashed or quit.\n"; + print_log "Turn the tree orange now.\n"; + print_log "----------- BloatTest Output --------------- \n"; + open READRUNLOG, "$binary_log"; + print_log $_ while ; + close READRUNLOG; + print_log "--------------- End of BloatTest Output ---------------- \n"; + + # HACK. Clobber isn't reporting bloat status properly, + # only turn tree orange for depend build. This has + # been filed as bug 22052. -mcafee + if ($Settings::BuildDepend == 1) { + return 'testfailed'; + } else { + return 'success'; + } + } + print_log "\n######################## BLOAT STATISTICS\n"; + + open DIFF, "$build_dir/../bloatdiff.pl $build_dir/bloat-prev.log $binary_log|" + or die "Unable to run bloatdiff.pl"; + print_log $_ while ; + close DIFF; + print_log "######################## END BLOAT STATISTICS\n\n"; + + print_log "----- success output from $binary_basename for BloatTest ----- \n"; + open READRUNLOG, "$binary_log"; + print_log $_ while ; close READRUNLOG; - print LOG "--------------- End of BloatTest Output -------------------- \n"; - - # HACK. Clobber isn't reporting bloat status properly, - # only turn tree orange for depend build. This has - # been filed as bug 22052. -mcafee - if ($BuildDepend == 1) { - return 333; - } else { - return 0; - } - } - - print LOG "\n######################## BLOAT STATISTICS\n"; - - - open DIFF, "$BuildDir/../bloatdiff.pl $BuildDir/bloat-prev.log $BinaryLog |" or - die "Unable to run bloatdiff.pl"; - - while (my $line = ) { - print LOG $line; - } - close(DIFF); - print LOG "######################## END BLOAT STATISTICS\n\n"; - - print LOG "----------- success output from $mozillaBinary for BloatTest --------------- \n"; - open READRUNLOG, "$BinaryLog"; - while () { - print $_; - print LOG $_; - } - close READRUNLOG; - print LOG "--------------- End of BloatTest Output -------------------- \n"; - return 0; - + print_log "--------------- End of BloatTest Output -------------------- \n"; + return 'success'; } - - __END__ #- PLEASE FILL THIS IN WITH YOUR PROPER EMAIL ADDRESS $BuildAdministrator = "$ENV{USER}\@$ENV{HOST}"; @@ -845,16 +734,24 @@ $DisplayServer = ':0.0'; #- Default values of command-line opts #- -$BuildDepend = 1; # Depend or Clobber -$ReportStatus = 1; # Send results to server, or not -$ReportFinalStatus = 1; # Finer control over $ReportStatus. -$BuildOnce = 0; # Build once, don't send results to server -$RunTest = 1; # Run the smoke tests on successful build, or not -$UseTimeStamp = 1; # Use the CVS 'pull-by-timestamp' option, or not -$TestOnly = 0; # Only run tests, don't pull/build +$BuildDepend = 1; # Depend or Clobber +$ReportStatus = 1; # Send results to server, or not +$ReportFinalStatus = 1; # Finer control over $ReportStatus. +$UseTimeStamp = 1; # Use the CVS 'pull-by-timestamp' option, or not +$BuildOnce = 0; # Build once, don't send results to server +$RunTest = 1; # Run the smoke tests on successful build, or not +$TestOnly = 0; # Only run tests, don't pull/build +# Extra tests +$BloatTest = 0; +$BloatStats = 0; +$DomToTextConversionTest = 0; +$EditorTest = 0; +$MailNewsTest = 0; +$ViewerTest = 0; +$MozConfigFileName = 'mozconfig'; #- Set these to what makes sense for your system -$Make = 'gmake'; # Must be GNU make +$Make = 'gmake'; # Must be GNU make $MakeOverrides = ''; $mail = '/bin/mail'; $CVS = 'cvs -q'; @@ -874,20 +771,14 @@ $BuildSleep = 10; #- change to the tree you're actually building $BuildTree = 'MozillaTest'; -$BuildName = ''; -$BuildTag = ''; -$BuildObjName = ''; -$BuildConfigDir = 'mozilla/config'; -$BuildStart = ''; -$TopLevel = '.'; -$Topsrcdir = 'mozilla'; -$ClobberStr = 'realclean'; +$BuildName = ''; +$BuildTag = ''; +$BuildConfigDir = 'mozilla/config'; +$Topsrcdir = 'mozilla'; +$BinaryName = 'mozilla-bin'; +$ShellOverride = ''; # Only used if the default shell is too stupid +$ConfigureArgs = ''; $ConfigureEnvArgs = ''; -$ConfigureArgs = ' --cache-file=/dev/null '; -$ConfigGuess = './build/autoconf/config.guess'; -$Logfile = '${BuildDir}.log'; -$Compiler = 'gcc'; -$ShellOverride = ''; # Only used if the default shell is too stupid - -# Need to end with a true value, (since we're using "require"). -1; +$Compiler = 'gcc'; +$NSPRArgs = ''; +$ShellOverride = '';