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