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

Last change on this file since 680 was 675, checked in by joergs, on May 15, 2004 at 10:26:56 AM

adding keyword properties

  • 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 675 2004-05-15 08:26:56Z 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 $build_cmd = "cd $dir && $build $base-[0-9]*rpm";
137 }
138
139 print "++++++++++++++++++++++++++++++++++++++++++\n";
140 print "BUILD_DIST: $ENV{'BUILD_DIST'}\n";
141 print "BUILD_MODE: $ENV{'BUILD_MODE'}\n";
142 print "executing build command:\n";
143 print "$build_cmd\n";
144
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 }
152 open( PIPE, "$build_cmd 2>&1 |" );
153 while( <PIPE> ) {
154 if( ! $opt_x ) {
155 print;
156 }
157 print LOG_FD if $do_log;
158 }
159 close PIPE; my $retval=$?;
160 close LOG_FD if $do_log;
161
162 if ( $retval == 0 )
163 {
164 $ArrayofBuilds[$i][3] = "OK";
165 print"****** ******\n";
166 print"****** building of $ArrayofBuilds[$i][0]: OK \n" ;
167 print"****** ******\n";
168 }
169 else
170 {
171 $ArrayofBuilds[$i][3] = "*FAILED*";
172 print"****** ******\n";
173 print"\n\n\nERROR: building of $ArrayofBuilds[$i][0]: *FAILED*\n";
174 print"****** ******\n";
175 }
176}
177
178print "Building results:\n";
179
180
181
182($wert1,$wert2,$wert3)= ("BUILD_DIST","Result","Package");
183$~="TABELLE";
184write;
185
186for my $i (0 .. $#ArrayofBuilds)
187 {
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]);
190 $~="TABELLE";
191 write;
192 # print("$ArrayofBuilds[$i][0]:Result: $ArrayofBuilds[$i][3]");
193 }
194
195print "buildall.pl terminated\n";
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.