| 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.17 2002/10/18 08:37:46 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 | 
 | 
|---|
| 27 | my $workdir=`pwd`;
 | 
|---|
| 28 | chomp $workdir;
 | 
|---|
| 29 | 
 | 
|---|
| 30 | # Pfad, zu dem die Pfade in buildlist stehen
 | 
|---|
| 31 | my $smartclient_root="../../";   
 | 
|---|
| 32 | 
 | 
|---|
| 33 | #my $smartclient_root="/home/joergs/projects/smartclient/stuttgarter-versicherung/technical/";
 | 
|---|
| 34 | #$workdir="";
 | 
|---|
| 35 | 
 | 
|---|
| 36 | my $build = "build.sh";
 | 
|---|
| 37 | our ($opt_b, $opt_x);
 | 
|---|
| 38 | my @ArrayofBuilds;
 | 
|---|
| 39 | getopts('b:x');
 | 
|---|
| 40 | 
 | 
|---|
| 41 | 
 | 
|---|
| 42 | if (!$opt_b) {
 | 
|---|
| 43 |   $opt_b = "buildlist";
 | 
|---|
| 44 |   print "using default buildlist: buildlist\n\n";
 | 
|---|
| 45 |   print "other buildlist can be specified with -b buildlist\n\n";
 | 
|---|
| 46 | };
 | 
|---|
| 47 | 
 | 
|---|
| 48 | (open(BUILDLIST,$opt_b)) || die "Die Buildlist $opt_b  konnte nicht gefunden werden";
 | 
|---|
| 49 | 
 | 
|---|
| 50 | 
 | 
|---|
| 51 | while (<BUILDLIST>) #Buildlist parsen
 | 
