Support mock roots with --uniqueext (and thus no arch at its suffix).
[nethome.git] / bin / hammock
index d477300..a25c20e 100755 (executable)
@@ -4,18 +4,18 @@
 use strict;
 use warnings;
 use POSIX qw(&strftime);
-use Getopt::Long;
+use Getopt::Long qw(:config no_ignore_case);
 use Carp qw(&carp);
 my $start=time();
 
 my $gdbcvsbare=$ENV{"HOME"}."/redhat/gdb-cvs-bare";
-my $archermaster=$ENV{"HOME"}."/redhat/master";
+my $binutilscvsbare=$ENV{"HOME"}."/redhat/binutils-cvs-bare";
+my $archermaster=$ENV{"HOME"}."/redhat/archer-master";
 my $fedoracvsroot=q{:pserver:anonymous:@cvs.fedoraproject.org:/cvs/pkgs};
 my $rhelcvsroot=q{:pserver:anonymous:@192.168.67.2:3401/cvs/dist};
 my $arch_i386=qr{(?:x86|i\d86|ia32)}io;
 my $arch_x86_64=qr{(?:x8664|x86_64|em64t)}io;
 my @arches=qw(i386 x86_64);
-my $arches_re=qr{(?:i386|x86_64)};
 
 my $error=0;
 sub error
@@ -28,11 +28,16 @@ my $userid;
 my $force;
 my $parallel=9;        # 1 or 2 or 3
 my @distro;
+my @componentdistro;
 my @path;
 my @arch;
 my $component;
 my $srcrpm;
 my @file;
