6 use POSIX qw(&strftime);
7 use Getopt::Long qw(:config no_ignore_case);
11 my $gdbcvsbare=$ENV{"HOME"}."/redhat/gdb-cvs-bare";
12 my $binutilscvsbare=$ENV{"HOME"}."/redhat/binutils-cvs-bare";
13 my $archermaster=$ENV{"HOME"}."/redhat/archer-master";
14 my $fedoracvsroot=q{:pserver:anonymous:@cvs.fedoraproject.org:/cvs/pkgs};
15 my $rhelcvsroot=q{:pserver:anonymous:@192.168.67.2:3401/cvs/dist};
16 my $arch_i386=qr{(?:x86|i\d86|ia32)}io;
17 my $arch_x86_64=qr{(?:x8664|x86_64|em64t)}io;
18 my @arches=qw(i386 x86_64);
29 my $parallel=9; # 1 or 2 or 3
39 # FIXME: Connect make paralellization to the children.
42 "i|userid=s"=>\$userid,
44 "1|serial"=>sub { $parallel=1; },
45 "2|standard"=>sub { $parallel=2; },
46 "3|parallel"=>sub { $parallel=3; },
47 "d|distro=s{,}"=>\@distro,
48 "cd|componentdistro=s{,}"=>\@componentdistro,
49 "p|path=s{,}"=>\@path,
50 "a|arch=s{,}"=>\@arch,
51 "c|component=s"=>\$component,
52 "s|srcrpm=s"=>\$srcrpm,
54 "target=s{,}"=>\@target,
55 "D|distrojobs=s"=>\$distrojobs,
56 "configure=s"=>\$configure,
58 $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/*");
59 $component and $component=~m{^/home/} and (-f "$component/gdb/gdbtypes.c" or die "$component/gdb/gdbtypes.c not found");
60 $component and $srcrpm and die "-c|--component excludes -s|--srcrpm";
61 $component or $srcrpm or die "-c|--component or -s|--srcrpm required";
62 $component||=""; # Make `eq' not complaining.
63 @target and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--target is available only for baretestsuite modes";
65 do { error "Duplicate target: $_\n" if $target{$_}++; } for @target;
66 @arch="x86_64" if @target&&!@arch;
67 for my $file (@file) {
68 -f $file and -r $file or error "-f|--file $file not readable: $!";
70 $distrojobs=(@target?1:2) if !defined $distrojobs;
71 $distrojobs=~/^\d+$/ or die "-D|distrojobs must be a number: $distrojobs";
72 $distrojobs>=1 or die "-D|distrojobs must be positive: $distrojobs";
73 # User may want to modify ASAP her files submitted for the test.
74 my $will_copy=@file || $component=~m{^/home/};
75 $parallel||=$will_copy ? 2 : 1;
76 error "Excessive arguments: @ARGV" if @ARGV;
77 @arch=@arches if !@arch;
78 my $path=join(":",@path) if @path;
79 @componentdistro and @componentdistro!=@distro and die "--cd|--componentdistro must have the same elements count as -d|--distro";
81 sub distro_normalize($;$)
86 s{^/var/lib/mock/+}{};
89 s/^(?:devel|rawhide)\b/fedora-rawhide/;
90 s/^(?:epel|rhel|centos)-?(\d)/epel-$1/;
91 s/^(?:f|fedora)-?(\d)/fedora-$1/;
93 @archuse="i386" if s/-$arch_i386$//o;
94 @archuse="x86_64" if s/-$arch_x86_64$//o;
96 for my $arch (@archuse?@archuse:@arch) {
97 my $dir="/var/lib/mock/$_-$arch";
98 $force or -d $dir or error "No distro: $dir";
101 return ($_,@archuse);
104 # epel-\d-i386|fedora-\d-i386|fedora-rawhide-i386
106 for my $distroi (0..$#distro) {
107 my $distro=$distro[$distroi];
108 my $componentdistro=$componentdistro[$distroi];
110 if ($componentdistro) {
111 my $force=($componentdistro=~s/!$//);
112 ($componentdistro,@archuse)=distro_normalize $componentdistro,$force;
113 @archuse and die "--cd|--componentdistro must have no arch: ".join(" ",@archuse);
115 ($distro,@archuse)=distro_normalize $distro;
116 $componentdistro||=$distro;
117 @archuse=@arch if !@archuse;
118 for my $archuse (@archuse) {
119 for my $target (@target?@target:undef()) {
120 push @distrouse,{"distro"=>"$distro-$archuse","componentdistro"=>$componentdistro,"target"=>$target};
129 warn "+ mkdir $dir\n";
130 mkdir $dir or die "mkdir $dir: $!";
138 $cmd="set -ex; $cmd";
139 my $ok="$log.ok" if $log;
140 $cmd="($cmd; touch $ok) 2>&1|tee -a $log; test -f $ok" if $log;
143 system $cmd and die "$cmd: $!";
147 my $basedir=$ENV{"HOME"}."/hammock";
148 -d $basedir or newdir $basedir;
149 my $idbase=strftime("%Y%m%d",localtime());
152 for my $seq (defined $userid ? $userid : (0..99)) {
153 $id=$idbase.(defined $userid ? $seq : sprintf("%02d",$seq));
157 spawn "rm -rf $dir" if -d $dir && $force && defined $userid;
158 error "Directory not free: $dir" if !$id || !$dir || -e $dir;
159 print STDERR "ID = $id | dir = $dir\n";
160 error "No distros specified" if !@distrouse;
161 die "$error errors seen, aborted" if $error;
165 my($fname,$content)=@_;
168 open F,">$fname" or die $fname;
169 print F $content or die $fname;
170 close F or die $fname;
173 spawn "renice 20 -p $$";
176 spawn "uname -r >$dir/kernel";
179 "component"=>$component,
181 "file"=>join("\n",@file),
182 "configure"=>$configure,
184 while (my($name,$val)=each(%dump)) {
185 writefile "$dir/$name","$val\n" if $val;
190 my($sub,$in,$out)=@_;
195 open F,$in or die $in;
196 local $_=do { local $/; <F>; } or die $in;
199 &{$sub}() or die $_."\nError substituting $in";
206 while (@distrouse || keys(%child)) {
207 while (keys(%child)<$distrojobs && @distrouse) {
208 my $distrouse=shift @distrouse;
209 my $distro=$distrouse->{"distro"};
210 my $componentdistro=$distrouse->{"componentdistro"};
211 my $target=$distrouse->{"target"};
212 my $rpmbuild="rpmbuild";
217 if ($component=~/^fedora(.*)$/) {
219 $cvsbasedir="F-$1" if $componentdistro=~/^fedora-(\d+)$/;
220 $cvsbasedir="devel" if $componentdistro=~/^fedora-rawhide$/;
221 die "$component vs. $componentdistro" if !$cvsbasedir;
222 $cvsroot=$fedoracvsroot;
224 if ($component=~/^rhel(.*)$/) {
226 $cvsbasedir="RHEL-$1" if $componentdistro=~/^epel-(\d+)$/;
227 die "$component vs. $componentdistro" if !$cvsbasedir;
228 $cvsroot=$rhelcvsroot;
229 # EPEL still uses Berkeley DB version 8 while F-11+ (F-10?) uses version 9.
230 # Using db_dump and db_load would no longer make it mock compatible.
231 $rpmbuild.=q{ --dbpath $PWD --nodeps};
234 my $distrodirbase=$distro;
235 $distrodirbase.="-$target" if $target;
236 my $distrodir="$dir/$distrodirbase";
238 $log="$distrodir/log";
239 my $out="$distrodir/out";
243 die if !defined $pid;
245 $child{$pid}=$distrodirbase;
250 my $builddir="$distrodir/build";
253 # Do not use mockrun as the rpm database may be in a different version.
254 spawn "rpm -r /var/lib/mock/$distro/root -qa|sort >$distrodir/rpm-qa";
261 $c="export PATH=\"$path:\$PATH\"; $c" if $path;
262 $c="export MAKEFLAGS=\"-j\$[`getconf _NPROCESSORS_ONLN`*3/2]\"; $c";
263 $c="export http_proxy=http://127.0.0.1:3128/; $c";
264 $c="set -ex; cd $builddir; $c";
265 die "found ': $c" if $c=~/'/;
266 spawn "mockrun $::distro '$c'";
272 spawn "cd $distrodir; cvs -q -z3 -d $cvsroot co rpms/$cvsrepo/$cvsbasedir";
273 my $componentdir="$distrodir/rpms/$cvsrepo/$cvsbasedir";
274 -d $componentdir or die "Failed checkout to: $componentdir";
275 # Required for RHEL; Fedora does so automatically.
276 spawn "cd $componentdir/..; cvs -q -z3 -d $cvsroot co common";
277 # Workaround (RHEL-5?) curl which uses `Pragma: nocache' on $http_proxy.
278 subst sub { s{echo "curl }{$&-H 'Pragma: cache' }; },"$componentdir/../common/Makefile.common";
280 for my $file (@file) {
282 $filebase=~s{^.*/}{};
283 my $target="$componentdir/$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";
289 my $glob="$componentdir/*.src.rpm";
290 @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
291 # No `spawn' as we could get:
292 # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
293 mockrun "cd $componentdir; make test-srpm";
294 my @srcrpm=(glob $glob);
295 @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
300 my $srcrpmbasename=$srcrpm;
301 $srcrpmbasename=~s{^.*/}{};
302 spawn "cp -p $srcrpm $builddir/$srcrpmbasename";
304 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"};
305 $rpmbuildlocal="orphanripper $rpmbuildlocal" if $cvsrepo && $cvsrepo eq "glibc";
306 mockrun $rpmbuildlocal." --rebuild --with testsuite".($parallel<2 ? "" : " --with parallel")." $srcrpmbasename";
311 if ($component=~/^(gdb|binutils)cvs$/) {
313 my $cvsbare=$which eq "gdb" ? $gdbcvsbare : $binutilscvsbare;
315 spawn "cp -a $cvsbare $builddir/src; cd $builddir/src; cvs update -A";
317 spawn "cd $builddir; cvs -q -z3 -d :pserver:anoncvs:\@sourceware.org:/cvs/src co $which";
319 spawn "cd $builddir/src".q{; test -z "$(cvs update -A)"};
320 $baretestsuite="$builddir/src";
323 if ($component=~/^archer-/) {
324 if (-d $archermaster) {
325 spawn "cp -a $archermaster $builddir/$component; cd $builddir/$component; git pull"
327 spawn "cd $builddir; git clone git://sourceware.org/git/archer.git; mv -f archer $component";
329 spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
330 $baretestsuite="$builddir/$component";
333 if ($component=~m{^/home/}) {
334 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 || :";
335 $baretestsuite="$builddir/src";
338 if ($baretestsuite) {
339 for my $file (@file) {
340 my $target="$baretestsuite/$file";
341 if ($file=~m{[.](R?)patch$}) {
344 $fileabs=$ENV{"PWD"}."/$fileabs" if $fileabs!~m{^/};
345 spawn "cd $baretestsuite; patch -${R}p".($component=~/binutils/ ? "0" : "1")." <$fileabs";
347 -f $target or $file=~m{/testsuite/} or die "File $file does not exist at $target";
348 spawn "rm -f $target; cp -p $file $target";
353 $errs1.=" --target=$target" if $target;
354 $errs1.=" $configure" if $configure;
356 if ($component eq "binutilscvs") {
357 mockrun "cd $baretestsuite; $errs1; errs2; ulimit -c unlimited; orphanripper make -k check || :; mkdir $out; ".q{for file in {gas/testsuite/gas,ld/ld,binutils/binutils}.{sum,log};do ln $file}." $out/binutils-$distro-".q{$(basename $file) || :; done;};
359 my @check=($distro=~/-x86_64/ ? qw(-m64 -m32) : -m32);
360 @check=map("check//unix/$_",@check);
361 # FSF GDB has no PIE support.
362 # @check=map({($_,"$_/-fPIE/-pie");} @check);
363 # for i in ".join(" ",@check).";do orphanripper make -k \$i || :;done
364 mockrun "cd $baretestsuite; $errs1; errs2; cd gdb; ulimit -c unlimited; orphanripper make -k ".join(" ",@check)." || :; mkdir $out; ".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-$distro".q{$suffix.$t || :; done; done;};
367 # perl -i -pe 's{\Q'"$HOME"'\E/.*?/build/[^/]*/}{}g' "$base"/*
368 my $HOME=$ENV{"HOME"};
369 for my $file (<$out/*>) {
370 subst sub { s{\Q$HOME\E/.*?/build/[^/]*/}{}g; },$file;
373 die "internal error" if @target;
376 # Call gdbunpack only if no direct $out directory will be created.
377 # It is needed only for .src.rpm-built testsuites, no matter how .src.rpm
380 if ($component=~/^(?:fedora|rhel)glibc$/) {
381 @testinlog=(qr/={20}TESTING DETAILS={17}/,qr/={20}PLT RELOCS END={18}/);
384 subst sub { s{^.*?\n($testinlog[0]\n.*\n$testinlog[1]\n).*$}{$1}s; },$log,$out;
385 } elsif ($cvsbasedir || $srcrpm) {
386 # Applies both to gdb and binutils.
387 spawn "gdbunpack $log";
390 exit 0 if $parallel>1;
393 print STDERR "waiting for ".scalar(keys(%child))." children, ".scalar(@distrouse)." distros to go...\n";
395 next if $pid==-1 && $!==10; # 10==No child processes
396 die "wait()==-1: $!" if $pid==-1;
397 die "not found pid $pid" if !$child{$pid};
398 error "weird status $? for pid $pid: ".$child{$pid} if $?;
399 print STDERR "finished: $pid ".$child{$pid}."\n";
411 $r.=int($sec/(60*60))."h";
414 if ($r || $sec>=60) {
415 $r.=int($sec/60)."m";
423 print STDERR "ID = $id | dir = $dir\n";
424 my $time=timestr(time()-$start);
425 print STDERR "total time=$time\n";
426 writefile "$dir/time","$time\n";
427 die "$error errors seen, aborted" if $error;
428 print STDERR "done\n";