6 use POSIX qw(&strftime);
7 use Getopt::Long qw(:config no_ignore_case);
11 my $gdbcvsmaster=$ENV{"HOME"}."/redhat/gdb-cvs-master";
12 my $binutilscvsmaster=$ENV{"HOME"}."/redhat/binutils-cvs-master";
13 my $archermaster=$ENV{"HOME"}."/redhat/archer-master";
14 my $fedoragitroot=q{git://pkgs.fedoraproject.org};
15 #Unknown host cvs.devel.redhat.com.
16 #my $rhelcvsroot=q{:pserver:anonymous:@cvs.devel.redhat.com:/cvs/dist};
17 my $rhelcvsroot=q{:ext:cvs.devel.redhat.com:/cvs/dist};
18 my $arch_i386=qr{(?:x86|i\d86|ia32)}io;
19 my $arch_x86_64=qr{(?:x8664|x86_64|em64t)}io;
20 my $resultdir=$ENV{"HOME"}."/.hammock-result";
21 my @arches=qw(i386 x86_64);
32 my $parallel=9; # 1 or 2 or 3
43 # FIXME: Connect make paralellization to the children.
48 "i|userid=s"=>\$userid,
50 "1|serial"=>sub { $parallel=1; },
51 "2|standard"=>sub { $parallel=2; },
52 "3|parallel"=>sub { $parallel=3; },
53 "d|distro=s{,}"=>\@distro,
54 "cd|componentdistro=s{,}"=>\@componentdistro,
55 "p|path=s{,}"=>\@path,
56 "a|arch=s{,}"=>\@arch,
57 "c|component=s"=>\$component,
58 "s|srcrpm=s"=>\$srcrpm,
60 "target=s{,}"=>\@target,
61 "D|distrojobs=s"=>\$distrojobs,
62 "configure=s"=>\$configure,
64 "gdbcvspie"=>\$gdbcvspie,
67 $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/*");
68 $component and $component=~m{^/home/} and (-f "$component/gdb/gdbtypes.c" or die "$component/gdb/gdbtypes.c not found");
69 $component and $srcrpm and die "-c|--component excludes -s|--srcrpm";
70 $component or $srcrpm or die "-c|--component or -s|--srcrpm required";
71 $component||=""; # Make `eq' not complaining.
73 if ($component=~/^(gdb|binutils)cvs$/) {
74 $cvsbranch=(!$branch?"-A":"-r $branch");
76 die "--branch currently unsupported for non-CVS sources" if $branch;
78 !$gdbcvspie or $component eq "gdbcvs" or die "--gdbcvspie requires -c gdbcvs";
79 @target and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--target is available only for baretestsuite modes";
80 $strip and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--strip is available only for baretestsuite modes";
82 do { error "Duplicate target: $_\n" if $target{$_}++; } for @target;
83 @arch="x86_64" if @target&&!@arch;
84 for my $file (@file) {
85 -f $file and -r $file or error "-f|--file $file not readable: $!";
87 $distrojobs=(@target?1:2) if !defined $distrojobs;
88 $distrojobs=~/^\d+$/ or die "-D|distrojobs must be a number: $distrojobs";
89 $distrojobs>=1 or die "-D|distrojobs must be positive: $distrojobs";
90 # User may want to modify ASAP her files submitted for the test.
91 my $will_copy=@file || $component=~m{^/home/};
92 $parallel||=$will_copy ? 2 : 1;
93 error "Excessive arguments: @ARGV" if @ARGV;
94 @arch=@arches if !@arch;
95 my $path=join(":",@path) if @path;
96 @componentdistro and @componentdistro!=@distro and die "--cd|--componentdistro must have the same elements count as -d|--distro";
98 sub distro_normalize($;$)
103 s{^/var/lib/mock/+}{};
106 s/^(?:devel|rawhide)\b/fedora-rawhide/;
107 s/^(?:epel|centos)-?(\d)/epel-$1/;
108 s/^(?:rhel)-?(\d)/rhel-$1/;
109 s/^(?:f|fedora)-?(\d)/fedora-$1/;
111 @archuse="" if -d "/var/lib/mock/$_";
112 @archuse="i386" if s/-$arch_i386$//o;
113 @archuse="x86_64" if s/-$arch_x86_64$//o;
115 for my $arch (@archuse?@archuse:@arch) {
116 my $dir="/var/lib/mock/$_".(!$arch?"":"-$arch");
117 $force or -d $dir or error "No distro: $dir";
120 return ($_,@archuse);
123 # epel-\d-i386|fedora-\d-i386|fedora-rawhide-i386
125 for my $distroi (0..$#distro) {
126 my $distro=$distro[$distroi];
127 my $componentdistro=$componentdistro[$distroi];
129 if ($componentdistro) {
130 my $force=($componentdistro=~s/!$//);
131 ($componentdistro,@archuse)=distro_normalize $componentdistro,$force;
132 @archuse and die "--cd|--componentdistro must have no arch: ".join(" ",@archuse);
134 ($distro,@archuse)=distro_normalize $distro;
135 $componentdistro||=$distro;
136 @archuse=@arch if !@archuse;
137 for my $archuse (@archuse) {
138 for my $target (@target?@target:undef()) {
139 push @distrouse,{"distro"=>$distro.(!$archuse?"":"-$archuse"),"componentdistro"=>$componentdistro,"target"=>$target};
149 my %opt=map(($_=>1),@opt);
150 warn "+ mkdir".($opt{"-p"} ? " -p" : "")." $dir\n";
151 mkdir $dir or ($opt{"mayexist"} && $!{EEXIST}) or die "mkdir $dir: $!";
160 my %opt=map(($_=>1),@opt);
163 $cmd="set -ex; $cmd";
164 $ok="$log.ok" if $log;
165 $cmd="($cmd; touch $ok) 2>&1|tee -a $log; test -f $ok" if $log;
171 system $cmd and die "$cmd: $!";
175 my $basedir=$ENV{"HOME"}."/hammock";
176 newdir $basedir,"mayexist";
177 my $idbase=strftime("%Y%m%d",localtime());
180 for my $seq (defined $userid ? $userid : (0..99)) {
181 $id=$idbase.(defined $userid ? $seq : sprintf("%02d",$seq));
185 spawn "chmod -R u+w $dir; rm -rf $dir" if -d $dir && $force && defined $userid;
186 error "Directory not free: $dir" if !$id || !$dir || -e $dir;
187 print STDERR "ID = $id | dir = $dir\n";
188 error "No distros specified" if !@distrouse;
189 die "$error errors seen, aborted" if $error;
193 my($fname,$content)=@_;
196 open F,">$fname" or die $fname;
197 print F $content or die $fname;
198 close F or die $fname;
201 spawn "renice +19 -p $$";
202 spawn "ionice -c3 -p $$";
205 my $resultid="$resultdir/$id";
206 my $resultidxz="$resultid.tar.xz";
207 newdir $resultdir,"mayexist";
208 spawn "rm -rf $resultid" if -d $resultid && $force;
210 unlink $resultidxz or $!{ENOENT} or die "unlink $resultidxz: $!";
211 spawn "uname -r >$dir/kernel";
214 "component"=>$component,
217 "file"=>join("\n",@file),
218 "configure"=>$configure,
219 "gdbcvspie"=>$gdbcvspie,
221 while (my($name,$val)=each(%dump)) {
223 writefile "$dir/$name","$val\n";
224 link "$dir/$name","$resultid/$name" or warn "link $dir/$name $resultid/$name: $!";
226 for my $file (@file) {
227 newdir "$dir/file.d","mayexist";
228 (my $base=$file)=~s{^.*/}{};
229 my $d="$dir/file.d/$base";
230 link $file,$d or die "link $file $d: $!";
231 newdir "$resultid/file.d","mayexist";
232 link $d,"$resultid/file.d/$base" or warn "link $file $resultid/file.d/$base: $!";
237 my($sub,$in,$out)=@_;
242 open F,$in or die $in;
243 local $_=do { local $/; <F>; } or die $in;
246 &{$sub}() or die $_."\nError substituting $in";
255 for my $file (@file) {
257 $filebase=~s{^.*/}{};
258 my $target="$targetdir/$filebase";
259 # Some *.patch files may be new.
260 # -f $target or die "File $file does not exist at $target";
261 spawn "rm -f $target; cp -p $file $target";
267 while (@distrouse || keys(%child)) {
268 while (keys(%child)<$distrojobs && @distrouse) {
269 my $distrouse=shift @distrouse;
270 my $distro=$distrouse->{"distro"};
271 my $componentdistro=$distrouse->{"componentdistro"};
272 my $target=$distrouse->{"target"};
273 my $rpmbuild="rpmbuild";
281 if ($component=~/^fedora(.*)$/) {
283 $gitbranch="f$1/master" if $componentdistro=~/^fedora-(\d+)$/;
284 $gitbranch="master" if $componentdistro=~/^fedora-rawhide$/;
285 die "$component vs. $componentdistro" if !$gitbranch;
286 $gitroot=$fedoragitroot;
288 if ($component=~/^rhel(.*)$/) {
290 $cvsbasedir="RHEL-$1" if $componentdistro=~/^(?:epel|rhel)-(\d+)$/;
291 die "$component vs. $componentdistro" if !$cvsbasedir;
292 $cvsroot=$rhelcvsroot;
293 # EPEL still uses Berkeley DB version 8 while F-11+ (F-10?) uses version 9.
294 # Using db_dump and db_load would no longer make it mock compatible.
295 $rpmbuild.=q{ --dbpath $PWD --nodeps};
298 my $distrodirbase=$distro;
299 $distrodirbase.="-$target" if $target;
300 my $distrodir="$dir/$distrodirbase";
302 $log="$distrodir/log";
303 my $out="$distrodir/out";
308 die if !defined $pid;
310 $child{$pid}=$distrodirbase;
315 my $builddir="$distrodir/build";
318 # Do not use mockrun as the rpm database may be in a different version.
319 spawn "rpm -r /var/lib/mock/$distro/root -qa|sort >$out/rpm-qa";
326 $c="export PATH=\"$path:\$PATH\"; $c" if $path;
327 $c="export MAKEFLAGS=\"-j\$[`getconf _NPROCESSORS_ONLN`*3/2]\"; $c";
328 $c="export http_proxy=http://127.0.0.1:3128/; $c";
329 $c="set -ex; cd $builddir; $c";
330 die "found ': $c" if $c=~/'/;
331 spawn "mockrun $::distro '$c'";
338 spawn "cd $distrodir; git clone -b $gitbranch $gitroot/$gitrepo $component";
339 my $componentdir="$distrodir/$component";
340 -d $componentdir or die "Failed checkout to: $componentdir";
341 copyfiles $componentdir;
342 spawn "cd $componentdir; fedpkg verrel >$out/verrel";
343 my $glob="$componentdir/*.src.rpm";
344 @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
345 # No `spawn' as we could get:
346 # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
347 mockrun "cd $componentdir; fedpkg srpm";
348 my @srcrpm=(glob $glob);
349 @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
357 spawn "cd $distrodir; cvs -q -z3 -d $cvsroot co rpms/$cvsrepo/$cvsbasedir";
358 my $componentdir="$distrodir/rpms/$cvsrepo/$cvsbasedir";
359 -d $componentdir or die "Failed checkout to: $componentdir";
360 # Required for RHEL; Fedora does so automatically.
361 spawn "cd $componentdir/..; cvs -q -z3 -d $cvsroot co common";
362 # Workaround (RHEL-5?) curl which uses `Pragma: nocache' on $http_proxy.
363 subst sub { s{echo "curl }{$&-H 'Pragma: cache' }; },"$componentdir/../common/Makefile.common";
364 copyfiles $componentdir;
365 spawn "cd $componentdir; make verrel >$out/verrel";
366 my $glob="$componentdir/*.src.rpm";
367 @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
368 # No `spawn' as we could get:
369 # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
370 mockrun "cd $componentdir; make test-srpm";
371 my @srcrpm=(glob $glob);
372 @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
377 my $srcrpmbasename=$srcrpm;
378 $srcrpmbasename=~s{^.*/}{};
379 spawn "cp -p $srcrpm $builddir/$srcrpmbasename";
381 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"};
382 $rpmbuildlocal="orphanripper $rpmbuildlocal" if $cvsrepo && $cvsrepo eq "glibc";
383 mockrun $rpmbuildlocal." --rebuild --with testsuite".($parallel<2 ? "" : " --with parallel")." $srcrpmbasename";
388 if ($component=~/^(gdb|binutils)cvs$/) {
390 my $cvsmaster=$which eq "gdb" ? $gdbcvsmaster : $binutilscvsmaster;
392 spawn "cp -a $cvsmaster $builddir/src; cd $builddir/src; cvs update $cvsbranch";
394 spawn "cd $builddir; cvs -q -z3 -d :pserver:anoncvs:\@sourceware.org:/cvs/src co $cvsbranch $which";
396 spawn "cd $builddir/src; test -z \"\$(cvs update $cvsbranch)\"";
397 $baretestsuite="$builddir/src";
400 if ($component=~/^archer-/) {
401 spawn "git clone ".(!-d $archermaster ? "" : "--reference $archermaster")." git://sourceware.org/git/archer.git $builddir/$component";
402 spawn "cd $builddir/$component; git fetch";
403 spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
404 $baretestsuite="$builddir/$component";
407 if ($component=~m{^/home/}) {
408 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 || :";
409 $baretestsuite="$builddir/src";
412 if ($baretestsuite) {
413 for my $file (@file) {
414 my $target="$baretestsuite/$file";
415 if ($file=~m{[.](R?)patch$}) {
418 $fileabs=$ENV{"PWD"}."/$fileabs" if $fileabs!~m{^/};
419 spawn "cd $baretestsuite; patch -${R}p1 <$fileabs";
421 -f $target or $file=~m{/testsuite/} or die "File $file does not exist at $target";
422 spawn "rm -f $target; cp -p $file $target";
427 $errs12.=" -s" if $strip;
428 $errs12.=" --target=$target" if $target;
429 $errs12.=" $configure" if $configure;
431 if ($component eq "binutilscvs") {
432 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;};
434 my @check=($distro=~/-x86_64/ ? qw(-m64 -m32) : -m32);
435 @check=map("check//unix/$_",@check);
436 @check=map({($_,"$_/-fPIE/-pie");} @check) if $gdbcvspie;
437 # for i in ".join(" ",@check).";do orphanripper make -k \$i || :;done
438 mockrun "cd $baretestsuite; $errs12; cd gdb; ulimit -c unlimited; orphanripper make -k ".join(" ",@check)." || :; ".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;};
441 # perl -i -pe 's{\Q'"$HOME"'\E/.*?/build/[^/]*/}{}g' "$base"/*
442 my $HOME=$ENV{"HOME"};
443 for my $file (glob("$out/*.sum"),glob("$out/*.log")) {
444 subst sub { s{\Q$HOME\E/.*?/build/[^/]*/}{}g; },$file;
447 die "internal error" if @target;
450 # Call gdbunpack only if no direct $out directory will be created.
451 # It is needed only for .src.rpm-built testsuites, no matter how .src.rpm
454 if ($component=~/^(?:fedora|rhel)glibc$/) {
455 @testinlog=(qr/={20}TESTING DETAILS={17}/,qr/={20}PLT RELOCS END={18}/);
458 subst sub { s{^.*?\n($testinlog[0]\n.*\n$testinlog[1]\n).*$}{$1}s; },$log,$out;
459 } elsif ($cvsbasedir || $srcrpm) {
460 # Applies both to gdb and binutils.
461 spawn "mv $out $out.x; gdbunpack $log; mv $out.x/* $out/; rmdir $out.x";
464 my $resultout="$resultdir/$id/$distrodirbase";
468 for my $fname (glob "$out/*") {
469 (my $base=$fname)=~s{^.*/}{};
470 my $d="$resultout/$base";
471 warn "+ link $fname $d\n";
472 link $fname,$d or warn $!;
475 exit 0 if $parallel>1;
478 print STDERR "waiting for ".scalar(keys(%child))." children, ".scalar(@distrouse)." distros to go...\n";
480 next if $pid==-1 && $!==10; # 10==No child processes
481 die "wait()==-1: $!" if $pid==-1;
482 die "not found pid $pid" if !$child{$pid};
483 error "weird status $? for pid $pid: ".$child{$pid} if $?;
484 print STDERR "finished: $pid ".$child{$pid}."\n";
490 spawn "(set -e -o pipefail;cd $resultdir;tar cf - $id|xz -9e >$resultidxz;rm -rf $id)&","bare";
498 $r.=int($sec/(60*60))."h";
501 if ($r || $sec>=60) {
502 $r.=int($sec/60)."m";
510 print STDERR "ID = $id | dir = $dir\n";
511 my $time=timestr(time()-$start);
512 print STDERR "total time=$time\n";
513 writefile "$dir/time","$time\n";
514 die "$error errors seen, aborted" if $error;
515 print STDERR "done\n";