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 |
|
---|
8 | use strict;
|
---|
9 | use Getopt::Std;
|
---|
10 | use File::stat;
|
---|
11 | use File::Basename;
|
---|
12 |
|
---|
13 | my $wert1;
|
---|
14 | my $wert2;
|
---|
15 | my $wert3;
|
---|
16 |
|
---|
17 | format 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 |
|
---|
28 | my $workdir=`pwd`;
|
---|
29 | chomp $workdir;
|
---|
30 |
|
---|
31 | # Pfad, zu dem die Pfade in buildlist stehen
|
---|
32 | my $smartclient_root="../../";
|
---|
33 |
|
---|
34 | #my $smartclient_root="/home/joergs/projects/smartclient/stuttgarter-versicherung/technical/";
|
---|
35 | #$workdir="";
|
---|
36 |
|
---|
37 | my $BUILD_DEST_DIR="/tmp/smartclient_build/";
|
---|
38 | my $INSTALL_SRC_SKEL_DIR="/net/dist/data/dist/sles/8/skeleton-i386/smartclient/";
|
---|
39 |
|
---|
40 | my $build = "build.sh";
|
---|
41 | our ( $opt_x, $opt_b, $opt_d );
|
---|
42 | my @ArrayofBuilds;
|
---|
43 | getopts('xb:d:');
|
---|
44 |
|
---|
45 |
|
---|
46 |
|
---|
47 | if (!$opt_b && !$opt_d) {
|
---|
48 | print <<EOF
|
---|
49 | Usage:
|
---|
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
|
---|
54 | EOF
|
---|
55 | };
|
---|
56 |
|
---|
57 |
|
---|
58 |
|
---|
59 | #
|
---|
60 | # build packages from buildlist
|
---|
61 | #
|
---|
62 |
|
---|
63 | if( $opt_b ) {
|
---|
64 | (open(BUILDLIST,$opt_b)) || die "Die Buildlist $opt_b konnte nicht gefunden werden";
|
---|
65 |
|
---|
66 |
|
---|
67 | while (<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 |
|
---|
85 | print "What will be done:\n\n";
|
---|
86 | ($wert1,$wert2,$wert3)= ("BUILD_DIST","BUILD_MODE","Package");
|
---|
87 | $~="TABELLE";
|
---|
88 | write;
|
---|
89 | for my $i (0 .. $#ArrayofBuilds)
|
---|
90 | {
|
---|
91 | ($wert1,$wert2,$wert3)= ($ArrayofBuilds[$i][1],$ArrayofBuilds[$i][2],$ArrayofBuilds[$i][0]);
|
---|
92 | $~="TABELLE";
|
---|
93 | write;
|
---|
94 | }
|
---|
95 |
|
---|
96 | print 'Are all the srpms extracted and all options OK? (y/n)';
|
---|
97 |
|
---|
98 | my $answer=<STDIN>;
|
---|
99 | chomp ($answer);
|
---|
100 | if ($answer ne "y") {die("canceled")};
|
---|
101 |
|
---|
102 | $ENV{'DEST_DIR'}=$BUILD_DEST_DIR;
|
---|
103 |
|
---|
104 | my $mypath;
|
---|
105 | for 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 |
|
---|
182 | print "Building results:\n";
|
---|
183 |
|
---|
184 |
|
---|
185 |
|
---|
186 | ($wert1,$wert2,$wert3)= ("BUILD_DIST","Result","Package");
|
---|
187 | $~="TABELLE";
|
---|
188 | write;
|
---|
189 |
|
---|
190 | for 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 |
|
---|
199 | print "buildall.pl terminated\n";
|
---|
200 | }
|
---|
201 |
|
---|
202 |
|
---|
203 |
|
---|
204 | #
|
---|
205 | # generating install source
|
---|
206 | #
|
---|
207 |
|
---|
208 | if( $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 |
|
---|
238 | sub 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 |
|
---|