Fix .in search.
[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=1;
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 $dwarf;
55 my $orphanripper=1;
56 die if !GetOptions(
57   "i|userid=s"=>\$userid,
58     "force"=>\$force,
59     "serial"=>sub { $parallel=0; },
60     "parallel"=>sub { $parallel=1; },
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     "dwarf=i"=>\$dwarf,
78     "orphanripper!"=>\$orphanripper,
79 );
80 $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/*");
81 $component and $component=~m{^/home/} and (-f "$component/gdb/gdbtypes.c" or die "$component/gdb/gdbtypes.c not found");
82 $component and $srcrpm and die "-c|--component excludes -s|--srcrpm";
83 $component or $srcrpm or die "-c|--component or -s|--srcrpm required";
84 $component||="";  # Make `eq' not complaining.
85 my $cvsbranch;
86 if ($component=~/^(gdb|binutils)cvs$/) {
87   $cvsbranch=(!$branch?"-A":"-r $branch");
88 } else {
89   die "--branch currently unsupported for non-CVS sources" if $branch;
90 }
91 !$gdbcvspie or $component eq "gdbcvs" or die "--gdbcvspie requires -c gdbcvs";
92 @target and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--target is available only for baretestsuite modes";
93 $strip and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--strip is available only for baretestsuite modes";
94 $gdbserver and $component ne "gdbcvs" and die "--gdbserver is available only for gdbcvs";
95 $valgrind and $component ne "gdbcvs" and die "--valgrind is available only for gdbcvs";
96 $gdbserver and $valgrind and die "--gdbserver and --valgrind are mutually exclusive";
97 ($gdbserver || $valgrind) and $gdbindex and die "--gdbserver|--valgrind and --gdbindex are mutually exclusive";
98 !defined $dwarf or ($dwarf>=2 && $dwarf<=4) or die "--dwarf requires DWARF version number";
99 ($gdbserver || $valgrind || $gdbindex) and $dwarf and die "--gdbserver|--valgrind|--gdbindex and --dwarf are mutually exclusive";
100 $orphanripper=($orphanripper?"orphanripper":"");
101 my %target;
102 do { error "Duplicate target: $_\n" if $target{$_}++; } for @target;
103 @arch="x86_64" if @target&&!@arch;
104 for my $file (@file) {
105   -f $file and -r $file or error "-f|--file $file not readable: $!";
106 }
107 $distrojobs=(@target?1:2) if !defined $distrojobs;
108 $distrojobs=~/^\d+$/ or die "-D|distrojobs must be a number: $distrojobs";
109 $distrojobs>=1 or die "-D|distrojobs must be positive: $distrojobs";
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   "dwarf"=>$dwarf,
244   "orphanripper"=>$orphanripper,
245 );
246 while (my($name,$val)=each(%dump)) {
247   next if !$val;
248   writefile "$dir/$name","$val\n";
249   link "$dir/$name","$resultid/$name" or warn "link $dir/$name $resultid/$name: $!";
250 }
251 for my $file (@file) {
252   newdir "$dir/file.d","mayexist";
253   (my $base=$file)=~s{^.*/}{};
254   my $d="$dir/file.d/$base";
255   link $file,$d or die "link $file $d: $!";
256   newdir "$resultid/file.d","mayexist";
257   link $d,"$resultid/file.d/$base" or warn "link $file $resultid/file.d/$base: $!";
258 }
259
260 sub subst
261 {
262   my($sub,$in,$out)=@_;
263
264   $out||=$in;
265
266   local *F;
267   open F,$in or die $in;
268   local $_=do { local $/; <F>; } or die $in;
269   close F or die $in;
270
271   &{$sub}() or die $_."\nError substituting $in";
272
273   writefile $out,$_;
274 }
275
276 sub copyfiles($)
277 {
278   my($targetdir)=@_;
279
280   for my $file (@file) {
281     my $filebase=$file;
282     $filebase=~s{^.*/}{};
283     my $target="$targetdir/$filebase";
284     # Some *.patch files may be new.
285     # -f $target or die "File $file does not exist at $target";
286     spawn "rm -f $target; cp -p $file $target";
287   }
288 }
289
290 # PID->distro
291 my %child;
292 while (@distrouse || keys(%child)) {
293   while (keys(%child)<$distrojobs && @distrouse) {
294     my $distrouse=shift @distrouse;
295     my $distro=$distrouse->{"distro"};
296     my $componentdistro=$distrouse->{"componentdistro"};
297     my $target=$distrouse->{"target"};
298     my $rpmbuild="rpmbuild";
299
300     my $cvsbasedir;
301     my $gitbranch;
302     my $cvsroot;
303     my $gitroot;
304     my $cvsrepo;
305     my $gitrepo;
306     if ($component=~/^fedora(.*)$/) {
307       $gitrepo=$1;
308       $gitbranch="f$1/master" if $componentdistro=~/^fedora-(\d+)$/;
309       $gitbranch="master" if $componentdistro=~/^fedora-rawhide$/;
310       die "$component vs. $componentdistro" if !$gitbranch;
311       $gitroot=$fedoragitroot;
312     }
313     if ($component=~/^rhel(.*)$/) {
314       $cvsrepo=$1;
315       $cvsbasedir="RHEL-$1" if $componentdistro=~/^(?:epel|rhel)-(\d+)$/;
316       die "$component vs. $componentdistro" if !$cvsbasedir;
317       $cvsroot=$rhelcvsroot;
318       # EPEL still uses Berkeley DB version 8 while F-11+ (F-10?) uses version 9.
319       # Using db_dump and db_load would no longer make it mock compatible.
320       $rpmbuild.=q{ --dbpath $PWD --nodeps};
321     }
322
323     my $distrodirbase=$distro;
324     $distrodirbase.="-$target" if $target;
325     my $distrodir="$dir/$distrodirbase";
326     newdir $distrodir;
327     $log="$distrodir/log";
328     my $out="$distrodir/out";
329     newdir $out;
330
331     if ($parallel) {
332       my $pid=fork();
333       die if !defined $pid;
334       if ($pid) {
335         $child{$pid}=$distrodirbase;
336         next;
337       }
338     }
339
340     my $builddir="$distrodir/build";
341     newdir $builddir;
342
343     # Do not use mockrun as the rpm database may be in a different version.
344     spawn "rpm -r /var/lib/mock/$distro/root -qa|sort >$out/rpm-qa";
345
346     $::distro=$distro;
347     sub mockrun($)
348     {
349       my($c)=@_;
350
351       $c="export PATH=\"$path:\$PATH\"; $c" if $path;
352       $c="export MAKEFLAGS=\"-j\$[`getconf _NPROCESSORS_ONLN`*3/2]\"; $c";
353       $c="export http_proxy=http://127.0.0.1:3128/; $c";
354       $c="set -ex; cd $builddir; $c";
355       die "found ': $c" if $c=~/'/;
356       spawn "mockrun $::distro '$c'";
357     }
358
359     if ($gitbranch) {
360       die if !$gitroot;
361       die if !$gitrepo;
362       die if !$gitbranch;
363       spawn "cd $distrodir; git clone -b $gitbranch $gitroot/$gitrepo $component";
364       my $componentdir="$distrodir/$component";
365       -d $componentdir or die "Failed checkout to: $componentdir";
366       copyfiles $componentdir;
367       spawn "cd $componentdir; fedpkg verrel >$out/verrel";
368       my $glob="$componentdir/*.src.rpm";
369       @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
370       # No `spawn' as we could get:
371       # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
372       mockrun "cd $componentdir; fedpkg srpm";
373       my @srcrpm=(glob $glob);
374       @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
375       $srcrpm=$srcrpm[0];
376     }
377
378     if ($cvsbasedir) {
379       die if !$cvsroot;
380       die if !$cvsrepo;
381       die if !$cvsbasedir;
382       spawn "cd $distrodir; cvs -q -z3 -d $cvsroot co rpms/$cvsrepo/$cvsbasedir";
383       my $componentdir="$distrodir/rpms/$cvsrepo/$cvsbasedir";
384       -d $componentdir or die "Failed checkout to: $componentdir";
385       # Required for RHEL; Fedora does so automatically.
386       spawn "cd $componentdir/..; cvs -q -z3 -d $cvsroot co common";
387       # Workaround (RHEL-5?) curl which uses `Pragma: nocache' on $http_proxy.
388       subst sub { s{echo "curl }{$&-H 'Pragma: cache' }; },"$componentdir/../common/Makefile.common";
389       copyfiles $componentdir;
390       spawn "cd $componentdir; make verrel >$out/verrel";
391       my $glob="$componentdir/*.src.rpm";
392       @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
393       # No `spawn' as we could get:
394       # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
395       mockrun "cd $componentdir; make test-srpm";
396       my @srcrpm=(glob $glob);
397       @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
398       $srcrpm=$srcrpm[0];
399     }
400
401     if ($srcrpm) {
402       my $srcrpmbasename=$srcrpm;
403       $srcrpmbasename=~s{^.*/}{};
404       spawn "cp -p $srcrpm $builddir/$srcrpmbasename";
405
406       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"};
407       $rpmbuildlocal="$orphanripper $rpmbuildlocal" if $cvsrepo && $cvsrepo eq "glibc";
408       mockrun $rpmbuildlocal." --rebuild --with testsuite $srcrpmbasename";
409     }
410
411     my $baretestsuite;
412
413     if ($component=~/^(gdb|binutils)cvs$/) {
414       my $which=$1;
415       my $cvsmaster=$which eq "gdb" ? $gdbcvsmaster : $binutilscvsmaster;
416       if (-d $cvsmaster) {
417         spawn "cp -a $cvsmaster $builddir/src; cd $builddir/src; cvs update $cvsbranch";
418       } else {
419         spawn "cd $builddir; cvs -q -z3 -d :pserver:anoncvs:\@sourceware.org:/cvs/src co $cvsbranch $which";
420       }
421       spawn "cd $builddir/src; test -z \"\$(cvs update $cvsbranch)\"";
422       $baretestsuite="$builddir/src";
423     }
424
425     if ($component=~/^archer-/) {
426       spawn "git clone ".(!-d $archermaster ? "" : "--reference $archermaster")." git://sourceware.org/git/archer.git $builddir/$component";
427       spawn "cd $builddir/$component; git fetch";
428       spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
429       $baretestsuite="$builddir/$component";
430     }
431
432     if ($component=~m{^/home/}) {
433       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 || :";
434       $baretestsuite="$builddir/src";
435     }
436
437     if ($baretestsuite) {
438       for my $file (@file) {
439         my $target="$baretestsuite/$file";
440         if ($file=~m{[.](R?)patch$}) {
441           my $R=$1;
442           my $fileabs=$file;
443           $fileabs=$ENV{"PWD"}."/$fileabs" if $fileabs!~m{^/};
444           spawn "cd $baretestsuite; patch -${R}p1 <$fileabs";
445         } else {
446           -f $target or $file=~m{/testsuite/} or die "File $file does not exist at $target";
447           spawn "rm -f $target; cp -p $file $target";
448         }
449       }
450
451       my $errs12="errs12";
452       $errs12.=" -s" if $strip;
453       $errs12.=" --target=$target" if $target;
454       $errs12.=" $configure" if $configure;
455
456       if ($component eq "binutilscvs") {
457         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;};
458       } else {
459         my @check=($distro=~/-x86_64/ ? qw(-m64 -m32) : -m32);
460         @check=map("check//unix/$_",@check);
461         @check=map({($_,"$_/-fPIE/-pie");} @check) if $gdbcvspie;
462         # for i in ".join(" ",@check).";do $orphanripper make -k \$i || :;done
463         mockrun "cd $baretestsuite;"
464                 .(!$valgrind?"":' HAMMOCK_VALGRIND=1')
465                 ." $errs12"
466                 .(!$valgrind?"":' --without-python')    # FIXME: Fix valgrind --suppressions
467                 ."; cd gdb; ulimit -c unlimited; "
468                 .(!$gdbserver?"":'DEJAGNU=$HOME/src/runtest-gdbserver/site.exp ')
469                 .(!$valgrind?"":'DEJAGNU=$HOME/src/runtest-valgrind/site.exp ')
470                 ."$orphanripper make -k ".join(" ",@check)
471                 # Ensure serial run if FORCE_PARALLEL=1 is not present
472                 ." RUNTESTFLAGS=DUMMY=dummy"
473                 .(!$gdbserver?"":' RUNTESTFLAGS=--target_board=native-gdbserver')
474                 .(!$valgrind?"":' RUNTESTFLAGS=--target_board=valgrind')
475                 .(!$gdbindex?"":' RUNTESTFLAGS="CC_FOR_TARGET=/bin/sh\ $PWD/cc-with-index.sh\ gcc CXX_FOR_TARGET=/bin/sh\ $PWD/cc-with-index.sh\ g++"')
476                 .(!$dwarf?"":' RUNTESTFLAGS="CC_FOR_TARGET=gcc\ -gdwarf-'.$dwarf.'\ -g0 CXX_FOR_TARGET=g++\ -gdwarf-'.$dwarf.'\ -g0"')
477                 .(!$parallel?"":' FORCE_PARALLEL=1')
478                 ." || :; ".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;};
479       }
480       # gdbunpack does:
481       #         perl -i -pe 's{\Q'"$HOME"'\E/.*?/build/[^/]*/}{}g' "$base"/*
482       my $HOME=$ENV{"HOME"};
483       for my $file (glob("$out/*.sum"),glob("$out/*.log")) {
484         subst sub { s{\Q$HOME\E/.*?/build/[^/]*/}{}g; },$file;
485       }
486     } else {
487       die "internal error" if @target;
488     }
489
490     # Call gdbunpack only if no direct $out directory will be created.
491     # It is needed only for .src.rpm-built testsuites, no matter how .src.rpm
492     # got created.
493     my @testinlog;
494     if ($component=~/^(?:fedora|rhel)glibc$/) {
495       @testinlog=(qr/={20}TESTING DETAILS={17}/,qr/={20}PLT RELOCS END={18}/);
496     }
497     if (@testinlog) {
498       subst sub { s{^.*?\n($testinlog[0]\n.*\n$testinlog[1]\n).*$}{$1}s; },$log,$out;
499     } elsif ($cvsbasedir || $srcrpm) {
500       # Applies both to gdb and binutils.
501       spawn "mv $out $out.x; gdbunpack $log; mv $out.x/* $out/; rmdir $out.x";
502     }
503
504     if ($valgrind) {
505       for my $from (glob "$out/*.log") {
506         (my $to=$from).="filt";
507         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;
508       }
509     }
510
511     my $resultout="$resultdir/$id/$distrodirbase";
512     newdir $resultout;
513     $resultout.="/out";
514     newdir $resultout;
515     for my $fname (glob "$out/*") {
516       (my $base=$fname)=~s{^.*/}{};
517       my $d="$resultout/$base";
518       warn "+ link $fname $d\n";
519       link $fname,$d or warn $!;
520     }
521
522     exit 0 if $parallel;
523   }
524
525   print STDERR "waiting for ".scalar(keys(%child))." children, ".scalar(@distrouse)." distros to go...\n";
526   my $pid=wait();
527   next if $pid==-1 && $!==10; # 10==No child processes
528   die "wait()==-1: $!" if $pid==-1;
529   die "not found pid $pid" if !$child{$pid};
530   error "weird status $? for pid $pid: ".$child{$pid} if $?;
531   print STDERR "finished: $pid ".$child{$pid}."\n";
532   delete $child{$pid};
533 }
534 die if keys(%child);
535 die if @distrouse;
536
537 spawn "(set -e -o pipefail;cd $resultdir;tar cf - $id|xz -9e >$resultidxz;rm -rf $id)&","bare";
538
539 sub timestr($)
540 {
541   my($sec)=@_;
542   my $r="";
543
544   if ($sec>=60*60) {
545     $r.=int($sec/(60*60))."h";
546     $sec%=60*60;
547   }
548   if ($r || $sec>=60) {
549     $r.=int($sec/60)."m";
550     $sec%=60;
551   }
552   $r.=$sec."s";
553
554   return $r;
555 }
556
557 print STDERR "ID = $id | dir = $dir\n";
558 my $time=timestr(time()-$start);
559 print STDERR "total time=$time\n";
560 writefile "$dir/time","$time\n";
561 die "$error errors seen, aborted" if $error;
562 print STDERR "done\n";