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