releasing/cbrtools/perl/InstCol2
changeset 607 378360dbbdba
parent 602 3145852acc89
equal deleted inserted replaced
591:22486c9c7b15 607:378360dbbdba
       
     1 #!perl
       
     2 # Copyright (c) 2003-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 File::Find;
       
    22 use File::Copy;
       
    23 use Getopt::Long;
       
    24 use IniData;
       
    25 use EnvDb;
       
    26 use Utils;
       
    27 
       
    28 
       
    29 #
       
    30 # Globals.
       
    31 #
       
    32 
       
    33 my $verbose = 0;
       
    34 my $dummyRun = 0;
       
    35 my $interactive = 0;
       
    36 my $force = 0;
       
    37 my $wins = 1;
       
    38 my $wincw = 1;
       
    39 my $udeb = 1;
       
    40 my $urel = 1;
       
    41 my $comp;
       
    42 my %affectedExtentions;
       
    43 
       
    44 
       
    45 #
       
    46 # Constants.
       
    47 #
       
    48 
       
    49 my %searchPath = (
       
    50 		   wins => {
       
    51 			    udeb => '\\epoc32\\release\\wins\\udeb\\z',
       
    52 			    urel => '\\epoc32\\release\\wins\\urel\\z'
       
    53 			    },
       
    54 		   wincw => {
       
    55 			    udeb => '\\epoc32\\release\\wincw\\udeb\\z',
       
    56 			    urel => '\\epoc32\\release\\wincw\\urel\\z'
       
    57 			    }
       
    58 		 );
       
    59 my $KBinCompareChunkSize = 16 * 1024;
       
    60 
       
    61 
       
    62 #
       
    63 # Main.
       
    64 #
       
    65 
       
    66 ProcessCommandLine();
       
    67 my $files = FindFiles();
       
    68 CopyFiles($files);
       
    69 
       
    70 
       
    71 #
       
    72 # Subs.
       
    73 #
       
    74 
       
    75 sub ProcessCommandLine {
       
    76   Getopt::Long::Configure ('bundling');
       
    77   my $help;
       
    78   my $extention;
       
    79   my $winsOnly = 0;
       
    80   my $wincwOnly = 0;
       
    81   my $udebOnly = 0;
       
    82   my $urelOnly = 0;
       
    83   GetOptions('h' => \$help, 'f' => \$force, 'n' => \$dummyRun, 'i' => \$interactive, 'w' => \$winsOnly, 'c' => \$wincwOnly, 'd' => \$udebOnly, 'r' => \$urelOnly, 'v+' => \$verbose);
       
    84 
       
    85   if ($help) {
       
    86     Usage(0);
       
    87   }
       
    88 
       
    89   $extention = lc(shift @ARGV);
       
    90   $comp = shift @ARGV;
       
    91 
       
    92   unless ($extention and ($extention eq 'cl' or $extention eq 'bw')) {
       
    93     print "Error: Invalid colour discription\n";
       
    94     Usage(1);
       
    95   }
       
    96   unless (scalar (@ARGV) == 0) {
       
    97     print "Error: Invalid number of arguments\n";
       
    98     Usage(1);
       
    99   }
       
   100   if ($winsOnly and $wincwOnly) {
       
   101     print "Error: -w and -c options are mutually exclusive\n";
       
   102     Usage(1);
       
   103   }
       
   104   if ($udebOnly and $urelOnly) {
       
   105     print "Error: -d and -r options are mutually exclusive\n";
       
   106     Usage(1);
       
   107   }
       
   108 
       
   109   if ($winsOnly) {
       
   110     $wincw = 0;
       
   111   }
       
   112   if ($wincwOnly) {
       
   113     $wins = 0;
       
   114   }
       
   115   if ($udebOnly) {
       
   116     $urel = 0;
       
   117   }
       
   118   if ($urelOnly) {
       
   119     $udeb = 0;
       
   120   }
       
   121 
       
   122   %affectedExtentions = (
       
   123 			  ".a$extention" => '.aif',
       
   124 			  ".i$extention" => '.ini',
       
   125 			  ".m$extention" => '.mbm'
       
   126 			 );
       
   127 }
       
   128 
       
   129 sub Usage {
       
   130   my $exitCode = shift;
       
   131 
       
   132   Utils::PrintDeathMessage($exitCode, "\nUsage: instcol2 [options] cl | bw [<component>]
       
   133 
       
   134 options:
       
   135 
       
   136 -h  help
       
   137 -f  force a copy of everything (i.e. instcol behaviour)
       
   138 -n  dummy run (list what would be done, but doesn't do anything)
       
   139 -i  interactive mode (ask before copying each file)
       
   140 -w  WINS emulator only
       
   141 -c  WINCW emulator only
       
   142 -d  UDEB builds only
       
   143 -r  UREL builds only
       
   144 -v  verbose output (-vv very verbose)\n");
       
   145 }
       
   146 
       
   147 sub FindFiles {
       
   148   my @files;
       
   149   if ($comp) {
       
   150     FindCompFiles($comp, \@files);
       
   151   }
       
   152   else {
       
   153     if ($wins) {
       
   154       if ($udeb) {
       
   155 	DoFindFiles($searchPath{wins}->{udeb}, \@files);
       
   156       }
       
   157       if ($urel) {
       
   158 	DoFindFiles($searchPath{wins}->{urel}, \@files);
       
   159       }
       
   160     }
       
   161     if ($wincw) {
       
   162       if ($udeb) {
       
   163 	DoFindFiles($searchPath{wincw}->{udeb}, \@files);
       
   164       }
       
   165       if ($urel) {
       
   166 	DoFindFiles($searchPath{wincw}->{urel}, \@files);
       
   167       }
       
   168     }
       
   169   }
       
   170   return \@files;
       
   171 }
       
   172 
       
   173 sub FindCompFiles {
       
   174   my $comp = shift;
       
   175   my $files = shift;
       
   176   my $iniData = IniData->New();
       
   177   my $envDb = EnvDb->Open($iniData, $verbose);
       
   178   unless ($envDb->Version($comp)) {
       
   179     print "Error: \"$comp\" is not currently installed\n";
       
   180     Usage(1);
       
   181   }
       
   182   my $info = $envDb->ListBins($comp);
       
   183   shift @$info; # Get rid of title.
       
   184   foreach my $line (@$info) {
       
   185     unless ($line->[0] =~ /^\\epoc32\\data/i) {
       
   186       my $extention = lc (Extention($line->[0]));
       
   187       if ($extention and ($line->[1] ne EnvDb::STATUS_STRING_MISSING) and exists $affectedExtentions{$extention}) {
       
   188 	push (@$files, lc($line->[0]));
       
   189       }
       
   190     }
       
   191   }
       
   192 }
       
   193 
       
   194 sub DoFindFiles {
       
   195   my $path = shift;
       
   196   my $files = shift;
       
   197   my $processFileSub = sub {
       
   198     if (-f $File::Find::name) {
       
   199       my $thisFile = lc($File::Find::name);
       
   200       my $extention = Extention($thisFile);
       
   201       if ($extention) {
       
   202 	if (exists $affectedExtentions{$extention}) {
       
   203 	  Utils::TidyFileName(\$thisFile);
       
   204 	  push (@$files, $thisFile);
       
   205 	}
       
   206       }
       
   207     }
       
   208   };
       
   209   if (-e $path) {
       
   210     find($processFileSub, $path);
       
   211   }
       
   212 }
       
   213 
       
   214 sub CopyFiles {
       
   215   my $files = shift;
       
   216   foreach my $thisFile (@$files) {
       
   217     (my $path, my $name, my $ext) = Utils::SplitFileName($thisFile);
       
   218     my $newExt = $affectedExtentions{$ext};
       
   219     my $newName = Utils::ConcatenateDirNames($path, "$name$newExt");
       
   220     CopyFile($thisFile, $newName);
       
   221   }
       
   222 }
       
   223 
       
   224 sub CopyFile {
       
   225   my $from = shift;
       
   226   my $to = shift;
       
   227 
       
   228   unless ($force) {
       
   229     if (-e $to) {
       
   230       (my $fromMtime, my $fromSize) = Utils::FileModifiedTimeAndSize($from);
       
   231       (my $toMtime, my $toSize) = Utils::FileModifiedTimeAndSize($to);
       
   232       if ($fromMtime == $toMtime) {
       
   233 	print "Last modified times of \"$from\" and \"$to\" are identical\n" if ($verbose > 2);
       
   234 	return;
       
   235       }
       
   236       if ($fromSize == $toSize) {
       
   237 	if (BinaryCompare($from, $to, $fromSize)) {
       
   238 	  print "Binary content of \"$from\" and \"$to\" are identical\n" if ($verbose > 2);
       
   239 	  return;
       
   240 	}
       
   241 	else {
       
   242 	  print "Binary content of \"$from\" and \"$to\" are different\n" if ($verbose > 1);
       
   243 	}
       
   244       }
       
   245       else {
       
   246 	print "Sizes of \"$from\" and \"$to\" are different\n" if ($verbose > 1);
       
   247       }
       
   248     }
       
   249     else {
       
   250       print "\"$to\" does not exist\n" if ($verbose > 1);
       
   251     }
       
   252   }
       
   253 
       
   254   if ($interactive) {
       
   255     print "Copy \"$from\" to \"$to\"? [y] ";
       
   256     my $response = <STDIN>;
       
   257     chomp $response;
       
   258     unless ($response =~ /^y$/i or not $response) {
       
   259       return;
       
   260     }
       
   261   }
       
   262 
       
   263   if ($verbose) {
       
   264     print "Copying \"$from\" to \"$to\"\n";
       
   265   }
       
   266   unless ($dummyRun) {
       
   267     copy ($from, $to) or die "Error: Couldn't copy \"$from\" to \"$to\": $!\n";
       
   268   }
       
   269 }
       
   270 
       
   271 sub BinaryCompare {
       
   272   my $file1 = shift;
       
   273   my $file2 = shift;
       
   274   my $size = shift;
       
   275   my $identical = 1;
       
   276   open (FILE1, $file1) or die "Error: Couldn't open \"$file1\": $!\n";
       
   277   open (FILE2, $file2) or die "Error: Couldn't open \"$file2\": $!\n";
       
   278   binmode (FILE1);
       
   279   binmode (FILE2);
       
   280   my $bytesCompared = 0;
       
   281   while ($bytesCompared < $size) {
       
   282     my $buf1;
       
   283     my $buf2;
       
   284     my $bytesRead1 = read (FILE1, $buf1, $KBinCompareChunkSize);
       
   285     my $bytesRead2 = read (FILE2, $buf2, $KBinCompareChunkSize);
       
   286     unless ($bytesRead1 eq $bytesRead2) {
       
   287       die "Error: Problem binary comparing \"$file1\" with \"$file2\": $!\n";
       
   288     }
       
   289     $bytesCompared += $bytesRead1;
       
   290     if ($buf1 ne $buf2) {
       
   291       $identical = 0;
       
   292       last;
       
   293     }
       
   294   }
       
   295   close (FILE1);
       
   296   close (FILE2);
       
   297   return $identical;
       
   298 }
       
   299 
       
   300 sub Extention {
       
   301   my $fileName = shift;
       
   302   (my $ext) = $fileName =~ /(\.[^\.]*)$/;
       
   303   return $ext;
       
   304 }
       
   305 
       
   306 __END__
       
   307 
       
   308 =head1 NAME
       
   309 
       
   310 InstCol2 - A more controlled instcol.
       
   311 
       
   312 =head1 SYNOPSIS
       
   313 
       
   314   instcol2 [options] cl | bw [<component>]
       
   315 
       
   316 options:
       
   317 
       
   318   -h  help
       
   319   -f  force a copy of everything (i.e. instcol behaviour)
       
   320   -n  dummy run (list what would be done, but doesn't do anything)
       
   321   -i  interactive mode (ask before copying each file)
       
   322   -w  WINS emulator only
       
   323   -c  WINCW emulator only
       
   324   -d  UDEB builds only
       
   325   -r  UREL builds only
       
   326   -v  verbose output (-vv very verbose)
       
   327 
       
   328 =head1 DESCRIPTION
       
   329 
       
   330 Symbian tools C<instcol> may be used to configure the emulator to be either colour or monochrome. Files with the extentions F<.aif>, F<.ini>, F<.mbm> are often provided in both colour and monochrome variants. The last two characters of the extention are replaced with F<cl> for colour, or F<bw> for monochrome. To install a particular variant, C<instcol> simply copies files with the required colour variant extention to files with the emulator required extention. For example, F<eikon.mcl> would be copied to a file named F<eikon.mbm> if the emulator were to be configured for colour.
       
   331 
       
   332 This emulator configuration technique has the unfortunate side effect of making development environments dirty from the point of view of the release tools. It is hoped that this problem will eventually disappear, if support for multiple colour variants of the emulator is dropped. In the meantime, C<InstCol2> was written to provide a higher degree of control over changes made to development environments than that offered by C<instcol>.
       
   333 
       
   334 C<InstCol2> only copies files if it really has to. A copy will only occur if:
       
   335 
       
   336 =over 4
       
   337 
       
   338 =item *
       
   339 
       
   340 The emulator required extention (F<.aif>, F<.ini> or F<.mbm>) copy of a particular file does not exist.
       
   341 
       
   342 =item *
       
   343 
       
   344 The emulator required extention copy for a particular file has a last modified time of less than the required colour variant of the file.
       
   345 
       
   346 =item *
       
   347 
       
   348 The emulator required exetention copy for a particular file contains different binary data to the required colour varaint of the file.
       
   349 
       
   350 =back
       
   351 
       
   352 =head1 EXAMPLES
       
   353 
       
   354  instcol2 -wd cl
       
   355 
       
   356 Installs the colour variants for the WINS UDEB emulator.
       
   357 
       
   358  instcol2 -cr bw alaunch
       
   359 
       
   360 Installs the monochrome variants for the WINCW UREL emulator for the component C<alaunch>.
       
   361 
       
   362 =head1 KNOWN BUGS
       
   363 
       
   364 None.
       
   365 
       
   366 =head1 COPYRIGHT
       
   367 
       
   368  Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
   369  All rights reserved.
       
   370  This component and the accompanying materials are made available
       
   371  under the terms of the License "Eclipse Public License v1.0"
       
   372  which accompanies this distribution, and is available
       
   373  at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
   374  
       
   375  Initial Contributors:
       
   376  Nokia Corporation - initial contribution.
       
   377  
       
   378  Contributors:
       
   379  
       
   380  Description:
       
   381  
       
   382 
       
   383 =cut