[589] | 1 | #!/usr/bin/perl -w
|
---|
[674] | 2 | # automatic buildskript
|
---|
| 3 | # reads configuration from option -b BUILDLIST
|
---|
[675] | 4 | # $Id: buildall.pl 675 2004-05-15 08:26:56Z joergs $
|
---|
[623] | 5 |
|
---|
[669] | 6 |
|
---|
[626] | 7 | use strict;
|
---|
[589] | 8 | use Getopt::Std;
|
---|
[623] | 9 | use File::stat;
|
---|
| 10 | use File::Basename;
|
---|
[589] | 11 |
|
---|
[626] | 12 | my $wert1;
|
---|
| 13 | my $wert2;
|
---|
| 14 | my $wert3;
|
---|
[599] | 15 |
|
---|
| 16 | format 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] | 27 | my $workdir=`pwd`;
|
---|
| 28 | chomp $workdir;
|
---|
| 29 |
|
---|
[628] | 30 | # Pfad, zu dem die Pfade in buildlist stehen
|
---|
| 31 | my $smartclient_root="../../";
|
---|
| 32 |
|
---|
[664] | 33 | my $BUILD_DEST_DIR="/tmp/smartclient_build/";
|
---|
| 34 | my $INSTALL_SRC_SKEL_DIR="/net/dist/data/dist/sles/8/skeleton-i386/smartclient/";
|
---|
[660] | 35 |
|
---|
[594] | 36 | my $build = "build.sh";
|
---|
[664] | 37 | our ( $opt_x, $opt_b, $opt_d );
|
---|
[589] | 38 | my @ArrayofBuilds;
|
---|
[664] | 39 | getopts('xb:d:');
|
---|
[589] | 40 |
|
---|
[610] | 41 |
|
---|
[664] | 42 |
|
---|
| 43 | if (!$opt_b && !$opt_d) {
|
---|
| 44 | print <<EOF
|
---|
| 45 | Usage:
|
---|
| 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
|
---|
| 50 | EOF
|
---|
[593] | 51 | };
|
---|
| 52 |
|
---|
[664] | 53 |
|
---|
| 54 |
|
---|
| 55 | #
|
---|
| 56 | # build packages from buildlist
|
---|
| 57 | #
|
---|
| 58 |
|
---|
| 59 | if( $opt_b ) {
|
---|
[589] | 60 | (open(BUILDLIST,$opt_b)) || die "Die Buildlist $opt_b konnte nicht gefunden werden";
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 | while (<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] | 81 | print "What will be done:\n\n";
|
---|
[664] | 82 | ($wert1,$wert2,$wert3)= ("BUILD_DIST","BUILD_MODE","Package");
|
---|
[599] | 83 | $~="TABELLE";
|
---|
| 84 | write;
|
---|
[626] | 85 | for 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] | 92 | print 'Are all options OK? (y/n)';
|
---|
[593] | 93 |
|
---|
[626] | 94 | my $answer=<STDIN>;
|
---|
[593] | 95 | chomp ($answer);
|
---|
| 96 | if ($answer ne "y") {die("canceled")};
|
---|
| 97 |
|
---|
[664] | 98 | $ENV{'DEST_DIR'}=$BUILD_DEST_DIR;
|
---|
[660] | 99 |
|
---|
[626] | 100 | my $mypath;
|
---|
| 101 | for 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] | 178 | print "Building results:\n";
|
---|
| 179 |
|
---|
[599] | 180 |
|
---|
| 181 |
|
---|
[664] | 182 | ($wert1,$wert2,$wert3)= ("BUILD_DIST","Result","Package");
|
---|
[599] | 183 | $~="TABELLE";
|
---|
| 184 | write;
|
---|
| 185 |
|
---|
[626] | 186 | for 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] | 195 | print "buildall.pl terminated\n";
|
---|
[664] | 196 | }
|
---|
| 197 |
|
---|
| 198 |
|
---|
| 199 |
|
---|
| 200 | #
|
---|
| 201 | # generating install source
|
---|
| 202 | #
|
---|
| 203 |
|
---|
| 204 | if( $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 |
|
---|
| 234 | sub 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 | }
|
---|