+my @target;
+my $configure;
+# FIXME: Connect make paralellization to the children.
+my $distrojobs;
 die if !GetOptions(
   "i|userid=s"=>\$userid,
     "force"=>\$force,
@@ -40,30 +45,44 @@ die if !GetOptions(
   "2|standard"=>sub { $parallel=2; },
   "3|parallel"=>sub { $parallel=3; },
   "d|distro=s{,}"=>\@distro,
+    "cd|componentdistro=s{,}"=>\@componentdistro,
   "p|path=s{,}"=>\@path,
   "a|arch=s{,}"=>\@arch,
   "c|component=s"=>\$component,
   "s|srcrpm=s"=>\$srcrpm,
     "file=s{,}"=>\@file,
+    "target=s{,}"=>\@target,
+  "D|distrojobs=s"=>\$distrojobs,
+    "configure=s"=>\$configure,
 );
-$component and ($component=~m{^(?:(?:fedora|rhel)(?:gdb|glibc)|gdbcvs|archer-.*|/home/.*)$} or die "-c|--component required to be: fedoragdb|rhelgdb|fedoraglibc|rhelglibc|gdbcvs|archer-*|/home/*");
+$component and ($component=~m{^(?:(?:fedora|rhel)(?:gdb|binutils|glibc)|gdbcvs|binutilscvs|archer-.*|/home/.*)$} or die "-c|--component required to be: fedoragdb|rhelgdb|fedorabinutils|rhelbinutils|fedoraglibc|rhelglibc|gdbcvs|binutilscvs|archer-*|/home/*");
 $component and $component=~m{^/home/} and (-f "$component/gdb/gdbtypes.c" or die "$component/gdb/gdbtypes.c not found");
 $component and $srcrpm and die "-c|--component excludes -s|--srcrpm";
 $component or $srcrpm or die "-c|--component or -s|--srcrpm required";
 $component||="";  # Make `eq' not complaining.
+@target and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--target is available only for baretestsuite modes";
+my %target;
+do { error "Duplicate target: $_\n" if $target{$_}++; } for @target;
+@arch="x86_64" if @target&&!@arch;
 for my $file (@file) {
   -f $file and -r $file or error "-f|--file $file not readable: $!";
 }
+$distrojobs=(@target?1:2) if !defined $distrojobs;
+$distrojobs=~/^\d+$/ or die "-D|distrojobs must be a number: $distrojobs";
+$distrojobs>=1 or die "-D|distrojobs must be positive: $distrojobs";
 # User may want to modify ASAP her files submitted for the test.
 my $will_copy=@file || $component=~m{^/home/};
 $parallel||=$will_copy ? 2 : 1;
 error "Excessive arguments: @ARGV" if @ARGV;
 @arch=@arches if !@arch;
 my $path=join(":",@path) if @path;
+@componentdistro and @componentdistro!=@distro and die "--cd|--componentdistro must have the same elements count as -d|--distro";
+
+sub distro_normalize($;$)
+{
+  my($name,$force)=@_;
+  local $_=$name;
 
-# epel-\d-i386|fedora-\d-i386|fedora-rawhide-i386
-my @distrouse;
-for (@distro) {
   s{^/var/lib/mock/+}{};
   s{/+$}{};
   s/^.*$/\L$&/s;
@@ -71,14 +90,36 @@ for (@distro) {
   s/^(?:epel|rhel|centos)-?(\d)/epel-$1/;
   s/^(?:f|fedora)-?(\d)/fedora-$1/;
   my @archuse;
+  @archuse="" if -d "/var/lib/mock/$_";
   @archuse="i386" if s/-$arch_i386$//o;
   @archuse="x86_64" if s/-$arch_x86_64$//o;
+
+  for my $arch (@archuse?@archuse:@arch) {
+    my $dir="/var/lib/mock/$_".(!$arch?"":"-$arch");
+    $force or -d $dir or error "No distro: $dir";
+  }
+
+  return ($_,@archuse);
+}
+
+# epel-\d-i386|fedora-\d-i386|fedora-rawhide-i386
+my @distrouse;
+for my $distroi (0..$#distro) {
+  my $distro=$distro[$distroi];
+  my $componentdistro=$componentdistro[$distroi];
+  my @archuse;
+  if ($componentdistro) {
+    my $force=($componentdistro=~s/!$//);
+    ($componentdistro,@archuse)=distro_normalize $componentdistro,$force;
+    @archuse and die "--cd|--componentdistro must have no arch: ".join(" ",@archuse);
+  }
+  ($distro,@archuse)=distro_normalize $distro;
+  $componentdistro||=$distro;
   @archuse=@arch if !@archuse;
   for my $archuse (@archuse) {
-    my $basename="$_-$archuse";
-    my $dir="/var/lib/mock/$basename";
-    -d $dir or error "No distro: $dir";
-    push @distrouse,$basename;
+    for my $target (@target?@target:undef()) {
+      push @distrouse,{"distro"=>$distro.(!$archuse?"":"-$archuse"),"componentdistro"=>$componentdistro,"target"=>$target};
+    }
   }
 }
 
@@ -120,6 +161,16 @@ print STDERR "ID = $id | dir = $dir\n";
 error "No distros specified" if !@distrouse;
 die "$error errors seen, aborted" if $error;
 
+sub writefile
+{
+  my($fname,$content)=@_;
+
+  local *F;
+  open F,">$fname" or die $fname;
+  print F $content or die $fname;
+  close F or die $fname;
+}
+
 spawn "renice 20 -p $$";
 newdir $dir;
 $log="$dir/log";
@@ -129,182 +180,228 @@ my %dump=(
   "component"=>$component,
   "srcrpm"=>$srcrpm,
   "file"=>join("\n",@file),
+  "configure"=>$configure,
 );
 while (my($name,$val)=each(%dump)) {
-  next if !$val;
+  writefile "$dir/$name","$val\n" if $val;
+}
+
+sub subst
+{
+  my($sub,$in,$out)=@_;
+
+  $out||=$in;
+
   local *F;
-  my $fname="$dir/$name";
-  open F,">$fname" or die $fname;
-  print F "$val\n" or die $fname;
-  close F or die $fname;
+  open F,$in or die $in;
+  local $_=do { local $/; <F>; } or die $in;
+  close F or die $in;
+
+  &{$sub}() or die $_."\nError substituting $in";
+
+  writefile $out,$_;
 }
 
 # PID->distro
 my %child;
-for my $distro (@distrouse) {
-  my $cvsbasedir;
-  my $cvsroot;
-  my $cvsrepo;
-  if ($component=~/^fedora(gdb|glibc)$/) {
-    $cvsrepo=$1;
-    $cvsbasedir="F-$1" if $distro=~/^fedora-(\d+)-$arches_re$/;
-    $cvsbasedir="devel" if $distro=~/^fedora-rawhide-$arches_re$/;
-    die "$component vs. $distro" if !$cvsbasedir;
-    $cvsroot=$fedoracvsroot;
-  }
-  if ($component=~/^rhel(gdb|glibc)$/) {
-    $cvsrepo=$1;
-    $cvsbasedir="RHEL-$1" if $distro=~/^epel-(\d+)-$arches_re$/;
-    die "$component vs. $distro" if !$cvsbasedir;
-    $cvsroot=$rhelcvsroot;
-  }
+while (@distrouse || keys(%child)) {
+  while (keys(%child)<$distrojobs && @distrouse) {
+    my $distrouse=shift @distrouse;
+    my $distro=$distrouse->{"distro"};
+    my $componentdistro=$distrouse->{"componentdistro"};
+    my $target=$distrouse->{"target"};
+    my $rpmbuild="rpmbuild";
+
+    my $cvsbasedir;
+    my $cvsroot;
+    my $cvsrepo;
+    if ($component=~/^fedora(.*)$/) {
+      $cvsrepo=$1;
+      $cvsbasedir="F-$1" if $componentdistro=~/^fedora-(\d+)$/;
+      $cvsbasedir="devel" if $componentdistro=~/^fedora-rawhide$/;
+      die "$component vs. $componentdistro" if !$cvsbasedir;
+      $cvsroot=$fedoracvsroot;
+    }
+    if ($component=~/^rhel(.*)$/) {
+      $cvsrepo=$1;
+      $cvsbasedir="RHEL-$1" if $componentdistro=~/^epel-(\d+)$/;
+      die "$component vs. $componentdistro" if !$cvsbasedir;
+      $cvsroot=$rhelcvsroot;
+      # EPEL still uses Berkeley DB version 8 while F-11+ (F-10?) uses version 9.
+      # Using db_dump and db_load would no longer make it mock compatible.
+      $rpmbuild.=q{ --dbpath $PWD --nodeps};
+    }
 
-  my $distrodir="$dir/$distro";
-  newdir $distrodir;
-  $log="$distrodir/log";
-  my $out="$distrodir/out";
-
-  if ($parallel>1) {
-    my $pid=fork();
-    die if !defined $pid;
-    if ($pid) {
-      $child{$pid}=$distro;
-      next;
+    my $distrodirbase=$distro;
+    $distrodirbase.="-$target" if $target;
+    my $distrodir="$dir/$distrodirbase";
+    newdir $distrodir;
+    $log="$distrodir/log";
+    my $out="$distrodir/out";
+
+    if ($parallel>1) {
+      my $pid=fork();
+      die if !defined $pid;
+      if ($pid) {
+       $child{$pid}=$distrodirbase;
+       next;
+      }
     }
-  }
 
-  my $builddir="$distrodir/build";
-  newdir $builddir;
+    my $builddir="$distrodir/build";
+    newdir $builddir;
 
-  $::distro=$distro;
-  sub mockrun($)
-  {
-    my($c)=@_;
+    # Do not use mockrun as the rpm database may be in a different version.
+    spawn "rpm -r /var/lib/mock/$distro/root -qa|sort >$distrodir/rpm-qa";
 
-    $c="export PATH=\"$path:\$PATH\"; $c" if $path;
-    $c="export MAKEFLAGS=\"-j\$[`getconf _NPROCESSORS_ONLN`*3/2]\"; $c";
-    $c="set -ex; cd $builddir; $c";
-    die "found ': $c" if $c=~/'/;
-    spawn "mockrun $::distro '$c'";
-  }
+    $::distro=$distro;
+    sub mockrun($)
+    {
+      my($c)=@_;
 
-  mockrun "rpm -qa|sort >$distrodir/rpm-qa";
-
-  if ($cvsbasedir) {
-    die if !$cvsroot;
-    die if !$cvsrepo;
-    spawn "cd $distrodir; cvs -q -z3 -d $cvsroot co rpms/$cvsrepo/$cvsbasedir";
-    my $componentdir="$distrodir/rpms/$cvsrepo/$cvsbasedir";
-    -d $componentdir or die "Failed checkout to: $componentdir";
-    # Required for RHEL; Fedora does so automatically.
-    spawn "cd $componentdir/..; cvs -q -z3 -d $cvsroot co common";
-
-    for my $file (@file) {
-      my $filebase=$file;
-      $filebase=~s{^.*/}{};
-      my $target="$componentdir/$filebase";
-      # Some *.patch files may be new.
-      # -f $target or die "File $file does not exist at $target";
-      spawn "rm -f $target; cp -p $file $target";
+      $c="export PATH=\"$path:\$PATH\"; $c" if $path;
+      $c="export MAKEFLAGS=\"-j\$[`getconf _NPROCESSORS_ONLN`*3/2]\"; $c";
+      $c="export http_proxy=http://127.0.0.1:3128/; $c";
+      $c="set -ex; cd $builddir; $c";
+      die "found ': $c" if $c=~/'/;
+      spawn "mockrun $::distro '$c'";
     }
 
-    my $glob="$componentdir/*.src.rpm";
-    @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
-    spawn "cd $componentdir; make test-srpm";
-    my @srcrpm=(glob $glob);
-    @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
-    $srcrpm=$srcrpm[0];
-  }
+    if ($cvsbasedir) {
+      die if !$cvsroot;
+      die if !$cvsrepo;
+      spawn "cd $distrodir; cvs -q -z3 -d $cvsroot co rpms/$cvsrepo/$cvsbasedir";
+      my $componentdir="$distrodir/rpms/$cvsrepo/$cvsbasedir";
+      -d $componentdir or die "Failed checkout to: $componentdir";
+      # Required for RHEL; Fedora does so automatically.
+      spawn "cd $componentdir/..; cvs -q -z3 -d $cvsroot co common";
+      # Workaround (RHEL-5?) curl which uses `Pragma: nocache' on $http_proxy.
+      subst sub { s{echo "curl }{$&-H 'Pragma: cache' }; },"$componentdir/../common/Makefile.common";
+
+      for my $file (@file) {
+       my $filebase=$file;
+       $filebase=~s{^.*/}{};
+       my $target="$componentdir/$filebase";
+       # Some *.patch files may be new.
+       # -f $target or die "File $file does not exist at $target";
+       spawn "rm -f $target; cp -p $file $target";
+      }
 
-  if ($srcrpm) {
-    my $srcrpmbasename=$srcrpm;
-    $srcrpmbasename=~s{^.*/}{};
-    spawn "cp -p $srcrpm $builddir/$srcrpmbasename";
+      my $glob="$componentdir/*.src.rpm";
+      @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
+      # No `spawn' as we could get:
+      # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
+      mockrun "cd $componentdir; make test-srpm";
+      my @srcrpm=(glob $glob);
+      @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
+      $srcrpm=$srcrpm[0];
+    }
 
-    my $rpmbuildlocal=q{rpmbuild --define "_topdir $PWD" --define "_builddir $PWD" --define "_rpmdir $PWD" --define "_sourcedir $PWD" --define "_specdir $PWD" --define "_srcrpmdir $PWD" --define "_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm"};
-    $rpmbuildlocal="orphanripper $rpmbuildlocal" if $cvsrepo && $cvsrepo eq "glibc";
-    mockrun $rpmbuildlocal." --rebuild --with testsuite".($parallel<2 ? "" : " --with parallel")." $srcrpmbasename";
-  }
+    if ($srcrpm) {
+      my $srcrpmbasename=$srcrpm;
+      $srcrpmbasename=~s{^.*/}{};
+      spawn "cp -p $srcrpm $builddir/$srcrpmbasename";
 
-  my $baretestsuite;
+      my $rpmbuildlocal=$rpmbuild.q{ --define "_topdir $PWD" --define "_builddir $PWD" --define "_rpmdir $PWD" --define "_sourcedir $PWD" --define "_specdir $PWD" --define "_srcrpmdir $PWD" --define "_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm"};
+      $rpmbuildlocal="orphanripper $rpmbuildlocal" if $cvsrepo && $cvsrepo eq "glibc";
+      mockrun $rpmbuildlocal." --rebuild --with testsuite".($parallel<2 ? "" : " --with parallel")." $srcrpmbasename";
+    }
 
-  if ($component eq "gdbcvs") {
-    if (-d $gdbcvsbare) {
-      spawn "cp -a $gdbcvsbare $builddir/src; cd $builddir/src; cvs update -A";
-    } else {
-      spawn "cd $builddir; cvs -q -z3 -d :pserver:anoncvs:\@sourceware.org:/cvs/src co gdb";
+    my $baretestsuite;
+
+    if ($component=~/^(gdb|binutils)cvs$/) {
+      my $which=$1;
+      my $cvsbare=$which eq "gdb" ? $gdbcvsbare : $binutilscvsbare;
+      if (-d $cvsbare) {
+       spawn "cp -a $cvsbare $builddir/src; cd $builddir/src; cvs update -A";
+      } else {
+       spawn "cd $builddir; cvs -q -z3 -d :pserver:anoncvs:\@sourceware.org:/cvs/src co $which";
+      }
+      spawn "cd $builddir/src".q{; test -z "$(cvs update -A)"};
+      $baretestsuite="$builddir/src";
     }
-    spawn "cd $builddir/src".q{; test -z "$(cvs update -A)"};
-    $baretestsuite="$builddir/src";
-  }
 
-  if ($component=~/^archer-/) {
-    if (-d $archermaster) {
-      spawn "cp -a $archermaster $builddir/$component; cd $builddir/$component; git pull"
-    } else {
-      spawn "cd $builddir; git clone git://sourceware.org/git/archer.git; mv -f archer $component";
+    if ($component=~/^archer-/) {
+      if (-d $archermaster) {
+       spawn "cp -a $archermaster $builddir/$component; cd $builddir/$component; git pull"
+      } else {
+       spawn "cd $builddir; git clone git://sourceware.org/git/archer.git; mv -f archer $component";
+      }
+      spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
+      $baretestsuite="$builddir/$component";
     }
-    spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
-    $baretestsuite="$builddir/$component";
-  }
 
-  if ($component=~m{^/home/}) {
-    spawn "cp -a $component $builddir/src; cd $builddir/src; find -name \"*.[oa]\" -o -name \"*.l[oa]\" -o -name gdb.sum -o -name gdb.log|xargs rm -f; make clean || :";
-    $baretestsuite="$builddir/src";
-  }
+    if ($component=~m{^/home/}) {
+      spawn "cp -a $component $builddir/src; cd $builddir/src; find -name \"*.[oa]\" -o -name \"*.l[oa]\" -o -name gdb.sum -o -name gdb.log|xargs rm -f; make clean || :";
+      $baretestsuite="$builddir/src";
+    }
 
-  if ($baretestsuite) {
-    for my $file (@file) {
-      my $target="$baretestsuite/$file";
-      if ($file=~m{\Q.patch\E$}) {
-       my $fileabs=$file;
-       $fileabs=$ENV{"PWD"}."/$fileabs" if $fileabs!~m{^/};
-       spawn "cd $baretestsuite; patch -p1 <$fileabs";
+    if ($baretestsuite) {
+      for my $file (@file) {
+       my $target="$baretestsuite/$file";
+       if ($file=~m{[.](R?)patch$}) {
+         my $R=$1;
+         my $fileabs=$file;
+         $fileabs=$ENV{"PWD"}."/$fileabs" if $fileabs!~m{^/};
+         spawn "cd $baretestsuite; patch -${R}p".($component=~/binutils/ ? "0" : "1")." <$fileabs";
+       } else {
+         -f $target or $file=~m{/testsuite/} or die "File $file does not exist at $target";
+         spawn "rm -f $target; cp -p $file $target";
+       }
+      }
+
+      my $errs1="errs1";
+      $errs1.=" --target=$target" if $target;
+      $errs1.=" $configure" if $configure;
+
+      if ($component eq "binutilscvs") {
+       mockrun "cd $baretestsuite; $errs1; errs2; ulimit -c unlimited; orphanripper make -k check || :; mkdir $out; ".q{for file in {gas/testsuite/gas,ld/ld,binutils/binutils}.{sum,log};do ln $file}." $out/binutils-$distro-".q{$(basename $file) || :; done;};
       } else {
-       -f $target or $file=~m{/testsuite/} or die "File $file does not exist at $target";
-       spawn "rm -f $target; cp -p $file $target";
+       my @check=($distro=~/-x86_64/ ? qw(-m64 -m32) : -m32);
+       @check=map("check//unix/$_",@check);
+       # FSF GDB has no PIE support.
+       # @check=map({($_,"$_/-fPIE/-pie");} @check);
+       # for i in ".join(" ",@check).";do orphanripper make -k \$i || :;done
+       mockrun "cd $baretestsuite; $errs1; errs2; cd gdb; ulimit -c unlimited; orphanripper make -k ".join(" ",@check)." || :; mkdir $out; ".q{for t in sum log;do for file in testsuite*/gdb.$t;do suffix="${file#testsuite.unix.}"; suffix="${suffix%/gdb.$t}"; ln $file}." $out/gdb-$distro".q{$suffix.$t || :; done; done;};
       }
+      # gdbunpack does:
+      #                perl -i -pe 's{\Q'"$HOME"'\E/.*?/build/[^/]*/}{}g' "$base"/*
+      my $HOME=$ENV{"HOME"};
+      for my $file (<$out/*>) {
+       subst sub { s{\Q$HOME\E/.*?/build/[^/]*/}{}g; },$file;
+      }
+    } else {
+      die "internal error" if @target;
     }
 
-    my @check=($distro=~/-x86_64/ ? qw(-m64 -m32) : -m32);
-    @check=map("check//unix/$_",@check);
-    # FSF GDB has no PIE support.
-    # @check=map({($_,"$_/-fPIE/-pie");} @check);
-    # for i in ".join(" ",@check).";do orphanripper make -k \$i || :;done
-    mockrun "cd $baretestsuite; errs1; errs2; cd gdb; ulimit -c unlimited; orphanripper make -k ".join(" ",@check)." || :; mkdir $out; ".q{for t in sum log;do for file in testsuite*/gdb.$t;do suffix="${file#testsuite.unix.}"; suffix="${suffix%/gdb.$t}"; ln $file}." $out/gdb-$distro".q{$suffix.$t || :; done; done;};
-  }
+    # Call gdbunpack only if no direct $out directory will be created.
+    # It is needed only for .src.rpm-built testsuites, no matter how .src.rpm
+    # got created.
+    my @testinlog;
+    if ($component=~/^(?:fedora|rhel)glibc$/) {
+      @testinlog=(qr/={20}TESTING DETAILS={17}/,qr/={20}PLT RELOCS END={18}/);
+    }
+    if (@testinlog) {
+      subst sub { s{^.*?\n($testinlog[0]\n.*\n$testinlog[1]\n).*$}{$1}s; },$log,$out;
+    } elsif ($cvsbasedir || $srcrpm) {
+      # Applies both to gdb and binutils.
+      spawn "gdbunpack $log";
+    }
 
-  # Call gdbunpack only if no direct $out directory will be created.
-  # It is needed only for .src.rpm-built testsuites, no matter how .src.rpm
-  # got created.
-  if ($component=~/^(?:fedora|rhel)glibc$/) {
-    local *F;
-    open F,$log or die $log;
-    my $F=do { local $/; <F>; } or die $log;
-    close F or die $log;
-    $F=~s{^.*?\n(={20}TESTING DETAILS={17}\n.*\n={20}PLT RELOCS END={18}\n).*$}{$1}s or die "No TESTING part found: $log";
-
-    open F,">$out" or die $out;
-    print F $F or die $out;
-    close F or die $out;
-  } elsif ($cvsbasedir || $srcrpm) {
-    spawn "gdbunpack $log";
+    exit 0 if $parallel>1;
   }
 
-  exit 0 if $parallel>1;
-}
-
-while (1) {
-  print STDERR "waiting for ".scalar(keys(%child))." children...\n";
+  print STDERR "waiting for ".scalar(keys(%child))." children, ".scalar(@distrouse)." distros to go...\n";
   my $pid=wait();
-  last if $pid==-1 && $!==10; # 10==No child processes
+  next if $pid==-1 && $!==10; # 10==No child processes
   die "wait()==-1: $!" if $pid==-1;
   die "not found pid $pid" if !$child{$pid};
   error "weird status $? for pid $pid: ".$child{$pid} if $?;
   print STDERR "finished: $pid ".$child{$pid}."\n";
   delete $child{$pid};
 }
-die "Uncollected children: ".keys(%child) if keys(%child);
+die if keys(%child);
+die if @distrouse;
 
 sub timestr($)
 {
@@ -325,7 +422,8 @@ sub timestr($)
 }
 
 print STDERR "ID = $id | dir = $dir\n";
-print STDERR "total time=".timestr(time()-$start)."\n";
+my $time=timestr(time()-$start);
+print STDERR "total time=$time\n";
+writefile "$dir/time","$time\n";
 die "$error errors seen, aborted" if $error;
-
 print STDERR "done\n";