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

Last change on this file since 690 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
Line 
1#!/usr/bin/perl -w
2# automatic buildskript
3# reads configuration from option -b BUILDLIST
4# $Id: buildall.pl 687 2004-08-15 10:00:04Z joergs $
5
6
7use strict;
8use Getopt::Std;
9use File::stat;
10use File::Basename;
11
12my $wert1;
13my $wert2;
14my $wert3;
15
16format TABELLE =
17@<<<<<<<<<<<<<<<<<< @<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
18$wert1, $wert2, $wert3
19.
20
21
22# Programmoptionen:
23# -b buildlist
24# -x (buildlog im seperaten xterm)
25# -d Zielpfad um Install Source zu erzeugen
26
27my $workdir=`pwd`;
28chomp $workdir;
29
30# Pfad, zu dem die Pfade in buildlist stehen
31my $smartclient_root="../../";
32
33my $BUILD_DEST_DIR="/tmp/smartclient_build/";
34my $INSTALL_SRC_SKEL_DIR="/net/dist/data/dist/sles/8/skeleton-i386/smartclient/";
35
36my $build = "build.sh";
37our ( $opt_x, $opt_b, $opt_d );
38my @ArrayofBuilds;
39getopts('xb:d:');
40
41
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
51};
52
53
54
55#
56# build packages from buildlist
57#
58
59if( $opt_b ) {
60(open(BUILDLIST,$opt_b)) || die "Die Buildlist $opt_b konnte nicht gefunden werden";
61
62
63while (<BUILDLIST>) #Buildlist parsen
64 {
65 my $dir;
66 my $arch;
67 my $opt;
68 next if (/^\#.*$/);
69 # if (/([\w\/]+)\s*:([\/\w\-\+\.]+)\s+:((\s*\-\-\w*)*)$/)
70 if (/(\S+)\s*:(\S+)\s*:(\S+)\s*$/)
71 {
72 ($dir, $arch, $opt) = ($1, $2, $3);
73 chomp ($arch);
74 my @build=($dir, $arch, $opt);
75 push @ArrayofBuilds, [@build];
76 }
77 }
78
79
80
81print "What will be done:\n\n";
82($wert1,$wert2,$wert3)= ("BUILD_DIST","BUILD_MODE","Package");
83$~="TABELLE";
84write;
85for my $i (0 .. $#ArrayofBuilds)
86 {
87 ($wert1,$wert2,$wert3)= ($ArrayofBuilds[$i][1],$ArrayofBuilds[$i][2],$ArrayofBuilds[$i][0]);
88 $~="TABELLE";
89 write;
90 }
91
92print 'Are all options OK? (y/n)';
93
94my $answer=<STDIN>;
95chomp ($answer);
96if ($answer ne "y") {die("canceled")};
97
98$ENV{'DEST_DIR'}=$BUILD_DEST_DIR;
99
100my $mypath;
101for my $i (0 .. $#ArrayofBuilds)
102 {
103 print("$ArrayofBuilds[$i][0]\t\t$ArrayofBuilds[$i][1]\t\t$ArrayofBuilds[$i][2]\n");
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];
115
116
117 $_=$ArrayofBuilds[$i][0];
118 print "$_ \n";
119 tr/\//\_/;
120 `mkdir -p $BUILD_DEST_DIR`;
121 my $logfilename = "$BUILD_DEST_DIR/$_$ArrayofBuilds[$i][1].log";
122
123 my $build_cmd="cd $mypath && $build";
124
125 # open a xterm to display build output
126 if ($opt_x)
127 {
128 system "xterm -T \"build log for PACKET: $mypath ARCH:$ArrayofBuilds[$i][1] \" -e less +F $logfilename &";
129 print "++++++++++++++++++++++++++++++++++++++++++\n";
130 }
131
132 # if mypath is not a directory, so it is a .src.rpm (hopefully)
133 if( ! -d $mypath ) {
134 my $base = basename($mypath);
135 my $dir = dirname($mypath);
136 # TODO: find the src.rpm with the highest version/release number
137 $build_cmd = "cd $dir && $build $base-[0-9]*rpm";
138 }
139
140 print "++++++++++++++++++++++++++++++++++++++++++\n";
141 print "BUILD_DIST: $ENV{'BUILD_DIST'}\n";
142 print "BUILD_MODE: $ENV{'BUILD_MODE'}\n";
143 print "executing build command:\n";
144 print "$build_cmd\n";
145
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 }
153 open( PIPE, "$build_cmd 2>&1 |" );
154 while( <PIPE> ) {
155 if( ! $opt_x ) {
156 print;
157 }
158 print LOG_FD if $do_log;
159 }
160 close PIPE; my $retval=$?;
161 close LOG_FD if $do_log;
162
163 if ( $retval == 0 )
164 {
165 $ArrayofBuilds[$i][3] = "OK";
166 print"****** ******\n";
167 print"****** building of $ArrayofBuilds[$i][0]: OK \n" ;
168 print"****** ******\n";
169 }
170 else
171 {
172 $ArrayofBuilds[$i][3] = "*FAILED*";
173 print"****** ******\n";
174 print"\n\n\nERROR: building of $ArrayofBuilds[$i][0]: *FAILED*\n";
175 print"****** ******\n";
176 }
177}
178
179print "Building results:\n";
180
181
182
183($wert1,$wert2,$wert3)= ("BUILD_DIST","Result","Package");
184$~="TABELLE";
185write;
186
187for my $i (0 .. $#ArrayofBuilds)
188 {
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]);
191 $~="TABELLE";
192 write;
193 # print("$ArrayofBuilds[$i][0]:Result: $ArrayofBuilds[$i][3]");
194 }
195
196print "buildall.pl terminated\n";
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.