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

Last change on this file since 674 was 674, checked in by joergs, on May 15, 2004 at 10:19:45 AM

clean up 6

File size: 5.7 KB
RevLine 
[589]1#!/usr/bin/perl -w
[674]2# automatic buildskript
3# reads configuration from option -b BUILDLIST
[664]4# $Id: buildall.pl,v 1.19 2003/09/01 13:34:07 joergs Exp $
[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 ) {
134 my $base = basename($mypath);
135 my $dir = dirname($mypath);
[626]136 $build_cmd = "cd $dir && $build $base-[0-9]*rpm";
[611]137 }
138
[623]139 print "++++++++++++++++++++++++++++++++++++++++++\n";
[673]140 print "BUILD_DIST: $ENV{'BUILD_DIST'}\n";
141 print "BUILD_MODE: $ENV{'BUILD_MODE'}\n";
[623]142 print "executing build command:\n";
[626]143 print "$build_cmd\n";
[611]144
[660]145 my $do_log = open( LOG_FD, ">$logfilename" );
146 if( $do_log ) {
147 print "you can watch building with following command: \n";
148 print "less +F $logfilename\n\n";
149 } else {
150 print "could not open logfile $logfilename\n";
151 }
[626]152 open( PIPE, "$build_cmd 2>&1 |" );
153 while( <PIPE> ) {
154 if( ! $opt_x ) {
155 print;
156 }
[628]157 print LOG_FD if $do_log;
[626]158 }
159 close PIPE; my $retval=$?;
[628]160 close LOG_FD if $do_log;
[626]161
[623]162 if ( $retval == 0 )
[596]163 {
[664]164 $ArrayofBuilds[$i][3] = "OK";
[596]165 print"****** ******\n";
[612]166 print"****** building of $ArrayofBuilds[$i][0]: OK \n" ;
[596]167 print"****** ******\n";
168 }
[623]169 else
[596]170 {
[664]171 $ArrayofBuilds[$i][3] = "*FAILED*";
[596]172 print"****** ******\n";
[612]173 print"\n\n\nERROR: building of $ArrayofBuilds[$i][0]: *FAILED*\n";
[596]174 print"****** ******\n";
175 }
[589]176}
177
[596]178print "Building results:\n";
179
[599]180
181
[664]182($wert1,$wert2,$wert3)= ("BUILD_DIST","Result","Package");
[599]183$~="TABELLE";
184write;
185
[626]186for my $i (0 .. $#ArrayofBuilds)
[596]187 {
[664]188 #($wert1,$wert2,$wert3)= ($ArrayofBuilds[$i][0],$ArrayofBuilds[$i][1],$ArrayofBuilds[$i][3]);
189 ($wert1,$wert2,$wert3) = ($ArrayofBuilds[$i][1],$ArrayofBuilds[$i][3],$ArrayofBuilds[$i][0]);
[599]190 $~="TABELLE";
191 write;
[619]192 # print("$ArrayofBuilds[$i][0]:Result: $ArrayofBuilds[$i][3]");
[596]193 }
194
[589]195print "buildall.pl terminated\n";
[664]196}
197
198
199
200#
201# generating install source
202#
203
204if( $opt_d ) {
205
206 my $INSTALL_SRC_DEST_DIR=$opt_d;
207 chomp $INSTALL_SRC_DEST_DIR;
208
209 # create target directory
210 run_command( "mkdir -p $INSTALL_SRC_DEST_DIR" );
211 # copy skeletion to dest
212 run_command( "rsync -av $INSTALL_SRC_SKEL_DIR $INSTALL_SRC_DEST_DIR" );
213
214 # copy build packages to dest
215 foreach my $i ( "i386", "i486", "i586", "i686", "noarch", "src" ) {
216 run_command( "mkdir -p $INSTALL_SRC_DEST_DIR/suse/$i" );
217 run_command( "rsync -av $BUILD_DEST_DIR/*/*.$i.rpm $INSTALL_SRC_DEST_DIR/suse/$i/" );
218 }
219
220 # create_package_descr (do that has to run on target distribution?)
221 run_command( "cd $INSTALL_SRC_DEST_DIR/suse/; /usr/lib/YaST2/bin/create_package_descr -o $INSTALL_SRC_DEST_DIR/setup/descr" );
222}
223
224
225#
226# functions
227#
228
229# executes a command (single string).
230# returns
231# the returncode
232# and (combined) stdout and stderr
233
234sub run_command
235{
236 my $command = shift;
237
238 print "executing command: " . $command . "\n";
239
240 open(RESULT, $command . ' 2>&1 |' );
241 my @result = <RESULT>;
242 close(RESULT);
243 my $retcode = $?>>8;
244
245 print @result;
246 if( $retcode ) { print "return code: " . $retcode . "\n"; }
247
248 return($retcode, @result);
249}
Note: See TracBrowser for help on using the repository browser.