[Collab-qa-commits] r514 - svnbuildstat/trunk/script

goneri-guest at alioth.debian.org goneri-guest at alioth.debian.org
Sun Nov 25 20:52:49 UTC 2007


Author: goneri-guest
Date: 2007-11-25 20:52:49 +0000 (Sun, 25 Nov 2007)
New Revision: 514

Modified:
   svnbuildstat/trunk/script/svnbuildstat_agent.pl
Log:
the current agent

Modified: svnbuildstat/trunk/script/svnbuildstat_agent.pl
===================================================================
--- svnbuildstat/trunk/script/svnbuildstat_agent.pl	2007-11-19 08:31:07 UTC (rev 513)
+++ svnbuildstat/trunk/script/svnbuildstat_agent.pl	2007-11-25 20:52:49 UTC (rev 514)
@@ -10,8 +10,9 @@
 use Sys::Hostname;
 use SvnBuildStat::Config;
 use LWP::Simple;
+use POSIX ":sys_wait_h";
+use File::Basename;
 
-
 ###########################################################################
 ###########################################################################
 ###########################################################################
@@ -68,7 +69,7 @@
 print CCACHECFG "EXTRAPACKAGES=ccache\n";
 print CCACHECFG "BINDMOUNTS=\"\${CCACHE_DIR}\"\n";
 # --buildresult foo doesn't work?
