diff options
Diffstat (limited to '')
-rwxr-xr-x | tools/build_perl_modules | 290 | ||||
-rwxr-xr-x | tools/tinderbox_build | 290 |
2 files changed, 580 insertions, 0 deletions
diff --git a/tools/build_perl_modules b/tools/build_perl_modules new file mode 100755 index 0000000..b8cd34c --- /dev/null +++ b/tools/build_perl_modules @@ -0,0 +1,290 @@ +#!/usr/bin/perl +# SYNTAX: +# build_perl_modules -d dest_dir [-c] [-m] [-t] [-i] [-s <section>] tarball_dir +# +# DESCRIPTION: +# Installs perl modules found in tarball_dir +# Expects a file called install_order, containing one line per distribution name +# Will take action against each distribution in turn +# -d is a necessary destination directory for the perl mods +# If -c is set, will remove the module build directories and exit +# If -e is set, will extract module +# If -m is set, will run perl Makefile.PL and make +# If -t is set, will run make test +# If -i is set, will run make install +# If -s <section> specified will only work on that section in the +# install_order file - defaults to first section only +# Options are discrete. This is because an overall ./configure, make, make test, make install +# are run in different invocations. Obviously, you can't run a -t without a -m, but there's no +# checking here for that + +# Can only use base modules +use warnings; +use strict; +use Config; +use Getopt::Std; +use Cwd; +use File::Path; + +# remove host site_lib directories to ensure this is a 'full & clean' build of deps +BEGIN: { + my @user_libs = split( /:/, $ENV{PERL5LIB} || "" ); + chomp(@user_libs); + + # clear out old PERL5LIB to avoid confusion with anything preinstalled + foreach my $lib (@INC) { + next if $lib eq "."; + foreach my $var (qw/ sitelib_stem sitelib sitearch sitearchexp /) { + foreach my $user_lib (@user_libs) { + $lib = '' if ( $lib =~ m/$user_lib/ ); + } + $lib = '' + if ( ( $Config{$var} && $lib =~ m/^$Config{$var}/ ) + || $lib =~ m/site_perl/ ); + } + } +} + +my $file_regexp = '(\.pm)?-v?([\d_]+\.?)*\.(?:tgz|tar\.gz)$'; + +my $have_yaml = 0; +my $have_module_build = 0; + +my $opts = {}; +getopts( 'd:cemtis:', $opts ) || die "Invalid options"; +my $moddir = shift @ARGV + or die "Must specify a directory where tarballs exist"; + +my $prefix = $opts->{d}; +die "Must set a destination directory" unless $prefix; + +my $destdir = ''; +my $mm_destdir = ''; +my $mb_destdir = ''; +if ( $ENV{DESTDIR} ) { + $destdir = $ENV{DESTDIR}; + $mm_destdir = 'DESTDIR=' . $destdir; + $mb_destdir = '--destdir ' . $destdir; +} + +chdir $moddir or die "Cannot change to $moddir"; +open F, "install_order" or die "Cannot open install_order file"; +my @files = grep { !/^#/ && chop } <F>; +close F; + +# Remove linux only perl module from Solaris systems +if ( $^O eq "solaris" ) { + @files = grep { !/Sys-Statistics-Linux/ } @files; +} + +my @filelist; +opendir( DIR, "." ); +foreach my $found ( readdir(DIR) ) { + push( @filelist, $found ) + if ( -f $found && $found =~ m/\.(?:tgz|tar\.gz)$/ ); +} +close(DIR); + +my $tag = $opts->{s} || "default"; +my $in_section = 0; + +my @tarballs; +foreach my $f (@files) { + next + if ( !$f || $f =~ m/^\s+$/ || $f =~ m/^\s*#/ ); # ignore all blank lines + $f =~ s/\s+//; # remove all whitespaces from line + $f =~ s/\s+#.*//; # remove all comments from the line + + if ( $f =~ m/^(\w+):$/ ) { + if ( $tag && $1 ne $tag && $tag ne "all" ) { + $in_section = 0; + next; + } + $in_section = 1; + $tag = $1 if ( !$tag ); + last if ( $1 ne $tag && $tag ne "all" ); + next; + } + + next if ( !$in_section ); + + # sort fully qualified names + #$f =~ s/(\.pm)?-v?(\d+\.?)*\.(?:tgz|tar\.gz)//; + #warn("b4 f=$f"); + $f =~ s/$file_regexp//; + + # Needs to be better. Also, what if there are two with same name? + #warn("f=$f"); + my $tarball = ( grep( /^$f$file_regexp/, @filelist ) )[0]; + + #warn("got f=$f tarball=$tarball"); + #eval '$tarball = <' . "$f" . '[-pmv0-9.]*.tar.gz>'; + die("Couldn't find tarball for $f in $moddir\n") + unless ( $tarball && -f $tarball ); + push @tarballs, $tarball; + ( my $dir = $tarball ) =~ s/\.(?:tgz|tar.gz)$//; + + # Need to do cleaning before doing each module in turn + if ( $opts->{c} ) { + print "Cleaning $dir", $/; + rmtree($dir) if ($dir); + } +} + +if ( $opts->{c} ) { + print "Finished cleaning", $/; + exit; +} + +my $libs = "$destdir/$prefix/lib:$destdir/$prefix/lib/$Config{archname}"; + +my $topdir = cwd(); + +# set an initial value if there isn't one already +# Need to use PERL5LIB to ensure we get pre-installed mods from earlier +# tags in the install_order file +$ENV{PERL5LIB} ||= q{}; + +# Set Module::AutoInstall to ignore CPAN, to avoid trying to pull dependencies in +$ENV{PERL_AUTOINSTALL} = "--skipdeps"; + +# keep a record of how many times a module build is done. This is so they may +# be built a second time to include optional prereq's that couldn't +# previously be built due to circular dependencies +my %built_modules; +foreach my $tarball (@tarballs) { + ( my $dir = $tarball ) =~ s/\.(?:tgz|tar.gz)$//; + + die if ( $dir eq "exit" ); + + if ( $opts->{e} ) { + unless ( -e $dir ) { + print 'Extracting ', $tarball, $/; + system("gunzip -c $tarball | tar -xf -") == 0 + or die "Cannot extract $tarball"; + } + next unless ( $opts->{m} || $opts->{t} || $opts->{i} ); + } + + # Need to add this so all modules is are for subsequent ones + # Done here to partial previous builds can be continued + $ENV{PERL5LIB} = "$topdir/$dir/blib/arch:" . $ENV{PERL5LIB}; # Required for IO-Compress, I think + $ENV{PERL5LIB} = "$topdir/$dir/blib/lib:" . $ENV{PERL5LIB}; + + # PathTools does something weird where it removes blib from @INC. We manually force ExtUtils::MakeMaker to be included + $ENV{PERL5LIB} = "$topdir/$dir/lib:" . $ENV{PERL5LIB} if ($dir =~/ExtUtils-MakeMaker/); + + # warn("PERL5LIB=$ENV{PERL5LIB}"); + + if ( !$have_yaml ) { + $have_yaml = 0; + } + + if ( !$have_module_build ) { + $have_module_build = check_for_module('Module::Build'); + } + + if ( $opts->{m} ) { + + # Don't compile if already done - this is because of invocating this + # script at different stages + print "******************** $tarball\n"; + if ( $built_modules{$dir} || !-f "$dir/Makefile" && !-f "$dir/Build" ) { + $built_modules{$dir}++; + my @missing; + chdir "$topdir/$dir" or die "Can't chdir into $dir"; + warn("\nWorking in: $topdir/$dir\n\n"); + + # Another horrible hack. XML-Parser uses special Makefile variables, so we add these on here for Solaris only + my $extra_args = ""; + if ( $^O eq "solaris" && $dir =~ /^XML-Parser-/ ) { + $extra_args = "EXPATLIBPATH=/usr/sfw/lib EXPATINCPATH=/usr/sfw/share/src/expat/lib/"; + } + + #warn("PERL5LIB=$ENV{PERL5LIB}\n"); + + if ( -f "Build.PL" && $have_module_build ) { + warn("Using Build.PL\n"); + } + elsif ( -f 'Makefile.PL' ) { + warn("Using Makefile.PL\n"); + + # Horribly hacky - remove xdefine if this is Time-HiRes + # because the subsequent perl Makefile.PL will fail + if ( $dir =~ /Time-HiRes/ ) { + unlink "xdefine"; + } + } + else { + die "No Makefile.PL nor Build.PL found"; + } + + my $command; + if ( -f "Build.PL" && $have_module_build ) { + open( CMD, "|-", "perl Build.PL $mb_destdir --install_base=$prefix --install_path lib=$prefix/lib --install_path arch=$prefix/lib/$Config{archname} --install_path bin=$prefix/bin --install_path script=$prefix/bin --install_path bindoc=$prefix/man/man1 --install_path libdoc=$prefix/man/man3" ) || die "Can't run perl Build.PL"; + $command = "./Build"; + } + elsif ( -f 'Makefile.PL' ) { + open( CMD, "|-", "perl Makefile.PL $mm_destdir INSTALL_BASE=$prefix INSTALLDIRS=site INSTALLSITELIB=$prefix/lib INSTALLSITEARCH=$prefix/lib/$Config{archname} $extra_args" ) || die "Can't run perl Makefile.PL"; + $command = "make"; + } + else { + die "No Makefile.PL nor Build.PL found"; + } + close(CMD); + system($command) == 0 + or die "Can't run $command. Please\n\trm -rf $topdir/$dir\nto remake from this point)"; + + chdir $topdir or die "Can't chdir to top"; + } + } + + chdir $dir or die "Can't chdir into $dir"; + + if ( $opts->{t} ) { + warn("****** Testing $dir ****** \n"); + if ( -f "Build.PL" ) { + system("./Build test") == 0 + or die "'Build test' failed in $dir: $!\n"; + } + else { + system("make test") == 0 + or die "'make test' failed in $dir: $!\n"; + } + } + if ( $opts->{i} && !-f 'installed' ) { + + # Need to set this so that XML::SAX will install ParserDetails.ini by finding the right XML::SAX copy + # Also makes sense to do this anyway, as I guess CPAN must be doing this for it to usually work + my $saved_PERL5LIB = $ENV{PERL5LIB}; + $ENV{PERL5LIB} = "$destdir/$prefix/lib:$saved_PERL5LIB"; + if ( -f "Build" ) { + system("./Build install") == 0 + or die "Can't run make install: $!\n"; + } + else { + system("make install") == 0 + or die "Can't run make install: $!\n"; + } + $ENV{PERL5LIB} = $saved_PERL5LIB; + open my $install_flag_file, '>', 'installed' + or die 'Unable to touch "installed": ', $!, $/; + close $install_flag_file + or die 'Unable to close "installed": ', $!, $/; + } + chdir $topdir or die "Can't go back to $topdir"; +} + +sub check_for_module { + my ($module) = @_; + + warn 'Checking if ', $module, ' is available yet...', $/; + if ( system("$^X -M$module -e 0 2>/dev/null") == 0 ) { + warn '... yes!', $/; + return 1; + } + + warn '... no!', $/; + return 0; + +} diff --git a/tools/tinderbox_build b/tools/tinderbox_build new file mode 100755 index 0000000..1a41f57 --- /dev/null +++ b/tools/tinderbox_build @@ -0,0 +1,290 @@ +#!/usr/bin/perl +# tinderbox_build.pl +# This script builds the monitoringplugins and then sends +# logs back to the master tinderbox server +# +# This script is based on mozilla-unix.pl which comes with tinderbox2 +# +# See http://tinderbox.altinity.org for more details + +require 5.000; + +use strict; +use Sys::Hostname; +use Cwd; +use Time::Local; + +my $Version = `git describe --abbrev=4 HEAD`; + +my $myhost = hostname; +chomp($myhost); +my ($host, $junk) = split(/\./, $myhost); + +my $BuildAdministrator = $ENV{TINDERBOX_BUILD_ADMIN} || "$ENV{'USER'}\@$myhost"; +my $TmpDir = $ENV{TMPDIR} || "/tmp"; + +#Default values of cmdline opts +my $ReportStatus = 0; # Do not send results to server + +# Set these to what makes sense for your system + +# Set these proper values for your tinderbox server +# Have the StrictHostKeyChecking=no so that a new host will automatically add hostkey without +# prompting. If host key changes, then will get error, so this should still be secure +my $Tinderbox_server = '-p 1022 -o StrictHostKeyChecking=no tinderbox2@tinderbox.opsera.com'; + +# These shouldn't really need to be changed +my $BuildTree = 'monitoringplug'; +my $BuildName = ''; +my $ConfigureArgs = $ENV{CONFIGURE_ARGS}; + +my $OS = `uname -s`; +my $OSVer = `uname -r`; + +chop($OS, $OSVer); + +if ( $OS eq 'AIX' ) { + $OSVer = `uname -v`; + chop($OSVer); + $OSVer = $OSVer . "." . `uname -r`; + chop($OSVer); +} + +if ( $OS eq 'IRIX64' ) { + $OS = 'IRIX'; +} + +if ( $OS eq 'SCO_SV' ) { + $OS = 'SCOOS'; + $OSVer = '5.0'; +} + +if ( "$host" ne "" ) { + $BuildName = $host . ' '; +} +$BuildName .= $OS . ' ' . $OSVer; +$_ = $BuildName; +s/ /_/g; + +my $logfile = "$_.log"; + +sub BuildIt { + my ($fe, @felist, $EarlyExit, $LastTime); + + my $StartDir = getcwd(); + $LastTime = 0; + + print "Starting dir is : $StartDir\n"; + + my $EarlyExit = 0; + + chdir("$StartDir"); + + my $StartTime = time; + if (-e (my $file = "monitoring-plugins.spec")) { + open F, $file; + while (<F>) { + if (/^Version: trunk-(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/) { + $StartTime = timegm(0, $5, $4, $3, ($2 - 1), ($1 - 1900)); + last; + } + } + } + + print "Start time is $StartTime",$/; + + my $CurrentDir = getcwd(); + if ( $CurrentDir ne $StartDir ) { + print "startdir: $StartDir, curdir $CurrentDir\n"; + die "curdir != startdir"; + } + + unlink( "$logfile" ); + + print "opening $logfile\n"; + open( LOG, ">$logfile" ) || print "can't open $?\n"; + print LOG "current dir is -- $host:$CurrentDir\n"; + print LOG "Build Administrator is $BuildAdministrator\n"; + &PrintEnv; + + my $BuildStatus; + if (&configure) { + if (&make) { + if (&maketest) { + $BuildStatus = "success"; + } else { + $BuildStatus = "test_failed"; + } + } else { + $BuildStatus = "build_failed"; + } + } else { + $BuildStatus = "busted"; + } + + print LOG "\nBuild Status = $BuildStatus\n"; + + close(LOG); + chdir("$StartDir"); + +# TV: Leaving this in, because process mail program probably has some +# limitation retained + +# 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 <cr>.<cr> 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, written 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. + + open(LOG, "$logfile") || die "Couldn't open logfile: $!\n"; + open(OUTLOG, ">${logfile}.last") || die "Couldn't open logfile: $!\n"; + + print OUTLOG $/; + print OUTLOG "tinderbox: tree: $BuildTree\n"; + print OUTLOG "tinderbox: builddate: $StartTime\n"; + print OUTLOG "tinderbox: status: $BuildStatus\n"; + print OUTLOG "tinderbox: build: $BuildName $fe\n"; + print OUTLOG "tinderbox: errorparser: unix\n"; + print OUTLOG "tinderbox: buildfamily: unix\n"; + print OUTLOG "tinderbox: END\n"; + print OUTLOG $/; + + while (<LOG>) { + my $q = 0; + + for (;;) { + my $val = $q * 1000; + my $Output = substr($_, $val, 1000); + + last if $Output eq undef; + + $Output =~ s/^\.$//g; + $Output =~ s/\n//g; + print OUTLOG "$Output\n"; + $q++; + } #EndFor + + } #EndWhile + + close(LOG); + close(OUTLOG); + + if ($ReportStatus) { + system( "ssh $Tinderbox_server tinderbox_receive < ${logfile}.last" ) + } else { + print <<"EOF" +Not sending logs to http://tinderbox.altinity.org +If you have SSH keys setup on the tinderbox server, you can manually send +with 'ssh $Tinderbox_server tinderbox_receive < ${logfile}.last' +EOF + } + + unlink("$logfile"); + print "Finished building for tinderbox",$/; + +} #EndSub-BuildIt + +sub ParseArgs { + my($i); + + $i = 0; + while( $i < @ARGV ) { + if ($ARGV[$i] eq '--version' || $ARGV[$i] eq '-v') { + die "$0: version $Version\n"; + } elsif ($ARGV[$i] eq '-y') { + $ReportStatus = 1; + } else { + &PrintUsage; + } + + $i++; + } #EndWhile + +} #EndSub-ParseArgs + +sub PrintUsage { + die "usage: $0 [-v | --version ] [-t do not send report to tinderbox server]\n"; +} + +sub PrintEnv { + my ($key); + foreach $key (keys %ENV) { + print LOG "$key = $ENV{$key}\n"; + print "$key = $ENV{$key}\n"; + } + + # Print the NPTest variables + if (-e "/var/tmp/NPTest.cache") { + open F, "/var/tmp/NPTest.cache"; + print LOG "NPTest variables:\n"; + print LOG <F>; + close F; + } + +} #EndSub-PrintEnv + +sub SetupPath { + my($Path); + $Path = $ENV{PATH}; + print "Path before: $Path\n"; + + # Don't alter path if we're building off a repository tree; + # SunOS make will be used only for snapshots and releases. + if ( $OS eq 'SunOS' && !( -e '.svn' || -e '.git' )) { + $ENV{'PATH'} = '/usr/ccs/bin:' . $ENV{'PATH'}; + } + + $Path = $ENV{PATH}; + print "Path After: $Path\n"; +} #EndSub-SetupPath + +sub configure { + # Configure + print LOG "./configure --enable-extra-opts --enable-libtap $ConfigureArgs 2>&1\n"; + open (CONFIGURE, "./configure --enable-extra-opts --enable-libtap $ConfigureArgs 2>&1 |") || die "../configure: $!\n"; + while (<CONFIGURE>) { + print $_; + print LOG $_; + } + close(CONFIGURE); + return ! $?; +} + +sub make { + # Building + print LOG "make 2>&1\n"; + open( MAKE, "make 2>&1 |"); + while ( <MAKE> ) { + print $_; + print LOG $_; + } + close( MAKE); + return ! $?; +} + +sub maketest { + # Tests + print LOG "LANG=C make test 2>&1 && make install DESTDIR=$TmpDir/tinderbox_build.$$ 2>&1 && make install-strip DESTDIR=$TmpDir/tinderbox_build2.$$ 2>&1\n"; + open( MAKE, "LANG=C make test 2>&1 && make install DESTDIR=$TmpDir/tinderbox_build.$$ 2>&1 && make install-strip DESTDIR=$TmpDir/tinderbox_build2.$$ 2>&1 |"); + while ( <MAKE> ) { + print $_; + print LOG $_; + } + close( MAKE); + my $rc = $?; + system("rm -fr $TmpDir/tinderbox_build.$$ $TmpDir/tinderbox_build2.$$"); + return ! $rc; +} + +# Main function +&ParseArgs; +&SetupPath; +&BuildIt; + +1; |