#!/usr/pkg/bin/perl # $NetBSD: post-build,v 1.43 2004/04/09 18:43:14 jschauma Exp $ # # Collect stuff after a pkg bulk build # # (c) 2000 Hubert Feyrer, All Rights Reserved. # use File::Basename; use POSIX (); # Where config vars are stored (/bin/sh syntax) if (-f $ENV{"BULK_BUILD_CONF"}) { $BULK_BUILD_CONF=$ENV{"BULK_BUILD_CONF"}; } else { $BULK_BUILD_CONF=dirname("$0")."/build.conf"; } # Dig given variable out of config file, and set it sub getconf { local($var)=@_; local($val); if ($BULK_BUILD_CONF =~ /^\//) { chomp($val=`. $BULK_BUILD_CONF ; echo \$$var`); } else { chomp($val=`. ./$BULK_BUILD_CONF ; echo \$$var`); } eval "\$$var=\"$val\";"; } getconf("ADMINSIG"); # "-Your Name" getconf("FTPURL"); # "pub/NetBSD/pkgstat/`date +%Y%m%d.%H%M`" getconf("FTP"); # "/disk1/ftp/${FTPURL}" getconf("FTPHOST"); # ftp://ftp.machi.ne/ getconf("REPORT"); # "broken.html" getconf("USR_PKGSRC"); # "/usr/pkgsrc" getconf("osrev"); # `uname -r` getconf("arch"); # `uname -m` $reportf=basename($REPORT); chomp($os=`uname -s`); # Extract the name of the files used for the build log and broken build log. # These have defaults set by bsd.bulk-pkg.mk and may be overridden in # /etc/mk.conf chomp($BROKENFILE=`( cd $USR_PKGSRC/pkgtools/pkglint ; $ENV{"BMAKE"} show-var VARNAME=BROKENFILE )`); # Also extract the names of the cache files used during the bulk build. We'll # save a copy of those to help debug if the build messed up. chomp($BULK_DBFILE=`( cd $USR_PKGSRC/pkgtools/pkglint ; $ENV{"BMAKE"} show-var VARNAME=BULK_DBFILE )`); chomp($DEPENDSTREEFILE=`( cd $USR_PKGSRC/pkgtools/pkglint ; $ENV{"BMAKE"} show-var VARNAME=DEPENDSTREEFILE )`); chomp($DEPENDSFILE=`( cd $USR_PKGSRC/pkgtools/pkglint ; $ENV{"BMAKE"} show-var VARNAME=DEPENDSFILE )`); chomp($SUPPORTSFILE=`( cd $USR_PKGSRC/pkgtools/pkglint ; $ENV{"BMAKE"} show-var VARNAME=SUPPORTSFILE )`); chomp($INDEXFILE=`( cd $USR_PKGSRC/pkgtools/pkglint ; $ENV{"BMAKE"} show-var VARNAME=INDEXFILE )`); chomp($ORDERFILE=`( cd $USR_PKGSRC/pkgtools/pkglint ; $ENV{"BMAKE"} show-var VARNAME=ORDERFILE )`); chomp($STARTFILE=`( cd $USR_PKGSRC/pkgtools/pkglint ; $ENV{"BMAKE"} show-var VARNAME=STARTFILE )`); chomp($LOCALBASE=`( cd $USR_PKGSRC/pkgtools/pkglint ; $ENV{"BMAKE"} show-var VARNAME=LOCALBASE )`); chomp($X11BASE=`( cd $USR_PKGSRC/pkgtools/pkglint ; $ENV{"BMAKE"} show-var VARNAME=X11BASE )`); chomp($FIND=`( cd $USR_PKGSRC/pkgtools/pkglint ; $ENV{"BMAKE"} show-var VARNAME=FIND )`); chomp($GTAR=`( cd $USR_PKGSRC/pkgtools/pkglint ; $ENV{"BMAKE"} show-var VARNAME=GTAR )`); $bulkdbfile=basename($BULK_DBFILE); $dtfile=basename($DEPENDSTREEFILE); $depfile=basename($DEPENDSFILE); $supfile=basename($SUPPORTSFILE); $indfile=basename($INDEXFILE); $ordfile=basename($ORDERFILE); $startfile=basename($STARTFILE); $startdate = (stat($STARTFILE))[9]; if ($startdate == 0) { $startdate = "unknown"; } else { local $ENV{TZ} = "UTC"; $startdate = POSIX::strftime("%c %Z", gmtime($startdate)); $enddate = POSIX::strftime("%c %Z", gmtime(time())); } $verbose=1; $report_head = <>$leftovers_txt"); system("${FIND} ${X11BASE} -newer ${USR_PKGSRC}/${startfile} -type f -print >>$leftovers_txt"); # Strip perl-files: { local $/; undef $/; $perlfiles = `pkg_info -qL perl`; } ($perlfiles_pattern = $perlfiles) =~ s/\n/|/g; $perlfiles_pattern =~ s/|$//; open (LEFT, $leftovers_txt) or die "can't read $leftovers_txt: $!"; @left = ; close (LEFT); @leftovers = grep(!/^(${perlfiles_pattern})$/, @left); open (LEFT, ">$leftovers_txt") or die "can't write $leftovers_txt: $!"; print LEFT @leftovers; close (LEFT); if (scalar(@leftovers)) { # Store leftovers, for easier identification: system("$GTAR -T $leftovers_txt -plcf - | (cd leftovers-${arch}; $GTAR -plxf -)"); } # Add links to leftover list: open (OUT, "> $leftovers_html") or die "can't write $leftovers_html"; print OUT <
EOOUT
	foreach (@leftovers) {
		chomp;
	    	print OUT "$_\n";
	}
	print OUT <


