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

Last change on this file since 687 was 687, checked in by joergs, on Aug 15, 2004 at 12:00:04 PM

beautified

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