commsfwtools/preparedefaultcommsdatabase/installdefaultcommdb/group/installdefaultcommdb.pl
changeset 0 dfb7c4ff071f
child 19 0b0e9fce0b58
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 #
       
    15 
       
    16 #!perl
       
    17 
       
    18 use strict;
       
    19 use File::Copy;
       
    20 use File::Path;
       
    21 use File::stat;
       
    22 use Getopt::Long;
       
    23 use Cwd;
       
    24 
       
    25 if ($^O =~ /MSWin32/)
       
    26 {
       
    27 	require Win32::Mutex;
       
    28 }
       
    29 
       
    30 $::emulatorCfg = 'emulator.cfg';
       
    31 $::targetCfg = 'target.cfg';
       
    32 
       
    33 GetOptions (
       
    34            'command=s' => \$::command,
       
    35            'platform=s' => \$::platform,
       
    36            'variant=s' => \$::variant,
       
    37            'targetcfg=s' => \$::targetCfg,
       
    38            'emulatorcfg=s' => \$::emulatorCfg,
       
    39            'platsec!' => \$::platsec
       
    40 		   );
       
    41 
       
    42 #
       
    43 # Constants.
       
    44 #
       
    45 
       
    46 my $epocRoot = GetEpocRoot();
       
    47 
       
    48 #
       
    49 # Main.
       
    50 #
       
    51 unless ($::command and $::platform and $::variant and (scalar(@ARGV) == 0)) 
       
    52 {
       
    53 	die "InstallDefaultCommdb Error: Invalid arguments\n";
       
    54 }
       
    55 
       
    56 my $platType;
       
    57 if ($::platform =~ /^(wins|wincw)/i) 
       
    58 {
       
    59 	$platType = 'emulator';
       
    60 }
       
    61 else 
       
    62 {
       
    63 	$platType = 'target';
       
    64 }
       
    65 
       
    66 
       
    67 my $cccccc00Root;
       
    68 my $cccccc00NameCre;
       
    69 
       
    70 $cccccc00Root = "/private/10202be9/";
       
    71 $cccccc00NameCre = "cccccc00.cre";
       
    72 
       
    73 my $data = 
       
    74 {
       
    75 	target => 
       
    76 	{
       
    77 		destinationCdb => $epocRoot . 'epoc32/data/z' . $cccccc00Root . $cccccc00NameCre,
       
    78 	},
       
    79 	emulator => 
       
    80 	{
       
    81 		destinationCdb => $epocRoot . "epoc32/release/$::platform/$::variant/z" . $cccccc00Root . $cccccc00NameCre,
       
    82 	}
       
    83 };
       
    84 
       
    85 my $CdbDest;
       
    86 my $cdbOut; 
       
    87 my $cdbOutPath;
       
    88 my $cdbDatFile = $ENV{DEFAULTCOMMSDATDATAFILE};
       
    89 
       
    90 $cdbOut = '/c/defaultcommdb/';
       
    91 
       
    92 $cdbOutPath = $epocRoot. 'epoc32/winscw' . $cdbOut;
       
    93 $cdbDatFile = $cdbOutPath . 'CommsDb.dat' if (! defined $cdbDatFile);
       
    94 
       
    95 $CdbDest = $data->{$platType}->{destinationCdb};
       
    96 
       
    97 
       
    98 if ($::command eq 'build') 
       
    99 {
       
   100 	PreBuild();
       
   101 }
       
   102 elsif ($::command eq 'clean')
       
   103 {
       
   104 	Clean();
       
   105 }
       
   106 elsif ($::command eq 'releasables') 
       
   107 {
       
   108 	Releasables();
       
   109 }
       
   110 
       
   111 #
       
   112 # Subs.
       
   113 #
       
   114 
       
   115 sub PreBuild
       
   116 {
       
   117 	if ($^O =~ /MSWin32/)
       
   118 	{
       
   119 		# We cannot have more than one instance of this script's activites running at the same time on Windows, so
       
   120 		# we safeguarded everything with a Windows mutex.  Mutex name needs to be unique for every build,
       
   121 		# so we add the current working directory and EPOCROOT to the mutex name
       
   122 		
       
   123 		my $drive = Win32::GetCwd();
       
   124 		$drive =~ s/^(\D:).*/$1/;
       
   125 		my $mutexname = $drive.lc($ENV{'EPOCROOT'});
       
   126 		$mutexname =~ s/[:\\\/]+/_/g;
       
   127 		
       
   128 		my $mutex = Win32::Mutex->new(1,"CEDMUTEX_".$mutexname);
       
   129 		die "Unable to create mutex, installdefaultcommdb.pl not run" if not $mutex;
       
   130 		if ($mutex->wait())
       
   131 		{
       
   132 			Build();
       
   133 			$mutex->release();
       
   134 		}
       
   135 		else
       
   136 		{
       
   137 			die "Unable to access mutex, installdefaultcommdb.pl not run";
       
   138 		}
       
   139 	}
       
   140 	else
       
   141 	{
       
   142 		Build();
       
   143 	}
       
   144 }
       
   145 
       
   146 sub Build
       
   147 {
       
   148 	unless (-e $cdbDatFile) 
       
   149 	{
       
   150 		die "InstallDefaultCommdb Error: $cdbDatFile cannot be found: $!\n";
       
   151 	}
       
   152 
       
   153 	if (FileIsYounger($cdbDatFile, $CdbDest) or not -e $CdbDest)
       
   154 	{
       
   155 		print ("Copy $cdbDatFile to $CdbDest\n");
       
   156 		CopyFile($cdbDatFile, $CdbDest);
       
   157 	}
       
   158 }
       
   159 
       
   160 
       
   161 sub Clean 
       
   162 {
       
   163 	print("Deleting $CdbDest..\n");
       
   164 
       
   165 	# Temporary workaround as default commsdat databases are not being created.
       
   166 	#DeleteFile($CdbDest);
       
   167 }
       
   168 
       
   169 sub Releasables 
       
   170 {
       
   171 	print("$CdbDest\n");
       
   172 }
       
   173 
       
   174 sub CopyFile 
       
   175 {
       
   176 	my $file1 = shift;
       
   177 	my $file2 = shift;
       
   178 	(my $path) = SplitFileName($file2);
       
   179 	
       
   180 	unless (-e $path) 
       
   181 	{
       
   182 		mkpath ($path) or die "InstallDefaultCommdb Error: Couldn't make path \"$path\": $!\n";
       
   183 	}
       
   184 	
       
   185 	if (-e $file2 and not -w $file2) 
       
   186 	{
       
   187 		system "attrib -r $file2";
       
   188 	}
       
   189 	copy ($file1, $file2) or die "InstallDefaultCommdb Error: Couldn't copy \"$file1\" to  \"$file2\": $!\n";
       
   190 }
       
   191 
       
   192 sub MoveFile 
       
   193 {
       
   194 	my $file1 = shift;
       
   195 	my $file2 = shift;
       
   196 	(my $path) = SplitFileName($file2);
       
   197 	
       
   198 	unless (-e $path) 
       
   199 	{
       
   200 		mkpath ($path) or die "InstallDefaultCommdb Error: Couldn't make path \"$path\": $!\n";
       
   201 	}
       
   202 	move ($file1, $file2) or die "InstallDefaultCommdb Error: Couldn't move \"$file1\" to  \"$file2\": $!\n";
       
   203 }
       
   204 
       
   205 sub DeleteFile 
       
   206 {
       
   207 	my $file = shift;
       
   208 	if (-e $file) 
       
   209 	{
       
   210 		unlink ($file) or die "InstallDefaultCommdb Error: Couldn't delete \"$file\": $!\n";
       
   211 	}
       
   212 }
       
   213 
       
   214 sub SplitFileName 
       
   215 {
       
   216 	my $fileName = shift;
       
   217 	my $path = '';
       
   218 	my $base = '';
       
   219 	my $ext = '';
       
   220 	
       
   221 	if ($fileName =~ /\/?([^\/]*?)(\.[^\/\.]*)?$/) 
       
   222 	{
       
   223 		$base = $1;
       
   224 	}
       
   225 	if ($fileName =~ /^(.*\/)/) 
       
   226 	{
       
   227 		$path = $1;
       
   228 	}
       
   229 	if ($fileName =~ /(\.[^\/\.]*)$/o) 
       
   230 	{
       
   231 		$ext =  $1;
       
   232 	}
       
   233 	
       
   234 	die unless ($fileName eq "$path$base$ext");
       
   235 	return ($path, $base, $ext);
       
   236 }
       
   237 
       
   238 sub CopyIfYounger 
       
   239 {
       
   240 	my $from = shift;
       
   241 	my $to = shift;
       
   242 	unless (-e $from) 
       
   243 	{
       
   244 		die "Error: \"$from\" not found\n";
       
   245 	}
       
   246 	
       
   247 	if (FileIsYounger($from, $to)) 
       
   248 	{
       
   249 		CopyFile($from, $to);
       
   250 	}
       
   251 }
       
   252 
       
   253 sub FileIsYounger 
       
   254 {
       
   255 	my $file1 = shift;
       
   256 	my $file2 = shift;
       
   257 	return (FileModifiedTime($file1) > FileModifiedTime($file2));
       
   258 }
       
   259 
       
   260 sub FileModifiedTime 
       
   261 {
       
   262 	my $file = shift;
       
   263 	if (-e $file) 
       
   264 	{
       
   265 		my $st = stat($file) or return 0;
       
   266 		return $st->mtime;
       
   267 	}
       
   268 	return 0;
       
   269 }
       
   270 
       
   271 sub RenameFile
       
   272 {
       
   273 	my $file1 = shift;
       
   274 	my $file2 = shift;
       
   275 	
       
   276 	rename ($file1, $file2) or die "InstallDefaultCommdb Error: Couldn't rename \"$file1\" to \"$file2\": $!\n";
       
   277 }
       
   278 
       
   279 sub GetEpocRoot
       
   280 {
       
   281 	my $path = $ENV{EPOCROOT};
       
   282 
       
   283 	# replace to forward slashes
       
   284 	$path =~ s/\\/\//g;
       
   285 
       
   286 	# append trailing slash if one isn't already present
       
   287 	if($path =~ m/.*\/$/)
       
   288 	{
       
   289 		return $path;
       
   290 	}
       
   291 	else
       
   292 	{
       
   293 		return $path."\/";
       
   294 	}
       
   295 }
       
   296