X-Git-Url: https://git.jankratochvil.net/?p=nethome.git;a=blobdiff_plain;f=bin%2Fhammock;h=3859c36c9b2c2c4e7136e6c7502ccebba3a9d716;hp=8f7a8b9368539129f4bee5ef87ee77f5eb944ce9;hb=7fbe5b56d5ccbf62cfa13f0dcd3611eb10753cc8;hpb=7a478e859d97605101392c02963f1add6a499e62 diff --git a/bin/hammock b/bin/hammock index 8f7a8b9..3859c36 100755 --- a/bin/hammock +++ b/bin/hammock @@ -10,13 +10,13 @@ my $start=time(); my $gdbcvsbare=$ENV{"HOME"}."/redhat/gdb-cvs-bare"; my $binutilscvsbare=$ENV{"HOME"}."/redhat/binutils-cvs-bare"; -my $archermaster=$ENV{"HOME"}."/redhat/master"; +my $archermaster=$ENV{"HOME"}."/redhat/archer-master"; my $fedoracvsroot=q{:pserver:anonymous:@cvs.fedoraproject.org:/cvs/pkgs}; my $rhelcvsroot=q{:pserver:anonymous:@192.168.67.2:3401/cvs/dist}; my $arch_i386=qr{(?:x86|i\d86|ia32)}io; my $arch_x86_64=qr{(?:x8664|x86_64|em64t)}io; +my $resultdir=$ENV{"HOME"}."/.hammock-result"; my @arches=qw(i386 x86_64); -my $arches_re=qr{(?:i386|x86_64)}; my $error=0; sub error @@ -29,14 +29,17 @@ my $userid; my $force; my $parallel=9; # 1 or 2 or 3 my @distro; +my @componentdistro; my @path; my @arch; my $component; my $srcrpm; my @file; my @target; +my $configure; +my $branch; # FIXME: Connect make paralellization to the children. -my $distrojobs=2; +my $distrojobs; die if !GetOptions( "i|userid=s"=>\$userid, "force"=>\$force, @@ -44,6 +47,7 @@ die if !GetOptions( "2|standard"=>sub { $parallel=2; }, "3|parallel"=>sub { $parallel=3; }, "d|distro=s{,}"=>\@distro, + "cd|componentdistro=s{,}"=>\@componentdistro, "p|path=s{,}"=>\@path, "a|arch=s{,}"=>\@arch, "c|component=s"=>\$component, @@ -51,16 +55,28 @@ die if !GetOptions( "file=s{,}"=>\@file, "target=s{,}"=>\@target, "D|distrojobs=s"=>\$distrojobs, + "configure=s"=>\$configure, + "branch=s"=>\$branch, ); $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/*"); $component and $component=~m{^/home/} and (-f "$component/gdb/gdbtypes.c" or die "$component/gdb/gdbtypes.c not found"); $component and $srcrpm and die "-c|--component excludes -s|--srcrpm"; $component or $srcrpm or die "-c|--component or -s|--srcrpm required"; $component||=""; # Make `eq' not complaining. +my $cvsbranch; +if ($component=~/^(gdb|binutils)cvs$/) { + $cvsbranch=(!$branch?"-A":"-r $branch"); +} else { + die "--branch currently unsupported for non-CVS sources" if $branch; +} @target and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--target is available only for baretestsuite modes"; +my %target; +do { error "Duplicate target: $_\n" if $target{$_}++; } for @target; +@arch="x86_64" if @target&&!@arch; for my $file (@file) { -f $file and -r $file or error "-f|--file $file not readable: $!"; } +$distrojobs=(@target?1:2) if !defined $distrojobs; $distrojobs=~/^\d+$/ or die "-D|distrojobs must be a number: $distrojobs"; $distrojobs>=1 or die "-D|distrojobs must be positive: $distrojobs"; # User may want to modify ASAP her files submitted for the test. @@ -69,54 +85,87 @@ $parallel||=$will_copy ? 2 : 1; error "Excessive arguments: @ARGV" if @ARGV; @arch=@arches if !@arch; my $path=join(":",@path) if @path; +@componentdistro and @componentdistro!=@distro and die "--cd|--componentdistro must have the same elements count as -d|--distro"; + +sub distro_normalize($;$) +{ + my($name,$force)=@_; + local $_=$name; -# epel-\d-i386|fedora-\d-i386|fedora-rawhide-i386 -my @distrouse; -for (@distro) { s{^/var/lib/mock/+}{}; s{/+$}{}; s/^.*$/\L$&/s; s/^(?:devel|rawhide)\b/fedora-rawhide/; - s/^(?:epel|rhel|centos)-?(\d)/epel-$1/; + s/^(?:epel|centos)-?(\d)/epel-$1/; + s/^(?:rhel)-?(\d)/rhel-$1/; s/^(?:f|fedora)-?(\d)/fedora-$1/; my @archuse; + @archuse="" if -d "/var/lib/mock/$_"; @archuse="i386" if s/-$arch_i386$//o; @archuse="x86_64" if s/-$arch_x86_64$//o; + + for my $arch (@archuse?@archuse:@arch) { + my $dir="/var/lib/mock/$_".(!$arch?"":"-$arch"); + $force or -d $dir or error "No distro: $dir"; + } + + return ($_,@archuse); +} + +# epel-\d-i386|fedora-\d-i386|fedora-rawhide-i386 +my @distrouse; +for my $distroi (0..$#distro) { + my $distro=$distro[$distroi]; + my $componentdistro=$componentdistro[$distroi]; + my @archuse; + if ($componentdistro) { + my $force=($componentdistro=~s/!$//); + ($componentdistro,@archuse)=distro_normalize $componentdistro,$force; + @archuse and die "--cd|--componentdistro must have no arch: ".join(" ",@archuse); + } + ($distro,@archuse)=distro_normalize $distro; + $componentdistro||=$distro; @archuse=@arch if !@archuse; for my $archuse (@archuse) { - my $basename="$_-$archuse"; - my $dir="/var/lib/mock/$basename"; - -d $dir or error "No distro: $dir"; - for my $target (@target ? @target : undef()) { - push @distrouse,{"distro"=>$basename,"target"=>$target}; + for my $target (@target?@target:undef()) { + push @distrouse,{"distro"=>$distro.(!$archuse?"":"-$archuse"),"componentdistro"=>$componentdistro,"target"=>$target}; } } } -sub newdir($) +# "-p", "mayexist" +sub newdir($;@) { - my($dir)=@_; + my($dir,@opt)=@_; - warn "+ mkdir $dir\n"; - mkdir $dir or die "mkdir $dir: $!"; + my %opt=map(($_=>1),@opt); + warn "+ mkdir".($opt{"-p"} ? " -p" : "")." $dir\n"; + mkdir $dir or ($opt{"mayexist"} && $!{EEXIST}) or die "mkdir $dir: $!"; } my $log; -sub spawn($) +# "bare" +sub spawn($;%) { - my($cmd)=@_; - - $cmd="set -ex; $cmd"; - my $ok="$log.ok" if $log; - $cmd="($cmd; touch $ok) 2>&1|tee -a $log; test -f $ok" if $log; - unlink $ok if $ok; + my($cmd,@opt)=@_; + + my %opt=map(($_=>1),@opt); + my $ok; + if (!$opt{"bare"}) { + $cmd="set -ex; $cmd"; + $ok="$log.ok" if $log; + $cmd="($cmd; touch $ok) 2>&1|tee -a $log; test -f $ok" if $log; + unlink $ok if $ok; + } else { + warn "+ $cmd\n"; + } # warn "+ $cmd\n"; system $cmd and die "$cmd: $!"; unlink $ok if $ok; } my $basedir=$ENV{"HOME"}."/hammock"; --d $basedir or newdir $basedir; +newdir $basedir,"mayexist"; my $idbase=strftime("%Y%m%d",localtime()); my $id; my $dir; @@ -131,23 +180,45 @@ print STDERR "ID = $id | dir = $dir\n"; error "No distros specified" if !@distrouse; die "$error errors seen, aborted" if $error; +sub writefile +{ + my($fname,$content)=@_; + + local *F; + open F,">$fname" or die $fname; + print F $content or die $fname; + close F or die $fname; +} + spawn "renice 20 -p $$"; newdir $dir; $log="$dir/log"; +my $resultid="$resultdir/$id"; +my $resultidxz="$resultid.tar.xz"; +newdir $resultdir,"mayexist"; +spawn "rm -rf $resultid" if -d $resultid && $force; +newdir $resultid; +unlink $resultidxz or $!{ENOENT} or die "unlink $resultidxz: $!"; spawn "uname -r >$dir/kernel"; my %dump=( "path"=>$path, "component"=>$component, "srcrpm"=>$srcrpm, "file"=>join("\n",@file), + "configure"=>$configure, ); while (my($name,$val)=each(%dump)) { next if !$val; - local *F; - my $fname="$dir/$name"; - open F,">$fname" or die $fname; - print F "$val\n" or die $fname; - close F or die $fname; + writefile "$dir/$name","$val\n"; + link "$dir/$name","$resultid/$name" or warn "link $dir/$name $resultid/$name: $!"; +} +for my $file (@file) { + newdir "$dir/file.d","mayexist"; + (my $base=$file)=~s{^.*/}{}; + my $d="$dir/file.d/$base"; + link $file,$d or die "link $file $d: $!"; + newdir "$resultid/file.d","mayexist"; + link $d,"$resultid/file.d/$base" or warn "link $file $resultid/file.d/$base: $!"; } sub subst @@ -163,9 +234,7 @@ sub subst &{$sub}() or die $_."\nError substituting $in"; - open F,">$out" or die $out; - print F $_ or die $out; - close F or die $out; + writefile $out,$_; } # PID->distro @@ -174,6 +243,7 @@ while (@distrouse || keys(%child)) { while (keys(%child)<$distrojobs && @distrouse) { my $distrouse=shift @distrouse; my $distro=$distrouse->{"distro"}; + my $componentdistro=$distrouse->{"componentdistro"}; my $target=$distrouse->{"target"}; my $rpmbuild="rpmbuild"; @@ -182,15 +252,15 @@ while (@distrouse || keys(%child)) { my $cvsrepo; if ($component=~/^fedora(.*)$/) { $cvsrepo=$1; - $cvsbasedir="F-$1" if $distro=~/^fedora-(\d+)-$arches_re$/; - $cvsbasedir="devel" if $distro=~/^fedora-rawhide-$arches_re$/; - die "$component vs. $distro" if !$cvsbasedir; + $cvsbasedir="F-$1" if $componentdistro=~/^fedora-(\d+)$/; + $cvsbasedir="devel" if $componentdistro=~/^fedora-rawhide$/; + die "$component vs. $componentdistro" if !$cvsbasedir; $cvsroot=$fedoracvsroot; } if ($component=~/^rhel(.*)$/) { $cvsrepo=$1; - $cvsbasedir="RHEL-$1" if $distro=~/^epel-(\d+)-$arches_re$/; - die "$component vs. $distro" if !$cvsbasedir; + $cvsbasedir="RHEL-$1" if $componentdistro=~/^(?:epel|rhel)-(\d+)$/; + die "$component vs. $componentdistro" if !$cvsbasedir; $cvsroot=$rhelcvsroot; # EPEL still uses Berkeley DB version 8 while F-11+ (F-10?) uses version 9. # Using db_dump and db_load would no longer make it mock compatible. @@ -278,11 +348,11 @@ while (@distrouse || keys(%child)) { my $which=$1; my $cvsbare=$which eq "gdb" ? $gdbcvsbare : $binutilscvsbare; if (-d $cvsbare) { - spawn "cp -a $cvsbare $builddir/src; cd $builddir/src; cvs update -A"; + spawn "cp -a $cvsbare $builddir/src; cd $builddir/src; cvs update $cvsbranch"; } else { - spawn "cd $builddir; cvs -q -z3 -d :pserver:anoncvs:\@sourceware.org:/cvs/src co $which"; + spawn "cd $builddir; cvs -q -z3 -d :pserver:anoncvs:\@sourceware.org:/cvs/src co $cvsbranch $which"; } - spawn "cd $builddir/src".q{; test -z "$(cvs update -A)"}; + spawn "cd $builddir/src; test -z \"\$(cvs update $cvsbranch)\""; $baretestsuite="$builddir/src"; } @@ -317,24 +387,23 @@ while (@distrouse || keys(%child)) { my $errs1="errs1"; $errs1.=" --target=$target" if $target; + $errs1.=" $configure" if $configure; if ($component eq "binutilscvs") { 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;}; - - # gdbunpack does: - # perl -i -pe 's{\Q'"$HOME"'\E/.*?/build/[^/]*/}{}g' "$base"/* - my $HOME=$ENV{"HOME"}; - for my $file (<$out/*>) { - subst sub { s{\Q$HOME\E/.*?/build/[^/]*/}{}g; },$file; - } } else { my @check=($distro=~/-x86_64/ ? qw(-m64 -m32) : -m32); @check=map("check//unix/$_",@check); - # FSF GDB has no PIE support. - # @check=map({($_,"$_/-fPIE/-pie");} @check); + @check=map({($_,"$_/-fPIE/-pie");} @check); # for i in ".join(" ",@check).";do orphanripper make -k \$i || :;done 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;}; } + # gdbunpack does: + # perl -i -pe 's{\Q'"$HOME"'\E/.*?/build/[^/]*/}{}g' "$base"/* + my $HOME=$ENV{"HOME"}; + for my $file (<$out/*>) { + subst sub { s{\Q$HOME\E/.*?/build/[^/]*/}{}g; },$file; + } } else { die "internal error" if @target; } @@ -353,6 +422,17 @@ while (@distrouse || keys(%child)) { spawn "gdbunpack $log"; } + my $resultout="$resultdir/$id/$distrodirbase"; + newdir $resultout; + $resultout.="/out"; + newdir $resultout; + for my $fname (glob "$out/*") { + (my $base=$fname)=~s{^.*/}{}; + my $d="$resultout/$base"; + warn "+ link $fname $d\n"; + link $fname,$d or warn $!; + } + exit 0 if $parallel>1; } @@ -368,6 +448,8 @@ while (@distrouse || keys(%child)) { die if keys(%child); die if @distrouse; +spawn "(set -e -o pipefail;cd $resultdir;tar cf - $id|xz -9e >$resultidxz;rm -rf $id)&","bare"; + sub timestr($) { my($sec)=@_; @@ -387,7 +469,8 @@ sub timestr($) } print STDERR "ID = $id | dir = $dir\n"; -print STDERR "total time=".timestr(time()-$start)."\n"; +my $time=timestr(time()-$start); +print STDERR "total time=$time\n"; +writefile "$dir/time","$time\n"; die "$error errors seen, aborted" if $error; - print STDERR "done\n";