source: trunk/technical/common/build/buildall.pl@ 731

Last change on this file since 731 was 695, checked in by joergs, on Nov 21, 2004 at 11:01:59 PM

optimized: skip building rpms that do already exist in the current version

  • Property svn:executable set to *
  • Property svn:keywords set to Id LastChangedDate LastChangedRevision
File size: 5.9 KB
RevLine 
[589]1#!/usr/bin/perl -w
[674]2# automatic buildskript
3# reads configuration from option -b BUILDLIST
[675]4# $Id: buildall.pl 695 2004-11-21 22:01:59Z joergs $
[623]5
[669]6
[626]7use strict;
[589]8use Getopt::Std;
[623]9use File::stat;
10use File::Basename;
[589]11
[626]12my $wert1;
13my $wert2;
14my $wert3;
[599]15
16format TABELLE =
[664]17@<<<<<<<<<<<<<<<<<< @<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
[599]18$wert1, $wert2, $wert3
19.
20
21
[626]22# Programmoptionen:
[672]23# -b buildlist
[671]24# -x (buildlog im seperaten xterm)
[664]25# -d Zielpfad um Install Source zu erzeugen
[589]26
[626]27my $workdir=`pwd`;
28chomp $workdir;
29
[628]30# Pfad, zu dem die Pfade in buildlist stehen
[694]31my $src_root="../../";
[628]32
[694]33
34my $BUILD_DEST_DIR="/tmp/build.$ENV{'USER'}/";
[664]35my $INSTALL_SRC_SKEL_DIR="/net/dist/data/dist/sles/8/skeleton-i386/smartclient/";
[660]36
[594]37my $build = "build.sh";
[664]38our ( $opt_x, $opt_b, $opt_d );
[589]39my @ArrayofBuilds;
[664]40getopts('xb:d:');
[589]41
[695]42my $skipped_last = 0;
[610]43
[664]44if (!$opt_b && !$opt_d) {
45 print <<EOF
46Usage:
47 -b BUILDLIST
48 compiles packages specified in BUILDLIST
49 -d INSTALL_SRC_DEST_DIR
50 creates a new install source in INSTALL_SRC_DEST_DIR
51EOF
[593]52};
53
[664]54
55
56#
57# build packages from buildlist
58#
59
60if( $opt_b ) {
[589]61(open(BUILDLIST,$opt_b)) || die "Die Buildlist $opt_b konnte nicht gefunden werden";
62
63
64while (<BUILDLIST>) #Buildlist parsen
65 {
[626]66 my $dir;
67 my $arch;
68 my $opt;
[589]69 next if (/^\#.*$/);
[626]70 # if (/([\w\/]+)\s*:([\/\w\-\+\.]+)\s+:((\s*\-\-\w*)*)$/)
[593]71 if (/(\S+)\s*:(\S+)\s*:(\S+)\s*$/)
[589]72 {
73 ($dir, $arch, $opt) = ($1, $2, $3);
74 chomp ($arch);
[626]75 my @build=($dir, $arch, $opt);
[589]76 push @ArrayofBuilds, [@build];
77 }
78 }
79
[593]80
81
[599]82print "What will be done:\n\n";
[664]83($wert1,$wert2,$wert3)= ("BUILD_DIST","BUILD_MODE","Package");
[599]84$~="TABELLE";
85write;
[626]86for my $i (0 .. $#ArrayofBuilds)
[589]87 {
[664]88 ($wert1,$wert2,$wert3)= ($ArrayofBuilds[$i][1],$ArrayofBuilds[$i][2],$ArrayofBuilds[$i][0]);
[599]89 $~="TABELLE";
90 write;
[593]91 }
[623]92
[668]93print 'Are all options OK? (y/n)';
[593]94
[626]95my $answer=<STDIN>;
[593]96chomp ($answer);
97if ($answer ne "y") {die("canceled")};
98
[664]99$ENV{'DEST_DIR'}=$BUILD_DEST_DIR;
[660]100
[626]101my $mypath;
102for my $i (0 .. $#ArrayofBuilds)
[593]103 {
104 print("$ArrayofBuilds[$i][0]\t\t$ArrayofBuilds[$i][1]\t\t$ArrayofBuilds[$i][2]\n");
[694]105 $mypath = $src_root.$ArrayofBuilds[$i][0];
[589]106
[695]107 if( $ArrayofBuilds[$i][2] && !$skipped_last )
[589]108 {
109 $ENV{'BUILD_MODE'}=$ArrayofBuilds[$i][2];
110 }
111 else
112 {
[695]113 $ENV{'BUILD_MODE'}="--verify";
[589]114 }
115 $ENV{'BUILD_DIST'}=$ArrayofBuilds[$i][1];
[596]116
[593]117
[589]118 $_=$ArrayofBuilds[$i][0];
119 print "$_ \n";
120 tr/\//\_/;
[664]121 `mkdir -p $BUILD_DEST_DIR`;
[694]122 `mkdir -p $BUILD_DEST_DIR/log`;
123 my $logfilename = "$BUILD_DEST_DIR/log/$_$ArrayofBuilds[$i][1].log";
[611]124
[623]125 my $build_cmd="cd $mypath && $build";
126
127 # open a xterm to display build output
128 if ($opt_x)
[611]129 {
[626]130 system "xterm -T \"build log for PACKET: $mypath ARCH:$ArrayofBuilds[$i][1] \" -e less +F $logfilename &";
131 print "++++++++++++++++++++++++++++++++++++++++++\n";
[611]132 }
[623]133
[664]134 # if mypath is not a directory, so it is a .src.rpm (hopefully)
[623]135 if( ! -d $mypath ) {
[685]136 my $base = basename($mypath);
137 my $dir = dirname($mypath);
138 # TODO: find the src.rpm with the highest version/release number
[626]139 $build_cmd = "cd $dir && $build $base-[0-9]*rpm";
[611]140 }
141
[623]142 print "++++++++++++++++++++++++++++++++++++++++++\n";
[673]143 print "BUILD_DIST: $ENV{'BUILD_DIST'}\n";
144 print "BUILD_MODE: $ENV{'BUILD_MODE'}\n";
[623]145 print "executing build command:\n";
[626]146 print "$build_cmd\n";
[611]147
[660]148 my $do_log = open( LOG_FD, ">$logfilename" );
149 if( $do_log ) {
150 print "you can watch building with following command: \n";
151 print "less +F $logfilename\n\n";
152 } else {
153 print "could not open logfile $logfilename\n";
154 }
[626]155 open( PIPE, "$build_cmd 2>&1 |" );
156 while( <PIPE> ) {
157 if( ! $opt_x ) {
158 print;
159 }
[628]160 print LOG_FD if $do_log;
[626]161 }
[695]162 close PIPE; my $retval=$?>>8;
[628]163 close LOG_FD if $do_log;
[626]164
[695]165 if ( $retval == 0 ) {
[664]166 $ArrayofBuilds[$i][3] = "OK";
[596]167 print"****** ******\n";
[612]168 print"****** building of $ArrayofBuilds[$i][0]: OK \n" ;
[596]169 print"****** ******\n";
[695]170 } elsif ( $retval == 1 ) {
171 $ArrayofBuilds[$i][3] = "skipped";
172 $skipped_last = 1;
173 } else {
[664]174 $ArrayofBuilds[$i][3] = "*FAILED*";
[596]175 print"****** ******\n";
[612]176 print"\n\n\nERROR: building of $ArrayofBuilds[$i][0]: *FAILED*\n";
[596]177 print"****** ******\n";
178 }
[589]179}
180
[596]181print "Building results:\n";
182
[599]183
184
[664]185($wert1,$wert2,$wert3)= ("BUILD_DIST","Result","Package");
[599]186$~="TABELLE";
187write;
188
[626]189for my $i (0 .. $#ArrayofBuilds)
[596]190 {
[664]191 #($wert1,$wert2,$wert3)= ($ArrayofBuilds[$i][0],$ArrayofBuilds[$i][1],$ArrayofBuilds[$i][3]);
192 ($wert1,$wert2,$wert3) = ($ArrayofBuilds[$i][1],$ArrayofBuilds[$i][3],$ArrayofBuilds[$i][0]);
[599]193 $~="TABELLE";
194 write;
[619]195 # print("$ArrayofBuilds[$i][0]:Result: $ArrayofBuilds[$i][3]");
[596]196 }
197
[589]198print "buildall.pl terminated\n";
[664]199}
200
201
202
203#
204# generating install source
205#
206
207if( $opt_d ) {
208
209 my $INSTALL_SRC_DEST_DIR=$opt_d;
210 chomp $INSTALL_SRC_DEST_DIR;
211
212 # create target directory
213 run_command( "mkdir -p $INSTALL_SRC_DEST_DIR" );
214 # copy skeletion to dest
215 run_command( "rsync -av $INSTALL_SRC_SKEL_DIR $INSTALL_SRC_DEST_DIR" );
216
217 # copy build packages to dest
218 foreach my $i ( "i386", "i486", "i586", "i686", "noarch", "src" ) {
219 run_command( "mkdir -p $INSTALL_SRC_DEST_DIR/suse/$i" );
220 run_command( "rsync -av $BUILD_DEST_DIR/*/*.$i.rpm $INSTALL_SRC_DEST_DIR/suse/$i/" );
221 }
222
223 # create_package_descr (do that has to run on target distribution?)
224 run_command( "cd $INSTALL_SRC_DEST_DIR/suse/; /usr/lib/YaST2/bin/create_package_descr -o $INSTALL_SRC_DEST_DIR/setup/descr" );
225}
226
227
228#
229# functions
230#
231
232# executes a command (single string).
233# returns
234# the returncode
235# and (combined) stdout and stderr
236
237sub run_command
238{
239 my $command = shift;
240
241 print "executing command: " . $command . "\n";
242
243 open(RESULT, $command . ' 2>&1 |' );
244 my @result = <RESULT>;
245 close(RESULT);
246 my $retcode = $?>>8;
247
248 print @result;
249 if( $retcode ) { print "return code: " . $retcode . "\n"; }
250
251 return($retcode, @result);
252}
Note: See TracBrowser for help on using the repository browser.