releasing/cbrtools/perl/mbld
changeset 607 378360dbbdba
parent 602 3145852acc89
equal deleted inserted replaced
591:22486c9c7b15 607:378360dbbdba
       
     1 #!perl
       
     2 # Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the License "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 # 
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 # 
       
    12 # Contributors:
       
    13 # 
       
    14 # Description:
       
    15 # 
       
    16 #
       
    17 
       
    18 use strict;
       
    19 use FindBin;
       
    20 use lib "$FindBin::Bin";
       
    21 use Cwd;
       
    22 use Getopt::Long;
       
    23 use Utils;
       
    24 
       
    25 $|++;
       
    26 
       
    27 #
       
    28 # Globals
       
    29 #
       
    30 
       
    31 my @bldData;
       
    32 my $descriptionFile;
       
    33 my $keepGoing = '';
       
    34 my $saveSpace = '';
       
    35 my $verbose = 0;
       
    36 my $clean = 0;
       
    37 my $outFile = "stdout.log";
       
    38 my $errorFile = "stderr.log";
       
    39 my $startTime;
       
    40 my $cwd;
       
    41 
       
    42 
       
    43 #
       
    44 # Main.
       
    45 #
       
    46 
       
    47 ProcessCommandLine();
       
    48 ParseDescriptionFile();
       
    49 Init();
       
    50 DoBuild();
       
    51 End();
       
    52 
       
    53 
       
    54 #
       
    55 # Subs
       
    56 #
       
    57 
       
    58 sub ProcessCommandLine {
       
    59   Getopt::Long::Configure ("bundling");
       
    60   my $help;
       
    61   GetOptions('c+' => \$clean, 'h' => \$help, 'k' => \$keepGoing, 's' => \$saveSpace, 'v+' => \$verbose);
       
    62 
       
    63   if ($help) {
       
    64     Usage(0);
       
    65   }
       
    66 
       
    67   $descriptionFile = shift @ARGV;
       
    68 
       
    69   unless ($descriptionFile and $#ARGV == -1) {
       
    70     print "Error: Invalid arguments\n";
       
    71     Usage(1);
       
    72   }
       
    73 }
       
    74 
       
    75 sub Usage {
       
    76   my $exitCode = shift;
       
    77 
       
    78   Utils::PrintDeathMessage($exitCode, "\nUsage: mbld [options] <build_description_file>
       
    79 
       
    80 options:
       
    81 
       
    82 -h  help
       
    83 -c  clean (-cc reallyclean)
       
    84 -k  keep going
       
    85 -s  save space
       
    86 -v  verbose output (-vv very verbose)\n");
       
    87 }
       
    88 
       
    89 sub Init {
       
    90   $startTime = time;
       
    91   unlink $outFile;
       
    92   unlink $errorFile;
       
    93   $cwd = cwd();
       
    94   $outFile = "$cwd\\$outFile";
       
    95   $errorFile = "$cwd\\$errorFile";
       
    96 }
       
    97 
       
    98 
       
    99 sub ParseDescriptionFile {
       
   100   open(FILE, $descriptionFile) or die "Error: Unable to open \"$descriptionFile\" for reading: $!\n";
       
   101 
       
   102   my $line = -1;
       
   103   while (<FILE>) {
       
   104     ++$line;
       
   105     # Remove line feed, white space and comments.
       
   106     chomp;
       
   107     s/^\s*$//;
       
   108     s/#.*//;
       
   109     if ($_ eq '') {
       
   110       # Nothing left.
       
   111       next;
       
   112     }
       
   113 
       
   114     (my @words) = split /\s+/;
       
   115 
       
   116     if ($#words < 2) {
       
   117       print "Warning: Not enough arguments on line $line\n";
       
   118       next;
       
   119     }
       
   120 
       
   121     my $bldEntry;
       
   122     $bldEntry->{name} = shift @words;
       
   123     $bldEntry->{bldInf} = shift @words;
       
   124     if ($words[0] eq 'test') {
       
   125       $bldEntry->{test} = 1;
       
   126       shift @words;
       
   127       if ($#words == -1) {
       
   128 	print "Warning: Not enough arguments on line $line\n";
       
   129 	next;
       
   130       }
       
   131     }
       
   132     $bldEntry->{plat} = shift @words;
       
   133     if ($#words >= 0) {
       
   134       if ($words[0] =~ /(udeb)|(urel)/) {
       
   135 	$bldEntry->{var} = shift @words;
       
   136       }
       
   137     }
       
   138     if ($#words >= 0) {
       
   139       $bldEntry->{mmp} = shift @words;
       
   140     }
       
   141 
       
   142     push (@bldData, $bldEntry);
       
   143   }
       
   144     
       
   145   close FILE;
       
   146 }
       
   147 
       
   148 sub DoBuild {
       
   149   if ($clean == 1) {
       
   150     DoPlatformVariantCommand('clean:       ', 'abld', 'clean');
       
   151   }
       
   152   elsif ($clean == 2) {
       
   153     DoPlatformVariantCommand('reallyclean: ', 'abld', 'reallyclean');
       
   154   }
       
   155   DoBldMake();
       
   156   DoExport();
       
   157   DoPlatformCommand('makefile:    ', 'abld', 'makefile');
       
   158   DoPlatformCommand('library:     ', 'abld', 'library');
       
   159   DoPlatformVariantCommand('resource:    ', 'abld', 'resource');
       
   160   my $target = 'target';
       
   161   if ($keepGoing) {
       
   162     $target .= " $keepGoing";
       
   163   }
       
   164   if ($saveSpace) {
       
   165     $target .= " $saveSpace";
       
   166   }
       
   167   DoPlatformVariantCommand('target:      ', 'abld', $target);
       
   168   DoPlatformVariantCommand('final:       ', 'abld', 'final');
       
   169   DoPlatformVariantCommand('check:       ', 'abld -check', 'build');
       
   170 }
       
   171 
       
   172 sub DoBldMake {
       
   173   my %built;
       
   174   foreach my $bldEntry (@bldData) {
       
   175     unless (exists $built{lc($bldEntry->{bldInf})}) {
       
   176       DoPrint("bldfiles:     $bldEntry->{name} [bldmake bldfiles]");
       
   177       chdir $bldEntry->{bldInf} or die "Error: Couldn't change working directory to \"$bldEntry->{bldInf}\": $!\n";
       
   178       system "bldmake bldfiles >>$outFile 2>>$errorFile";
       
   179       chdir $cwd or die "Error: Couldn't change working directory to \"$cwd\": $!\n";
       
   180       $built{lc($bldEntry->{bldInf})} = 1;
       
   181     }
       
   182   }
       
   183 }
       
   184 
       
   185 sub DoExport {
       
   186   my %built;
       
   187   my %builtTest;
       
   188   foreach my $bldEntry (@bldData) {
       
   189     if (exists $bldEntry->{test}) {
       
   190       unless (exists $builtTest{lc($bldEntry->{bldInf})}) {
       
   191 	DoPrint("export:       $bldEntry->{name} [abld test export]");
       
   192 	chdir $bldEntry->{bldInf} or die "Error: Couldn't change working directory to \"$bldEntry->{bldInf}\": $!\n";
       
   193 	system "abld test export >>$outFile 2>>$errorFile";
       
   194 	chdir $cwd or die "Error: Couldn't change working directory to \"$cwd\": $!\n";
       
   195 	$builtTest{lc($bldEntry->{bldInf})} = 1;
       
   196       }
       
   197     }
       
   198     else {
       
   199       unless (exists $built{lc($bldEntry->{bldInf})}) {
       
   200 	DoPrint("export:       $bldEntry->{name} [abld export]");
       
   201 	chdir $bldEntry->{bldInf} or die "Error: Couldn't change working directory to \"$bldEntry->{bldInf}\": $!\n";
       
   202 	system "abld export >>$outFile 2>>$errorFile";
       
   203 	chdir $cwd or die "Error: Couldn't change working directory to \"$cwd\": $!\n";
       
   204 	$built{lc($bldEntry->{bldInf})} = 1;
       
   205       }
       
   206     }
       
   207   }
       
   208 }
       
   209 
       
   210 sub DoPlatformCommand {
       
   211   my $prompt = shift;
       
   212   my $command1 = shift;
       
   213   my $command2 = shift;
       
   214 
       
   215   foreach my $bldEntry (@bldData) {
       
   216     my $command = $command1;
       
   217     if (exists $bldEntry->{test}) {
       
   218       $command .= ' test';
       
   219     }
       
   220     $command .= " $command2 $bldEntry->{plat}";
       
   221     if (exists $bldEntry->{mmp}) {
       
   222       $command .= " $bldEntry->{mmp}";
       
   223     }
       
   224     DoPrint("$prompt $bldEntry->{name} [$command]");
       
   225     chdir $bldEntry->{bldInf} or die "Error: Couldn't change working directory to \"$bldEntry->{bldInf}\": $!\n";
       
   226     system "$command >>$outFile 2>>$errorFile";
       
   227     chdir $cwd or die "Error: Couldn't change working directory to \"$cwd\": $!\n";
       
   228   }
       
   229 }
       
   230 
       
   231 sub DoPlatformVariantCommand {
       
   232   my $prompt = shift;
       
   233   my $command1 = shift;
       
   234   my $command2 = shift;
       
   235 
       
   236   foreach my $bldEntry (@bldData) {
       
   237     my $command = $command1;
       
   238     if (exists $bldEntry->{test}) {
       
   239       $command .= ' test';
       
   240     }
       
   241     $command .= " $command2 $bldEntry->{plat}";
       
   242     if (exists $bldEntry->{var}) {
       
   243       $command .= " $bldEntry->{var}";
       
   244     }
       
   245     if (exists $bldEntry->{mmp}) {
       
   246       $command .= " $bldEntry->{mmp}";
       
   247     }
       
   248     DoPrint("$prompt $bldEntry->{name} [$command]");
       
   249     chdir $bldEntry->{bldInf} or die "Error: Couldn't change working directory to \"$bldEntry->{bldInf}\": $!\n";
       
   250     system "$command >>$outFile 2>>$errorFile";
       
   251     chdir $cwd or die "Error: Couldn't change working directory to \"$cwd\": $!\n";
       
   252   }
       
   253 }
       
   254 
       
   255 sub DoPrint {
       
   256   my $prompt = $_[0];
       
   257 
       
   258   print "$prompt\n";
       
   259   system "echo === $prompt >> $outFile";
       
   260   system "echo === $prompt >> $errorFile";
       
   261 }
       
   262 
       
   263 sub End {
       
   264   my $finishTime = time;
       
   265   my $total = $finishTime - $startTime;
       
   266   my $seconds =  $total % 60;$total = ($total - $seconds) / 60;
       
   267   my $minutes =  $total % 60;$total = ($total - $minutes) / 60;
       
   268   my $hours =  $total % 24;$total = ($total - $hours)   / 24;
       
   269 
       
   270   print "\nTotal build time: $hours:$minutes:$seconds\n";
       
   271   chdir $cwd;
       
   272 }
       
   273 
       
   274 
       
   275 __END__
       
   276 
       
   277 =head1 NAME
       
   278 
       
   279 MBld - Builds multiple components in one pass.
       
   280 
       
   281 =head1 SYNOPSIS
       
   282 
       
   283   mbld [options] <build_description_file>
       
   284 
       
   285 options:
       
   286 
       
   287   -h  help
       
   288   -c  clean (-cc reallyclean)
       
   289   -k  keep going
       
   290   -s  save space
       
   291   -v  verbose output (-vv very verbose)
       
   292 
       
   293 =head1 DESCRIPTION
       
   294 
       
   295 The build description file must be plain text with lines of the following format (one for each item that you want to be built):
       
   296 
       
   297  component_name  bld_inf_path  [test] platform [variant] [mmp_file]
       
   298 
       
   299 =over 4
       
   300 
       
   301 =item component_name
       
   302 
       
   303 A string that can be used to identify the component being built - can be anything you like provided it's a single word.
       
   304 
       
   305 =item bld_inf_path
       
   306 
       
   307 An absolute or relative path to where the componen't F<bld.inf> file can be found.
       
   308 
       
   309 =item test
       
   310 
       
   311 An optional argument to allow test code to be built.
       
   312 
       
   313 =item platform
       
   314 
       
   315 The build plaform required (e.g. C<WINS>, C<WINCW>, C<THUMB>, C<ARM4>, C<ARMI>, C<MISA> etc).
       
   316 
       
   317 =item variant
       
   318 
       
   319 The build variant (either C<udeb> or C<urel>). If ommitted, both variants will be built.
       
   320 
       
   321 =item mmp_file
       
   322 
       
   323 A optional argument that allows specific projects (defined by an F<mmp> file) to be built. If ommitted all F<mmp> files will be used.
       
   324 
       
   325 =back
       
   326 
       
   327 The build output is captured to a pair of log files; F<stdout.log> for C<STDOUT> and F<stderr.log> for C<STDERR>.
       
   328 
       
   329 
       
   330 =head1 KNOWN BUGS
       
   331 
       
   332 None.
       
   333 
       
   334 =head1 COPYRIGHT
       
   335 
       
   336  Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
   337  All rights reserved.
       
   338  This component and the accompanying materials are made available
       
   339  under the terms of the License "Eclipse Public License v1.0"
       
   340  which accompanies this distribution, and is available
       
   341  at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
   342  
       
   343  Initial Contributors:
       
   344  Nokia Corporation - initial contribution.
       
   345  
       
   346  Contributors:
       
   347  
       
   348  Description:
       
   349  
       
   350 
       
   351 =cut