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