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

Last change on this file since 664 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
Line 
1#!/usr/bin/perl -w
2# automatisches buildskript fuer smartclient
3# liest die konfiguration aus der mit -b übergebenen Datei
4# $Id: buildall.pl,v 1.19 2003/09/01 13:34:07 joergs Exp $
5# Philipp Storz, SuSE Linux AG
6# pstorz@suse.de
7
8use strict;
9use Getopt::Std;
10use File::stat;
11use File::Basename;
12
13my $wert1;
14my $wert2;
15my $wert3;
16
17format TABELLE =
18@<<<<<<<<<<<<<<<<<< @<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
19$wert1, $wert2, $wert3
20.
21
22
23# Programmoptionen:
24# -b (buildlist)
25# -x (buildlog im seperaten xtern
26# -d Zielpfad um Install Source zu erzeugen
27
28my $workdir=`pwd`;
29chomp $workdir;
30
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
37my $BUILD_DEST_DIR="/tmp/smartclient_build/";
38my $INSTALL_SRC_SKEL_DIR="/net/dist/data/dist/sles/8/skeleton-i386/smartclient/";
39
40my $build = "build.sh";
41our ( $opt_x, $opt_b, $opt_d );
42my @ArrayofBuilds;
43getopts('xb:d:');
44
45
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
55};
56
57
58
59#
60# build packages from buildlist
61#
62
63if( $opt_b ) {
64(open(BUILDLIST,$opt_b)) || die "Die Buildlist $opt_b konnte nicht gefunden werden";
65
66
67while (<BUILDLIST>) #Buildlist parsen
68 {
69 my $dir;
70 my $arch;
71 my $opt;
72 next if (/^\#.*$/);
73 # if (/([\w\/]+)\s*:([\/\w\-\+\.]+)\s+:((\s*\-\-\w*)*)$/)
74 if (/(\S+)\s*:(\S+)\s*:(\S+)\s*$/)
75 {
76 ($dir, $arch, $opt) = ($1, $2, $3);
77 chomp ($arch);
78 my @build=($dir, $arch, $opt);
79 push @ArrayofBuilds, [@build];
80 }
81 }
82
83
84
85print "What will be done:\n\n";
86($wert1,$wert2,$wert3)= ("BUILD_DIST","BUILD_MODE","Package");
87$~="TABELLE";
88write;
89for my $i (0 .. $#ArrayofBuilds)
90 {
91 ($wert1,$wert2,$wert3)= ($ArrayofBuilds[$i][1],$ArrayofBuilds[$i][2],$ArrayofBuilds[$i][0]);
92 $~="TABELLE";
93 write;
94 }
95
96print 'Are all the srpms extracted and all options OK? (y/n)';
97
98my $answer=<STDIN>;
99chomp ($answer);
100if ($answer ne "y") {die("canceled")};
101
102$ENV{'DEST_DIR'}=$BUILD_DEST_DIR;
103
104my $mypath;
105for my $i (0 .. $#ArrayofBuilds)
106 {
107 print("$ArrayofBuilds[$i][0]\t\t$ArrayofBuilds[$i][1]\t\t$ArrayofBuilds[$i][2]\n");
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];
119
120
121 $_=$ArrayofBuilds[$i][0];
122 print "$_ \n";
123 tr/\//\_/;
124 `mkdir -p $BUILD_DEST_DIR`;
125 my $logfilename = "$BUILD_DEST_DIR/$_$ArrayofBuilds[$i][1].log";
126
127 my $build_cmd="cd $mypath && $build";
128
129 # open a xterm to display build output
130 if ($opt_x)
131 {
132 system "xterm -T \"build log for PACKET: $mypath ARCH:$ArrayofBuilds[$i][1] \" -e less +F $logfilename &";
133 print "++++++++++++++++++++++++++++++++++++++++++\n";
134 }
135
136 # if mypath is not a directory, so it is a .src.rpm (hopefully)
137 if( ! -d $mypath ) {
138 my $base = basename($mypath);
139 my $dir = dirname($mypath);
140 $build_cmd = "cd $dir && $build $base-[0-9]*rpm";
141 }
142
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";
147 print "$build_cmd\n";
148
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 }
156 open( PIPE, "$build_cmd 2>&1 |" );
157 while( <PIPE> ) {
158 if( ! $opt_x ) {
159 print;
160 }
161 print LOG_FD if $do_log;
162 }
163 close PIPE; my $retval=$?;
164 close LOG_FD if $do_log;
165
166 if ( $retval == 0 )
167 {
168 $ArrayofBuilds[$i][3] = "OK";
169 print"****** ******\n";
170 print"****** building of $ArrayofBuilds[$i][0]: OK \n" ;
171 print"****** ******\n";
172 }
173 else
174 {
175 $ArrayofBuilds[$i][3] = "*FAILED*";
176 print"****** ******\n";
177 print"\n\n\nERROR: building of $ArrayofBuilds[$i][0]: *FAILED*\n";
178 print"****** ******\n";
179 }
180}
181
182print "Building results:\n";
183
184
185
186($wert1,$wert2,$wert3)= ("BUILD_DIST","Result","Package");
187$~="TABELLE";
188write;
189
190for my $i (0 .. $#ArrayofBuilds)
191 {
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]);
194 $~="TABELLE";
195 write;
196 # print("$ArrayofBuilds[$i][0]:Result: $ArrayofBuilds[$i][3]");
197 }
198
199print "buildall.pl terminated\n";
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.