+--gdbindex
[nethome.git] / bin / hammock
1 #! /usr/bin/perl
2
3 use strict;
4 use warnings;
5 use POSIX qw(&strftime);
6 use Getopt::Long qw(:config no_ignore_case);
7 use Carp qw(&carp);
8 my $start=time();
9
10 my $gdbcvsmaster=$ENV{"HOME"}."/redhat/gdb-cvs-master";
11 my $binutilscvsmaster=$ENV{"HOME"}."/redhat/binutils-cvs-master";
12 my $archermaster=$ENV{"HOME"}."/redhat/archer-master";
13 my $fedoragitroot=q{git://pkgs.fedoraproject.org};
14 #Unknown host cvs.devel.redhat.com.
15 #my $rhelcvsroot=q{:pserver:anonymous:@cvs.devel.redhat.com:/cvs/dist};
16 my $rhelcvsroot=q{:ext:cvs.devel.redhat.com:/cvs/dist};
17 my $arch_i386=qr{(?:x86|i\d86|ia32)}io;
18 my $arch_x86_64=qr{(?:x8664|x86_64|em64t)}io;
19 my $resultdir=$ENV{"HOME"}."/.hammock-result";
20 my @arches=qw(i386 x86_64);
21
22 my $error=0;
23 sub error
24 {
25   carp @_;
26   $error++;
27 }
28
29 my $userid;
30 my $force;
31 my $parallel=9; # 1 or 2 or 3
32 my @distro;
33 my @componentdistro;
34 my @path;
35 my @arch;
36 my $component;
37 my $srcrpm;
38 my @file;
39 my @target;
40 my $configure;
41 my $branch;
42 # FIXME: Connect make paralellization to the children.
43 my $distrojobs;
44 my $gdbcvspie;
45 my $strip;
46 # FIXME: 20100911servpatched-f14:
47 # readchar: Connection reset by peer
48 # Remote side has terminated connection.  GDBserver will reopen the connection.
49 # Can't bind address: Address already in use.
50 # <last 2 lines repearing>
51 my $gdbserver;
52 my $valgrind;
53 my $gdbindex;
54 my $dwarf4;
55 die if !GetOptions(
56   "i|userid=s"=>\$userid,
57     "force"=>\$force,
58   "1|serial"=>sub { $parallel=1; },
59   "2|standard"=>sub { $parallel=2; },
60   "3|parallel"=>sub { $parallel=3; },
61   "d|distro=s{,}"=>\@distro,
62     "cd|componentdistro=s{,}"=>\@componentdistro,
63   "p|path=s{,}"=>\@path,
64   "a|arch=s{,}"=>\@arch,
65   "c|component=s"=>\$component,
66   "s|srcrpm=s"=>\$srcrpm,
67     "file=s{,}"=>\@file,
68     "target=s{,}"=>\@target,
69   "D|distrojobs=s"=>\$distrojobs,
70     "configure=s"=>\$configure,
71     "branch=s"=>\$branch,
72     "gdbcvspie"=>\$gdbcvspie,
73     "strip"=>\$strip,
74     "gdbserver"=>\$gdbserver,
75     "valgrind"=>\$valgrind,
76     "gdbindex"=>\$gdbindex,
77     "dwarf4"=>\$dwarf4,
78 );
79 $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/*");
80 $component and $component=~m{^/home/} and (-f "$component/gdb/gdbtypes.c" or die "$component/gdb/gdbtypes.c not found");
81 $component and $srcrpm and die "-c|--component excludes -s|--srcrpm";
82 $component or $srcrpm or die "-c|--component or -s|--srcrpm required";
83 $component||="";  # Make `eq' not complaining.
84 my $cvsbranch;
85 if ($component=~/^(gdb|binutils)cvs$/) {
86   $cvsbranch=(!$branch?"-A":"-r $branch");
87 } else {
88   die "--branch currently unsupported for non-CVS sources" if $branch;
89 }
90 !$gdbcvspie or $component eq "gdbcvs" or die "--gdbcvspie requires -c gdbcvs";
91 @target and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--target is available only for baretestsuite modes";
92 $strip and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--strip is available only for baretestsuite modes";
93 $gdbserver and $component ne "gdbcvs" and die "--gdbserver is available only for gdbcvs";
94 $valgrind and $component ne "gdbcvs" and die "--valgrind is available only for gdbcvs";
95 $gdbserver and $valgrind and die "--gdbserver and --valgrind are mutually exclusive";
96 ($gdbserver || $valgrind) and $gdbindex and die "--gdbserver|--valgrind and --gdbindex are mutually exclusive";
97 ($gdbserver || $valgrind || $gdbindex) and $dwarf4 and die "--gdbserver|--valgrind|--gdbindex and --dwarf4 are mutually exclusive";
98 my %target;
99 do { error "Duplicate target: $_\n" if $target{$_}++; } for @target;
100 @arch="x86_64" if @target&&!@arch;
101 for my $file (@file) {
102   -f $file and -r $file or error "-f|--file $file not readable: $!";
103 }
104 $distrojobs=(@target?1:2) if !defined $distrojobs;
105 $distrojobs=~/^\d+$/ or die "-D|distrojobs must be a number: $distrojobs";
106 $distrojobs>=1 or die "-D|distrojobs must be positive: $distrojobs";
107 # User may want to modify ASAP her files submitted for the test.
108 my $will_copy=@file || $component=~m{^/home/};
109 $parallel||=$will_copy ? 2 : 1;
110 error "Excessive arguments: @ARGV" if @ARGV;
111 @arch=@arches if !@arch;
112 my $path=join(":",@path) if @path;
113 @componentdistro and @componentdistro!=@distro and die "--cd|--componentdistro must have the same elements count as -d|--distro";
114
115 sub distro_normalize($;$)
116 {
117   my($name,$force)=@_;
118   local $_=$name;
119
120   s{^/var/lib/mock/+}{};
121   s{/+$}{};
122   s/^.*$/\L$&/s;
123   s/^(?:devel|rawhide)\b/fedora-rawhide/;
124   s/^(?:epel|centos)-?(\d)/epel-$1/;
125   s/^(?:rhel)-?(\d)/rhel-$1/;
126   s/^(?:f|fedora)-?(\d)/fedora-$1/;
127   my @archuse;
128   @archuse="" if -d "/var/lib/mock/$_";
129   @archuse="i386" if s/-$arch_i386$//o;
130   @archuse="x86_64" if s/-$arch_x86_64$//o;
131
132   for my $arch (@archuse?@archuse:@arch) {
133     my $dir="/var/lib/mock/$_".(!$arch?"":"-$arch");
134     $force or -d $dir or error "No distro: $dir";
135   }
136
137   return ($_,@archuse);
138 }
139
140 # epel-\d-i386|fedora-\d-i386|fedora-rawhide-i386
141 my @distrouse;
142 for my $distroi (0..$#distro) {
143   my $distro=$distro[$distroi];
144   my $componentdistro=$componentdistro[$distroi];
145   my @archuse;
146   if ($componentdistro) {
147     my $force=($componentdistro=~s/!$//);
148     ($componentdistro,@archuse)=distro_normalize $componentdistro,$force;
149     @archuse and die "--cd|--componentdistro must have no arch: ".join(" ",@archuse);
150   }
151   ($distro,@archuse)=distro_normalize $distro;
152   $componentdistro||=$distro;
153   @archuse=@arch if !@archuse;
154   for my $archuse (@archuse) {
155     for my $target (@target?@target:undef()) {
156       push @distrouse,{"distro"=>$distro.(!$archuse?"":"-$archuse"),"componentdistro"=>$componentdistro,"target"=>$target};
157     }
158   }
159 }
160
161 # "-p", "mayexist"
162 sub newdir($;@)
163 {
164   my($dir,@opt)=@_;
165
166   my %opt=map(($_=>1),@opt);
167   warn "+ mkdir".($opt{"-p"} ? " -p" : "")." $dir\n";
168   mkdir $dir or ($opt{"mayexist"} && $!{EEXIST}) or die "mkdir $dir: $!";
169 }
170
171 my $log;
172 # "bare"
173 sub spawn($;%)
174 {
175   my($cmd,@opt)=@_;
176
177   my %opt=map(($_=>1),@opt);
178   my $ok;
179   if (!$opt{"bare"}) {
180     $cmd="set -ex; $cmd";
181     $ok="$log.ok" if $log;
182     $cmd="($cmd; touch $ok) 2>&1|tee -a $log; test -f $ok" if $log;
183     unlink $ok if $ok;
184   } else {
185     warn "+ $cmd\n";
186   }
187   # warn "+ $cmd\n";
188   system $cmd and die "$cmd: $!";
189   unlink $ok if $ok;
190 }
191
192 my $basedir=$ENV{"HOME"}."/hammock";
193 newdir $basedir,"mayexist";
194 my $idbase=strftime("%Y%m%d",localtime());
195 my $id;
196 my $dir;
197 for my $seq (defined $userid ? $userid : (0..99)) {
198   $id=$idbase.(defined $userid ? $seq : sprintf("%02d",$seq));
199   $dir="$basedir/$id";
200   last if ! -e $dir;
201 }
202 spawn "chmod -R u+w $dir; rm -rf $dir" if -d $dir && $force && defined $userid;
203 error "Directory not free: $dir" if !$id || !$dir || -e $dir;
204 print STDERR "ID = $id | dir = $dir\n";
205 error "No distros specified" if !@distrouse;
206 die "$error errors seen, aborted" if $error;
207
208 sub writefile
209 {
210   my($fname,$content)=@_;
211
212   local *F;
213   open F,">$fname" or die $fname;
214   print F $content or die $fname;
215   close F or die $fname;
216 }
217
218 # /etc/cgconfig.conf
219 spawn "echo cgclassify -g '*':hammock $$ || :";
220
221 spawn "renice +19 -p $$";
222 spawn "ionice -c3 -p $$";
223 newdir $dir;
224 $log="$dir/log";
225 my $resultid="$resultdir/$id";
226 my $resultidxz="$resultid.tar.xz";
227 newdir $resultdir,"mayexist";
228 spawn "rm -rf $resultid" if -d $resultid && $force;
229 newdir $resultid;
230 unlink $resultidxz or $!{ENOENT} or die "unlink $resultidxz: $!";
231 spawn "uname -r >$dir/kernel";
232 my %dump=(
233   "path"=>$path,
234   "component"=>$component,
235   "branch"=>$branch,
236   "srcrpm"=>$srcrpm,
237   "file"=>join("\n",@file),
238   "configure"=>$configure,
239   "gdbcvspie"=>$gdbcvspie,
240   "gdbserver"=>$gdbserver,
241   "valgrind"=>$valgrind,
242   "gdbindex"=>$gdbindex,
243   "dwarf4"=>$dwarf4,
244 );
245 while (my($name,$val)=each(%dump)) {
246   next if !$val;
247   writefile "$dir/$name","$val\n";
248   link "$dir/$name","$resultid/$name" or warn "link $dir/$name $resultid/$name: $!";
249 }
250 for my $file (@file) {
251   newdir "$dir/file.d","mayexist";
252   (my $base=$file)=~s{^.*/}{};
253   my $d="$dir/file.d/$base";
254   link $file,$d or die "link $file $d: $!";
255   newdir "$resultid/file.d","mayexist";
256   link $d,"$resultid/file.d/$base" or warn "link $file $resultid/file.d/$base: $!";
257 }
258
259 sub subst
260 {
261   my($sub,$in,$out)=@_;
262
263   $out||=$in;
264
265   local *F;
266   open F,$in or die $in;
267   local $_=do { local $/; <F>; } or die $in;
268   close F or die $in;
269
270   &{$sub}() or die $_."\nError substituting $in";
271
272   writefile $out,$_;
273 }
274
275 sub copyfiles($)
276 {
277   my($targetdir)=@_;
278
279   for my $file (@file) {
280     my $filebase=$file;
281     $filebase=~s{^.*/}{};
282     my $target="$targetdir/$filebase";
283     # Some *.patch files may be new.
284     # -f $target or die "File $file does not exist at $target";
285     spawn "rm -f $target; cp -p $file $target";
286   }
287 }
288
289 # PID->distro
290 my %child;
291 while (@distrouse || keys(%child)) {
292   while (keys(%child)<$distrojobs && @distrouse) {
293     my $distrouse=shift @distrouse;
294     my $distro=$distrouse->{"distro"};
295     my $componentdistro=$distrouse->{"componentdistro"};
296     my $target=$distrouse->{"target"};
297     my $rpmbuild="rpmbuild";
298
299     my $cvsbasedir;
300     my $gitbranch;
301     my $cvsroot;
302     my $gitroot;
303     my $cvsrepo;
304     my $gitrepo;
305     if ($component=~/^fedora(.*)$/) {
306       $gitrepo=$1;
307       $gitbranch="f$1/master" if $componentdistro=~/^fedora-(\d+)$/;
308       $gitbranch="master" if $componentdistro=~/^fedora-rawhide$/;
309       die "$component vs. $componentdistro" if !$gitbranch;
310       $gitroot=$fedoragitroot;
311     }
312     if ($component=~/^rhel(.*)$/) {
313       $cvsrepo=$1;
314       $cvsbasedir="RHEL-$1" if $componentdistro=~/^(?:epel|rhel)-(\d+)$/;
315       die "$component vs. $componentdistro" if !$cvsbasedir;
316       $cvsroot=$rhelcvsroot;
317       # EPEL still uses Berkeley DB version 8 while F-11+ (F-10?) uses version 9.
318       # Using db_dump and db_load would no longer make it mock compatible.
319       $rpmbuild.=q{ --dbpath $PWD --nodeps};
320     }
321
322     my $distrodirbase=$distro;
323     $distrodirbase.="-$target" if $target;
324     my $distrodir="$dir/$distrodirbase";
325     newdir $distrodir;
326     $log="$distrodir/log";
327     my $out="$distrodir/out";
328     newdir $out;
329
330     if ($parallel>1) {
331       my $pid=fork();
332       die if !defined $pid;
333       if ($pid) {
334         $child{$pid}=$distrodirbase;
335         next;
336       }
337     }
338
339     my $builddir="$distrodir/build";
340     newdir $builddir;
341
342     # Do not use mockrun as the rpm database may be in a different version.
343     spawn "rpm -r /var/lib/mock/$distro/root -qa|sort >$out/rpm-qa";
344
345     $::distro=$distro;
346     sub mockrun($)
347     {
348       my($c)=@_;
349
350       $c="export PATH=\"$path:\$PATH\"; $c" if $path;
351       $c="export MAKEFLAGS=\"-j\$[`getconf _NPROCESSORS_ONLN`*3/2]\"; $c";
352       $c="export http_proxy=http://127.0.0.1:3128/; $c";
353       $c="set -ex; cd $builddir; $c";
354       die "found ': $c" if $c=~/'/;
355       spawn "mockrun $::distro '$c'";
356     }
357
358     if ($gitbranch) {
359       die if !$gitroot;
360       die if !$gitrepo;
361       die if !$gitbranch;
362       spawn "cd $distrodir; git clone -b $gitbranch $gitroot/$gitrepo $component";
363       my $componentdir="$distrodir/$component";
364       -d $componentdir or die "Failed checkout to: $componentdir";
365       copyfiles $componentdir;
366       spawn "cd $componentdir; fedpkg verrel >$out/verrel";
367       my $glob="$componentdir/*.src.rpm";
368       @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
369       # No `spawn' as we could get:
370       # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
371       mockrun "cd $componentdir; fedpkg srpm";
372       my @srcrpm=(glob $glob);
373       @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
374       $srcrpm=$srcrpm[0];
375     }
376
377     if ($cvsbasedir) {
378       die if !$cvsroot;
379       die if !$cvsrepo;
380       die if !$cvsbasedir;
381       spawn "cd $distrodir; cvs -q -z3 -d $cvsroot co rpms/$cvsrepo/$cvsbasedir";
382       my $componentdir="$distrodir/rpms/$cvsrepo/$cvsbasedir";
383       -d $componentdir or die "Failed checkout to: $componentdir";
384       # Required for RHEL; Fedora does so automatically.
385       spawn "cd $componentdir/..; cvs -q -z3 -d $cvsroot co common";
386       # Workaround (RHEL-5?) curl which uses `Pragma: nocache' on $http_proxy.
387       subst sub { s{echo "curl }{$&-H 'Pragma: cache' }; },"$componentdir/../common/Makefile.common";
388       copyfiles $componentdir;
389       spawn "cd $componentdir; make verrel >$out/verrel";
390       my $glob="$componentdir/*.src.rpm";
391       @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
392       # No `spawn' as we could get:
393       # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
394       mockrun "cd $componentdir; make test-srpm";
395       my @srcrpm=(glob $glob);
396       @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
397       $srcrpm=$srcrpm[0];
398     }
399
400     if ($srcrpm) {
401       my $srcrpmbasename=$srcrpm;
402       $srcrpmbasename=~s{^.*/}{};
403       spawn "cp -p $srcrpm $builddir/$srcrpmbasename";
404
405       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"};
406       $rpmbuildlocal="orphanripper $rpmbuildlocal" if $cvsrepo && $cvsrepo eq "glibc";
407       mockrun $rpmbuildlocal." --rebuild --with testsuite".($parallel<2 ? "" : " --with parallel")." $srcrpmbasename";
408     }
409
410     my $baretestsuite;
411
412     if ($component=~/^(gdb|binutils)cvs$/) {
413       my $which=$1;
414       my $cvsmaster=$which eq "gdb" ? $gdbcvsmaster : $binutilscvsmaster;
415       if (-d $cvsmaster) {
416         spawn "cp -a $cvsmaster $builddir/src; cd $builddir/src; cvs update $cvsbranch";
417       } else {
418         spawn "cd $builddir; cvs -q -z3 -d :pserver:anoncvs:\@sourceware.org:/cvs/src co $cvsbranch $which";
419       }
420       spawn "cd $builddir/src; test -z \"\$(cvs update $cvsbranch)\"";
421       $baretestsuite="$builddir/src";
422     }
423
424     if ($component=~/^archer-/) {
425       spawn "git clone ".(!-d $archermaster ? "" : "--reference $archermaster")." git://sourceware.org/git/archer.git $builddir/$component";
426       spawn "cd $builddir/$component; git fetch";
427       spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
428       $baretestsuite="$builddir/$component";
429     }
430
431     if ($component=~m{^/home/}) {
432       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 || :";
433       $baretestsuite="$builddir/src";
434     }
435
436     if ($baretestsuite) {
437       for my $file (@file) {
438         my $target="$baretestsuite/$file";
439         if ($file=~m{[.](R?)patch$}) {
440           my $R=$1;
441           my $fileabs=$file;
442           $fileabs=$ENV{"PWD"}."/$fileabs" if $fileabs!~m{^/};
443           spawn "cd $baretestsuite; patch -${R}p1 <$fileabs";
444         } else {
445           -f $target or $file=~m{/testsuite/} or die "File $file does not exist at $target";
446           spawn "rm -f $target; cp -p $file $target";
447         }
448       }
449
450       my $errs12="errs12";
451       $errs12.=" -s" if $strip;
452       $errs12.=" --target=$target" if $target;
453       $errs12.=" $configure" if $configure;
454
455       if ($component eq "binutilscvs") {
456         mockrun "cd $baretestsuite; $errs12; ulimit -c unlimited; orphanripper make -k check || :; ".q{for file in {gas/testsuite/gas,ld/ld,binutils/binutils}.{sum,log};do ln $file}." $out/binutils-$distro-".q{$(basename $file) || :; done;};
457       } else {
458         my @check=($distro=~/-x86_64/ ? qw(-m64 -m32) : -m32);
459         @check=map("check//unix/$_",@check);
460         @check=map({($_,"$_/-fPIE/-pie");} @check) if $gdbcvspie;
461         # for i in ".join(" ",@check).";do orphanripper make -k \$i || :;done
462         mockrun "cd $baretestsuite; $errs12"
463                 .(!$valgrind?"":' --without-python')    # FIXME: Fix valgrind --suppressions
464                 ."; cd gdb; ulimit -c unlimited; "
465                 .(!$gdbserver?"":'DEJAGNU=$HOME/src/runtest-gdbserver/site.exp ')
466                 .(!$valgrind?"":'DEJAGNU=$HOME/src/runtest-valgrind/site.exp ')
467                 ."orphanripper make -k ".join(" ",@check)
468                 .(!$gdbserver?"":' RUNTESTFLAGS=--target_board=native-gdbserver')
469                 .(!$valgrind?"":' RUNTESTFLAGS=--target_board=valgrind')
470                 .(!$gdbindex?"":' RUNTESTFLAGS="CC_FOR_TARGET=/bin/sh\ $PWD/cc-with-index.sh\ gcc CXX_FOR_TARGET=/bin/sh\ $PWD/cc-with-index.sh\ g++"')
471                 .(!$dwarf4?"":' RUNTESTFLAGS="CC_FOR_TARGET=gcc\ -gdwarf-4\ -g0 CXX_FOR_TARGET=g++\ -gdwarf-4\ -g0"')
472                 ." FORCE_PARALLEL=1 || :; ".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".q{$suffix.$t || :; done; done;};
473       }
474       # gdbunpack does:
475       #         perl -i -pe 's{\Q'"$HOME"'\E/.*?/build/[^/]*/}{}g' "$base"/*
476       my $HOME=$ENV{"HOME"};
477       for my $file (glob("$out/*.sum"),glob("$out/*.log")) {
478         subst sub { s{\Q$HOME\E/.*?/build/[^/]*/}{}g; },$file;
479       }
480     } else {
481       die "internal error" if @target;
482     }
483
484     # Call gdbunpack only if no direct $out directory will be created.
485     # It is needed only for .src.rpm-built testsuites, no matter how .src.rpm
486     # got created.
487     my @testinlog;
488     if ($component=~/^(?:fedora|rhel)glibc$/) {
489       @testinlog=(qr/={20}TESTING DETAILS={17}/,qr/={20}PLT RELOCS END={18}/);
490     }
491     if (@testinlog) {
492       subst sub { s{^.*?\n($testinlog[0]\n.*\n$testinlog[1]\n).*$}{$1}s; },$log,$out;
493     } elsif ($cvsbasedir || $srcrpm) {
494       # Applies both to gdb and binutils.
495       spawn "mv $out $out.x; gdbunpack $log; mv $out.x/* $out/; rmdir $out.x";
496     }
497
498     if ($valgrind) {
499       for my $from (glob "$out/*.log") {
500         (my $to=$from).="filt";
501         spawn q{sed -n 's/^==[0-9]*== \([A-Z]\)/\1/p' <}.$from.q{|grep -v '^\(Conditional jump \|Invalid read \|Use of uninitialised value \|Syscall param .* uninitialised byte\)' >}.$to;
502       }
503     }
504
505     my $resultout="$resultdir/$id/$distrodirbase";
506     newdir $resultout;
507     $resultout.="/out";
508     newdir $resultout;
509     for my $fname (glob "$out/*") {
510       (my $base=$fname)=~s{^.*/}{};
511       my $d="$resultout/$base";
512       warn "+ link $fname $d\n";
513       link $fname,$d or warn $!;
514     }
515
516     exit 0 if $parallel>1;
517   }
518
519   print STDERR "waiting for ".scalar(keys(%child))." children, ".scalar(@distrouse)." distros to go...\n";
520   my $pid=wait();
521   next if $pid==-1 && $!==10; # 10==No child processes
522   die "wait()==-1: $!" if $pid==-1;
523   die "not found pid $pid" if !$child{$pid};
524   error "weird status $? for pid $pid: ".$child{$pid} if $?;
525   print STDERR "finished: $pid ".$child{$pid}."\n";
526   delete $child{$pid};
527 }
528 die if keys(%child);
529 die if @distrouse;
530
531 spawn "(set -e -o pipefail;cd $resultdir;tar cf - $id|xz -9e >$resultidxz;rm -rf $id)&","bare";
532
533 sub timestr($)
534 {
535   my($sec)=@_;
536   my $r="";
537
538   if ($sec>=60*60) {
539     $r.=int($sec/(60*60))."h";
540     $sec%=60*60;
541   }
542   if ($r || $sec>=60) {
543     $r.=int($sec/60)."m";
544     $sec%=60;
545   }
546   $r.=$sec."s";
547
548   return $r;
549 }
550
551 print STDERR "ID = $id | dir = $dir\n";
552 my $time=timestr(time()-$start);
553 print STDERR "total time=$time\n";
554 writefile "$dir/time","$time\n";
555 die "$error errors seen, aborted" if $error;
556 print STDERR "done\n";