EOOUT2
    	close(OUT);
}

# print the result of a single broken package
sub pkgResult {
	my ($pinfo, $state) = @_;
	my $pkg = $pinfo->{pkg};
	my $nbrokenby = $pinfo->{nbrokenby};
	my $nerrors = $pinfo->{nerrors};

	@idents = `${FIND} ${USR_PKGSRC}/${pkg} -type f -print | xargs grep \\\$NetBSD`;
	$datetime = "";
	$file = "";
	$ver = "";
	foreach $ident (@idents) {
		$ident =~ /\$[N]etBSD: ([^ ]*),v ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) Exp \$/;
		if ("$3 $4" gt $datetime) {
			$datetime = "$3 $4";
			$file = $1;
			$ver = $1;
		}
	}

	$maintainer = `grep ^MAINTAINER $USR_PKGSRC/$pkg/Makefile`;
	$maintainer =~ s/MAINTAINER=[ \t]*//;
	$maintainer =~ s//>/g;
	chomp($maintainer);

	(my $state_style = $state) =~ s/ //g;

	$nbrokenby_html = ' '; 
	$nbrokenby_html =
		''.$nbrokenby.''
		if $nbrokenby > 0;

	if ($pinfo->{nerrors} != 0 && $verbose) {
		print swrite($report_form, $pkg, $nbrokenby > 0 ? $nbrokenby : "", $maintainer);
	}

	return <
  $pkg
  $nbrokenby_html
  $file
  $maintainer


EOHTML
}

# write the build report
sub writeReport {
	my $broken = getBroken();
	$nbroken = scalar(@{$broken->{"broken"}});
	$nbrokendep = scalar(@{$broken->{"broken depends"}});
	$nunpackaged = scalar(@{$broken->{"not packaged"}});
	$nbrokentot = $nbroken + $nbrokendep;
	$ntotal = $nunpackaged + $nbroken + $nbrokendep;

	# determine the number of packages attempted, and then successful
	open(ORDER, $ordfile) || die "can't open $ordfile: $!";
	my @order = ;
	close(ORDER);
	my $nattempted = scalar(@order);
	my $nsuccessful = $nattempted - $ntotal;

	if ($verbose) {
		print <$REPORT") or die "Can't write $REPORT: $!\n";
	print HTML <

$os $osrev/$arch bulk package build





pkgsrc bulk build results

$os $osrev/$arch

Summary

Build started: $startdate
Build ended: $enddate
   
Successfully packaged: $nsuccessful
Packages really broken: $nbroken
Packages broken due to them: $nbrokendep
Total broken: $nbrokentot
Not packaged: $nunpackaged
Total: $ntotal

Packages not listed here resulted in a binary package. Results of failed packages are available below.

Files leftover from the build (because of broken PLISTs, etc.) can be found in this list.

EOHTML my %state_head = ( "broken" => "Broken packages", "broken depends" => "Broken dependencies", "not packaged" => "Not packaged" ); foreach my $state ("broken", "broken depends", "not packaged") { next unless scalar(@{$broken->{$state}}); print HTML <$state_head{$state} EOHTML if ($verbose && $state ne "not packaged") { print "\n\n$state_head{$state}\n\n"; print $report_head; } foreach my $pinfo (@{$broken->{$state}}) { print HTML pkgResult($pinfo, $state); } print HTML "
Package Breaks File touched last Maintainer
\n"; } print HTML <

The following cache files were used during the build:


EOHTML close(HTML); if ($verbose) { print "\n\n$ADMINSIG\n\n"; print "[* This message was created by the Packages Collection bulk build software *]\n"; } } # get and sort the broken packages sub getBroken { if (!open (BF, $BROKENFILE)) { return undef; } my @in = ; close (BF); my $res = {}; foreach (@in) { chomp; my ($nerrors, $bf, $nbrokenby) = split; (my $pkg = $bf) =~ s,/$BROKENFILE,,; my %tmp = ( bf => $bf, pkg => $pkg, nbrokenby => $nbrokenby, nerrors => $nerrors, ); if ($nerrors > 0) { push(@{$res->{"broken"}}, \%tmp); } elsif ($nerrors == -1) { push(@{$res->{"broken depends"}}, \%tmp); } else { push(@{$res->{"not packaged"}}, \%tmp); } } # sort pkgs in each state foreach my $state ("broken", "broken depends", "not packaged") { $res->{$state} = [ sort { $a->{pkg} cmp $b->{pkg} } @{$res->{$state}} ]; } return $res; } sub swrite { my $format = shift; $^A = ""; formline($format, @_); $^A =~ s/\n\n/\n/; return $^A; }