rpmsafe: realpath fixes
[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 $sourcewaregdbgit="git://sourceware.org/git/binutils-gdb.git";
11 #my $sourcewaregdbgit="https://gitorious.org/gdb/gdb.git";
12 my $gdbgitmaster=$ENV{"HOME"}."/redhat/gdb-master";
13 my $fedoragitroot=q{git://pkgs.fedoraproject.org/rpms};
14 my $rhelgitroot=q{git://pkgs.devel.redhat.com/rpms};
15 my $sourcewaregit=q{git://pkgs.devel.redhat.com/rpms};
16 my $arch_i386=qr{(?:x86|i\d86|ia32)}io;
17 my $arch_x86_64=qr{(?:x8664|x86_64|em64t)}io;
18 my $resultdir=$ENV{"HOME"}."/.hammock-result";
19 my @arches=qw(i386 x86_64);
20 #$ENV{"CCACHE_DISABLE"}="1";delete $ENV{"CCACHE_NODISABLE"};
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 @prefixpath;
36 my @arch;
37 my $component;
38 my $srcrpm;
39 my @file;
40 my @target;
41 my $configure;
42 my $branch;
43 # FIXME: Connect make paralellization to the children.
44 my $distrojobs;
45 my $gdbgitpie;
46 my $strip;
47 # FIXME: 20100911servpatched-f14:
48 # readchar: Connection reset by peer
49 # Remote side has terminated connection.  GDBserver will reopen the connection.
50 # Can't bind address: Address already in use.
51 # <last 2 lines repearing>
52 my $gdbserver;
53 my $valgrind;
54 my $bfd32;
55 my $gdbindex;
56 my $dwz;
57 my $dwarf;
58 # Use --dwarf=X0 for: --dwarf=X -fno-debug-types-section
59 # Use --dwarf=X1 for: --dwarf=X    -fdebug-types-section
60 my $optimg;
61 my $stabs;
62 my $debug_types_section;
63 my $orphanripper=1;
64 my $options;
65 my $asan;
66 die if !GetOptions(
67   "i|userid=s"=>\$userid,
68     "force"=>\$force,
69     "serial"=>sub { $parallel=0; },
70     "parallel"=>sub { $parallel=1; },
71   "d|distro=s{,}"=>\@distro,
72     "cd|componentdistro=s{,}"=>\@componentdistro,
73   "p|path=s{,}"=>\@path,
74   "P|prefixpath=s{,}"=>\@prefixpath,
75   "a|arch=s{,}"=>\@arch,
76   "c|component=s"=>\$component,
77   "s|srcrpm=s"=>\$srcrpm,
78     "file=s{,}"=>\@file,
79     "target=s{,}"=>\@target,
80   "D|distrojobs=s"=>\$distrojobs,
81     "configure=s"=>\$configure,
82     "branch=s"=>\$branch,
83     "gdbgitpie"=>\$gdbgitpie,
84     "strip"=>\$strip,
85     "gdbserver"=>\$gdbserver,
86     "valgrind"=>\$valgrind,
87     "bfd32"=>\$bfd32,
88     "gdbindex"=>\$gdbindex,
89     "dwz"=>\$dwz,
90     "dwarf=i"=>\$dwarf,
91     "optimg"=>\$optimg,
92     "stabs=i"=>\$stabs,
93     "orphanripper!"=>\$orphanripper,
94     "options=s"=>\$options,
95     "asan"=>\$asan,
96 );
97 $component and ($component=~m{^(?:(?:fedora|rhel)(?:gdb|binutils|glibc)|gdbgit|/home/.*)$} or die "-c|--component required to be: fedoragdb|rhelgdb|fedorabinutils|rhelbinutils|fedoraglibc|rhelglibc|gdbgit|/home/*");
98 $component and $component=~m{^/home/} and (-f "$component/gdb/gdbtypes.c" or die "$component/gdb/gdbtypes.c not found");
99 $component and $srcrpm and die "-c|--component excludes -s|--srcrpm";
100 $component or $srcrpm or die "-c|--component or -s|--srcrpm required";
101 $component||="";  # Make `eq' not complaining.
102 if ($component ne "gdbgit") {
103 #  $gitbranch=(!$branch?"":"-r $branch"); # "-A" is broken with new sourceware.org
104   die "--branch currently unsupported for non-GIT sources" if $branch;
105 }
106 $branch||="master";
107 !$gdbgitpie or $component eq "gdbgit" or die "--gdbgitpie requires -c gdbgit";
108 @target and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--target is available only for baretestsuite modes";
109 $strip and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--strip is available only for baretestsuite modes";
110 $options and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--options is available only for baretestsuite modes";
111 $gdbserver and $component!~m{^(?:gdbgit|/home/.*)$} and die "--gdbserver is available only for gdbgit||/home/*";
112 $valgrind and $component!~m{^(?:gdbgit|/home/.*)$} and die "--valgrind is available only for gdbgit||/home/*";
113 $asan and $component!~m{^(?:gdbgit|/home/.*)$} and die "--asan is available only for gdbgit||/home/*";
114 $gdbserver and $valgrind and die "--gdbserver and --valgrind are mutually exclusive";
115 ($gdbserver || $valgrind) and ($gdbindex || $dwz) and die "--gdbserver|--valgrind and --gdbindex|--dwz are mutually exclusive";
116 do { $debug_types_section=$dwarf%10; $dwarf=int($dwarf/10); } if ($dwarf||0)>=40;
117 !defined $dwarf or ($dwarf>=2 && $dwarf<=5) or die "--dwarf requires DWARF version number";
118 !defined $stabs or ($stabs>=0 && $stabs<=2) or die "--stabs is 0=off or 1=-gstabs or 2=-gstabs+";
119 ($gdbserver || $valgrind || $gdbindex || $dwz) and ($dwarf || $stabs) and die "--gdbserver|--valgrind|--gdbindex and --dwarf|--stabs are mutually exclusive";
120 $orphanripper=($orphanripper?"orphanripper":"");
121 my %target;
122 do { error "Duplicate target: $_\n" if $target{$_}++; } for @target;
123 @arch="x86_64" if @target&&!@arch;
124 for my $file (@file) {
125   -f $file and -r $file or error "-f|--file $file not readable: $!";
126 }
127 ###push @file,"/home/jkratoch/redhat/fedora/gdb/master/gdb-index-assert.patch" if $component eq "gdbgit";
128 ###push @file,"/home/jkratoch/redhat/fedora/gdb/master/gdb-dejagnu-go.patch"   if $component eq "gdbgit";
129 ###push @file,"/home/jkratoch/t/signed32.patch"   if $component eq "gdbgit";
130 $distrojobs=(@target?1:2) if !defined $distrojobs;
131 ###$distrojobs=1; # FIXME
132 $distrojobs=~/^\d+$/ or die "-D|distrojobs must be a number: $distrojobs";
133 $distrojobs>=1 or die "-D|distrojobs must be positive: $distrojobs";
134 error "Excessive arguments: @ARGV" if @ARGV;
135 @arch=@arches if !@arch;
136 my $path=join(":",@path) if @path;
137 @componentdistro and @componentdistro!=@distro and die "--cd|--componentdistro must have the same elements count as -d|--distro";
138
139 #FIXME:push @file,"/home/jkratoch/t/gdbserverasyncnonstop.patch" if $component eq "gdbgit";
140 push @file,"/home/jkratoch/t/watchpointfork2.patch" if $component eq "gdbgit";
141 #push @file,"/home/jkratoch/t/or1k-m32.patch" if $component eq "gdbgit";
142 #push @file,"/home/jkratoch/t/gdb-breakpointchanged.patch" if $component eq "gdbgit";
143
144 sub distro_normalize($;$)
145 {
146   my($name,$force)=@_;
147   local $_=$name;
148
149   s{^/var/lib/mock/+}{};
150   s{/+$}{};
151   s/^.*$/\L$&/s;
152   s/^(?:devel|rawhide)\b/fedora-rawhide/;
153   s/^(?:epel|centos)-?(\d)/epel-$1/;
154   s/^(?:rhel)-?(\d)/rhel-$1/;
155   s/^(?:f|fedora)-?(\d)/fedora-$1/;
156   my @archuse;
157   @archuse="" if -d "/var/lib/mock/$_";
158   @archuse="i386" if s/-$arch_i386$//o;
159   @archuse="x86_64" if s/-$arch_x86_64$//o;
160
161   for my $arch (@archuse?@archuse:@arch) {
162     my $dir="/var/lib/mock/$_".(!$arch?"":"-$arch");
163     $force or -d $dir or error "No distro: $dir";
164   }
165
166   return ($_,@archuse);
167 }
168
169 # epel-\d-i386|fedora-\d-i386|fedora-rawhide-i386
170 my @distrouse;
171 for my $distroi (0..$#distro) {
172   my $distro=$distro[$distroi];
173   my $componentdistro=$componentdistro[$distroi];
174   my @archuse;
175   if ($componentdistro) {
176     my $force=($componentdistro=~s/!$//);
177     ($componentdistro,@archuse)=distro_normalize $componentdistro,$force;
178     @archuse and die "--cd|--componentdistro must have no arch: ".join(" ",@archuse);
179   }
180   ($distro,@archuse)=distro_normalize $distro;
181   $componentdistro||=$distro;
182   @archuse=@arch if !@archuse;
183   for my $archuse (@archuse) {
184     for my $target (@target?@target:undef()) {
185       push @distrouse,{"distro"=>$distro.(!$archuse?"":"-$archuse"),"componentdistro"=>$componentdistro,"target"=>$target};
186     }
187   }
188 }
189
190 # "-p", "mayexist"
191 sub newdir($;@)
192 {
193   my($dir,@opt)=@_;
194
195   my %opt=map(($_=>1),@opt);
196   warn "+ mkdir".($opt{"-p"} ? " -p" : "")." $dir\n";
197   mkdir $dir or ($opt{"mayexist"} && $!{EEXIST}) or die "mkdir $dir: $!";
198 }
199
200 my $log;
201 # "bare"
202 sub spawn($;%)
203 {
204   my($cmd,@opt)=@_;
205
206   my %opt=map(($_=>1),@opt);
207   my $ok;
208   if (!$opt{"bare"}) {
209     $cmd="set -ex; $cmd";
210     $ok="$log.ok" if $log;
211     $cmd="($cmd; touch $ok) 2>&1|tee -a $log; test -f $ok" if $log;
212     unlink $ok if $ok;
213   } else {
214     warn "+ $cmd\n";
215   }
216   # warn "+ $cmd\n";
217   system $cmd and die "$cmd: $!";
218   unlink $ok if $ok;
219 }
220
221 my $basedir=$ENV{"HOME"}."/hammock";
222 newdir $basedir,"mayexist";
223 my $idbase=strftime("%Y%m%d",localtime());
224 my $id;
225 my $dir;
226 for my $seq (defined $userid ? $userid : (0..99)) {
227   $id=$idbase.(defined $userid ? $seq : sprintf("%02d",$seq));
228   $dir="$basedir/$id";
229   last if ! -e $dir;
230 }
231 spawn "chmod -R u+w $dir; rm -rf $dir" if -d $dir && $force && defined $userid;
232 error "Directory not free: $dir" if !$id || !$dir || -e $dir;
233 print STDERR "ID = $id | dir = $dir\n";
234 error "No distros specified" if !@distrouse;
235 die "$error errors seen, aborted" if $error;
236
237 sub writefile
238 {
239   my($fname,$content)=@_;
240
241   local *F;
242   open F,">$fname" or die $fname;
243   print F $content or die $fname;
244   close F or die $fname;
245 }
246
247 sub readfile
248 {
249   my($fname)=@_;
250
251   local *F;
252   open F,"$fname" or die $fname;
253   local $/=undef();
254   defined(my $r=<F>) or die $fname;
255   close F or die $fname;
256   return $r;
257 }
258
259 sub ln($$)
260 {
261   my($old,$new)=@_;
262   link $old,$new or spawn "cp -p '$old' '$new'";
263 }
264
265 # /etc/cgconfig.conf
266 spawn "cgclassify -g '*':hammock $$ || :";
267
268 #spawn "renice +19 -p $$";
269 spawn "renice +5 -p $$||:";
270 spawn "ionice -c3 -p $$";
271 newdir $dir;
272 $log="$dir/log";
273 my $resultid="$resultdir/$id";
274 my $resultidxz="$resultid.tar.xz";
275 newdir $resultdir,"mayexist";
276 spawn "rm -rf $resultid" if -d $resultid && $force;
277 newdir $resultid;
278 unlink $resultidxz or $!{ENOENT} or die "unlink $resultidxz: $!";
279 spawn "uname -r >$dir/kernel";
280 my %dump=(
281   "path"=>$path,
282   "prefixpath"=>join(":",@prefixpath),
283   "component"=>$component,
284   "branch"=>$branch,
285   "srcrpm"=>$srcrpm,
286   "file"=>join("\n",@file),
287   "configure"=>$configure,
288   "gdbgitpie"=>$gdbgitpie,
289   "gdbserver"=>$gdbserver,
290   "valgrind"=>$valgrind,
291   "bfd32"=>$bfd32,
292   "gdbindex"=>$gdbindex,
293   "dwz"=>$dwz,
294   "dwarf"=>$dwarf,
295   "optimg"=>$optimg,
296   "stabs"=>$stabs,
297   "debug_types_section"=>$debug_types_section,
298   "orphanripper"=>$orphanripper,
299   "options"=>$options,
300 );
301 while (my($name,$val)=each(%dump)) {
302   next if !$val;
303   writefile "$dir/$name","$val\n";
304   ln "$dir/$name","$resultid/$name";
305 }
306 for my $file (@file) {
307   newdir "$dir/file.d","mayexist";
308   (my $base=$file)=~s{^.*/}{};
309   my $d="$dir/file.d/$base";
310   ln $file,$d;
311   newdir "$resultid/file.d","mayexist";
312   ln $d,"$resultid/file.d/$base";
313 }
314
315 sub subst
316 {
317   my($sub,$in,$out)=@_;
318
319   $out||=$in;
320
321   local *F;
322   open F,$in or die $in;
323   local $_=do { local $/; <F>; } or die $in;
324   close F or die $in;
325
326   &{$sub}() or die $_."\nError substituting $in";
327
328   writefile $out,$_;
329 }
330
331 sub copyfiles($)
332 {
333   my($targetdir)=@_;
334
335   for my $file (@file) {
336     my $filebase=$file;
337     $filebase=~s{^.*/}{};
338     my $target="$targetdir/$filebase";
339     # Some *.patch files may be new.
340     # -f $target or die "File $file does not exist at $target";
341     spawn "rm -f $target; cp -p $file $target";
342   }
343 }
344
345 # PID->distro
346 my %child;
347 while (@distrouse || keys(%child)) {
348   while (keys(%child)<$distrojobs && @distrouse) {
349     my $distrouse=shift @distrouse;
350     my $distro=$distrouse->{"distro"};
351     my $componentdistro=$distrouse->{"componentdistro"};
352     my $target=$distrouse->{"target"};
353     my $rpmbuild="rpmbuild --with buildisa";
354
355     my $gitbranch;
356     my $gitpkg;
357     my $gitroot;
358     my $gitrepo;
359     if ($component=~/^fedora(.*)$/) {
360       $gitrepo=$1;
361       $gitbranch="f$1" if $componentdistro=~/^fedora-(\d+)/;
362       $gitbranch="master" if $componentdistro=~/^fedora-rawhide/;
363       die "$component vs. $componentdistro" if !$gitbranch;
364       $gitroot=$fedoragitroot;
365       $gitpkg="fedpkg";
366     }
367     if ($component=~/^rhel(.*)$/) {
368       $gitrepo=$1;
369       $gitbranch="auto";
370       $gitroot=$rhelgitroot;
371       $gitpkg="https_proxy= rhpkg";
372       #$gitpkg="https_proxy= fedpkg --dist master";
373       # EPEL still uses Berkeley DB version 8 while F-11+ (F-10?) uses version 9.
374       # Using db_dump and db_load would no longer make it mock compatible.
375       $rpmbuild.=q{ --dbpath $PWD --nodeps};
376     }
377
378     my $distrodirbase=$distro;
379     $distrodirbase.="-$target" if $target;
380     my $distrodir="$dir/$distrodirbase";
381     newdir $distrodir;
382     $log="$distrodir/log";
383     my $out="$distrodir/out";
384     newdir $out;
385
386     if ($parallel) {
387       my $pid=fork();
388       die if !defined $pid;
389       if ($pid) {
390         $child{$pid}=$distrodirbase;
391         next;
392       }
393     }
394
395     my $builddir="$distrodir/build";
396     newdir $builddir;
397
398     # Do not use mockrun as the rpm database may be in a different version.
399     spawn "rpm -r /var/lib/mock/$distro/root -qa|sort >$out/rpm-qa";
400
401     $::distro=$distro;
402     sub mockrun($)
403     {
404       my($c)=@_;
405
406       $c="export PATH=\"$path:\$PATH\"; $c" if $path;
407       for my $prefixpath (@prefixpath) {
408         $c="export PATH=\"$prefixpath/bin:\$PATH\"; $c";
409         $c="export LD_LIBRARY_PATH=\"$prefixpath/lib64:$prefixpath/lib\${LD_LIBRARY_PATH:+:\$LD_LIBRARY_PATH}\"; $c";
410       }
411       $c="export PATH=\"\$HOME/bin:\$PATH\"; $c";
412       # $c="export MAKEFLAGS=\"-j\$[`getconf _NPROCESSORS_ONLN`*3/2]\"; $c";
413       # gdbgit: 16=6m5s 32=5m49s(seen OOM) 64=5m42s
414       $c="export MAKEFLAGS=\"-j24\"; $c";
415       $c="export http_proxy=http://127.0.0.1:3128/; $c";
416       $c="set -ex; cd $builddir; $c";
417       die "found ': $c" if $c=~/'/;
418       spawn "mockrun $::distro '$c'";
419     }
420
421     if ($gitbranch) {
422       die if !$gitroot;
423       die if !$gitrepo;
424       die if !$gitbranch;
425       die if !$gitpkg;
426       spawn "cd $distrodir; git clone ".($gitbranch eq "auto"?"":"-b $gitbranch")." $gitroot/$gitrepo $component";
427       my $componentdir="$distrodir/$component";
428       -d $componentdir or die "Failed checkout to: $componentdir";
429       if ($gitbranch eq "auto") {
430         $componentdistro=~/^(?:rhel|epel)-(\d+)$/ or die $componentdistro;
431         my $major=$1;
432         my @l=grep { m{^\s*origin/rhel-$major\.\d+\s*$} } split /\n/,readfile "cd $componentdir; git branch -r |";
433         sub minor
434         {
435           local $_=$_[0];
436           s{^\s*origin/rhel-\d+\.(\d+)\s*$}{$1} or die;
437           return $_;
438         }
439         @l=sort { minor($b) <=> minor($a); } @l;
440         $gitbranch=($l[0]=~m{^\s*origin/(.*?)\s*$})[0] or die;
441         spawn "cd $componentdir; git checkout $gitbranch";
442       }
443       copyfiles $componentdir;
444       spawn "cd $componentdir; $gitpkg verrel >$out/verrel";
445       my $glob="$componentdir/*.src.rpm";
446       @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
447       # No `spawn' as we could get:
448       # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
449       mockrun "cd $componentdir; $gitpkg srpm";
450       my @srcrpm=(glob $glob);
451       @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
452       $srcrpm=$srcrpm[0];
453     }
454
455     if ($srcrpm) {
456       my $srcrpmbasename=$srcrpm;
457       $srcrpmbasename=~s{^.*/}{};
458       spawn "cp -p $srcrpm $builddir/$srcrpmbasename";
459
460       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"};
461       # $rpmbuildlocal="$orphanripper $rpmbuildlocal" if $gitrepo && $gitrepo eq "glibc";
462       mockrun $rpmbuildlocal." --rebuild --with testsuite $srcrpmbasename";
463     }
464
465     my $baretestsuite;
466
467     if ($component eq "gdbgit") {
468       spawn "git clone ".(!-d $gdbgitmaster ? "" : "--reference $gdbgitmaster")." -b $branch $sourcewaregdbgit $builddir/$component";
469       #spawn "cd $builddir/$component; git fetch";
470       spawn "cd $builddir/$component; git pull";
471 ###      spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
472       $baretestsuite="$builddir/$component";
473     }
474
475     if ($component=~m{^/home/}) {
476       # 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 || :";
477       spawn "git clone $component $builddir/src; cd $builddir/src";
478       $baretestsuite="$builddir/src";
479     }
480
481     if ($baretestsuite) {
482       for my $file (@file) {
483         my $target="$baretestsuite/$file";
484         if ($file=~m{[.](R?)patch$}) {
485           my $R=$1;
486           my $fileabs=$file;
487           $fileabs=$ENV{"PWD"}."/$fileabs" if $fileabs!~m{^/};
488           spawn "cd $baretestsuite; patch -${R}p1 <$fileabs";
489         } else {
490           -f $target or $file=~m{/testsuite/} or die "File $file does not exist at $target";
491           spawn "rm -f $target; cp -p $file $target";
492         }
493         spawn "rm -f $baretestsuite/gdb/testsuite/dg-extract-results.py"; ### Fedora gdb-no-dg-extract-results-py.patch
494       }
495
496       my $errs12="errs12";
497       $errs12.=" --noasan" if !$asan;
498       $errs12.=" -s" if $strip;
499       $errs12.=" --target=$target" if $target;
500       #$errs12.=" --disable-binutils --disable-gas --disable-gold --disable-gprof --disable-ld";
501       #$errs12.=" --binutils" if $gdbindex; # for objcopy but that is needed only for cross-targets
502       $errs12.=" $options" if $options;
503       $errs12.=" $configure" if $configure;
504
505 #      if ($component eq "binutilsgit") {
506 #       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;};
507 #      }
508       {
509         if ($valgrind) {
510           # FIXME
511           do { unlink $_ or warn "$_: $!"; } for "$baretestsuite/gdb/testsuite/gdb.base/break-interp.exp";
512         }
513         my @check=($distro=~/-x86_64/ ? qw(-m64 -m32) : -m32);
514         @check=map("check//unix/$_",@check);
515         @check=map({($_,"$_/-fPIE/-pie");} @check) if $gdbgitpie;
516         my %flags=("CC_FOR_TARGET"   =>"gcc",
517                    "CXX_FOR_TARGET"  =>"g++",
518                    "GO_FOR_TARGET"   =>"gccgo",
519                    "GO_LD_FOR_TARGET"=>"gccgo",
520                    );
521         # for i in ".join(" ",@check).";do $orphanripper make -k \$i || :;done
522         sub runtestcc($)
523         {
524           my($q0)=@_;
525           (my $q1=$q0)=~s/ /\\ /g;
526           (my $q2=$q1)=~s/ /\\ /g;
527           return ' RUNTESTFLAGS="'.join(' ',map($_.'='.$flags{$_}.'\ '.$q1,keys(%flags))).' GNATMAKE_FOR_TARGET=gnatmake\ --GCC=gcc\\ '.$q2.'"';
528         }
529         die "FIXME" if $valgrind;
530           # .(!$valgrind?"":' RUNTESTFLAGS=--target_board=valgrind')
531           # .(!$valgrind?"":' HAMMOCK_VALGRIND=1')
532           # .(!$valgrind?"":' --without-python')        # FIXME: Fix valgrind --suppressions
533         if ($gdbindex||$dwz) {
534           for my $key (keys(%flags)) {
535             writefile "$baretestsuite/hammock-$key",''
536               .' GDB="'.$baretestsuite.'/gdb/gdb -data-directory '.$baretestsuite.'/gdb/data-directory"'
537               .' GDB_ADD_INDEX='.$baretestsuite.'/gdb/contrib/gdb-add-index.sh'
538               .' '.$baretestsuite.'/gdb/contrib/cc-with-tweaks.sh '
539                 .(!$gdbindex?'':' -i')
540                 .(!$dwz?'':' -m')
541                 .' '.$flags{$key}.' "$@"'
542               ."\n";
543           }
544         }
545         mockrun "cd $baretestsuite;"
546                 ." $errs12"
547                 .(!$bfd32?"":' --disable-64-bit-bfd')
548                 ."; cd gdb; ulimit -c unlimited; DEJAGNU=$baretestsuite/site.exp "
549                 ."$orphanripper make -k ".join(" ",@check)
550                 # Ensure serial run if FORCE_PARALLEL=1 is not present
551                 ." RUNTESTFLAGS=DUMMY=dummy"
552                 .(!$gdbserver?"":' RUNTESTFLAGS=--target_board=native-gdbserver')
553                 # Missing GNATMAKE_FOR_TARGET!
554                 .(!($gdbindex||$dwz)?"":' RUNTESTFLAGS="'.join(' ',map("$_=/bin/sh\\ $baretestsuite/hammock-$_",keys(%flags))).'"')
555                 .(!$dwarf?"":runtestcc "-gdwarf-$dwarf".(!defined $debug_types_section?"":'\ '.($debug_types_section?"-fdebug-types-section":"-fno-debug-types-section"))." -g0")
556                 .(!$optimg?"":runtestcc "-Og -g0")
557                 .(!$stabs?"":runtestcc(($stabs==1?"-gstabs":"-gstabs+")." -g0"))
558                 .(!$parallel?"":' FORCE_PARALLEL=1')
559                 ." || :; ".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;};
560       }
561       # gdbunpack does:
562       #         perl -i -pe 's{\Q'"$HOME"'\E/.*?/build/[^/]*/}{}g' "$base"/*
563       my $HOME=$ENV{"HOME"};
564       for my $file (glob("$out/*.sum"),glob("$out/*.log")) {
565         subst sub { s{\Q$HOME\E/.*?/build/[^/]*/}{}g; },$file;
566       }
567     } else {
568       die "internal error" if @target;
569     }
570
571     # Call gdbunpack only if no direct $out directory will be created.
572     # It is needed only for .src.rpm-built testsuites, no matter how .src.rpm
573     # got created.
574     my @testinlog;
575     if ($component=~/^(?:fedora|rhel)glibc$/) {
576       @testinlog=(qr/={20}TESTING DETAILS={17}/,qr/={20}PLT RELOCS END={18}/);
577     }
578     if (@testinlog) {
579       subst sub { s{^.*?\n($testinlog[0]\n.*\n$testinlog[1]\n).*$}{$1}s; },$log,$out;
580     } elsif ($srcrpm) {
581       # Applies both to gdb and binutils.
582       spawn "mv $out $out.x; gdbunpack $log; mv $out.x/* $out/; rmdir $out.x";
583     }
584
585     if ($valgrind) {
586       for my $from (glob "$out/*.log") {
587         (my $to=$from).="filt";
588         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;
589       }
590     }
591
592     my $resultout="$resultdir/$id/$distrodirbase";
593     newdir $resultout;
594     $resultout.="/out";
595     newdir $resultout;
596     for my $fname (glob "$out/*") {
597       (my $base=$fname)=~s{^.*/}{};
598       my $d="$resultout/$base";
599       warn "+ link $fname $d\n";
600       ln $fname,$d;
601     }
602
603     exit 0 if $parallel;
604   }
605
606   print STDERR "waiting for ".scalar(keys(%child))." children, ".scalar(@distrouse)." distros to go...\n";
607   my $pid=wait();
608   next if $pid==-1 && $!==10; # 10==No child processes
609   die "wait()==-1: $!" if $pid==-1;
610   die "not found pid $pid" if !$child{$pid};
611   error "weird status $? for pid $pid: ".$child{$pid} if $?;
612   print STDERR "finished: $pid ".$child{$pid}."\n";
613   delete $child{$pid};
614 }
615 die if keys(%child);
616 die if @distrouse;
617
618 spawn "(set -e -o pipefail;cd $resultdir;tar cf - $id|xz -9e >$resultidxz;rm -rf $id)&","bare";
619
620 sub timestr($)
621 {
622   my($sec)=@_;
623   my $r="";
624
625   if ($sec>=60*60) {
626     $r.=int($sec/(60*60))."h";
627     $sec%=60*60;
628   }
629   if ($r || $sec>=60) {
630     $r.=int($sec/60)."m";
631     $sec%=60;
632   }
633   $r.=$sec."s";
634
635   return $r;
636 }
637
638 print STDERR "ID = $id | dir = $dir\n";
639 my $time=timestr(time()-$start);
640 print STDERR "total time=$time\n";
641 writefile "$dir/time","$time\n";
642 die "$error errors seen, aborted" if $error;
643 print STDERR "done\n";