|---|
| 52 |   {
 | 
|---|
| 53 |         my $dir;
 | 
|---|
| 54 |         my $arch;
 | 
|---|
| 55 |         my $opt;
 | 
|---|
| 56 |     next if (/^\#.*$/);
 | 
|---|
| 57 |         # if (/([\w\/]+)\s*:([\/\w\-\+\.]+)\s+:((\s*\-\-\w*)*)$/)
 | 
|---|
| 58 |     if (/(\S+)\s*:(\S+)\s*:(\S+)\s*$/)
 | 
|---|
| 59 |       {
 | 
|---|
| 60 |         ($dir, $arch, $opt) = ($1, $2, $3);
 | 
|---|
| 61 |         chomp ($arch);
 | 
|---|
| 62 |         my @build=($dir, $arch, $opt);
 | 
|---|
| 63 |         push @ArrayofBuilds, [@build];
 | 
|---|
| 64 |       }
 | 
|---|
| 65 |   }
 | 
|---|
| 66 | 
 | 
|---|
| 67 | 
 | 
|---|
| 68 | 
 | 
|---|
| 69 | print "What will be done:\n\n";
 | 
|---|
| 70 | ($wert1,$wert2,$wert3)= ("Path","Distribuition","Buildoptions");
 | 
|---|
| 71 | $~="TABELLE";
 | 
|---|
| 72 | write;
 | 
|---|
| 73 | print "\n";
 | 
|---|
| 74 | for my $i (0 .. $#ArrayofBuilds)
 | 
|---|
| 75 |   {
 | 
|---|
| 76 |     ($wert1,$wert2,$wert3)= ($ArrayofBuilds[$i][0],$ArrayofBuilds[$i][1],$ArrayofBuilds[$i][2]);
 | 
|---|
| 77 |     $~="TABELLE";
 | 
|---|
| 78 |     write;
 | 
|---|
| 79 |   }
 | 
|---|
| 80 | 
 | 
|---|
| 81 | print 'Are all the srpms extracted and all options OK? (y/n)';
 | 
|---|
| 82 | 
 | 
|---|
| 83 | my $answer=<STDIN>;
 | 
|---|
| 84 | chomp ($answer);
 | 
|---|
| 85 | if ($answer ne "y") {die("canceled")};
 | 
|---|
| 86 | 
 | 
|---|
| 87 | my $mypath;
 | 
|---|
| 88 | for my $i (0 .. $#ArrayofBuilds)
 | 
|---|
| 89 |   {
 | 
|---|
| 90 |   print("$ArrayofBuilds[$i][0]\t\t$ArrayofBuilds[$i][1]\t\t$ArrayofBuilds[$i][2]\n");
 | 
|---|
| 91 |   $mypath = $smartclient_root.$ArrayofBuilds[$i][0];
 | 
|---|
| 92 | 
 | 
|---|
| 93 |   if ($ArrayofBuilds[$i][2])
 | 
|---|
| 94 |     {
 | 
|---|
| 95 |       $ENV{'BUILD_MODE'}=$ArrayofBuilds[$i][2];
 | 
|---|
| 96 |     }
 | 
|---|
| 97 |   else 
 | 
|---|
| 98 |     {
 | 
|---|
| 99 |       $ENV{'BUILD_MODE'}="--clean";
 | 
|---|
| 100 |     }
 | 
|---|
| 101 |   $ENV{'BUILD_DIST'}=$ArrayofBuilds[$i][1];
 | 
|---|
| 102 | 
 | 
|---|
| 103 |   
 | 
|---|
| 104 |   $_=$ArrayofBuilds[$i][0];
 | 
|---|
| 105 |   print "$_ \n";
 | 
|---|
| 106 |   tr/\//\_/;
 | 
|---|
| 107 |   my $logfilename = "/tmp/smartclient_build/$_.$ArrayofBuilds[$i][1].log";
 | 
|---|
| 108 | 
 | 
|---|
| 109 |   my $build_cmd="cd $mypath && $build";
 | 
|---|
| 110 | 
 | 
|---|
| 111 |   # open a xterm to display build output
 | 
|---|
| 112 |   if ($opt_x)
 | 
|---|
| 113 |   {
 | 
|---|
| 114 |     system "xterm -T \"build log for PACKET: $mypath    ARCH:$ArrayofBuilds[$i][1] \" -e less +F $logfilename &";
 | 
|---|
| 115 |     print "++++++++++++++++++++++++++++++++++++++++++\n";
 | 
|---|
| 116 |   }
 | 
|---|
| 117 | 
 | 
|---|
| 118 |   # if mypath is not a directory, so it is a src.rpm (hopefully)
 | 
|---|
| 119 |   if( ! -d $mypath ) {
 | 
|---|
| 120 |     my $base    = basename($mypath);
 | 
|---|
| 121 |     my $dir     = dirname($mypath);
 | 
|---|
| 122 |         $build_cmd      = "cd $dir && $build $base-[0-9]*rpm";
 | 
|---|
| 123 |   }
 | 
|---|
| 124 | 
 | 
|---|
| 125 |   print "++++++++++++++++++++++++++++++++++++++++++\n";
 | 
|---|
| 126 |   print "BUILD_DIST ist $ENV{'BUILD_DIST'}\n";
 | 
|---|
| 127 |   print "BUILD_MODE ist $ENV{'BUILD_MODE'}\n";
 | 
|---|
| 128 |   print "executing build command:\n";
 | 
|---|
| 129 |   print "$build_cmd\n";
 | 
|---|
| 130 |   print "you can watch building with following command: \n";
 | 
|---|
| 131 |   print "less +F $logfilename\n\n";
 | 
|---|
| 132 | 
 | 
|---|
| 133 |   my $do_log = open( LOG_FD, ">$logfilename" ) || print "could not open logfile $logfilename";
 | 
|---|
| 134 |   open( PIPE, "$build_cmd 2>&1 |" );
 | 
|---|
| 135 |   while( <PIPE> ) {
 | 
|---|
| 136 |         if( ! $opt_x ) {
 | 
|---|
| 137 |           print;
 | 
|---|
| 138 |         }
 | 
|---|
| 139 |         print LOG_FD if $do_log;
 | 
|---|
| 140 |   }
 | 
|---|
| 141 |   close PIPE; my $retval=$?;
 | 
|---|
| 142 |   close LOG_FD if $do_log;
 | 
|---|
| 143 |   
 | 
|---|
| 144 |   if ( $retval == 0 )
 | 
|---|
| 145 |    {
 | 
|---|
| 146 |      $ArrayofBuilds[$i][3]= "SUCCESS $ArrayofBuilds[$i][0]: OK";
 | 
|---|
| 147 |      print"******                                                      ******\n";
 | 
|---|
| 148 |      print"******   building of $ArrayofBuilds[$i][0]: OK                    \n" ;
 | 
|---|
| 149 |      print"******                                                      ******\n";
 | 
|---|
| 150 |    }
 | 
|---|
| 151 |   else
 | 
|---|
| 152 |    {
 | 
|---|
| 153 |      $ArrayofBuilds[$i][3]="ERROR  $ArrayofBuilds[$i][0]: *FAILED*\n";
 | 
|---|
| 154 |      print"******                                                      ******\n";
 | 
|---|
| 155 |      print"\n\n\nERROR: building of $ArrayofBuilds[$i][0]: *FAILED*\n";
 | 
|---|
| 156 |      print"******                                                      ******\n";
 | 
|---|
| 157 |    }
 | 
|---|
| 158 | }
 | 
|---|
| 159 | 
 | 
|---|
| 160 | print "Building results:\n";
 | 
|---|
| 161 | 
 | 
|---|
| 162 | 
 | 
|---|
| 163 | 
 | 
|---|
| 164 | ($wert1,$wert2,$wert3)= ("Path","Distribuition","Result");
 | 
|---|
| 165 | $~="TABELLE";
 | 
|---|
| 166 | write;
 | 
|---|
| 167 | print "\n";
 | 
|---|
| 168 | 
 | 
|---|
| 169 | for my $i (0 .. $#ArrayofBuilds)
 | 
|---|
| 170 |   {
 | 
|---|
| 171 |     ($wert1,$wert2,$wert3)= ($ArrayofBuilds[$i][0],$ArrayofBuilds[$i][1],$ArrayofBuilds[$i][3]);
 | 
|---|
| 172 |     $~="TABELLE";
 | 
|---|
| 173 |     write;
 | 
|---|
| 174 |         # print("$ArrayofBuilds[$i][0]:Result: $ArrayofBuilds[$i][3]");
 | 
|---|
| 175 |   }
 | 
|---|
| 176 | 
 | 
|---|
| 177 | print "buildall.pl terminated\n";
 | 
|---|