-print CCACHECFG "BUILDRESULT=\"$tmpdir\"\n"; 
+#print CCACHECFG "BUILDRESULT=\"$tmpdir\"\n"; 
 close CCACHECFG;
 
 sub isFull {
@@ -87,32 +88,25 @@
 sub howxsnext {
   my $p;
 
-  my $tobuild = LWP::Simple::get($config->agent_source."/".$arch);
-  if (!$tobuild) {
-    print "Failed to contact the server to get a package to build\n";
-    exit 1;
+  my $dsc = LWP::Simple::get("http://svnbuildstat.debian.net/packages/tobuildv2/".$arch);
+  if (!$dsc) {
+    print "Failed to contact the serveur to get a package to build\n";
   }
-  my @tobuild = split /;/, $tobuild;
-  $p->{svnbase} = $tobuild[0];
-  $p->{tarballuri} = $tobuild[1];
-
-  if (!$p->{packageuri}||!$p->{svnbase}) {
-    print "Failed to parse the package information from ".
-    $config->agent_source."/".$arch."\n";
-    return;
-  }
+  $dsc;
 }
 
 sub build {
-  my $p = shift;
+  my $dsc = shift;
 
   my $threadworkplace = $workplace .'/'. $$;
   my $threadreportarea = $reportarea .'/'. $$;
   my $threadbuildarea = $buildarea .'/'. $$;
+  my $threadtmpdir = $tmpdir .'/'. $$;
 
   die if (!-d $threadworkplace && !mkdir $threadworkplace);
   die if (!-d $threadreportarea && !mkdir $threadreportarea);
   die if (!-d $threadbuildarea && !mkdir $threadbuildarea);
+  die if (!-d $threadtmpdir && !mkdir $threadtmpdir);
 
   my %report;
   $report{'arch'} = $arch;
@@ -121,42 +115,40 @@
   $report{distro} = $distro;
 
   $report{'agent_release'} = $RELEASE;
-  $report{'svnbp_release'} = `dpkg-query -W -f='\${Version}' svn-buildpackage`;
   $report{'linda_release'} = `dpkg-query -W -f='\${Version}' linda`;
   $report{'lintian_release'} = `dpkg-query -W -f='\${Version}' lintian`;
   $report{'pbuilder_release'} = `dpkg-query -W -f='\${Version}' pbuilder`;
-  $report{'subversion_release'} = `dpkg-query -W -f='\${Version}' subversion`;
   $report{'piuparts_release'} = `dpkg-query -W -f='\${Version}' piuparts`;
 ###########################################################################
 ###########################################################################
 ###########################################################################
 
+  my $pbuildertgz = "$pbuilderplace/$distro.tar.gz";
+  if (-f $pbuildertgz) {
+    my @s = stat($pbuildertgz);
+    if ($s[9] + 3600*24*7 < time) {
+      `mv $pbuildertgz $pbuildertgz.bak`
+    }
+  }
 
-  my $pdebuildparam = "--debootstrap debootstrap --mirror ".$config->agent_debmirror." --buildplace $pbuilderplace --othermirror 'deb ".$config->agent_debmirror." $distro main contrib non-free' --distribution $distro --basetgz $pbuilderplace/$distro.tar.gz";
+  my $pdebuildparam = "--debootstrap debootstrap --mirror ".$config->agent_debmirror." --buildplace $pbuilderplace --othermirror 'deb ".$config->agent_debmirror." $distro main contrib non-free' --distribution $distro --basetgz $pbuildertgz";
   `/usr/sbin/pbuilder update $pdebuildparam >$threadreportarea/pbuilder-update.log 2>&1`;
   if (($? >> 8)!=0){
     `/usr/sbin/pbuilder create $pdebuildparam >$threadreportarea/pbuilder-create.log 1>&2`;
     if (($? >> 8)!=0) {
       print "Failed to create pbuilder image\n";
+      `mv $pbuildertgz.bak $pbuildertgz`if -f "$pbuildertgz.bak"; # restore the previous tarball
       exit 1
     }
   }
-  foreach (`LC_ALL=C svn info $p->{svnbase}`) {
-    $report{'svn_rev'} = $1 if /Last Changed Rev:\ (\d+)/;
-  }
-  `svn co $p->{svnbase} $threadworkplace >$threadreportarea/svn.log 2>&1`;
-  my @tmp = `cd $threadworkplace ; svn log -q --limit 1`;
-  foreach (`LC_ALL=C svn info $p->{svnbase}`) {
-    if (/Last Changed Rev:\ (\d+)/) {
-      if( $report{'svn_rev'} ne $1 ) {
-        print "HACK: svn info> rev changed during checkout\n";
-      }
-    }
-  }
 
-
-  if (!open CTRL, "<$threadworkplace/debian/control") {
-    #$report{checkout} = 'nok';
+  my $tarballdir;
+  foreach (`cd $threadworkplace; dget -qx $dsc`) {
+    $tarballdir = $1 if /dpkg-source:\sextracting\s\S+\sin\s(\S+)/;
+  }
+  print "tarballdir: $tarballdir\n";
+die "FUCK" unless $tarballdir;
+  if (!open CTRL, "<$threadworkplace/$tarballdir/debian/control") {
     return;
   } else {
 
@@ -166,11 +158,18 @@
         last;
       }
     }
-    $report{checkout} = 'ok';
     close CTRL;
   }
 
-  foreach (`cd $threadworkplace ; dpkg-parsechangelog 2>&1`) {
+  if (!open REV, "<$threadworkplace/$tarballdir/debian/rev") {
+    return;
+  } else {
+    $report{'svn_rev'} = <REV>;
+    print "rev: ".$report{'svn_rev'}."\n";
+    close REV;
+  }
+
+  foreach (`cd $threadworkplace/$tarballdir; dpkg-parsechangelog 2>&1`) {
     if (/Source: (.+)/) {
       $report{'source'} = $1;
     } elsif (/Version: (.+?)(-.+|$)/) {
@@ -179,61 +178,37 @@
   }
 
 
-  if (!$p->{tarballuri}) {
-    $report{'download'} = "native";
-  } else {
-    my @t = split /\//, $p->{tarballuri};
-    my $tarball = pop @t;
+  $report{'stamp_build-start'} = time;
 
-    my $t = $config->agent_debmirror;
-    $p->{tarballuri} =~ s/\@DEBMIRROR\@/$t/;
-    `cd $tarballsplace ; wget -O $tarball -c \"$p->{tarballuri}\" >$threadreportarea/wget.log 2>&1`;
-    `tar tf $tarballsplace/$tarball`;
-    if (($? >> 8)!=0) {
-      print "download nok\n";
-      $report{'download'} = "nok";
-      unlink $tarballsplace."/".$tarball;
-    } else {
-      print "download ok\n";
-      $report{'download'} = "ok";
-    }
-  }
 
+  my $dsc_localpath = $threadworkplace.'/'.basename($dsc);
+  `pbuilder --build --buildresult $threadbuildarea --configfile $ccachedir/ccache.cfg --buildplace $pbuilderplace --aptcache $aptcachedir --distribution $distro --basetgz $pbuilderplace/$distro.tar.gz $dsc_localpath >$threadreportarea/build.log.tmp 2>&1`;
+  $report{'stamp_build-end'} = time;
 
-  if ($report{'download'} ne "nok") {
-    $report{'stamp_build-start'} = time;
-
-# If the there is just a debian directory I assum it's a mergeWithUpstream layout and I add the property
-    if (!grep (!/^debian$/, `/bin/ls $threadworkplace`)) {
-      `cd $threadworkplace; svn propset mergeWithUpstream 1 debian`;
-    }
-
-    `cd $threadworkplace ; svn-buildpackage --svn-ignore-new --svn-builder "pdebuild --use-pdebuild-internal --configfile $ccachedir/ccache.cfg -- --buildplace $pbuilderplace --aptcache $aptcachedir --distribution $distro --basetgz $pbuilderplace/$distro.tar.gz" --svn-override=origDir=$tarballsplace --svn-override=buildArea=$threadbuildarea --svn-noninteractive >$threadreportarea/build.log.tmp 2>&1`;
-    $report{'stamp_build-end'} = time;
-
 # To avoid breakage with tar on the service side, I do some clean up in the logs
-    open BUILDLOGTMP, "<$threadreportarea/build.log.tmp" or die;
-    open BUILDLOG, ">$threadreportarea/build.log" or die;
-    foreach (<BUILDLOGTMP>) {
-      s/[[:cntrl:]]//g;
-      print BUILDLOG $_."\n";
-    }
+  open BUILDLOGTMP, "<$threadreportarea/build.log.tmp" or die;
+  open BUILDLOG, ">$threadreportarea/build.log" or die;
+  foreach (<BUILDLOGTMP>) {
+    s/[[:cntrl:]]//g;
+    print BUILDLOG $_."\n";
+  }
 
-    close BUILDLOGTMP;
-    close BUILDLOG;
-    unlink "$threadreportarea/build.log.tmp";
+  close BUILDLOGTMP;
+  close BUILDLOG;
+  unlink "$threadreportarea/build.log.tmp";
 
-    my $debfiles;
-    $debfiles .= $_." " foreach (<$threadbuildarea/*.{,u}deb>);
-    if ($debfiles) {
-      $report{build} = "ok"; 
-      `cd $threadbuildarea ; lintian --allow-root $debfiles *.dsc > $threadreportarea/lintian.log`;
-      `cd $threadbuildarea ; linda --show-tag $debfiles *.dsc 2>/dev/null > $threadreportarea/linda.log`;
-      `cd $threadbuildarea ; /usr/sbin/piuparts $debfiles | grep -v DEBUG > $threadreportarea/piuparts.log`;
-      $report{piuparts} = (($? >> 8)==0)?'ok':'nok';
-    } else {
-      $report{build} = "nok";
-    }
+  my $debfiles;
+  $debfiles .= $_." " foreach (<$threadbuildarea/*.{,u}deb>);
+  print "debfiles: ".$debfiles." in ".$threadbuildarea."\n";
+  if ($debfiles) {
+    $report{build} = "ok"; 
+    `cd $threadbuildarea ; lintian --allow-root $debfiles *.dsc > $threadreportarea/lintian.log`;
+    `cd $threadbuildarea ; linda --show-tag $debfiles *.dsc 2>/dev/null > $threadreportarea/linda.log`;
+    print "\npiupart\n";
+    `cd $threadbuildarea ; /usr/sbin/piuparts $debfiles | grep -v DEBUG > $threadreportarea/piuparts.log`;
+    $report{piuparts} = (($? >> 8)==0)?'ok':'nok';
+  } else {
+    $report{build} = "nok";
   }
 
 # Prepare and send the report
@@ -244,19 +219,19 @@
     print BUILDREPORT $_."=".$report{$_}."\n";
   }
   close BUILDREPORT;
-
+  
   my $ftp = Net::FTP->new($config->agent_ftphost, Debug => 0) or die "Cannot connect
   to ".$config->agent_ftphost.": $@";
 
-  my $reporttarball = "$report{'source'}_$report{'svn_rev'}_".$arch."$hostname.tar";
+  my $reporttarball = "$report{'source'}_$report{'svn_rev'}_".$arch."_$hostname.tar";
   $ftp->login($config->agent_ftplogin,$config->agent_ftppassword) or die "Cannot login ", $ftp->message;
-  `cd $tmpdir ; cp -r $threadreportarea . ; tar cf  $reporttarball report 2>&1`;
-  $ftp->put($tmpdir."/".$reporttarball) or warn "Failed to send the report\n";
+  `cd $threadtmpdir ; cp -r $threadreportarea report ; tar cf  $reporttarball report 2>&1`;
+  $ftp->put($threadtmpdir."/".$reporttarball) or warn "Failed to send the report\n";
   $ftp->close or warn "Failed to close the ftp connection to the server\n";
 
 }
 
-$SIG{CHLD} = 'IGNORE';
+#$SIG{CHLD} = 'IGNORE';
 while (sleep 1) {
 
   if (isFull($workplace)||isFull($reportarea)||isFull($buildarea)) {
@@ -275,21 +250,20 @@
       sleep 5;
     }
     if (! -d "/proc/".$pid) {
-      `rm -rf $workplace/$pid $reportarea/$pid $buildarea/$pid`;
+#      `rm -rf $workplace/$pid $reportarea/$pid $buildarea/$pid`;
       delete ($job{$pid});
     }
+    waitpid($pid,WNOHANG);
   }
 
   if (keys %job < $maxjobs) {
     my $pid = fork;
     if ($pid) {
-      print "$$ papa $pid\n";
       $job{$pid} = time;
     } else {
-      print "fille $$\n";
-      my $p;# = howxsnext();
-      $p = {svn => "svn://svn.debian.org/svn/pkg-perl/trunk/libtest-object-perl", tarballuri => "http://backpan.perl.org/authors/id/A/AD/ADAMK/Test-Object-0.07.tar.gz;libtest-object-perl_0.07.orig.tar.gz"};
-      build($p);
+      my $dsc = howxsnext ();
+      build($dsc) if $dsc;
+      print "done\n";
       last;
     }
   }




More information about the Collab-qa-commits mailing list