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

Last change on this file since 667 was 664, checked in by joergs, on Sep 1, 2003 at 3:34:07 PM

extend buildall.pl to generate install sources.

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