build/tools/sw_version.pl
branchRCL_3
changeset 21 ea3e26ea6629
parent 6 c8ecf89eb77f
equal deleted inserted replaced
6:c8ecf89eb77f 21:ea3e26ea6629
     1 #
       
     2 # Copyright (c) 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 "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 
       
    19 use strict;
       
    20 use Time::Local;
       
    21 use File::Copy;
       
    22 use Getopt::Long;
       
    23 
       
    24 
       
    25 # Parameters
       
    26 
       
    27 my $window_title;
       
    28 my @custom_version;
       
    29 my $S60_platform;
       
    30 my $S60_version;
       
    31 my $date;
       
    32 my $string;
       
    33 my $fwstring;
       
    34 my $file;
       
    35 my $bt;
       
    36 my $fwid;
       
    37 
       
    38 my $result = GetOptions(
       
    39 		'w=s' => \$window_title, 
       
    40 		'c=s' => \@custom_version, 
       
    41 		'p=s' => \$S60_platform, 
       
    42 		'pv=s' => \$S60_version,
       
    43 		'pd=s' => \$date, 
       
    44 		'bt' => \$bt,
       
    45 		'fw=s' => \$fwid);	
       
    46 if (!$result){&error_msg("Required Argument(s) are missing or wrong");}
       
    47 
       
    48 	
       
    49 #
       
    50 # Main program
       
    51 #
       
    52 if ((!defined $S60_platform) && (!scalar @custom_version) && (!defined $window_title) && (!defined $bt)) {
       
    53 	&error_msg("Required Argument(s) are missing");
       
    54 }
       
    55 
       
    56 if (defined $S60_platform) {
       
    57 	initial_s60();
       
    58 	sw_version(); 
       
    59 }
       
    60 elsif (scalar @custom_version){
       
    61 	initial_custom();
       
    62 	sw_version(); 
       
    63 }
       
    64 
       
    65 if (defined $window_title) {
       
    66 	window_title ();
       
    67 }
       
    68 
       
    69 if (defined $bt) {
       
    70 	bt_port_value();
       
    71 }
       
    72 
       
    73 if (defined $fwid) {
       
    74 	fwid_version();
       
    75 }
       
    76 
       
    77 
       
    78 #
       
    79 # S60 initialisation
       
    80 #
       
    81 sub initial_s60 (){
       
    82 	my $version_short;
       
    83 
       
    84 	if (defined $date) {
       
    85 		unless ($date=~/now/i || $date=~/today/i || $date=~/\d\d-\d\d-\d\d/ ) {  &error_msg("Wrong date format. ");}
       
    86 	}
       
    87 
       
    88 # convert platform version string to short format
       
    89 # like: S60_X_Y -> S60-XY
       
    90 	my @temp_version = split('_',$S60_platform);
       
    91 
       
    92 	foreach (@temp_version) {
       
    93 		if ($version_short eq "") {
       
    94 			$version_short = $_;
       
    95 			$version_short .= "-";
       
    96 		}
       
    97 		else {
       
    98 			$version_short .= $_;
       
    99 		}
       
   100 	}
       
   101 	
       
   102 	# create version string
       
   103 	#V S60_31_200616\n20-04-06\nS60-31\n(c)NMP
       
   104 	if (defined $date) {
       
   105 		$string='V '.$S60_platform.'_'.$S60_version.'\n*DD*-*MM*-*YY*\n'.$version_short.'\n(c)NMP';
       
   106 	}
       
   107 	else {
       
   108 		$string='V '.$S60_platform.'_'.$S60_version.'\nxx-xx-xx\nxxx-xxx\n(c)NMP';
       
   109 	}
       
   110 
       
   111 	$fwstring='V '.$S60_platform.'_'.$S60_version;
       
   112 	
       
   113 # set today to date
       
   114 	if ($date=~/now/i || $date=~/today/i) {
       
   115 		my ($time,$sek, $min, $hour, $day, $month, $year);
       
   116 	  ($sek, $min, $hour, $day, $month, $year) = (localtime)[0,1,2,3,4,5];
       
   117 	  $month += 1;
       
   118 	  $year += 1900;
       
   119 	  
       
   120 	  my $year_short=$year;
       
   121 	  $year_short=~s/.*(\d\d)$/-$1/;
       
   122 	  $date=$day.'-'.$month.$year_short
       
   123 	}
       
   124 	
       
   125 	$string=~s/\*DD\*-\*MM\*-\*YY\*/$date/; 
       
   126 }
       
   127 
       
   128 #
       
   129 # Custom initialisation
       
   130 #
       
   131 sub initial_custom (){
       
   132 	foreach (@custom_version) {
       
   133 		if ($string eq "") {
       
   134 			$string=$_;
       
   135 		}
       
   136 		else {
       
   137 			$string.='\n';
       
   138 			$string.=$_;
       
   139 		}
       
   140 	}
       
   141 }
       
   142 
       
   143 #
       
   144 # Write new version information for Version project
       
   145 #
       
   146 sub sw_version (){
       
   147 	$file="\\sf\\os\\deviceplatformrelease\\version\\data\\sw.txt";
       
   148   open (to_file,">$file") || die " Cannot create $file Reason: $!\n";
       
   149   #
       
   150   # Writing the version string in the unicode format.
       
   151   #
       
   152   print to_file "\xFF\xFE";
       
   153   for (my $i = 0; $i < length($string); $i++) {
       
   154     printf to_file "%s\0", substr($string,$i, 1);
       
   155   }
       
   156   close (to_file);
       
   157 }
       
   158 
       
   159 
       
   160 #
       
   161 # Write new fwid version information to fwid files
       
   162 #
       
   163 sub fwid_version (){
       
   164 # $fwid (is path to fwid files) = \\s60_RnD\build_RnD\version_rnd\data\
       
   165 
       
   166 	my $fwid_file=$fwid."fwid1.txt";
       
   167 	write_unicode ($fwid_file, "id=core", "version=".$fwstring );
       
   168 
       
   169 	my $fwid_file=$fwid."fwid2.txt";
       
   170 	write_unicode ($fwid_file, "id=language", "version=".$fwstring." lang" );
       
   171 
       
   172 	my $fwid_file=$fwid."fwid3.txt";
       
   173 	write_unicode ($fwid_file, "id=customer", "version=".$fwstring." cust" );
       
   174 }
       
   175 
       
   176 #
       
   177 # Writing the version string in the unicode format.
       
   178 #
       
   179 
       
   180 sub write_unicode (){
       
   181   my $unicode_file = shift;
       
   182   my @unicode_lines = @_;
       
   183 
       
   184 
       
   185   open (to_file,">$unicode_file") || die " Cannot create $unicode_file Reason: $!\n";
       
   186 	binmode to_file;
       
   187 
       
   188   print to_file "\xFF\xFE";
       
   189 	my $size = scalar(@unicode_lines);
       
   190 
       
   191 	foreach my $l (@unicode_lines) {
       
   192 	  for (my $i = 0; $i < length($l); $i++) {
       
   193      printf to_file "%s\0", substr($l,$i, 1);
       
   194  	  }
       
   195 
       
   196   	$size--;
       
   197 
       
   198 		if ($size) {
       
   199 	  	print to_file "\x0D\x00\x0A\x00";
       
   200 	  }
       
   201 	}	
       
   202   close (to_file);
       
   203 }
       
   204 
       
   205 #
       
   206 # Change window title for s60config project
       
   207 # Set new window title to epoc*.ini files 
       
   208 #
       
   209 sub window_title ($){
       
   210   my(@files);
       
   211   # read configuration files from epoc.ini
       
   212 	my $epoc_ini_file="\\s60\\mw\\uiresources\\uiconfig\\s60config\\src\\epoc.ini";
       
   213   open(INI,$epoc_ini_file) or die "Cannot open $epoc_ini_file\n";
       
   214   while (<INI>) {
       
   215 	  chomp; #Remove line feed and carriage return  
       
   216 	  if (/^configuration /) {
       
   217       $_ =~ s/^configuration //;
       
   218       push @files, $_;
       
   219     }
       
   220 	}
       
   221   close INI;
       
   222 
       
   223 # change window title to each configuration file
       
   224 	foreach my $input_file (@files) {
       
   225 	  my @lines;
       
   226 		$file="\\s60\\mw\\uiresources\\uiconfig\\s60config\\src\\$input_file";
       
   227 	  open(IN,$file) or die "Cannot open $file";
       
   228 	  @lines=<IN>;
       
   229 	  close IN;
       
   230 	
       
   231 	  foreach (@lines){
       
   232 	  	$string = $_;
       
   233 	    if (/^\s*WindowTitle\s+\S+/i) {
       
   234 	      $_ = "WindowTitle ".$window_title."\n";
       
   235 	    }
       
   236 		}
       
   237 		
       
   238 	  open (OUT,">$file") || die "Cannot open $file for overwriting!\n";
       
   239 	  print OUT @lines;
       
   240 	  close OUT;
       
   241 	}
       
   242 }
       
   243 
       
   244 #
       
   245 # Change correct port value to allow emulator booting
       
   246 #
       
   247 sub bt_port_value(){
       
   248   my @lines;  
       
   249   my $bt_string;
       
   250 	$file="\\epoc32\\release\\WINSCW\\UDEB\\Z\\private\\101f7989\\Esock\\bt.bt.esk";
       
   251   open(IN,$file) or die "Cannot open $file";
       
   252   @lines=<IN>;
       
   253   close IN;
       
   254 
       
   255   foreach (@lines){
       
   256   	$bt_string = $_;
       
   257     if (/^\s*port=\s+\S+/i) {
       
   258       $_ = "port= -1\n";
       
   259     }
       
   260 	}
       
   261 	
       
   262   open (OUT,">$file") || die "Cannot open $file for overwriting!\n";
       
   263   print OUT @lines;
       
   264   close OUT;
       
   265 }
       
   266 
       
   267 
       
   268 sub error_msg ($){
       
   269   my($ErrorMsg);
       
   270   ($ErrorMsg)=@_;
       
   271   my $given_command=$0;
       
   272   $given_command =~ s/.*\\(\w+\.\w+)$/$1/;
       
   273   print "";
       
   274   print "\n";
       
   275   print "Error: $ErrorMsg \n";
       
   276   print "\n";  
       
   277   print "Usage: $given_command [options]\n\n";
       
   278   print "  Options for change version information\n";
       
   279   print "    -p S60_platform [optional with -c]\n";
       
   280   print "    -pv S60_version [optional, require -p]\n";
       
   281   print "    -pd date [optional, require -p]\n";
       
   282   print "    -c custom_version [optional with -p]\n\n";
       
   283   print "  Option for change emulator window title\n";
       
   284   print "    -w window_title [optional]\n\n";
       
   285   print "  Option for change bt port to -1 for emulator\n";
       
   286   print "    -bt [optional]\n";
       
   287   print "    -fwid [optional](To update fwid files for Fota in rnd)\n"; 
       
   288   print "\n\n";  
       
   289   print "DATE uses dd-mm-yy format or you can give now/today\n\n";  
       
   290   print "Example: $given_command -p S60_3_1 -pv 200616 -pd now\n";  
       
   291   print "Example: $given_command -w 92_200614 -p S60_3_1 -pv 200616 -pd now -bt\n";  
       
   292   print "Example: $given_command -w 92_200614 -p S60_3_1 -pv 200616 -pd 26-04-06\n";  
       
   293   print "Example: $given_command -c \"custom\" -c \"version\"\n";  
       
   294   print "Example: $given_command -fw \s60_RnD\build_RnD\version_rnd\data\"\n";  
       
   295   die "\n";    
       
   296 }
       
   297